@libp2p/floodsub 0.29.0 → 1.0.2
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/dist/src/index.d.ts +15 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +31 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/message/rpc.d.ts +669 -0
- package/dist/src/message/rpc.js +1876 -0
- package/package.json +20 -12
- package/src/index.ts +37 -14
- package/src/message/rpc.d.ts +669 -0
- package/src/message/rpc.js +1876 -0
- package/src/message/rpc.proto +52 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/floodsub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
"extends": "ipfs",
|
|
41
41
|
"parserOptions": {
|
|
42
42
|
"sourceType": "module"
|
|
43
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"ignorePatterns": [
|
|
45
|
+
"*.d.ts"
|
|
46
|
+
]
|
|
44
47
|
},
|
|
45
48
|
"release": {
|
|
46
49
|
"branches": [
|
|
@@ -125,8 +128,12 @@
|
|
|
125
128
|
},
|
|
126
129
|
"scripts": {
|
|
127
130
|
"lint": "aegir lint",
|
|
128
|
-
"dep-check": "aegir dep-check",
|
|
129
|
-
"build": "tsc",
|
|
131
|
+
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
|
|
132
|
+
"build": "tsc && npm run build:copy-proto-files",
|
|
133
|
+
"build:copy-proto-files": "mkdirp dist/src/message && cp src/message/*.js src/message/*.d.ts dist/src/message",
|
|
134
|
+
"generate": "npm run generate:proto && npm run generate:proto-types",
|
|
135
|
+
"generate:proto": "pbjs -t static-module -w es6 -r libp2p-floodsub --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/rpc.js ./src/message/rpc.proto",
|
|
136
|
+
"generate:proto-types": "pbts -o src/message/rpc.d.ts src/message/rpc.js",
|
|
130
137
|
"pretest": "npm run build",
|
|
131
138
|
"test": "aegir test -f dist/test",
|
|
132
139
|
"test:chrome": "npm run test -- -t browser --cov",
|
|
@@ -138,17 +145,18 @@
|
|
|
138
145
|
"release": "semantic-release"
|
|
139
146
|
},
|
|
140
147
|
"dependencies": {
|
|
141
|
-
"@libp2p/interfaces": "^1.3.
|
|
142
|
-
"@libp2p/logger": "^1.
|
|
143
|
-
"@libp2p/pubsub": "^1.2.
|
|
148
|
+
"@libp2p/interfaces": "^1.3.18",
|
|
149
|
+
"@libp2p/logger": "^1.1.2",
|
|
150
|
+
"@libp2p/pubsub": "^1.2.12",
|
|
151
|
+
"protobufjs": "^6.11.2",
|
|
144
152
|
"uint8arrays": "^3.0.0"
|
|
145
153
|
},
|
|
146
154
|
"devDependencies": {
|
|
147
|
-
"@libp2p/interface-compliance-tests": "^1.
|
|
148
|
-
"@libp2p/peer-id": "^1.1.
|
|
149
|
-
"@libp2p/peer-id-factory": "^1.0.
|
|
150
|
-
"@multiformats/multiaddr": "^10.1.
|
|
151
|
-
"aegir": "^36.1.
|
|
155
|
+
"@libp2p/interface-compliance-tests": "^1.1.19",
|
|
156
|
+
"@libp2p/peer-id": "^1.1.8",
|
|
157
|
+
"@libp2p/peer-id-factory": "^1.0.8",
|
|
158
|
+
"@multiformats/multiaddr": "^10.1.8",
|
|
159
|
+
"aegir": "^36.1.3",
|
|
152
160
|
"multiformats": "^9.4.5",
|
|
153
161
|
"p-wait-for": "^4.1.0",
|
|
154
162
|
"sinon": "^13.0.1",
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { toString } from 'uint8arrays/to-string'
|
|
2
|
-
import {
|
|
2
|
+
import { PubSubBaseProtocol } from '@libp2p/pubsub'
|
|
3
3
|
import { multicodec } from './config.js'
|
|
4
4
|
import { SimpleTimeCache } from './cache.js'
|
|
5
|
-
import type { PubSub,
|
|
5
|
+
import type { PubSub, PubSubInit, Message, PubSubRPC, PubSubRPCMessage } from '@libp2p/interfaces/pubsub'
|
|
6
6
|
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
7
|
+
import { logger } from '@libp2p/logger'
|
|
8
|
+
import { RPC } from './message/rpc.js'
|
|
7
9
|
|
|
8
|
-
const
|
|
10
|
+
const log = logger('libp2p:floodsub')
|
|
9
11
|
|
|
10
12
|
export { multicodec }
|
|
11
13
|
|
|
12
|
-
export interface
|
|
14
|
+
export interface FloodSubInit extends PubSubInit {
|
|
13
15
|
seenTTL?: number
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -18,13 +20,12 @@ export interface FloodSubOptions extends PubSubOptions {
|
|
|
18
20
|
* delivering an API for Publish/Subscribe, but with no CastTree Forming
|
|
19
21
|
* (it just floods the network).
|
|
20
22
|
*/
|
|
21
|
-
export class FloodSub
|
|
23
|
+
export class FloodSub extends PubSubBaseProtocol implements PubSub {
|
|
22
24
|
public seenCache: SimpleTimeCache<boolean>
|
|
23
25
|
|
|
24
|
-
constructor (
|
|
26
|
+
constructor (init?: FloodSubInit) {
|
|
25
27
|
super({
|
|
26
|
-
...
|
|
27
|
-
debugName: debugName,
|
|
28
|
+
...init,
|
|
28
29
|
canRelayMessage: true,
|
|
29
30
|
multicodecs: [multicodec]
|
|
30
31
|
})
|
|
@@ -35,10 +36,32 @@ export class FloodSub <EventMap extends PubSubEvents = PubSubEvents> extends Pub
|
|
|
35
36
|
* @type {TimeCache}
|
|
36
37
|
*/
|
|
37
38
|
this.seenCache = new SimpleTimeCache<boolean>({
|
|
38
|
-
validityMs:
|
|
39
|
+
validityMs: init?.seenTTL ?? 30000
|
|
39
40
|
})
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Decode a Uint8Array into an RPC object
|
|
45
|
+
*/
|
|
46
|
+
decodeRpc (bytes: Uint8Array): PubSubRPC {
|
|
47
|
+
return RPC.decode(bytes)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Encode an RPC object into a Uint8Array
|
|
52
|
+
*/
|
|
53
|
+
encodeRpc (rpc: PubSubRPC): Uint8Array {
|
|
54
|
+
return RPC.encode(rpc).finish()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
decodeMessage (bytes: Uint8Array): PubSubRPCMessage {
|
|
58
|
+
return RPC.Message.decode(bytes)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
encodeMessage (rpc: PubSubRPCMessage): Uint8Array {
|
|
62
|
+
return RPC.Message.encode(rpc).finish()
|
|
63
|
+
}
|
|
64
|
+
|
|
42
65
|
/**
|
|
43
66
|
* Process incoming message
|
|
44
67
|
* Extends base implementation to check router cache.
|
|
@@ -64,22 +87,22 @@ export class FloodSub <EventMap extends PubSubEvents = PubSubEvents> extends Pub
|
|
|
64
87
|
const peers = this.getSubscribers(message.topic)
|
|
65
88
|
|
|
66
89
|
if (peers == null || peers.length === 0) {
|
|
67
|
-
|
|
90
|
+
log('no peers are subscribed to topic %s', message.topic)
|
|
68
91
|
return
|
|
69
92
|
}
|
|
70
93
|
|
|
71
94
|
peers.forEach(id => {
|
|
72
|
-
if (this.
|
|
73
|
-
|
|
95
|
+
if (this.components.getPeerId().equals(id)) {
|
|
96
|
+
log('not sending message on topic %s to myself', message.topic)
|
|
74
97
|
return
|
|
75
98
|
}
|
|
76
99
|
|
|
77
100
|
if (id.equals(from)) {
|
|
78
|
-
|
|
101
|
+
log('not sending message on topic %s to sender %p', message.topic, id)
|
|
79
102
|
return
|
|
80
103
|
}
|
|
81
104
|
|
|
82
|
-
|
|
105
|
+
log('publish msgs on topics %s %p', message.topic, id)
|
|
83
106
|
|
|
84
107
|
this.send(id, { messages: [message] })
|
|
85
108
|
})
|