go-libp2p icon indicating copy to clipboard operation
go-libp2p copied to clipboard

The Autonat manager should test the public IP with the tcp/udp listen ports

Open hsanjuan opened this issue 5 years ago • 5 comments

Opening based on the memory of a convo with @Stebalien a couple of weeks ago.

Currently running a libp2p host on "/ip4/0.0.0.0/tcp/4001" inside a NAT with Autonat enabled does not automatically detect that the router port may have been manually open. The "/ip4/public_address/tcp/4001" addressed is becomes only part of the current host Addresses only after it has received several successful connections to it, however, since it is never among the official addresses provided on dhts or exchanged in Identify, that is unlikely to happen.

For the history of p2p (eMule, Bittorrent, some multiplayer games...), users have simply gone and opened the necessary ports on the routers, rather than relying on upnp etc.. However libp2p autonat components do not check at all if the peers are reachable on the public IP+default listen port, which is actually likely.

What is also very easy is to tell users with NAT problems that they should just open port 4001 in their routers and things will work. We cannot tell them this at the moment and that sucks for them and for us.

The current workaround is to manually set the announce addresses, but that prevents the parts of the address-autodiscovery that work (i.e. LAN interfaces etc).

hsanjuan avatar Feb 07 '20 12:02 hsanjuan

https://github.com/libp2p/go-libp2p-autonat-svc/issues/34 (but your issue is better)

Stebalien avatar Feb 07 '20 22:02 Stebalien

You cannot access the open port 4001 under non-public network nodes. TCP Hole Punching needs bind a nat mapping port to your local address. Example:

  YourPC(192.168.1.2:4001) -> Router(10.250.x.x:#a random mapping port#) -> ISP(forward to internet) -> Internet(183.193.57.91:#random#)

If other pc want to connect your pc. he can dial with the source port + ip with Internet(183.193.57.91:#random#) then the isp will forward the message to your Router(10.250.x.x:#a random mapping port#) if not mapping the isp will forward the message to your Router(10.250.x.x:4001)

So this should only be detected when the Router or YourPC is on the public network In addition, libp2p does not seem to assign the NAT port bind to the local port.

godcong avatar Aug 26 '20 07:08 godcong

ipfs id Addresses has no public IP and port. I use image: 'IPFs / go IPFs: v0.10.0'

Now, besides setting announcement, are there any other methods that can be added actively? I don't want to give up address autodiscovery

abing258 avatar Aug 16 '22 12:08 abing258

Reproducing ipfs/kubo#7621 here. I got the port forwarding set on the router, but libp2p made up its own. Not a big deal except for, well, the fact that it's random (so people can't remember my node or something) when I got a perfectly fixed one. upnpc -l gives the expected 60-second lease from libp2p.

Announce somehow figured out the manually set 4001 UDP, but not the 4001 and 4002 TCP. Bummer.

Oh and I don't have a static public ip nor do I have DDNS.

Artoria2e5 avatar Apr 09 '23 05:04 Artoria2e5

@Artoria2e5 This will be fixed soon (in a couple of months). The team is now working on a new address pipeline (https://github.com/libp2p/go-libp2p/issues/2229), which will include AutoNAT v2 (https://github.com/libp2p/specs/issues/503).

marten-seemann avatar Apr 09 '23 06:04 marten-seemann