I am learning libp2p examples and have been experimenting on my own.
I started a relay server in a Node.js environment, along with two regular nodes, configuring the address of the relay server as the bootstrap address.
The relay server can discover both nodes, but The CID obtained after Node 1 adds data cannot be used to retrieve data in Node 2. and Node 2 can’t find Node 1 based on its peer ID.
I’m not sure what to do next. Did I miss something?
Implementation of relay:
const relay = await createLibp2p({
privateKey: privateKeyFromRaw(privateKeyRaw),
addresses: {
listen: ['/ip4/127.0.0.1/tcp/54321/ws']
},
transports: [
webSockets({
filter: filters.all
})
],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
services: {
dht: kadDHT({
clientMode: false
}),
identify: identify(),
relay: circuitRelayServer({
reservations: {
maxReservations: Infinity
}
})
}
})
Node 1 and Node 2 Implementation:
const libp2p = await createLibp2p({
privateKey: privateKeyFromRaw(privateKeyRaw),
addresses: {
listen: [
'/p2p-circuit',
'/webrtc'
],
// announce: [
// '/ip4/127.0.0.1/tcp/54321/ws/p2p/12D3KooWGMYMmN1RGUYjWaSV6P3XtnBjwnosnJGNMnttfVCRnd6g/p2p-circuit/webrtc'
// ]
},
transports: [
webSockets({
filter: filters.all
}),
webRTC(),
circuitRelayTransport({
discoverRelays: 1
})
],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
connectionGater: {
denyDialMultiaddr: () => {
return false
}
},
services: {
dht: kadDHT(),
identify: identify(),
identifyPush: identifyPush({runOnSelfUpdate: true}),
ping: ping()
},
peerDiscovery: [
bootstrap({
list: [
// address of relay
'/ip4/127.0.0.1/tcp/54321/ws/p2p/12D3KooWGMYMmN1RGUYjWaSV6P3XtnBjwnosnJGNMnttfVCRnd6g'
]
})
]
})