Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@chainsafe/libp2p-gossipsub

ChainSafe65.9kApache-2.014.1.1TypeScript support: included

A typescript implementation of gossipsub

libp2p, pubsub, gossip

readme

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

changelog

1.0.0 (2022-05-10)

⚠ BREAKING CHANGES

Bug Fixes

Miscellaneous

14.1.1 (2025-03-28)

Bug Fixes

14.1.0 (2024-09-13)

Features

14.0.0 (2024-09-11)

⚠ BREAKING CHANGES

Features

13.2.0 (2024-08-19)

Features

  • add gossipFactor parameter to GossipsubOpts (#502) (07b995c)

Miscellaneous

13.1.1 (2024-08-09)

Bug Fixes

Miscellaneous

  • deps-dev: bump undici from 5.28.2 to 5.28.4 (#495) (7aa91c2)

13.1.0 (2024-06-20)

Features

  • add service capabilities and dependencies definition (#497) (9ffc2a2)
  • publish at least mesh_n peers (#493) (bc3906f)

13.0.0 (2024-02-27)

⚠ BREAKING CHANGES

  • The allowPublishToZeroPeers option has been renamed to allowPublishToZeroTopicPeers

Features

  • graft/prune events and mesh peer tagging (#383) (42b5b92)

Bug Fixes

  • make PublishError.InsufficientPeers more self-explanatory (#487) (1958aab), closes #472

12.0.0 (2024-02-10)

⚠ BREAKING CHANGES

  • switch back to protons (#468)

Features

11.2.1 (2024-02-05)

Bug Fixes

11.2.0 (2024-01-30)

Features

  • add runOnTransientConnection option to pass to registrar (#485) (986ff6c)

Bug Fixes

  • write peer stream messages atomically (#484) (cc4ff3b)

11.1.0 (2024-01-08)

Features

11.0.1 (2023-12-05)

Bug Fixes

  • make peer score use component logger (#476) (dba38d1)

11.0.0 (2023-12-03)

⚠ BREAKING CHANGES

  • requires libp2p v1

Bug Fixes

10.1.1 (2023-11-21)

Bug Fixes

Miscellaneous

10.1.0 (2023-08-22)

Features

Bug Fixes

10.0.0 (2023-08-03)

⚠ BREAKING CHANGES

  • stream close methods are now asyc, requires libp2p@0.46.x or later

Features

Bug Fixes

9.1.0 (2023-06-29)

Features

Bug Fixes

Miscellaneous

  • track backoff time for connected peers (#445) (8646b4d)

9.0.0 (2023-06-20)

⚠ BREAKING CHANGES

  • reportMessageValidationResult to accept peer id string (#432)

Features

  • track async validation delay from first seen (#435) (e2505d6)

Bug Fixes

  • reportMessageValidationResult to accept peer id string (a963680)
  • reportMessageValidationResult to accept peer id string (#432) (a963680)

8.0.1 (2023-06-15)

Bug Fixes

8.0.0 (2023-05-16)

⚠ BREAKING CHANGES

Bug Fixes

Miscellaneous

7.0.0 (2023-04-20)

⚠ BREAKING CHANGES

  • the type of the source/sink properties have changed

Bug Fixes

6.3.0 (2023-04-13)

Features

Bug Fixes

Miscellaneous

  • deps: bump @libp2p/interface-connection to 4.0.0 (#421) (50a99c7)
  • deps: bump xml2js, @azure/ms-rest-js, @azure/storage-blob and aws-sdk (#420) (2a2e9fa)
  • remove lead maintainer (#422) (38d5d65)

6.2.0 (2023-02-21)

Features

  • allow ignoring PublishError.Duplicate (#404) (dcde3c9)

Miscellaneous

  • deps: bump http-cache-semantics from 4.1.0 to 4.1.1 (#400) (bae1492)

6.1.0 (2023-01-19)

Features

  • added allowPublishToZeroPeers as optional param to publish function (#395) (e7c88ac)

Bug Fixes

Miscellaneous

6.0.0 (2023-01-09)

⚠ BREAKING CHANGES

  • update multiformats and related dependencies (#393)

Bug Fixes

  • fix browser tests (dcece33)
  • update multiformats and related dependencies (#393) (2090501)

Miscellaneous

  • update readme code example to new API. (#382) (b24d1ff)

5.4.1 (2022-12-23)

Bug Fixes

5.4.0 (2022-12-22)

Features

Bug Fixes

  • tracer to track delivered message if duplicate (#385) (0c8ddee)

5.3.0 (2022-12-01)

Features

  • add src folder to package to enable access to source map (#337) (7a20b0c)

Bug Fixes

5.2.1 (2022-11-15)

Bug Fixes

5.2.0 (2022-11-13)

Features

  • remove unnecessary conversion from Multiaddr to IP (#369) (e37c7c2)

5.1.1 (2022-11-03)

Bug Fixes

5.1.0 (2022-10-28)

Features

  • Add stream option to limit inbound message size (#349) (3475242)

Bug Fixes

5.0.0 (2022-10-22)

Bug Fixes

  • TimeCache handle key collision to prevent leak (#358) (8f0ba37)

Miscellaneous

4.2.0 (2022-10-18)

Features

Bug Fixes

Miscellaneous

4.1.1 (2022-08-24)

Bug Fixes

4.1.0 (2022-08-24)

Features

  • add option to limit OutboundStream buffer size (#325) (ce9b671)

Bug Fixes

  • skip heartbeat only if it's close to the next heartbeat (#332) (0c6c42b)

4.0.0 (2022-08-11)

⚠ BREAKING CHANGES

3.5.1 (2022-08-11)

Bug Fixes

  • freeze libp2p dependencies to get through build errors (#316) (5e6ce1f)
  • handle closing outbound stream (#314) (74c08b1)

Miscellaneous

3.5.0 (2022-08-02)

Features

3.4.0 (2022-07-22)

Features

3.3.0 (2022-07-20)

Features

  • remove unnecessary direct dependency (#303) (77baa6e)

3.2.0 (2022-07-19)

Features

3.1.0 (2022-07-11)

Features

3.0.2 (2022-06-30)

Bug Fixes

3.0.1 (2022-06-29)

Bug Fixes

3.0.0 (2022-06-29)

⚠ BREAKING CHANGES

  • connection interface updated

Miscellaneous

2.0.0 (2022-06-15)

⚠ BREAKING CHANGES

  • uses new single-issue libp2p interface modules

Features

1.2.0 (2022-06-15)

Features

Bug Fixes

Miscellaneous

1.1.2 (2022-06-03)

Bug Fixes

1.1.1 (2022-06-03)

Bug Fixes

1.1.0 (2022-06-03)

Features

Bug Fixes

Miscellaneous

1.0.1 (2022-05-23)

Miscellaneous

0.14.0 (2022-04-05)

  • New gossipsub implementation: better performance, async validation flow, improved peer scores significantly, add a lot of metrics

0.13.2 (2022-03-25)

  • Do not apply P3 penalty if peers are pruned from topic mesh
  • Fix flood publish behavior
  • Increase the default for seenTTL to match that of go-libp2p
  • _publish: Only compute score if peer stream has FloodsubID protocol
  • Migrate tests to Typescript
  • Prettier
  • Apply strict-boolean-expression eslint rule

0.13.1 (2022-02-14)

  • Fix async getFastMsgIdStr function

0.13.0 (2022-01-20)

0.12.2 (2022-01-20)

Features

BREAKING CHANGES

  • peerstore methods and pubsub start/stop are now all async

Features

  • Add optional fast message id cache via the fastMsgIdFn option
    • In certain applications, computing the message id (getMsgId) is relatively expensive. This addition allows for an application to optionally define a "fast" message id function that will be used internally.
  • Add optional cached message id function via getCachedMsgIdStr method override
    • Applications can maintain their own cache of message ids

0.12.1 (2021-12-03)

0.12.0 (2021-12-02)

chore

BREAKING CHANGES

  • requires node 15+

0.11.4 (2021-09-20)

Bug Fixes

Features

0.11.3 (2021-09-03)

0.11.2 (2021-09-02)

0.11.1 (2021-08-24)

0.11.0 (2021-07-09)

chore

BREAKING CHANGES

  • the new peer-id module uses the new CID class and not the old one

0.10.0 (2021-05-28)

0.9.2 (2021-05-28)

Reverts

  • Revert "chore: update pubsub interface to run subsystem tests (#148)" (87607fb), closes #148

0.9.1 (2021-05-28)

0.9.0 (2021-04-28)

0.8.0 (2020-12-19)

0.7.0 (2020-11-13)

0.6.6 (2020-11-13)

0.6.5 (2020-11-12)

0.6.4 (2020-10-22)

0.6.3 (2020-10-05)

0.6.2 (2020-09-22)

0.6.1 (2020-09-03)

0.6.0 (2020-08-25)

Bug Fixes

Features

  • add _acceptFrom filter (1ff5816)
  • add adaptive gossip (0c56763)
  • add direct peer connections (7103b83)
  • add extended topic validators (a1208b6)
  • add flood publishing (5854d26)
  • add invalid message spam protection (27fe567)
  • add iwant request tracking (b3942e4)
  • add opportunistic grafting (cbee3a2)
  • add outbound mesh quota (47bc4a7)
  • add peer exchange (a0a691b)
  • add prune backoff (4eb492c)
  • libp2p as gossipsub parameter (02dff12)
  • track ihave/iwant counts (8e04a11)

BREAKING CHANGES

  • Gossipsub default export parameter changed, now accepts (libp2p, options)

0.5.0 (2020-08-12)

Bug Fixes

  • replace node buffers with uint8arrays (#118) (2f50108)

BREAKING CHANGES

    • The .data and .seq properties of messages used to be node Buffers, now they are Uint8Arrays
  • All deps of this module now use Uint8Arrays instead of Buffers

  • chore: remove gh url from dep version

0.4.6 (2020-07-07)

Bug Fixes

  • connected with a subscriber before a mesh is created should send messages (060346a)

0.4.5 (2020-06-04)

Bug Fixes

0.4.4 (2020-06-03)

Bug Fixes

  • add static member for multicodec (#81) (dd86739)

0.4.3 (2020-06-03)

0.4.2 (2020-05-27)

Features

  • add topic validators to pubsub (5712fd1)

0.4.1 (2020-05-27)

0.4.0 (2020-04-23)

Chores

BREAKING CHANGES

  • using new topology api with peer-id instead of peer-info and new pubsub internal peer data structure

0.3.0 (2020-04-23)

Bug Fixes

  • add buffer and update deps (d8e9d1b)

0.2.6 (2020-04-04)

0.2.5 (2020-03-21)

0.2.4 (2020-02-14)

Bug Fixes

0.2.3 (2020-02-03)

Bug Fixes

Chores

Code Refactoring

  • switch to async iterators (3027835)

Performance Improvements

BREAKING CHANGES

  • getPeersSubscribed from parent class renamed to getSubscribers to remove redundant wording
  • Switch to using async/await and async iterators for all the API. Moreover, gossipsub does not need the libp2p instance anymore, receiving a registerar that enables it to receive the necessary events from libp2p

0.2.2 (2020-01-24)

Bug Fixes

Chores

Code Refactoring

  • switch to async iterators (3027835)

BREAKING CHANGES

  • getPeersSubscribed from parent class renamed to getSubscribers to remove redundant wording
  • Switch to using async/await and async iterators for all the API. Moreover, gossipsub does not need the libp2p instance anymore, receiving a registerar that enables it to receive the necessary events from libp2p

0.2.1 (2019-01-14)

Bug Fixes

0.2.0 (2019-12-02)

Chores

BREAKING CHANGES

  • getPeersSubscribed from parent class renamed to getSubscribers to remove redundant wording.

0.1.0 (2019-19-14)

Code Refactoring

  • switch to async iterators (ec8db51)

BREAKING CHANGES

  • Switch to using async/await and async iterators.

0.0.2 (2019-06-04)

0.0.1 (2019-06-04)

Bug Fixes

  • integration with js-libp2p (f894281)