Code Monkey home page Code Monkey logo

js-libp2p-gossipsub's Introduction

js-libp2p-gossipsub

Travis CI ES Version Node Version

Table of Contents

Specs

Gossipsub is an implementation of pubsub based on meshsub and floodsub. You can read the specification here.

libp2p-gossipsub currently implements the v1.1 of the spec.

Install

npm install @chainsafe/libp2p-gossipsub

Usage

import { gossipsub } from '@chainsafe/libp2p-gossipsub'


const libp2p = await createLibp2p({
  // ...
  services: {
    pubsub: gossipsub(options)
  }
});

libp2p.services.pubsub.addEventListener('message', (message) => {
  console.log(`${message.detail.topic}:`, new TextDecoder().decode(message.detail.data))
})

libp2p.services.pubsub.subscribe('fruit')

libp2p.services.pubsub.publish('fruit', new TextEncoder().encode('banana'))

API

Create a gossipsub implementation

const options = {}
const gossipsub = gossipsub(options)(libp2p)

Options is an optional object with the following key-value pairs:

  • emitSelf: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to false).
  • gossipIncoming: boolean identifying if incoming messages on a subscribed topic should be automatically gossiped (defaults to true).
  • fallbackToFloodsub: boolean identifying whether the node should fallback to the floodsub protocol, if another connecting peer does not support gossipsub (defaults to true).
  • floodPublish: boolean identifying if self-published messages should be sent to all peers, (defaults to true).
  • doPX: boolean identifying whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted nodes (defaults to false).
  • msgIdFn: a function with signature (message) => string defining the message id given a message, used internally to deduplicate gossip (defaults to (message) => message.from + message.seqno.toString('hex'))
  • signMessages: boolean identifying if we want to sign outgoing messages or not (default: true)
  • strictSigning: boolean identifying if message signing is required for incoming messages or not (default: true)
  • messageCache: optional, a customized MessageCache instance, see the implementation for the interface.
  • scoreParams: optional, a customized peer score parameters Object.
  • scoreThresholds: optional, a customized peer score thresholds Object.
  • directPeers: optional, an array of AddrInfo of peers with which we will maintain direct connections.

For the remaining API, see @libp2p/interface-pubsub.

Contribute

This module is actively under development. Please check out the issues and submit PRs!

License

MIT © ChainSafe Systems

js-libp2p-gossipsub's People

Contributors

wemeetagain avatar vasco-santos avatar twoeths avatar mikerah avatar achingbrain avatar github-actions[bot] avatar dapplion avatar mpetrunic avatar gregthegreek avatar alanshaw avatar jacobheun avatar philknows avatar chainsafesystems avatar d4nte avatar dependabot[bot] avatar maschad avatar alexmesser avatar atheartengineer avatar hugomrdias avatar jhonnyjason avatar nflaig avatar saul-jb avatar stbrody avatar zaach avatar fryorcraken avatar g11tech avatar eng-cc avatar tabcat avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.