Closed
Description
Version: libp2p 0.23.1
libp2p-websocket-star 0.8.1
Node js 10.0
Platform: 64-bit (Windows 10).
Type: Bug (Maybe)
Severity: High
Description: I'm trying to create a libp2p pubsub room. I have two instances (in same machine) joined the same room but can't find each other. I've set a time interval to check the number of peers in the room but it's 0 always.
Here's the code:
const defaultsDeep = require('@nodeutils/defaults-deep')
const libp2p = require('libp2p')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const WSStar = require('libp2p-websocket-star')
PeerId.create((err, id) => {
if(err){ throw err }
const peerInfo = new PeerInfo(id)
peerInfo.multiaddrs.add('/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star/ipfs/' + peerInfo.id._idB58String)
const wsS = new WSStar({ id: id })
const defaults = {
modules: {
transport: [
wsS
],
peerDiscovery: [
wsS.discovery
]
},
config: {
EXPERIMENTAL:{
pubsub:true
}
}
}
const node = new libp2p(defaultsDeep({peerInfo:peerInfo}, defaults))
node.start((err) => {
if (err) { throw err }
const topic = 'abcd'
const receiveMsg = (msg) => console.log(msg.data.toString())
node.pubsub.subscribe(topic, receiveMsg, (err) => {
if (err) {
return console.error(`failed to subscribe to ${topic}`, err)
}
console.log(`subscribed to ${topic}`)
})
setInterval(() => {
node.pubsub.peers(topic, (err, peerIds) => {
if (err) { throw err }
console.log(peerIds)
})
}, 3000)
})
})
Metadata
Metadata
Assignees
Labels
No labels