Automatic usage of relays for nodes under NAT (mobile network)


I have a network of nodes where each node is bootstrapped with some predefined nodes which can also act as relays. I set Autorelay as true and also use StaticRelays (so I would basically announce only them when a device is in a network under NAT).

I check that my addresses are properly announced and that we establish the connection to relay. Also I can ping the other NAT’d node via relay. But the finding of the peer through DHT doesn’t work.

Here and in some other places I saw indication that the node will not add NAT’d nodes’ addresses to DHT (Don’t join DHT when behind a NAT · Issue #778 · libp2p/go-libp2p · GitHub), is that correct? When I tried to do Ipfs findpeer ... that didn’t work, but when I did ipfs query ... it gave me the list of closest peers. So in theory I could’ve just tried to check if one of these closest peers is a relay and then try to establish a connection through such a relay peer, but I am not sure if something like this is already implemented.

Are there any other mechanism which can help me find the addresses of the peers which are already connected to relay (i.e. me and the node I am trying to connect to both connected to relay)?

You hay have been bitten by findpeer should work even on peers that are not part of DHT queries by aschmahmann · Pull Request #711 · libp2p/go-libp2p-kad-dht · GitHub? Try updating to the latest DHT version.

Note: You’ll need some publicly dialable nodes in your DHT for this to work.