Hi,
node 1 has to be configured as a relayer. You can use a configuration like this:
var id = await createRSAPeerId()
const node = await createLibp2p({
peerId: id,
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/34100/ws',
],
},
dht: new KadDHT(),
transports: [new WebSockets()],
connectionEncryption: [new Noise()],
streamMuxers: [new Mplex()],
pubsub: new GossipSub(),
relay: {
enabled: true,
hop: {
enabled: true
},
advertise: {
enabled: true,
}
}
})
You need to note the Public IP of the relayer and the peerId.
For the normal nodes you can use a configuration like this:
peerId = createRSAPeerId();
const node = await createLibp2p( {
peerId: id,
transports: [
new WebSockets(),
],
connectionEncryption: [new Noise()],
streamMuxers: [
new Mplex()
],
peerDiscovery: [
new Bootstrap({
list: ["/ip4/X.X.X.X/tcp/34100/ws/p2p/Qma5QbMXc4DsZCa55vGhQAhK1ZLxy4ZBFTQALRyNCjYVYg"],
})
],
dht: new KadDHT(),
pubsub: new GossipSub(),
addresses: {
listen: [
"/ip4/0.0.0.0/tcp/0/ws",
],
},
connectionManager: {
autoDial: true
},
relay: {
enabled: true,
autoRelay: {
enabled: true,
maxListeners: 10
}
},
})
Replace X.X.X.X with the Public IP of the relayer and Qma5QbMXc4DsZCa55vGhQAhK1ZLxy4ZBFTQALRyNCjYVYg with the peerId of your relayer.
With this the NAT-Nodes should automatically connect to the relayer, and discover each other. through KadDHT.
Be aware, the connections between the NAT-Nodes are not direct as in your diagram. All traffic goes through the public node.
Also checkout the auto-relay example.
Regards Sneaker