libp2p-gossip-discovery
v0.1.1
Published
implements peer discovery using a gossip protocol
Downloads
4
Readme
Synopsis
This implements peer discovery using gossip. A peer first connects to peers
known to it vai its peer book and asks for more peers. This processes continues
untill targetNumberOfPeers
is reached.
Install
npm install libp2p-gossip-discovery
Usage
const GossipDiscovery = require('gossip-discovery')
const libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const multiplex = require('libp2p-multiplex')
class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}
const discovery = new GossipDiscovery(this, 10)
const modules = {
transport: [
new TCP()
],
connection: {
muxer: [
multiplex
]
}, discovery: [discovery]
}
super(modules, peerInfo, peerBook, options)
discovery.attach(this)
}
}
////
const node = new Node(peerInfo)
node.start(() => {
console.log('started!')
})
API
Table of Contents
constructor
Parameters
targetNumberOfPeers
Number the max number of peers to add to the peer book
attach
Attach an instance of libp2p to the discovery instance
Parameters
node
Object the libp2p instance
start
starts the gossip process, this is called by libp2p but if you are using this standalone then this needs to be called
Parameters
cb
Function a callback
stop
stop discovery, this is called by libp2p but if you are using this standalone then this needs to be called
License
All code and designs are open sourced under GPL V3.