1.0.0 • Published 5 years ago

libp2p-signalhub v1.0.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
5 years ago

libp2p-signalhub

npm.io

peer discovery for libp2p using signalhubs

Install - Usage - License: Apache-2.0

npm travis standard

Install

npm install libp2p-signalhub

Usage

var Signalhub = require('libp2p-signalhub')

new Libp2p({
  modules: {
    peerDiscovery: [Signalhub]
  },
  config: {
    peerDiscovery: {
      signalhub: {
        appName: 'your-app-name',
        hubs: ['https://signalhub.myapp.org']
      }
    }
  }
})

API

node = new Signalhub(opts)

Create a new peer discover node.

  • opts.appName - required, name of your application, so different apps on one signalhub don't interfere
  • opts.channel - channel name for broadcasts, default 'libp2p-discover'
  • opts.peerInfo - PeerInfo instance, normally passed in by libp2p itself
  • opts.broadcast - whether to broadcast the local multiaddresses to the signalhub, allowing other nodes to find you, default false
  • opts.interval - broadcast interval in ms, default 10 seconds
  • opts.hubs - array of signalhub HTTP URLs to subscribe/broadcast to

node.start(cb)

Start listening for other peers (and broadcasting if opts.broadcast).

cb is called with an error if the subscription could not be started.

node.stop(cb)

Stop listening and broadcasting.

node.on('peer', function(peerInfo))

Event emitted when a new peer is discovered. peerInfo is a PeerInfo instance.

License

Apache-2.0