[AutoNAT] Clarification regarding NAT traversal

Questions may be trivial but,
I was going throught the auto nat implementation, and I have some queries,

  1. Does autoNAT check whether the NAT is punchable? If yes -> say the downstream or dial back is successful it returns me the remote multi addr of the TCP socket. Shouldnt the connection to the autoNAT node persist in order for the host.AutoNat.PublicAddr() to be valid?

  2. In cases when NAT punching is not possible, we tend to use relays. so, after connecting to a relay, should the address be updated to all and in dht via the IdentifyPush protocol?

  3. Auto Relay documentation link?

@gilfoyle

Great questions !

We are in process of releasing some documentation regarding how libp2p address discovery and advertisement works. But, in the meanwhile, here are the answers:

  1. AutoNAT does NOT check if a peer is punchable. This is because after a peer dials an AutoNAT server and sends a “dial me” request, the AutoNAT server uses a different host/dialer and hence a different socket for the dial back. This means that it will get a new NAT port mapping and thus the originating peer’s NAT will NOT consider this to be a hole punch. AutoNAT simply checks if any of the peer’s advertised addresses are dialable. They coulda g be dialable because of UPnP, because the peer has great NAT that allows all incoming connections on a port after it’s been used for an outgoing connection irrespective of the destination and a multitude of other reasons.

  2. We have a component called AutoRelay that gets peer to advertises their “relay addresses” after they connect to Relay servers. The address updates are pushed via the Identify protocol. The code is here:
    go-libp2p/autorelay.go at 890f2e86b21412fabf98fa121cf9c0b5529dfe18 · libp2p/go-libp2p · GitHub
    But, if you do NOT enable AutoRelay and connect to a Relay server directly, this adverisement of the Relay address will not happen.

  3. This will be part of the documentation :slight_smile: I’ll post the link here once we have it up in a few days.

Thanks for your quick reply @aarshkshah1992
looking forward to the doc.

I have an even more trivial question about AutoNAT. The default config section for AutoNAT is

"AutoNAT": { }

How do you enable it? Is it

"AutoNAT": { 
        "Enabled": true
}

I’m just kind of guessing that it might be similar to enabling MDNS

@zacharywhitley , I used Go based impl where we have to specify options when creating the Host instance. It is as simple as enabling auto nat to true / depends on the language.

The works: It has to be connected to some other peer for autonat to start working. It will recieve a callback from host network from where it will request dialback to that particular node. The connections anf dialing logic is handled by the swarm module.

So long story short, enable autonat connect to some other peer node and observe for LocalReachabilityChanged event. That might help you to understand the working

Thanks for the pointers but I’m looking for how to enable it in the go-ipfs config. It isn’t obvious how that is done.