go-libp2p, is it possible to get a boolean value indicating whether my host is behind a NAT? This would allow applications using libp2p to have different behavior when they are behind NAT – for example, not joining the DHT. I know IPFS is interested in this.
It looks to me like my code could call
a := autonat.NewAutoNAT()
and then test this condition
a.Status() == autonat.NATStatusPublic
Am I on the right track?
Yes, you can do this through an AutoNAT instance. You have to be aware of
NATStatusUnknown, which may be returned if we haven’t discovered any autonat peers or the service hasn’t been able to assert NAT status yet.
Note that there is currently one burried in the autorelay code; we plan to make it part of the
Omnihost with the host refactor and expose it to the user so that we can easily assert NAT status.
Seeing Omnihost in monospace scared me a bit. I hope that doesn’t take off as a type name