Hello,
From the gossip example, I am learning libp2p by building a local network of peers exchanging messages. For now, peers are well discovered, and each one subscribes to the same topic. Each peer can publish a short message, but the gossip handler does not receive anything. I don’t see if I’ve misunderstood or forgotten anything (all libs are latest current version).
this is how each node joins the p2p network
const libp2p = await Libp2p.create({
peerId: state.peerid,
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0'],
},
modules: {
transport: [TCP],
streamMuxer: [Mplex],
connEncryption: [NOISE, SECIO],
peerDiscovery: [MulticastDNS],
pubsub: Gossipsub,
},
config: {
peerDiscovery: {
autoDial: true,
mdns: {
interval: 20e3,
enabled: true,
},
},
pubsub: {
enabled: true,
emitSelf: false,
},
},
});
libp2p.connectionManager.on('peer:connect', (connection) => {
// cf https://github.com/libp2p/js-libp2p/blob/master/examples/pubsub/1.js
libp2p.peerStore.addressBook.set(connection.remotePeer, connection.remoteAddr);
});
await libp2p.start();
await libp2p.pubsub.subscribe("messages", (msg) => {
debug(`pubsub messages received: ${msg.data.toString()}`)
});
This code works on several computers on my local network, and I can see other peers are well connected. Fine.
But now, when I do :
libp2p.pubsub.publish("messages", Buffer.from("test"));
the pubsub.subscribe
handler is never called.
By looking further in the pubsub code, it looks like it comes from the fact that peersInTopic
is void on line 507 in js-libp2p-gossipsub… but I can not manage to find out why, as peers are connected and should have subscribed to the same topic.
thanks for any clue.