@libp2p/floodsub 4.0.1 → 6.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 +23 -12
- package/dist/index.min.js +24 -0
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/message/rpc.d.ts.map +1 -1
- package/dist/src/message/rpc.js +93 -102
- package/dist/src/message/rpc.js.map +1 -1
- package/package.json +15 -16
- package/src/index.ts +13 -5
- package/src/message/rpc.ts +93 -93
package/src/message/rpc.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable complexity */
|
|
2
3
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
3
5
|
|
|
4
6
|
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
5
7
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
@@ -22,23 +24,23 @@ export namespace RPC {
|
|
|
22
24
|
|
|
23
25
|
export const codec = (): Codec<SubOpts> => {
|
|
24
26
|
if (_codec == null) {
|
|
25
|
-
_codec = message<SubOpts>((obj,
|
|
27
|
+
_codec = message<SubOpts>((obj, w, opts = {}) => {
|
|
26
28
|
if (opts.lengthDelimited !== false) {
|
|
27
|
-
|
|
29
|
+
w.fork()
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
if (obj.subscribe != null) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
w.uint32(8)
|
|
34
|
+
w.bool(obj.subscribe)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
if (obj.topic != null) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
w.uint32(18)
|
|
39
|
+
w.string(obj.topic)
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
if (opts.lengthDelimited !== false) {
|
|
41
|
-
|
|
43
|
+
w.ldelim()
|
|
42
44
|
}
|
|
43
45
|
}, (reader, length) => {
|
|
44
46
|
const obj: any = {}
|
|
@@ -91,43 +93,43 @@ export namespace RPC {
|
|
|
91
93
|
|
|
92
94
|
export const codec = (): Codec<Message> => {
|
|
93
95
|
if (_codec == null) {
|
|
94
|
-
_codec = message<Message>((obj,
|
|
96
|
+
_codec = message<Message>((obj, w, opts = {}) => {
|
|
95
97
|
if (opts.lengthDelimited !== false) {
|
|
96
|
-
|
|
98
|
+
w.fork()
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
if (obj.from != null) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
w.uint32(10)
|
|
103
|
+
w.bytes(obj.from)
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
if (obj.data != null) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
w.uint32(18)
|
|
108
|
+
w.bytes(obj.data)
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
if (obj.sequenceNumber != null) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
w.uint32(26)
|
|
113
|
+
w.bytes(obj.sequenceNumber)
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
if (obj.topic != null) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
w.uint32(34)
|
|
118
|
+
w.string(obj.topic)
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
if (obj.signature != null) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
w.uint32(42)
|
|
123
|
+
w.bytes(obj.signature)
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
if (obj.key != null) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
w.uint32(50)
|
|
128
|
+
w.bytes(obj.key)
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
if (opts.lengthDelimited !== false) {
|
|
130
|
-
|
|
132
|
+
w.ldelim()
|
|
131
133
|
}
|
|
132
134
|
}, (reader, length) => {
|
|
133
135
|
const obj: any = {}
|
|
@@ -182,36 +184,38 @@ export namespace RPC {
|
|
|
182
184
|
|
|
183
185
|
export const codec = (): Codec<RPC> => {
|
|
184
186
|
if (_codec == null) {
|
|
185
|
-
_codec = message<RPC>((obj,
|
|
187
|
+
_codec = message<RPC>((obj, w, opts = {}) => {
|
|
186
188
|
if (opts.lengthDelimited !== false) {
|
|
187
|
-
|
|
189
|
+
w.fork()
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
if (obj.subscriptions != null) {
|
|
191
193
|
for (const value of obj.subscriptions) {
|
|
192
|
-
|
|
193
|
-
RPC.SubOpts.codec().encode(value,
|
|
194
|
+
w.uint32(10)
|
|
195
|
+
RPC.SubOpts.codec().encode(value, w, {
|
|
196
|
+
writeDefaults: true
|
|
197
|
+
})
|
|
194
198
|
}
|
|
195
|
-
} else {
|
|
196
|
-
throw new Error('Protocol error: required field "subscriptions" was not found in object')
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
if (obj.messages != null) {
|
|
200
202
|
for (const value of obj.messages) {
|
|
201
|
-
|
|
202
|
-
RPC.Message.codec().encode(value,
|
|
203
|
+
w.uint32(18)
|
|
204
|
+
RPC.Message.codec().encode(value, w, {
|
|
205
|
+
writeDefaults: true
|
|
206
|
+
})
|
|
203
207
|
}
|
|
204
|
-
} else {
|
|
205
|
-
throw new Error('Protocol error: required field "messages" was not found in object')
|
|
206
208
|
}
|
|
207
209
|
|
|
208
210
|
if (obj.control != null) {
|
|
209
|
-
|
|
210
|
-
ControlMessage.codec().encode(obj.control,
|
|
211
|
+
w.uint32(26)
|
|
212
|
+
ControlMessage.codec().encode(obj.control, w, {
|
|
213
|
+
writeDefaults: false
|
|
214
|
+
})
|
|
211
215
|
}
|
|
212
216
|
|
|
213
217
|
if (opts.lengthDelimited !== false) {
|
|
214
|
-
|
|
218
|
+
w.ldelim()
|
|
215
219
|
}
|
|
216
220
|
}, (reader, length) => {
|
|
217
221
|
const obj: any = {
|
|
@@ -268,49 +272,49 @@ export namespace ControlMessage {
|
|
|
268
272
|
|
|
269
273
|
export const codec = (): Codec<ControlMessage> => {
|
|
270
274
|
if (_codec == null) {
|
|
271
|
-
_codec = message<ControlMessage>((obj,
|
|
275
|
+
_codec = message<ControlMessage>((obj, w, opts = {}) => {
|
|
272
276
|
if (opts.lengthDelimited !== false) {
|
|
273
|
-
|
|
277
|
+
w.fork()
|
|
274
278
|
}
|
|
275
279
|
|
|
276
280
|
if (obj.ihave != null) {
|
|
277
281
|
for (const value of obj.ihave) {
|
|
278
|
-
|
|
279
|
-
ControlIHave.codec().encode(value,
|
|
282
|
+
w.uint32(10)
|
|
283
|
+
ControlIHave.codec().encode(value, w, {
|
|
284
|
+
writeDefaults: true
|
|
285
|
+
})
|
|
280
286
|
}
|
|
281
|
-
} else {
|
|
282
|
-
throw new Error('Protocol error: required field "ihave" was not found in object')
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
if (obj.iwant != null) {
|
|
286
290
|
for (const value of obj.iwant) {
|
|
287
|
-
|
|
288
|
-
ControlIWant.codec().encode(value,
|
|
291
|
+
w.uint32(18)
|
|
292
|
+
ControlIWant.codec().encode(value, w, {
|
|
293
|
+
writeDefaults: true
|
|
294
|
+
})
|
|
289
295
|
}
|
|
290
|
-
} else {
|
|
291
|
-
throw new Error('Protocol error: required field "iwant" was not found in object')
|
|
292
296
|
}
|
|
293
297
|
|
|
294
298
|
if (obj.graft != null) {
|
|
295
299
|
for (const value of obj.graft) {
|
|
296
|
-
|
|
297
|
-
ControlGraft.codec().encode(value,
|
|
300
|
+
w.uint32(26)
|
|
301
|
+
ControlGraft.codec().encode(value, w, {
|
|
302
|
+
writeDefaults: true
|
|
303
|
+
})
|
|
298
304
|
}
|
|
299
|
-
} else {
|
|
300
|
-
throw new Error('Protocol error: required field "graft" was not found in object')
|
|
301
305
|
}
|
|
302
306
|
|
|
303
307
|
if (obj.prune != null) {
|
|
304
308
|
for (const value of obj.prune) {
|
|
305
|
-
|
|
306
|
-
ControlPrune.codec().encode(value,
|
|
309
|
+
w.uint32(34)
|
|
310
|
+
ControlPrune.codec().encode(value, w, {
|
|
311
|
+
writeDefaults: true
|
|
312
|
+
})
|
|
307
313
|
}
|
|
308
|
-
} else {
|
|
309
|
-
throw new Error('Protocol error: required field "prune" was not found in object')
|
|
310
314
|
}
|
|
311
315
|
|
|
312
316
|
if (opts.lengthDelimited !== false) {
|
|
313
|
-
|
|
317
|
+
w.ldelim()
|
|
314
318
|
}
|
|
315
319
|
}, (reader, length) => {
|
|
316
320
|
const obj: any = {
|
|
@@ -370,27 +374,25 @@ export namespace ControlIHave {
|
|
|
370
374
|
|
|
371
375
|
export const codec = (): Codec<ControlIHave> => {
|
|
372
376
|
if (_codec == null) {
|
|
373
|
-
_codec = message<ControlIHave>((obj,
|
|
377
|
+
_codec = message<ControlIHave>((obj, w, opts = {}) => {
|
|
374
378
|
if (opts.lengthDelimited !== false) {
|
|
375
|
-
|
|
379
|
+
w.fork()
|
|
376
380
|
}
|
|
377
381
|
|
|
378
382
|
if (obj.topic != null) {
|
|
379
|
-
|
|
380
|
-
|
|
383
|
+
w.uint32(10)
|
|
384
|
+
w.string(obj.topic)
|
|
381
385
|
}
|
|
382
386
|
|
|
383
387
|
if (obj.messageIDs != null) {
|
|
384
388
|
for (const value of obj.messageIDs) {
|
|
385
|
-
|
|
386
|
-
|
|
389
|
+
w.uint32(18)
|
|
390
|
+
w.bytes(value)
|
|
387
391
|
}
|
|
388
|
-
} else {
|
|
389
|
-
throw new Error('Protocol error: required field "messageIDs" was not found in object')
|
|
390
392
|
}
|
|
391
393
|
|
|
392
394
|
if (opts.lengthDelimited !== false) {
|
|
393
|
-
|
|
395
|
+
w.ldelim()
|
|
394
396
|
}
|
|
395
397
|
}, (reader, length) => {
|
|
396
398
|
const obj: any = {
|
|
@@ -440,22 +442,20 @@ export namespace ControlIWant {
|
|
|
440
442
|
|
|
441
443
|
export const codec = (): Codec<ControlIWant> => {
|
|
442
444
|
if (_codec == null) {
|
|
443
|
-
_codec = message<ControlIWant>((obj,
|
|
445
|
+
_codec = message<ControlIWant>((obj, w, opts = {}) => {
|
|
444
446
|
if (opts.lengthDelimited !== false) {
|
|
445
|
-
|
|
447
|
+
w.fork()
|
|
446
448
|
}
|
|
447
449
|
|
|
448
450
|
if (obj.messageIDs != null) {
|
|
449
451
|
for (const value of obj.messageIDs) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
+
w.uint32(10)
|
|
453
|
+
w.bytes(value)
|
|
452
454
|
}
|
|
453
|
-
} else {
|
|
454
|
-
throw new Error('Protocol error: required field "messageIDs" was not found in object')
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
if (opts.lengthDelimited !== false) {
|
|
458
|
-
|
|
458
|
+
w.ldelim()
|
|
459
459
|
}
|
|
460
460
|
}, (reader, length) => {
|
|
461
461
|
const obj: any = {
|
|
@@ -502,18 +502,18 @@ export namespace ControlGraft {
|
|
|
502
502
|
|
|
503
503
|
export const codec = (): Codec<ControlGraft> => {
|
|
504
504
|
if (_codec == null) {
|
|
505
|
-
_codec = message<ControlGraft>((obj,
|
|
505
|
+
_codec = message<ControlGraft>((obj, w, opts = {}) => {
|
|
506
506
|
if (opts.lengthDelimited !== false) {
|
|
507
|
-
|
|
507
|
+
w.fork()
|
|
508
508
|
}
|
|
509
509
|
|
|
510
510
|
if (obj.topic != null) {
|
|
511
|
-
|
|
512
|
-
|
|
511
|
+
w.uint32(10)
|
|
512
|
+
w.string(obj.topic)
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
if (opts.lengthDelimited !== false) {
|
|
516
|
-
|
|
516
|
+
w.ldelim()
|
|
517
517
|
}
|
|
518
518
|
}, (reader, length) => {
|
|
519
519
|
const obj: any = {}
|
|
@@ -560,32 +560,32 @@ export namespace ControlPrune {
|
|
|
560
560
|
|
|
561
561
|
export const codec = (): Codec<ControlPrune> => {
|
|
562
562
|
if (_codec == null) {
|
|
563
|
-
_codec = message<ControlPrune>((obj,
|
|
563
|
+
_codec = message<ControlPrune>((obj, w, opts = {}) => {
|
|
564
564
|
if (opts.lengthDelimited !== false) {
|
|
565
|
-
|
|
565
|
+
w.fork()
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
if (obj.topic != null) {
|
|
569
|
-
|
|
570
|
-
|
|
569
|
+
w.uint32(10)
|
|
570
|
+
w.string(obj.topic)
|
|
571
571
|
}
|
|
572
572
|
|
|
573
573
|
if (obj.peers != null) {
|
|
574
574
|
for (const value of obj.peers) {
|
|
575
|
-
|
|
576
|
-
PeerInfo.codec().encode(value,
|
|
575
|
+
w.uint32(18)
|
|
576
|
+
PeerInfo.codec().encode(value, w, {
|
|
577
|
+
writeDefaults: true
|
|
578
|
+
})
|
|
577
579
|
}
|
|
578
|
-
} else {
|
|
579
|
-
throw new Error('Protocol error: required field "peers" was not found in object')
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
if (obj.backoff != null) {
|
|
583
|
-
|
|
584
|
-
|
|
583
|
+
w.uint32(24)
|
|
584
|
+
w.uint64(obj.backoff)
|
|
585
585
|
}
|
|
586
586
|
|
|
587
587
|
if (opts.lengthDelimited !== false) {
|
|
588
|
-
|
|
588
|
+
w.ldelim()
|
|
589
589
|
}
|
|
590
590
|
}, (reader, length) => {
|
|
591
591
|
const obj: any = {
|
|
@@ -639,23 +639,23 @@ export namespace PeerInfo {
|
|
|
639
639
|
|
|
640
640
|
export const codec = (): Codec<PeerInfo> => {
|
|
641
641
|
if (_codec == null) {
|
|
642
|
-
_codec = message<PeerInfo>((obj,
|
|
642
|
+
_codec = message<PeerInfo>((obj, w, opts = {}) => {
|
|
643
643
|
if (opts.lengthDelimited !== false) {
|
|
644
|
-
|
|
644
|
+
w.fork()
|
|
645
645
|
}
|
|
646
646
|
|
|
647
647
|
if (obj.peerID != null) {
|
|
648
|
-
|
|
649
|
-
|
|
648
|
+
w.uint32(10)
|
|
649
|
+
w.bytes(obj.peerID)
|
|
650
650
|
}
|
|
651
651
|
|
|
652
652
|
if (obj.signedPeerRecord != null) {
|
|
653
|
-
|
|
654
|
-
|
|
653
|
+
w.uint32(18)
|
|
654
|
+
w.bytes(obj.signedPeerRecord)
|
|
655
655
|
}
|
|
656
656
|
|
|
657
657
|
if (opts.lengthDelimited !== false) {
|
|
658
|
-
|
|
658
|
+
w.ldelim()
|
|
659
659
|
}
|
|
660
660
|
}, (reader, length) => {
|
|
661
661
|
const obj: any = {}
|