Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libp2p pubsub room failing to find peers #239

Closed
ajayrao80 opened this issue Aug 18, 2018 · 3 comments
Closed

libp2p pubsub room failing to find peers #239

ajayrao80 opened this issue Aug 18, 2018 · 3 comments

Comments

@ajayrao80
Copy link

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)

  })
})
@ajayrao80 ajayrao80 changed the title libp2p pubsub room is not finding peers libp2p pubsub room failing to find peers Aug 18, 2018
@ajayrao80
Copy link
Author

I have an update on this. When one of the instances is ipfs, it works fine. But when both instances are libp2p instances, it doesn't work. Anybody has any idea why?

@jacobheun
Copy link
Contributor

Libp2p doesn't currently automatically handle dialing to peers that are discovered. This works with an ipfs node because ipfs is listening to the 'peer:discovery' event on the node and triggering dials to each peer it finds. While your nodes might be setup to the same room, they're not connected yet, so pubsub won't work.

The current pubsub example uses MulticastDNS for discovery but the idea is the same, https://github.com/libp2p/js-libp2p/blob/master/examples/pubsub/1.js#L65, you'll just need to change once to on as other peers will be connected to the discovery node.

@ajayrao80
Copy link
Author

That worked. Thank you so much.

maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
Increases default inactivity timeout to 5 minutes.

closes libp2p#239
maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
## [6.0.9](libp2p/js-libp2p-tcp@v6.0.8...v6.0.9) (2023-01-17)

### Bug Fixes

* increase default socket close timeout ([libp2p#242](libp2p/js-libp2p-tcp#242)) ([a64ba41](libp2p/js-libp2p-tcp@a64ba41)), closes [libp2p#239](libp2p/js-libp2p-tcp#239)

### Trivial Changes

* replace err-code with CodeError ([libp2p#240](libp2p/js-libp2p-tcp#240)) ([5c44562](libp2p/js-libp2p-tcp@5c44562)), closes [js-libp2p#1269](libp2p#1269)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants