maidsafe / safe_network

72 stars 41 forks source link

bug: UPnP error when trying to map a port #1987

Open mickvandijke opened 1 month ago

mickvandijke commented 1 month ago

I noticed that nodes weren't opening any ports on my router through UPnP. I checked with miniupnpc and in my router logs. UPnP is definitely supported and enabled on my ASUS consumer router (tested it with other apps and miniupnpc).

So I checked the node logs to see what is going on:

SN_LOG=all,libp2p=trace cargo run --bin safenode --features "upnp" -- --upnp --peer /ip4/139.59.168.228/udp/56309/quic-v1/p2p/12D3KooWFTMtaqu24ddDSXk9v5YxnuhJmTLFRunER1CG4wZ2XLUU
2024-07-19T12:08:46.155489Z DEBUG libp2p_upnp::behaviour/Swarm::poll] network gateway not found, UPnP port mapping of multiaddres discarded multiaddres=/ip4/192.168.0.207/udp/56711/quic-v1

It looks like the issue stemmed from libp2p. To test it, I ran the libp2p upnp example and got this error:

Gateway does not support UPnP

Again, I saw that no ports were opened.

@b-zee then asked me to test the igd_next example, which did work:

It worked! Got port 59710
...
3 UDP 59710->192.168.0.207:8080  'add_port example' '' 52
...

I'm afraid that lots of other users are running into the same issue without them knowing. Perhaps this is the reason that some users report not receiving any node rewards?

mickvandijke commented 1 month ago

cc @b-zee @joshuef @grumbach

b-zee commented 1 month ago

I have searched the forums and Discord but can not find people experiencing the same problem. If this is a bug, it's likely a bug that needs fixed in libp2p.

Depending on how many bump into this problem, it can cause problems. However, home nodes should function properly even without port forwarding by using relays.

mickvandijke commented 1 month ago

Opened an issue on the libp2p repo for this: https://github.com/libp2p/rust-libp2p/issues/5506

mickvandijke commented 1 month ago

I have opened a PR to fix this in igd-next (which libp2p uses): https://github.com/dariusc93/rust-igd/pull/8

The issue was that I have multiple UPnP enabled devices on my network (like a Philips HUE bridge). When searching for a router/gateway to open the UPnP ports on, igd-next incorrectly assumed that the first UPnP enabled device would be the router (but for me, it happened to be my HUE bridge). Instead of trying other UPnP enabled devices to look for the router, the search would just fail if the first device is not the router/gateway.