Convert mDNS to DHT

Hi everyone, I’m doing a simulation of a super simple bitcoin-like protocol on a GossipSub network (and it also uses direct messaging with a stream handler for some messages).
I made everything following this example (go-libp2p-examples/pubsub/chat at master · libp2p/go-libp2p-examples · GitHub) with mDNS for peer routing and discovery, but now I need to use DHT discovery to use the protocol outside LAN.
This is my code (GitHub - 0xfederama/bitcoin-simulation-libp2p: Simple Bitcoin protocol simulation using Go and Libp2p). How can I modify my routing system to use DHT instead of mDNS?

You’d need to set the DHT when creating the libp2p node, and make sure you connect to some bootstrappers on boot.

An example:

1 Like

@hector I modified it (GitHub - 0xfederama/bitcoin-simulation-libp2p at mdns-to-dht), but it doesn’t work properly. I tried running the cose with two peers. At line 78 I print every new peer that I find, and I can see that it prints the other peer’s ID. But then it seems like every peer connects to a different GossipSub network, because at line 119 it prints 0 peers and one peer cannot receive the other peer’s message.

Could you please help me to resolve this? I can’t find a fix

I had a quick look on master and I am not sure why peers would not receive the messages. Things seem ok.

Now I fixed it, it works. Thanks for your help <3