Hello, in the chat-with-mdns example, if my two hosts (p1, p2) are in different LANs, can p1 and p2 discover each other using mdns through the relay server (r1) which has a public ip?
No. mDNS is an IP-level service discovery mechanism and doesn’t operate over libp2p transports.
So if I use libp2p’s hole punching capability, in order to allow two LAN nodes to communicate, I must synchronize the peerID information of each node by myself.
Maybe we can use autonat?? Does the autonat can implement the service discovery cross lan, so the two hosts(p1, p2) can know each other’s peerID and node information?
Why do you want these nodes to auto-connect?
- Bitswap will find providers of content using the DHT, connecting to nodes as necessary.
- Pubsub will find other peers interested in the same topic (again, using the DHT).
In other words, service discovery is a second layer issue. If you want all nodes in your libp2p network to automatically connect, you can implement a simple peer exchange protocol to facilitate this.
Thanks the reply.
My scenario is that I have some nodes, these nodes are behind NAT. I want to use libp2p’s hole punching and relay capabilities to build our underlying communication network and do traffic forwarding for these machines. Such as tcp traffic, http traffic.
So I need each node to know the connection information of other nodes, especially the peerID, so that when P1 node need to do traffic forwarding to P2 node, P1 node can connect and forward the traffic to P2 nodes.
“implement a simple peer exchange protocol to facilitate this” means that I can store all the peer information in a database, such as redis or mysql, and a new peer try to fetch all the peer infromations and save it’s peer information to the database?