Closed uriva closed 1 month ago
I'm also seeing this. A complete working end-to-end example with libp2p would be great
It seems that the browser nodes are not being subscribed to the topic, those bootstrap nodes are not subscribed to the fruit
topic and so you would need to be running other - in this case browser - nodes which are subscribed to the fruit
topic which would be discoverable by Kademlia (you could utilize the protocol prefix to ensure only your nodes are discovered).
You could take a look at the universal connectivity example example for more detailed usage of gossipsub for browser nodes.
I met the same problem. After debugging, I realized that the subscribe operation of node1 does not use rpc to add a topic in node2. This is because there is no link established between node1 and node2. So just add another node's information (directPeers) in the gossipsub's constructor parameter.
const createNode1 = async () => {
const node = await createLibp2p({
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0']
},
transports: [tcp()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()],
services: {
// we add the Pubsub module we want
pubsub: gossipsub({
allowPublishToZeroPeers: true,
awaitRpcMessageHandler: true,
})
}
})
return node
}
const node1 = await createNode1()
const createNode2 = async () => {
const node = await createLibp2p({
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0']
},
transports: [tcp()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()],
services: {
// we add the Pubsub module we want
pubsub: gossipsub({
allowPublishToZeroPeers: true,
directPeers: [{id: node1.peerId, addrs: node1.getMultiaddrs()}]
})
}
})
return node
}
const node2 = await createNode2()
Example can be found here: https://github.com/libp2p/js-libp2p-examples/tree/main/examples/js-libp2p-example-pubsub