# libp2p-gossipsub

> A typescript implementation of gossipsub

Latest version **0.13.0** (published 2022-01-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install libp2p-gossipsub
pnpm add libp2p-gossipsub
yarn add libp2p-gossipsub
bun add libp2p-gossipsub
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.13.0 |
| Published | 2022-01-20 |
| First published | 2019-06-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 900.6 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 166 |
| Author | Cayman Nava |
| Maintainers | vascosantos, gregthegreek, mpetrunic, wemeetagain |
| Keywords | libp2p, pubsub, gossip |

## Links

- npm: https://www.npmjs.com/package/libp2p-gossipsub
- Repository: https://github.com/ChainSafe/js-libp2p-gossipsub
- Homepage: https://github.com/ChainSafe/js-libp2p-gossipsub#readme
- Issues: https://github.com/ChainSafe/js-libp2p-gossipsub/issues
- npm.io page: https://npm.io/package/libp2p-gossipsub

## Dependencies (9)

- [debug](https://npm.io/package/debug.md) ^4.3.1
- [denque](https://npm.io/package/denque.md) ^1.5.0
- [it-pipe](https://npm.io/package/it-pipe.md) ^1.1.0
- [peer-id](https://npm.io/package/peer-id.md) ^0.16.0
- [err-code](https://npm.io/package/err-code.md) ^3.0.1
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.11.2
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [@types/debug](https://npm.io/package/@types/debug.md) ^4.1.7
- [libp2p-interfaces](https://npm.io/package/libp2p-interfaces.md) ^4.0.4

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.13.0 (latest) — 2022-01-20
- 0.14.1 (beta) — 2022-08-17
- 0.14.0 — 2022-04-05
- 0.11.5 — 2022-03-27
- 0.13.2 — 2022-03-25
- 0.12.3 — 2022-01-20
- 0.12.2 — 2022-01-20
- 0.12.1 — 2021-12-03
- 0.12.0 — 2021-12-02
- 0.11.4 — 2021-09-20
- 0.11.3 — 2021-09-03
- 0.11.1 — 2021-08-24
- 0.11.0 — 2021-07-09
- 0.10.0 — 2021-05-28
- 0.9.2 — 2021-05-28
- … 35 more at https://npm.io/package/libp2p-gossipsub/versions

## README

js-libp2p-gossipsub
==================

[![](https://img.shields.io/badge/made%20by-ChainSafe-blue.svg?style=flat-square)](https://chainsafe.io/)
[![Travis CI](https://flat.badgen.net/travis/ChainSafe/gossipsub-js)](https://travis-ci.com/ChainSafe/gossipsub-js)
![ES Version](https://img.shields.io/badge/ES-2017-yellow)
![Node Version](https://img.shields.io/badge/node-10.x-green)

## Lead Maintainer

[Cayman Nava](https://github.com/wemeetagain)

## Table of Contents

* [Specs](#specs)
* [Install](#Install)
* [Usage](#Usage)
* [API](#API)
* [Contribute](#Contribute)
* [License](#License)

## Specs
Gossipsub is an implementation of pubsub based on meshsub and floodsub. You can read the specification [here](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub).

`libp2p-gossipsub` currently implements the [`v1.1`](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md) of the spec.

## Install

`npm install libp2p-gossipsub`

## Usage

```javascript
const Gossipsub = require('libp2p-gossipsub')

const gsub = new Gossipsub(libp2p, options)

await gsub.start()

gsub.on('fruit', (data) => {
  console.log(data)
})
gsub.subscribe('fruit')

gsub.publish('fruit', new TextEncoder().encode('banana'))
```

## API

### Create a gossipsub implementation

```js
const options = {…}
const gossipsub = new Gossipsub(libp2p, options)
```

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-interfaces/pubsub](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interfaces/src/pubsub).

## Contribute

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

## License

MIT © ChainSafe Systems

---
_Source: https://npm.io/package/libp2p-gossipsub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
