@libp2p/floodsub 10.1.46-6059227cb → 10.1.46-87bc8d4fb
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 +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/config.d.ts +2 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/index.d.ts +8 -221
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +88 -37
- package/dist/src/index.js.map +1 -1
- package/package.json +15 -24
- package/src/config.ts +1 -0
- package/src/index.ts +97 -225
- package/dist/src/constants.d.ts +0 -6
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -6
- package/dist/src/constants.js.map +0 -1
- package/dist/src/floodsub.d.ts +0 -205
- package/dist/src/floodsub.d.ts.map +0 -1
- package/dist/src/floodsub.js +0 -641
- package/dist/src/floodsub.js.map +0 -1
- package/dist/src/peer-streams.d.ts +0 -71
- package/dist/src/peer-streams.d.ts.map +0 -1
- package/dist/src/peer-streams.js +0 -154
- package/dist/src/peer-streams.js.map +0 -1
- package/dist/src/sign.d.ts +0 -23
- package/dist/src/sign.d.ts.map +0 -1
- package/dist/src/sign.js +0 -75
- package/dist/src/sign.js.map +0 -1
- package/dist/src/utils.d.ts +0 -29
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -129
- package/dist/src/utils.js.map +0 -1
- package/src/constants.ts +0 -5
- package/src/floodsub.ts +0 -794
- package/src/peer-streams.ts +0 -200
- package/src/sign.ts +0 -93
- package/src/utils.ts +0 -157
package/src/index.ts
CHANGED
|
@@ -32,266 +32,138 @@
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
import { pubSubSymbol } from '
|
|
36
|
-
import {
|
|
37
|
-
import
|
|
38
|
-
import
|
|
35
|
+
import { pubSubSymbol, serviceCapabilities, serviceDependencies } from '@libp2p/interface'
|
|
36
|
+
import { PubSubBaseProtocol } from '@libp2p/pubsub'
|
|
37
|
+
import { toString } from 'uint8arrays/to-string'
|
|
38
|
+
import { SimpleTimeCache } from './cache.js'
|
|
39
|
+
import { multicodec } from './config.js'
|
|
40
|
+
import { RPC } from './message/rpc.js'
|
|
41
|
+
import type { PeerId, PubSubInit, Message, PubSubRPC, PubSubRPCMessage, PublishResult, PubSub } from '@libp2p/interface'
|
|
42
|
+
import type { PubSubComponents } from '@libp2p/pubsub'
|
|
43
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
44
|
+
|
|
45
|
+
export { multicodec }
|
|
46
|
+
|
|
47
|
+
export interface FloodSubInit extends PubSubInit {
|
|
48
|
+
seenTTL?: number
|
|
49
|
+
}
|
|
39
50
|
|
|
40
|
-
export
|
|
51
|
+
export interface FloodSubComponents extends PubSubComponents {
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
* On the producing side:
|
|
44
|
-
* - Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
|
45
|
-
*
|
|
46
|
-
* On the consuming side:
|
|
47
|
-
* - Enforce the fields to be present, reject otherwise.
|
|
48
|
-
* - Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
|
49
|
-
*/
|
|
50
|
-
export const StrictSign = 'StrictSign'
|
|
53
|
+
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* On the consuming side:
|
|
58
|
-
* - Enforce the fields to be absent, reject otherwise.
|
|
59
|
-
* - Propagate only if the fields are absent, reject otherwise.
|
|
60
|
-
* - A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
|
|
56
|
+
* FloodSub (aka dumbsub is an implementation of pubsub focused on
|
|
57
|
+
* delivering an API for Publish/Subscribe, but with no CastTree Forming
|
|
58
|
+
* (it just floods the network).
|
|
61
59
|
*/
|
|
62
|
-
|
|
60
|
+
class FloodSub extends PubSubBaseProtocol {
|
|
61
|
+
public seenCache: SimpleTimeCache<boolean>
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
constructor (components: FloodSubComponents, init?: FloodSubInit) {
|
|
64
|
+
super(components, {
|
|
65
|
+
...init,
|
|
66
|
+
canRelayMessage: true,
|
|
67
|
+
multicodecs: [multicodec]
|
|
68
|
+
})
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
type: 'signed'
|
|
68
|
-
from: PeerId
|
|
69
|
-
topic: string
|
|
70
|
-
data: Uint8Array
|
|
71
|
-
sequenceNumber: bigint
|
|
72
|
-
signature: Uint8Array
|
|
73
|
-
key: PublicKey
|
|
74
|
-
}
|
|
70
|
+
this.log = components.logger.forComponent('libp2p:floodsub')
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Cache of seen messages
|
|
74
|
+
*
|
|
75
|
+
* @type {TimeCache}
|
|
76
|
+
*/
|
|
77
|
+
this.seenCache = new SimpleTimeCache<boolean>({
|
|
78
|
+
validityMs: init?.seenTTL ?? 30000
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
readonly [pubSubSymbol] = true
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
topic: string
|
|
86
|
-
subscribe: boolean
|
|
87
|
-
}
|
|
84
|
+
readonly [Symbol.toStringTag] = '@libp2p/floodsub'
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
86
|
+
readonly [serviceCapabilities]: string[] = [
|
|
87
|
+
'@libp2p/pubsub'
|
|
88
|
+
]
|
|
93
89
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
90
|
+
readonly [serviceDependencies]: string[] = [
|
|
91
|
+
'@libp2p/identify'
|
|
92
|
+
]
|
|
98
93
|
|
|
99
|
-
export interface PublishResult {
|
|
100
|
-
recipients: PeerId[]
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export enum TopicValidatorResult {
|
|
104
|
-
/**
|
|
105
|
-
* The message is considered valid, and it should be delivered and forwarded to the network
|
|
106
|
-
*/
|
|
107
|
-
Accept = 'accept',
|
|
108
|
-
/**
|
|
109
|
-
* The message is neither delivered nor forwarded to the network
|
|
110
|
-
*/
|
|
111
|
-
Ignore = 'ignore',
|
|
112
94
|
/**
|
|
113
|
-
*
|
|
95
|
+
* Decode a Uint8Array into an RPC object
|
|
114
96
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
export interface TopicValidatorFn {
|
|
119
|
-
(peer: PeerId, message: Message): TopicValidatorResult | Promise<TopicValidatorResult>
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface PeerStreamEvents {
|
|
123
|
-
'stream:inbound': CustomEvent<never>
|
|
124
|
-
'stream:outbound': CustomEvent<never>
|
|
125
|
-
close: CustomEvent<never>
|
|
126
|
-
}
|
|
97
|
+
decodeRpc (bytes: Uint8Array | Uint8ArrayList): PubSubRPC {
|
|
98
|
+
return RPC.decode(bytes)
|
|
99
|
+
}
|
|
127
100
|
|
|
128
|
-
export { pubSubSymbol }
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Returns true if the passed argument is a PubSub implementation
|
|
132
|
-
*/
|
|
133
|
-
export function isPubSub (obj?: any): obj is FloodSub {
|
|
134
|
-
return Boolean(obj?.[pubSubSymbol])
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface FloodSub extends TypedEventTarget<FloodSubEvents> {
|
|
138
101
|
/**
|
|
139
|
-
*
|
|
140
|
-
* signed or unsigned messages.
|
|
141
|
-
*
|
|
142
|
-
* Signed messages prevent spoofing message senders and should be preferred to
|
|
143
|
-
* using unsigned messages.
|
|
102
|
+
* Encode an RPC object into a Uint8Array
|
|
144
103
|
*/
|
|
145
|
-
|
|
104
|
+
encodeRpc (rpc: PubSubRPC): Uint8Array {
|
|
105
|
+
return RPC.encode(rpc)
|
|
106
|
+
}
|
|
146
107
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
protocols: string[]
|
|
108
|
+
decodeMessage (bytes: Uint8Array | Uint8ArrayList): PubSubRPCMessage {
|
|
109
|
+
return RPC.Message.decode(bytes)
|
|
110
|
+
}
|
|
151
111
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* values are the validators.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
*
|
|
159
|
-
* ```TypeScript
|
|
160
|
-
* const topic = 'topic'
|
|
161
|
-
* const validateMessage = (msgTopic, msg) => {
|
|
162
|
-
* const input = uint8ArrayToString(msg.data)
|
|
163
|
-
* const validInputs = ['a', 'b', 'c']
|
|
164
|
-
*
|
|
165
|
-
* if (!validInputs.includes(input)) {
|
|
166
|
-
* throw new Error('no valid input received')
|
|
167
|
-
* }
|
|
168
|
-
* }
|
|
169
|
-
* libp2p.pubsub.topicValidators.set(topic, validateMessage)
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
topicValidators: Map<string, TopicValidatorFn>
|
|
173
|
-
|
|
174
|
-
getPeers(): PeerId[]
|
|
112
|
+
encodeMessage (rpc: PubSubRPCMessage): Uint8Array {
|
|
113
|
+
return RPC.Message.encode(rpc)
|
|
114
|
+
}
|
|
175
115
|
|
|
176
116
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* ```TypeScript
|
|
180
|
-
* const topics = libp2p.pubsub.getTopics()
|
|
181
|
-
* ```
|
|
117
|
+
* Process incoming message
|
|
118
|
+
* Extends base implementation to check router cache.
|
|
182
119
|
*/
|
|
183
|
-
|
|
120
|
+
async processMessage (from: PeerId, message: Message): Promise<void> {
|
|
121
|
+
// Check if I've seen the message, if yes, ignore
|
|
122
|
+
const seqno = await super.getMsgId(message)
|
|
123
|
+
const msgIdStr = toString(seqno, 'base64')
|
|
184
124
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* @example
|
|
189
|
-
*
|
|
190
|
-
* ```TypeScript
|
|
191
|
-
* const topic = 'topic'
|
|
192
|
-
* const handler = (msg) => {
|
|
193
|
-
* if (msg.topic === topic) {
|
|
194
|
-
* // msg.data - pubsub data received
|
|
195
|
-
* }
|
|
196
|
-
* }
|
|
197
|
-
*
|
|
198
|
-
* libp2p.pubsub.addEventListener('message', handler)
|
|
199
|
-
* libp2p.pubsub.subscribe(topic)
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
subscribe(topic: string): void
|
|
125
|
+
if (this.seenCache.has(msgIdStr)) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
203
128
|
|
|
204
|
-
|
|
205
|
-
* Unsubscribes from a pubsub topic.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
*
|
|
209
|
-
* ```TypeScript
|
|
210
|
-
* const topic = 'topic'
|
|
211
|
-
* const handler = (msg) => {
|
|
212
|
-
* // msg.data - pubsub data received
|
|
213
|
-
* }
|
|
214
|
-
*
|
|
215
|
-
* libp2p.pubsub.removeEventListener(topic handler)
|
|
216
|
-
* libp2p.pubsub.unsubscribe(topic)
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
unsubscribe(topic: string): void
|
|
129
|
+
this.seenCache.put(msgIdStr, true)
|
|
220
130
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
*
|
|
226
|
-
* ```TypeScript
|
|
227
|
-
* const peerIds = libp2p.pubsub.getSubscribers(topic)
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
getSubscribers(topic: string): PeerId[]
|
|
131
|
+
await super.processMessage(from, message)
|
|
132
|
+
}
|
|
231
133
|
|
|
232
134
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
*
|
|
237
|
-
* ```TypeScript
|
|
238
|
-
* const topic = 'topic'
|
|
239
|
-
* const data = uint8ArrayFromString('data')
|
|
240
|
-
*
|
|
241
|
-
* await libp2p.pubsub.publish(topic, data)
|
|
242
|
-
* ```
|
|
135
|
+
* Publish message created. Forward it to the peers.
|
|
243
136
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
137
|
+
async publishMessage (from: PeerId, message: Message): Promise<PublishResult> {
|
|
138
|
+
const peers = this.getSubscribers(message.topic)
|
|
139
|
+
const recipients: PeerId[] = []
|
|
246
140
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
logger: ComponentLogger
|
|
252
|
-
}
|
|
141
|
+
if (peers == null || peers.length === 0) {
|
|
142
|
+
this.log('no peers are subscribed to topic %s', message.topic)
|
|
143
|
+
return { recipients }
|
|
144
|
+
}
|
|
253
145
|
|
|
254
|
-
|
|
255
|
-
|
|
146
|
+
peers.forEach(id => {
|
|
147
|
+
if (this.components.peerId.equals(id)) {
|
|
148
|
+
this.log('not sending message on topic %s to myself', message.topic)
|
|
149
|
+
return
|
|
150
|
+
}
|
|
256
151
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
*/
|
|
262
|
-
protocols?: string[]
|
|
152
|
+
if (id.equals(from)) {
|
|
153
|
+
this.log('not sending message on topic %s to sender %p', message.topic, id)
|
|
154
|
+
return
|
|
155
|
+
}
|
|
263
156
|
|
|
264
|
-
|
|
265
|
-
* defines how signatures should be handled
|
|
266
|
-
*/
|
|
267
|
-
globalSignaturePolicy?: SignaturePolicy
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* if can relay messages not subscribed
|
|
271
|
-
*/
|
|
272
|
-
canRelayMessage?: boolean
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* if publish should emit to self, if subscribed
|
|
276
|
-
*/
|
|
277
|
-
emitSelf?: boolean
|
|
157
|
+
this.log('publish msgs on topics %s %p', message.topic, id)
|
|
278
158
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
messageProcessingConcurrency?: number
|
|
159
|
+
recipients.push(id)
|
|
160
|
+
this.send(id, { messages: [message] })
|
|
161
|
+
})
|
|
283
162
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
*/
|
|
287
|
-
maxInboundStreams?: number
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* How many parallel outgoing streams to allow on the pubsub protocol per-connection
|
|
291
|
-
*/
|
|
292
|
-
maxOutboundStreams?: number
|
|
163
|
+
return { recipients }
|
|
164
|
+
}
|
|
293
165
|
}
|
|
294
166
|
|
|
295
|
-
export function floodsub (init: FloodSubInit = {}): (components: FloodSubComponents) =>
|
|
296
|
-
return (components: FloodSubComponents) => new
|
|
167
|
+
export function floodsub (init: FloodSubInit = {}): (components: FloodSubComponents) => PubSub {
|
|
168
|
+
return (components: FloodSubComponents) => new FloodSub(components, init)
|
|
297
169
|
}
|
package/dist/src/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,YAAY,eAA+B,CAAA"}
|
package/dist/src/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA"}
|
package/dist/src/floodsub.d.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { serviceCapabilities, serviceDependencies } from '@libp2p/interface';
|
|
2
|
-
import { PeerMap, PeerSet } from '@libp2p/peer-collections';
|
|
3
|
-
import { TypedEventEmitter } from 'main-event';
|
|
4
|
-
import Queue from 'p-queue';
|
|
5
|
-
import { SimpleTimeCache } from './cache.js';
|
|
6
|
-
import { pubSubSymbol } from './constants.ts';
|
|
7
|
-
import { PeerStreams } from './peer-streams.js';
|
|
8
|
-
import { StrictNoSign, StrictSign } from './index.js';
|
|
9
|
-
import type { FloodSubComponents, FloodSubEvents, FloodSubInit, FloodSub as FloodSubInterface, Message, PublishResult, TopicValidatorFn } from './index.js';
|
|
10
|
-
import type { Logger, Connection, PeerId, Stream } from '@libp2p/interface';
|
|
11
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
12
|
-
export interface PubSubRPCMessage {
|
|
13
|
-
from?: Uint8Array;
|
|
14
|
-
topic?: string;
|
|
15
|
-
data?: Uint8Array;
|
|
16
|
-
sequenceNumber?: Uint8Array;
|
|
17
|
-
signature?: Uint8Array;
|
|
18
|
-
key?: Uint8Array;
|
|
19
|
-
}
|
|
20
|
-
export interface PubSubRPCSubscription {
|
|
21
|
-
subscribe?: boolean;
|
|
22
|
-
topic?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface PubSubRPC {
|
|
25
|
-
subscriptions: PubSubRPCSubscription[];
|
|
26
|
-
messages: PubSubRPCMessage[];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* PubSubBaseProtocol handles the peers and connections logic for pubsub routers
|
|
30
|
-
* and specifies the API that pubsub routers should have.
|
|
31
|
-
*/
|
|
32
|
-
export declare class FloodSub extends TypedEventEmitter<FloodSubEvents> implements FloodSubInterface {
|
|
33
|
-
protected log: Logger;
|
|
34
|
-
started: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Map of topics to which peers are subscribed to
|
|
37
|
-
*/
|
|
38
|
-
topics: Map<string, PeerSet>;
|
|
39
|
-
/**
|
|
40
|
-
* List of our subscriptions
|
|
41
|
-
*/
|
|
42
|
-
subscriptions: Set<string>;
|
|
43
|
-
/**
|
|
44
|
-
* Map of peer streams
|
|
45
|
-
*/
|
|
46
|
-
peers: PeerMap<PeerStreams>;
|
|
47
|
-
/**
|
|
48
|
-
* The signature policy to follow by default
|
|
49
|
-
*/
|
|
50
|
-
globalSignaturePolicy: typeof StrictNoSign | typeof StrictSign;
|
|
51
|
-
/**
|
|
52
|
-
* If router can relay received messages, even if not subscribed
|
|
53
|
-
*/
|
|
54
|
-
canRelayMessage: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* if publish should emit to self, if subscribed
|
|
57
|
-
*/
|
|
58
|
-
emitSelf: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Topic validator map
|
|
61
|
-
*
|
|
62
|
-
* Keyed by topic
|
|
63
|
-
* Topic validators are functions with the following input:
|
|
64
|
-
*/
|
|
65
|
-
topicValidators: Map<string, TopicValidatorFn>;
|
|
66
|
-
queue: Queue;
|
|
67
|
-
protocols: string[];
|
|
68
|
-
components: FloodSubComponents;
|
|
69
|
-
private _registrarTopologyIds;
|
|
70
|
-
private readonly maxInboundStreams;
|
|
71
|
-
private readonly maxOutboundStreams;
|
|
72
|
-
seenCache: SimpleTimeCache<boolean>;
|
|
73
|
-
constructor(components: FloodSubComponents, init: FloodSubInit);
|
|
74
|
-
readonly [pubSubSymbol] = true;
|
|
75
|
-
readonly [Symbol.toStringTag] = "@libp2p/floodsub";
|
|
76
|
-
readonly [serviceCapabilities]: string[];
|
|
77
|
-
readonly [serviceDependencies]: string[];
|
|
78
|
-
/**
|
|
79
|
-
* Register the pubsub protocol onto the libp2p node.
|
|
80
|
-
*/
|
|
81
|
-
start(): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* Unregister the pubsub protocol and the streams with other peers will be closed.
|
|
84
|
-
*/
|
|
85
|
-
stop(): Promise<void>;
|
|
86
|
-
isStarted(): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* On an inbound stream opened
|
|
89
|
-
*/
|
|
90
|
-
protected _onIncomingStream(stream: Stream, connection: Connection): void;
|
|
91
|
-
/**
|
|
92
|
-
* Registrar notifies an established connection with pubsub protocol
|
|
93
|
-
*/
|
|
94
|
-
protected _onPeerConnected(peerId: PeerId, conn: Connection): Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* Registrar notifies a closing connection with pubsub protocol
|
|
97
|
-
*/
|
|
98
|
-
protected _onPeerDisconnected(peerId: PeerId, conn?: Connection): void;
|
|
99
|
-
/**
|
|
100
|
-
* Notifies the router that a peer has been connected
|
|
101
|
-
*/
|
|
102
|
-
addPeer(peerId: PeerId, protocol: string): PeerStreams;
|
|
103
|
-
/**
|
|
104
|
-
* Notifies the router that a peer has been disconnected
|
|
105
|
-
*/
|
|
106
|
-
protected _removePeer(peerId: PeerId): PeerStreams | undefined;
|
|
107
|
-
/**
|
|
108
|
-
* Responsible for processing each RPC message received by other peers.
|
|
109
|
-
*/
|
|
110
|
-
processMessages(peerId: PeerId, stream: AsyncIterable<Uint8ArrayList>, peerStreams: PeerStreams): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Handles an rpc request from a peer
|
|
113
|
-
*/
|
|
114
|
-
processRpc(from: PeerId, peerStreams: PeerStreams, rpc: PubSubRPC): Promise<boolean>;
|
|
115
|
-
/**
|
|
116
|
-
* Handles a subscription change from a peer
|
|
117
|
-
*/
|
|
118
|
-
processRpcSubOpt(id: PeerId, subOpt: PubSubRPCSubscription): void;
|
|
119
|
-
/**
|
|
120
|
-
* Handles a message from a peer
|
|
121
|
-
*/
|
|
122
|
-
processMessage(from: PeerId, msg: Message): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* The default msgID implementation
|
|
125
|
-
* Child class can override this.
|
|
126
|
-
*/
|
|
127
|
-
getMsgId(msg: Message): Promise<Uint8Array> | Uint8Array;
|
|
128
|
-
/**
|
|
129
|
-
* Whether to accept a message from a peer
|
|
130
|
-
* Override to create a gray list
|
|
131
|
-
*/
|
|
132
|
-
acceptFrom(id: PeerId): boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Decode Uint8Array into an RPC object.
|
|
135
|
-
* This can be override to use a custom router protobuf.
|
|
136
|
-
*/
|
|
137
|
-
decodeRpc(bytes: Uint8Array | Uint8ArrayList): PubSubRPC;
|
|
138
|
-
/**
|
|
139
|
-
* Encode RPC object into a Uint8Array.
|
|
140
|
-
* This can be override to use a custom router protobuf.
|
|
141
|
-
*/
|
|
142
|
-
encodeRpc(rpc: PubSubRPC): Uint8Array;
|
|
143
|
-
/**
|
|
144
|
-
* Encode RPC object into a Uint8Array.
|
|
145
|
-
* This can be override to use a custom router protobuf.
|
|
146
|
-
*/
|
|
147
|
-
encodeMessage(rpc: PubSubRPCMessage): Uint8Array;
|
|
148
|
-
/**
|
|
149
|
-
* Send an rpc object to a peer
|
|
150
|
-
*/
|
|
151
|
-
send(peer: PeerId, data: {
|
|
152
|
-
messages?: Message[];
|
|
153
|
-
subscriptions?: string[];
|
|
154
|
-
subscribe?: boolean;
|
|
155
|
-
}): void;
|
|
156
|
-
/**
|
|
157
|
-
* Send an rpc object to a peer
|
|
158
|
-
*/
|
|
159
|
-
sendRpc(peer: PeerId, rpc: PubSubRPC): void;
|
|
160
|
-
/**
|
|
161
|
-
* Validates the given message. The signature will be checked for authenticity.
|
|
162
|
-
* Throws an error on invalid messages
|
|
163
|
-
*/
|
|
164
|
-
validate(from: PeerId, message: Message): Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* Normalizes the message and signs it, if signing is enabled.
|
|
167
|
-
* Should be used by the routers to create the message to send.
|
|
168
|
-
*/
|
|
169
|
-
buildMessage(message: {
|
|
170
|
-
from: PeerId;
|
|
171
|
-
topic: string;
|
|
172
|
-
data: Uint8Array;
|
|
173
|
-
sequenceNumber: bigint;
|
|
174
|
-
}): Promise<Message>;
|
|
175
|
-
/**
|
|
176
|
-
* Get a list of the peer-ids that are subscribed to one topic.
|
|
177
|
-
*/
|
|
178
|
-
getSubscribers(topic: string): PeerId[];
|
|
179
|
-
/**
|
|
180
|
-
* Publishes messages to all subscribed peers
|
|
181
|
-
*/
|
|
182
|
-
publish(topic: string, data?: Uint8Array): Promise<PublishResult>;
|
|
183
|
-
/**
|
|
184
|
-
* Overriding the implementation of publish should handle the appropriate algorithms for the publish/subscriber implementation.
|
|
185
|
-
* For example, a Floodsub implementation might simply publish each message to each topic for every peer.
|
|
186
|
-
*
|
|
187
|
-
* `sender` might be this peer, or we might be forwarding a message on behalf of another peer, in which case sender
|
|
188
|
-
* is the peer we received the message from, which may not be the peer the message was created by.
|
|
189
|
-
*/
|
|
190
|
-
publishMessage(from: PeerId, message: Message): Promise<PublishResult>;
|
|
191
|
-
/**
|
|
192
|
-
* Subscribes to a given topic.
|
|
193
|
-
*/
|
|
194
|
-
subscribe(topic: string): void;
|
|
195
|
-
/**
|
|
196
|
-
* Unsubscribe from the given topic
|
|
197
|
-
*/
|
|
198
|
-
unsubscribe(topic: string): void;
|
|
199
|
-
/**
|
|
200
|
-
* Get the list of topics which the peer is subscribed to.
|
|
201
|
-
*/
|
|
202
|
-
getTopics(): string[];
|
|
203
|
-
getPeers(): PeerId[];
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=floodsub.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"floodsub.d.ts","sourceRoot":"","sources":["../../src/floodsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC1I,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,MAAM,SAAS,CAAA;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAkC,MAAM,mBAAmB,CAAA;AAG/E,OAAO,EAAY,YAAY,EAAwB,UAAU,EAAE,MAAM,YAAY,CAAA;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,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