Skip to content

dfinity-side-projects/js-libp2p-gossip-discovery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synopsis

NPM Package Build Status Coverage Status

js-standard-style

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

index.js:19-23

Parameters

  • targetNumberOfPeers Number the max number of peers to add to the peer book

attach

index.js:29-31

Attach an instance of libp2p to the discovery instance

Parameters

  • node Object the libp2p instance

start

index.js:38-57

starts the gossip process, this is called by libp2p but if you are using this standalone then this needs to be called

Parameters

stop

index.js:63-66

stop discovery, this is called by libp2p but if you are using this standalone then this needs to be called

License

(C) 2017 DFINITY STIFTUNG

All code and designs are open sourced under GPL V3.

image

About

implements peer discovery using a gossip protocol

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •