@libp2p/floodsub 1.0.5 → 2.0.0

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,17 +1,14 @@
1
- # js-libp2p-floodsub <!-- omit in toc -->
1
+ # @libp2p/floodsub <!-- omit in toc -->
2
2
 
3
- [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
4
- [![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
5
- [![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
6
- [![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
7
- [![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-floodsub/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-floodsub?branch=master)
8
- [![Build Status](https://github.com/libp2p/js-libp2p-floodsub/actions/workflows/js-test-and-release.yml/badge.svg?branch=main)](https://github.com/libp2p/js-libp2p-floodsub/actions/workflows/js-test-and-release.yml)
9
- [![Dependency Status](https://david-dm.org/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-floodsub) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
10
- [![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-floodsub)
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-floodsub)
7
+ [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-floodsub/actions/workflows/js-test-and-release.yml)
11
8
 
12
9
  > libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).
13
10
 
14
- ## Table of Contents <!-- omit in toc -->
11
+ ## Table of contents <!-- omit in toc -->
15
12
 
16
13
  - [Install](#install)
17
14
  - [Usage](#usage)
@@ -20,11 +17,12 @@
20
17
  - [Events](#events)
21
18
  - [Contribute](#contribute)
22
19
  - [License](#license)
20
+ - [Contribution](#contribution)
23
21
 
24
22
  ## Install
25
23
 
26
- ```sh
27
- > npm install @libp2p/floodsub
24
+ ```console
25
+ $ npm i @libp2p/floodsub
28
26
  ```
29
27
 
30
28
  ## Usage
@@ -56,26 +54,32 @@ const floodsub = new Floodsub(peerId, registrar, options)
56
54
 
57
55
  Options is an optional object with the following key-value pairs:
58
56
 
59
- * **`emitSelf`**: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to **false**).
57
+ - **`emitSelf`**: boolean identifying whether the node should emit to self on publish, in the event of the topic being subscribed (defaults to **false**).
60
58
 
61
- For the remaining API, see https://github.com/libp2p/js-libp2p-pubsub
59
+ For the remaining API, see <https://github.com/libp2p/js-libp2p-pubsub>
62
60
 
63
61
  ## Events
64
62
 
65
63
  Floodsub emits two kinds of events:
64
+
66
65
  1. `<topic>` when a message is received for a particular topic
67
- ```Javascript
68
- fsub.on('fruit', (data) => { ... })
69
- ```
70
- - `data`: a Uint8Array containing the data that was published to the topic
66
+
67
+ ```Javascript
68
+ fsub.on('fruit', (data) => { ... })
69
+ ```
70
+
71
+ - `data`: a Uint8Array containing the data that was published to the topic
72
+
71
73
  2. `floodsub:subscription-change` when the local peer receives an update to the subscriptions of a remote peer.
72
- ```Javascript
73
- fsub.on('floodsub:subscription-change', (peerId, topics, changes) => { ... })
74
- ```
75
- - `peerId`: a [PeerId](https://github.com/libp2p/js-peer-id) object
76
- - `topics`: the topics that the peer is now subscribed to
77
- - `changes`: an array of `{ topicID: <topic>, subscribe: <boolean> }`
78
- eg `[ { topicID: 'fruit', subscribe: true }, { topicID: 'vegetables': false } ]`
74
+
75
+ ```Javascript
76
+ fsub.on('floodsub:subscription-change', (peerId, topics, changes) => { ... })
77
+ ```
78
+
79
+ - `peerId`: a [PeerId](https://github.com/libp2p/js-peer-id) object
80
+ - `topics`: the topics that the peer is now subscribed to
81
+ - `changes`: an array of `{ topicID: <topic>, subscribe: <boolean> }`
82
+ eg `[ { topicID: 'fruit', subscribe: true }, { topicID: 'vegetables': false } ]`
79
83
 
80
84
  ## Contribute
81
85
 
@@ -85,4 +89,11 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
85
89
 
86
90
  ## License
87
91
 
88
- [Apache-2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT) © Protocol Labs
92
+ Licensed under either of
93
+
94
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
95
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
96
+
97
+ ## Contribution
98
+
99
+ 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.
@@ -1,8 +1,8 @@
1
1
  import { PubSubBaseProtocol } from '@libp2p/pubsub';
2
2
  import { multicodec } from './config.js';
3
3
  import { SimpleTimeCache } from './cache.js';
4
- import type { PubSub, PubSubInit, Message, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub';
5
- import type { PeerId } from '@libp2p/interfaces/peer-id';
4
+ import type { PubSubInit, Message, PubSubRPC, PubSubRPCMessage, PublishResult } from '@libp2p/interface-pubsub';
5
+ import type { PeerId } from '@libp2p/interface-peer-id';
6
6
  export { multicodec };
7
7
  export interface FloodSubInit extends PubSubInit {
8
8
  seenTTL?: number;
@@ -12,7 +12,7 @@ export interface FloodSubInit extends PubSubInit {
12
12
  * delivering an API for Publish/Subscribe, but with no CastTree Forming
13
13
  * (it just floods the network).
14
14
  */
15
- export declare class FloodSub extends PubSubBaseProtocol implements PubSub {
15
+ export declare class FloodSub extends PubSubBaseProtocol {
16
16
  seenCache: SimpleTimeCache<boolean>;
17
17
  constructor(init?: FloodSubInit);
18
18
  /**
@@ -33,6 +33,6 @@ export declare class FloodSub extends PubSubBaseProtocol implements PubSub {
33
33
  /**
34
34
  * Publish message created. Forward it to the peers.
35
35
  */
36
- publishMessage(from: PeerId, message: Message): Promise<void>;
36
+ publishMessage(from: PeerId, message: Message): Promise<PublishResult>;
37
37
  }
38
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACzG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAMxD,OAAO,EAAE,UAAU,EAAE,CAAA;AAErB,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,kBAAmB,YAAW,MAAM;IACzD,SAAS,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;gBAE7B,IAAI,CAAC,EAAE,YA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,UAAU;IAIjD;;;OAGG;IACG,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAcpD;;OAEG;IACG,cAAc,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;CA4B9E"}
package/dist/src/index.js CHANGED
@@ -64,9 +64,10 @@ export class FloodSub extends PubSubBaseProtocol {
64
64
  */
65
65
  async publishMessage(from, message) {
66
66
  const peers = this.getSubscribers(message.topic);
67
+ const recipients = [];
67
68
  if (peers == null || peers.length === 0) {
68
69
  log('no peers are subscribed to topic %s', message.topic);
69
- return;
70
+ return { recipients };
70
71
  }
71
72
  peers.forEach(id => {
72
73
  if (this.components.getPeerId().equals(id)) {
@@ -78,8 +79,10 @@ export class FloodSub extends PubSubBaseProtocol {
78
79
  return;
79
80
  }
80
81
  log('publish msgs on topics %s %p', message.topic, id);
82
+ recipients.push(id);
81
83
  this.send(id, { messages: [message] });
82
84
  });
85
+ return { recipients };
83
86
  }
84
87
  }
85
88
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,MAAM,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA;AAErC,OAAO,EAAE,UAAU,EAAE,CAAA;AAMrB;;;;GAIG;AACH,MAAM,OAAO,QAAS,SAAQ,kBAAkB;IAG9C,YAAa,IAAmB;QAC9B,KA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AE,OAAgB;QAClD,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAChD,MAAM,UAAU,GAAa,EAAE,CAAA;QAE/B,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACvC,GAAG,CAAC,qCAAqC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;YACzD,OAAO,EAAE,UAAU,EAAE,CAAA;SACtB;QAED,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YACjB,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;gBAC1C,GAAG,CAAC,2CAA2C,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;gBAC/D,OAAM;aACP;YAED,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;gBACnB,GAAG,CAAC,8CAA8C,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;gBACtE,OAAM;aACP;YAED,GAAG,CAAC,8BAA8B,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;YAEtD,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YACnB,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,UAAU,EAAE,CAAA;IACvB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/floodsub",
3
- "version": "1.0.5",
3
+ "version": "2.0.0",
4
4
  "description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme",
@@ -33,6 +33,7 @@
33
33
  ],
34
34
  "exports": {
35
35
  ".": {
36
+ "types": "./src/index.d.ts",
36
37
  "import": "./dist/src/index.js"
37
38
  }
38
39
  },
@@ -142,23 +143,26 @@
142
143
  "release": "aegir release"
143
144
  },
144
145
  "dependencies": {
145
- "@libp2p/interfaces": "^1.3.22",
146
+ "@libp2p/interface-peer-id": "^1.0.2",
147
+ "@libp2p/interface-pubsub": "^1.0.1",
146
148
  "@libp2p/logger": "^1.1.4",
147
- "@libp2p/pubsub": "^1.2.18",
149
+ "@libp2p/pubsub": "^2.0.0",
148
150
  "protons-runtime": "^1.0.3",
149
151
  "uint8arrays": "^3.0.0"
150
152
  },
151
153
  "devDependencies": {
152
- "@libp2p/interface-compliance-tests": "^1.1.23",
154
+ "@libp2p/components": "^1.0.0",
155
+ "@libp2p/interface-mocks": "^1.0.1",
156
+ "@libp2p/interface-pubsub-compliance-tests": "^1.0.1",
153
157
  "@libp2p/peer-collections": "^1.0.2",
154
158
  "@libp2p/peer-id": "^1.1.10",
155
159
  "@libp2p/peer-id-factory": "^1.0.9",
156
160
  "@multiformats/multiaddr": "^10.1.8",
157
- "aegir": "^37.0.14",
161
+ "aegir": "^37.2.0",
158
162
  "multiformats": "^9.4.5",
159
163
  "p-wait-for": "^4.1.0",
160
164
  "protons": "^3.0.3",
161
- "sinon": "^13.0.1",
165
+ "sinon": "^14.0.0",
162
166
  "wherearewe": "^1.0.0"
163
167
  }
164
168
  }
package/src/index.ts CHANGED
@@ -2,8 +2,8 @@ import { toString } from 'uint8arrays/to-string'
2
2
  import { PubSubBaseProtocol } from '@libp2p/pubsub'
3
3
  import { multicodec } from './config.js'
4
4
  import { SimpleTimeCache } from './cache.js'
5
- import type { PubSub, PubSubInit, Message, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub'
6
- import type { PeerId } from '@libp2p/interfaces/peer-id'
5
+ import type { PubSubInit, Message, PubSubRPC, PubSubRPCMessage, PublishResult } from '@libp2p/interface-pubsub'
6
+ import type { PeerId } from '@libp2p/interface-peer-id'
7
7
  import { logger } from '@libp2p/logger'
8
8
  import { RPC } from './message/rpc.js'
9
9
 
@@ -20,7 +20,7 @@ export interface FloodSubInit extends PubSubInit {
20
20
  * delivering an API for Publish/Subscribe, but with no CastTree Forming
21
21
  * (it just floods the network).
22
22
  */
23
- export class FloodSub extends PubSubBaseProtocol implements PubSub {
23
+ export class FloodSub extends PubSubBaseProtocol {
24
24
  public seenCache: SimpleTimeCache<boolean>
25
25
 
26
26
  constructor (init?: FloodSubInit) {
@@ -83,12 +83,13 @@ export class FloodSub extends PubSubBaseProtocol implements PubSub {
83
83
  /**
84
84
  * Publish message created. Forward it to the peers.
85
85
  */
86
- async publishMessage (from: PeerId, message: Message) {
86
+ async publishMessage (from: PeerId, message: Message): Promise<PublishResult> {
87
87
  const peers = this.getSubscribers(message.topic)
88
+ const recipients: PeerId[] = []
88
89
 
89
90
  if (peers == null || peers.length === 0) {
90
91
  log('no peers are subscribed to topic %s', message.topic)
91
- return
92
+ return { recipients }
92
93
  }
93
94
 
94
95
  peers.forEach(id => {
@@ -104,7 +105,10 @@ export class FloodSub extends PubSubBaseProtocol implements PubSub {
104
105
 
105
106
  log('publish msgs on topics %s %p', message.topic, id)
106
107
 
108
+ recipients.push(id)
107
109
  this.send(id, { messages: [message] })
108
110
  })
111
+
112
+ return { recipients }
109
113
  }
110
114
  }