@libp2p/gossipsub 17.1.1 → 17.1.2-776cdedf6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,83 +1,87 @@
1
1
  # @libp2p/gossipsub
2
2
 
3
- ![ES Version](https://img.shields.io/badge/ES-2017-yellow)
4
- ![Node Version](https://img.shields.io/badge/node-10.x-green)
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)
5
7
 
6
- ## Table of Contents
8
+ > A typescript implementation of gossipsub
7
9
 
8
- - [@libp2p/gossipsub](#libp2pgossipsub)
9
- - [Lead Maintainer](#lead-maintainer)
10
- - [Table of Contents](#table-of-contents)
11
- - [Specs](#specs)
12
- - [Install](#install)
13
- - [Usage](#usage)
14
- - [API](#api)
15
- - [Create a gossipsub implementation](#create-a-gossipsub-implementation)
16
- - [Contribute](#contribute)
17
- - [License](#license)
10
+ # About
18
11
 
19
- ## Specs
12
+ <!--
20
13
 
21
- 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).
14
+ !IMPORTANT!
22
15
 
23
- `@libp2p/gossipsub` currently implements the [`v1.1`](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md) of the spec.
16
+ Everything in this README between "# About" and "# Install" is automatically
17
+ generated and will be overwritten the next time the doc generator is run.
24
18
 
25
- ## Install
19
+ To make changes to this section, please update the @packageDocumentation section
20
+ of src/index.js or src/index.ts
26
21
 
27
- `npm install @libp2p/gossipsub`
22
+ To experiment with formatting, please run "npm run docs" from the root of this
23
+ repo and examine the changes made.
28
24
 
29
- ## Usage
25
+ -->
30
26
 
31
- ```javascript
32
- import { gossipsub } from '@libp2p/gossipsub'
27
+ Gossipsub is an implementation of pubsub based on meshsub and floodsub.
28
+
29
+ You can read the specification [here](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub).
30
+
31
+ `@libp2p/gossipsub` currently implements [version 1.1](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md) of the spec.
32
+
33
+ Formerly published as [`@chainsafe/libp2p-gossipsub`](https://www.npmjs.com/package/@chainsafe/libp2p-gossipsub).
34
+
35
+ ## Example - Configuring libp2p to use gossipsub
33
36
 
37
+ ```typescript
38
+ import { identify } from '@libp2p/identify'
39
+ import { createLibp2p } from 'libp2p'
40
+ import { gossipsub } from '@libp2p/gossipsub'
34
41
 
35
- const libp2p = await createLibp2p({
36
- // ...
42
+ const node = await createLibp2p({
37
43
  services: {
38
- pubsub: gossipsub(options)
44
+ identify: identify(),
45
+ pubsub: gossipsub()
39
46
  }
40
- });
47
+ //... other options
48
+ })
49
+ await node.start()
41
50
 
42
- libp2p.services.pubsub.addEventListener('message', (message) => {
43
- console.log(`${message.detail.topic}:`, new TextDecoder().decode(message.detail.data))
51
+ node.services.pubsub.addEventListener('message', (evt) => {
52
+ console.log(`${evt.detail.topic}:`, new TextDecoder().decode(evt.detail.data))
44
53
  })
45
54
 
46
- libp2p.services.pubsub.subscribe('fruit')
55
+ node.services.pubsub.subscribe('fruit')
56
+
57
+ node.services.pubsub.publish('fruit', new TextEncoder().encode('banana'))
58
+ ```
59
+
60
+ # Install
47
61
 
48
- libp2p.services.pubsub.publish('fruit', new TextEncoder().encode('banana'))
62
+ ```console
63
+ $ npm i @libp2p/gossipsub
49
64
  ```
50
65
 
51
- ## API
66
+ ## Browser `<script>` tag
52
67
 
53
- ### Create a gossipsub implementation
68
+ Loading this module through a script tag will make its exports available as `Libp2pGossipsub` in the global namespace.
54
69
 
55
- ```js
56
- const options = {…}
57
- const gossipsub = gossipsub(options)(libp2p)
70
+ ```html
71
+ <script src="https://unpkg.com/@libp2p/gossipsub/dist/index.min.js"></script>
58
72
  ```
59
73
 
60
- Options is an optional object with the following key-value pairs:
74
+ # API Docs
61
75
 
62
- - **`emitSelf`**: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to **false**).
63
- - **`gossipIncoming`**: boolean identifying if incoming messages on a subscribed topic should be automatically gossiped (defaults to **true**).
64
- - **`fallbackToFloodsub`**: boolean identifying whether the node should fallback to the floodsub protocol, if another connecting peer does not support gossipsub (defaults to **true**).
65
- - **`floodPublish`**: boolean identifying if self-published messages should be sent to all peers, (defaults to **true**).
66
- - **`doPX`**: boolean identifying whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted nodes (defaults to **false**).
67
- - **`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')`)
68
- - **`signMessages`**: boolean identifying if we want to sign outgoing messages or not (default: `true`)
69
- - **`strictSigning`**: boolean identifying if message signing is required for incoming messages or not (default: `true`)
70
- - **`messageCache`**: optional, a customized `MessageCache` instance, see the implementation for the interface.
71
- - **`scoreParams`**: optional, a customized peer score parameters Object.
72
- - **`scoreThresholds`**: optional, a customized peer score thresholds Object.
73
- - **`directPeers`**: optional, an array of `AddrInfo` of peers with which we will maintain direct connections.
76
+ - <https://libp2p.github.io/js-libp2p/modules/_libp2p_gossipsub.html>
74
77
 
75
- For the remaining API, see [@libp2p/interface-pubsub](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-pubsub).
78
+ # License
76
79
 
77
- ## Contribute
80
+ Licensed under either of
78
81
 
79
- This module is actively under development. Please check out the issues and submit PRs!
82
+ - Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/gossipsub/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
83
+ - MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/gossipsub/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
80
84
 
81
- ## License
85
+ # Contribution
82
86
 
83
- MIT © ChainSafe Systems
87
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.