DHT peer discovery and routing not working with a private network

Hello everyone,

I’m trying to create a private network that uses the KadDHT so that the private nodes can discover each other. My code is in the Gist below, I’ve run it with js-ipfs@0.45.0.

In this code I’m testing with two nodes (apart from the bootstrap node). In
line 93 I first explicitely connect the two nodes together and then I look up the DHT for the same node to find the other node to which it just connected. While the connection is successful, dht.findpeer fails with Error: Peer lookup failed.

The bootstrap server runs using the go-ipfs cli and nodes are successfully connecting to it, when I run ipfs swarm peers I can see the nodejs peers in the output. Also, when I run additional nodes from the command line in the same private network, these nodes can successfully find the nodejs nodes connected to the bootstrap node. So the problem appears to be with the js-ipfs nodes only.

I tried to explore the problem more so I checked if js-ipfs nodes can use the DHT successfully when they’re connected in the public network, and sure enough they can discover and connect automatically to other nodes. So it seems that the DHT functionality isn’t working only for private networks.

Has anyone created private networks that utilize the DHT successfully?

I’ve been trying to configure a pnet for development and run into a similar issue, I suspect I have something configured incorrectly as I think I have all the relays setup yet the js-ipfs nodes will not automatically use the bootstrap node as a relay.

To work around it for now I manually instruct the js-ipfs nodes to connect via a bootstrap node, so instead of:

ipfs.swarm.connect("/ipfs/Qmtarget")

do

ipfs.swarm.connect("/ipfs/QmRelay/p2p-circuit/ipfs/QmTarget")

This seems to work reliably for me but it is frustrating they don’t use relays automatically, hopefully someone has a better answer!

Thanks @mike7c2

I wonder if it’s a relay issue in my case since the two nodes can connect directly with each other, when the connection is created explicitely.