@libp2p/autonat-v2 2.0.13 → 2.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/autonat-v2",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "description": "Implementation of the AutoNAT Protocol v2",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat-v2#readme",
@@ -45,28 +45,28 @@
45
45
  "doc-check": "aegir doc-check"
46
46
  },
47
47
  "dependencies": {
48
- "@libp2p/interface": "^3.1.0",
49
- "@libp2p/interface-internal": "^3.0.13",
50
- "@libp2p/peer-collections": "^7.0.13",
51
- "@libp2p/utils": "^7.0.13",
48
+ "@libp2p/interface": "^3.1.1",
49
+ "@libp2p/interface-internal": "^3.0.14",
50
+ "@libp2p/peer-collections": "^7.0.14",
51
+ "@libp2p/utils": "^7.0.14",
52
52
  "@multiformats/multiaddr": "^13.0.1",
53
53
  "any-signal": "^4.1.1",
54
54
  "main-event": "^1.0.1",
55
- "protons-runtime": "^5.6.0",
55
+ "protons-runtime": "^6.0.1",
56
56
  "uint8arraylist": "^2.4.8",
57
57
  "uint8arrays": "^5.1.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@libp2p/crypto": "^5.1.13",
61
- "@libp2p/logger": "^6.2.2",
62
- "@libp2p/peer-id": "^6.0.4",
60
+ "@libp2p/crypto": "^5.1.14",
61
+ "@libp2p/logger": "^6.2.3",
62
+ "@libp2p/peer-id": "^6.0.5",
63
63
  "aegir": "^47.0.22",
64
64
  "delay": "^7.0.0",
65
65
  "it-all": "^3.0.9",
66
66
  "it-length-prefixed": "^10.0.1",
67
67
  "it-pipe": "^3.0.1",
68
68
  "p-retry": "^7.0.0",
69
- "protons": "^7.7.0",
69
+ "protons": "^8.1.1",
70
70
  "sinon": "^21.0.0",
71
71
  "sinon-ts": "^2.0.0"
72
72
  },
package/src/pb/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { decodeMessage, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime'
1
+ import { decodeMessage, encodeMessage, enumeration, MaxLengthError, message, streamMessage } from 'protons-runtime'
2
2
  import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc'
3
3
  import type { Codec, DecodeOptions } from 'protons-runtime'
4
4
  import type { Uint8ArrayList } from 'uint8arraylist'
@@ -134,19 +134,105 @@ export namespace Message {
134
134
  }
135
135
 
136
136
  return obj
137
+ }, function * (reader, length, prefix, opts = {}) {
138
+ const end = length == null ? reader.len : reader.pos + length
139
+
140
+ while (reader.pos < end) {
141
+ const tag = reader.uint32()
142
+
143
+ switch (tag >>> 3) {
144
+ case 1: {
145
+ yield * DialRequest.codec().stream(reader, reader.uint32(), `${prefix}.dialRequest`, {
146
+ limits: opts.limits?.dialRequest
147
+ })
148
+
149
+ break
150
+ }
151
+ case 2: {
152
+ yield * DialResponse.codec().stream(reader, reader.uint32(), `${prefix}.dialResponse`, {
153
+ limits: opts.limits?.dialResponse
154
+ })
155
+
156
+ break
157
+ }
158
+ case 3: {
159
+ yield * DialDataRequest.codec().stream(reader, reader.uint32(), `${prefix}.dialDataRequest`, {
160
+ limits: opts.limits?.dialDataRequest
161
+ })
162
+
163
+ break
164
+ }
165
+ case 4: {
166
+ yield * DialDataResponse.codec().stream(reader, reader.uint32(), `${prefix}.dialDataResponse`, {
167
+ limits: opts.limits?.dialDataResponse
168
+ })
169
+
170
+ break
171
+ }
172
+ default: {
173
+ reader.skipType(tag & 7)
174
+ break
175
+ }
176
+ }
177
+ }
137
178
  })
138
179
  }
139
180
 
140
181
  return _codec
141
182
  }
142
183
 
143
- export const encode = (obj: Partial<Message>): Uint8Array => {
184
+ export interface MessageDialRequestAddrsFieldEvent {
185
+ field: '$.dialRequest.addrs[]'
186
+ index: number
187
+ value: Uint8Array
188
+ }
189
+
190
+ export interface MessageDialRequestNonceFieldEvent {
191
+ field: '$.dialRequest.nonce'
192
+ value: bigint
193
+ }
194
+
195
+ export interface MessageDialResponseStatusFieldEvent {
196
+ field: '$.dialResponse.status'
197
+ value: DialResponse.ResponseStatus
198
+ }
199
+
200
+ export interface MessageDialResponseAddrIdxFieldEvent {
201
+ field: '$.dialResponse.addrIdx'
202
+ value: number
203
+ }
204
+
205
+ export interface MessageDialResponseDialStatusFieldEvent {
206
+ field: '$.dialResponse.dialStatus'
207
+ value: DialStatus
208
+ }
209
+
210
+ export interface MessageDialDataRequestAddrIdxFieldEvent {
211
+ field: '$.dialDataRequest.addrIdx'
212
+ value: number
213
+ }
214
+
215
+ export interface MessageDialDataRequestNumBytesFieldEvent {
216
+ field: '$.dialDataRequest.numBytes'
217
+ value: bigint
218
+ }
219
+
220
+ export interface MessageDialDataResponseDataFieldEvent {
221
+ field: '$.dialDataResponse.data'
222
+ value: Uint8Array
223
+ }
224
+
225
+ export function encode (obj: Partial<Message>): Uint8Array {
144
226
  return encodeMessage(obj, Message.codec())
145
227
  }
146
228
 
147
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message => {
229
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Message {
148
230
  return decodeMessage(buf, Message.codec(), opts)
149
231
  }
232
+
233
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Message>): Generator<MessageDialRequestAddrsFieldEvent | MessageDialRequestNonceFieldEvent | MessageDialResponseStatusFieldEvent | MessageDialResponseAddrIdxFieldEvent | MessageDialResponseDialStatusFieldEvent | MessageDialDataRequestAddrIdxFieldEvent | MessageDialDataRequestNumBytesFieldEvent | MessageDialDataResponseDataFieldEvent> {
234
+ return streamMessage(buf, Message.codec(), opts)
235
+ }
150
236
  }
151
237
 
152
238
  export interface DialRequest {
@@ -164,7 +250,7 @@ export namespace DialRequest {
164
250
  w.fork()
165
251
  }
166
252
 
167
- if (obj.addrs != null) {
253
+ if (obj.addrs != null && obj.addrs.length > 0) {
168
254
  for (const value of obj.addrs) {
169
255
  w.uint32(10)
170
256
  w.bytes(value)
@@ -193,7 +279,7 @@ export namespace DialRequest {
193
279
  switch (tag >>> 3) {
194
280
  case 1: {
195
281
  if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) {
196
- throw new MaxLengthError('Decode error - map field "addrs" had too many elements')
282
+ throw new MaxLengthError('Decode error - repeated field "addrs" had too many elements')
197
283
  }
198
284
 
199
285
  obj.addrs.push(reader.bytes())
@@ -211,19 +297,73 @@ export namespace DialRequest {
211
297
  }
212
298
 
213
299
  return obj
300
+ }, function * (reader, length, prefix, opts = {}) {
301
+ const obj = {
302
+ addrs: 0
303
+ }
304
+
305
+ const end = length == null ? reader.len : reader.pos + length
306
+
307
+ while (reader.pos < end) {
308
+ const tag = reader.uint32()
309
+
310
+ switch (tag >>> 3) {
311
+ case 1: {
312
+ if (opts.limits?.addrs != null && obj.addrs === opts.limits.addrs) {
313
+ throw new MaxLengthError('Streaming decode error - repeated field "addrs" had too many elements')
314
+ }
315
+
316
+ yield {
317
+ field: `${prefix}.addrs[]`,
318
+ index: obj.addrs,
319
+ value: reader.bytes()
320
+ }
321
+
322
+ obj.addrs++
323
+
324
+ break
325
+ }
326
+ case 2: {
327
+ yield {
328
+ field: `${prefix}.nonce`,
329
+ value: reader.fixed64()
330
+ }
331
+ break
332
+ }
333
+ default: {
334
+ reader.skipType(tag & 7)
335
+ break
336
+ }
337
+ }
338
+ }
214
339
  })
215
340
  }
216
341
 
217
342
  return _codec
218
343
  }
219
344
 
220
- export const encode = (obj: Partial<DialRequest>): Uint8Array => {
345
+ export interface DialRequestAddrsFieldEvent {
346
+ field: '$.addrs[]'
347
+ index: number
348
+ value: Uint8Array
349
+ }
350
+
351
+ export interface DialRequestNonceFieldEvent {
352
+ field: '$.nonce'
353
+ value: bigint
354
+ }
355
+
356
+ export function encode (obj: Partial<DialRequest>): Uint8Array {
221
357
  return encodeMessage(obj, DialRequest.codec())
222
358
  }
223
359
 
224
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialRequest>): DialRequest => {
360
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialRequest>): DialRequest {
225
361
  return decodeMessage(buf, DialRequest.codec(), opts)
226
362
  }
363
+
364
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialRequest>): Generator<DialRequestAddrsFieldEvent | DialRequestNonceFieldEvent> {
365
+ return streamMessage(buf, DialRequest.codec(), opts)
366
+ }
227
367
  }
228
368
 
229
369
  export interface DialDataRequest {
@@ -282,19 +422,60 @@ export namespace DialDataRequest {
282
422
  }
283
423
 
284
424
  return obj
425
+ }, function * (reader, length, prefix, opts = {}) {
426
+ const end = length == null ? reader.len : reader.pos + length
427
+
428
+ while (reader.pos < end) {
429
+ const tag = reader.uint32()
430
+
431
+ switch (tag >>> 3) {
432
+ case 1: {
433
+ yield {
434
+ field: `${prefix}.addrIdx`,
435
+ value: reader.uint32()
436
+ }
437
+ break
438
+ }
439
+ case 2: {
440
+ yield {
441
+ field: `${prefix}.numBytes`,
442
+ value: reader.uint64()
443
+ }
444
+ break
445
+ }
446
+ default: {
447
+ reader.skipType(tag & 7)
448
+ break
449
+ }
450
+ }
451
+ }
285
452
  })
286
453
  }
287
454
 
288
455
  return _codec
289
456
  }
290
457
 
291
- export const encode = (obj: Partial<DialDataRequest>): Uint8Array => {
458
+ export interface DialDataRequestAddrIdxFieldEvent {
459
+ field: '$.addrIdx'
460
+ value: number
461
+ }
462
+
463
+ export interface DialDataRequestNumBytesFieldEvent {
464
+ field: '$.numBytes'
465
+ value: bigint
466
+ }
467
+
468
+ export function encode (obj: Partial<DialDataRequest>): Uint8Array {
292
469
  return encodeMessage(obj, DialDataRequest.codec())
293
470
  }
294
471
 
295
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataRequest>): DialDataRequest => {
472
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataRequest>): DialDataRequest {
296
473
  return decodeMessage(buf, DialDataRequest.codec(), opts)
297
474
  }
475
+
476
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataRequest>): Generator<DialDataRequestAddrIdxFieldEvent | DialDataRequestNumBytesFieldEvent> {
477
+ return streamMessage(buf, DialDataRequest.codec(), opts)
478
+ }
298
479
  }
299
480
 
300
481
  export enum DialStatus {
@@ -404,19 +585,72 @@ export namespace DialResponse {
404
585
  }
405
586
 
406
587
  return obj
588
+ }, function * (reader, length, prefix, opts = {}) {
589
+ const end = length == null ? reader.len : reader.pos + length
590
+
591
+ while (reader.pos < end) {
592
+ const tag = reader.uint32()
593
+
594
+ switch (tag >>> 3) {
595
+ case 1: {
596
+ yield {
597
+ field: `${prefix}.status`,
598
+ value: DialResponse.ResponseStatus.codec().decode(reader)
599
+ }
600
+ break
601
+ }
602
+ case 2: {
603
+ yield {
604
+ field: `${prefix}.addrIdx`,
605
+ value: reader.uint32()
606
+ }
607
+ break
608
+ }
609
+ case 3: {
610
+ yield {
611
+ field: `${prefix}.dialStatus`,
612
+ value: DialStatus.codec().decode(reader)
613
+ }
614
+ break
615
+ }
616
+ default: {
617
+ reader.skipType(tag & 7)
618
+ break
619
+ }
620
+ }
621
+ }
407
622
  })
408
623
  }
409
624
 
410
625
  return _codec
411
626
  }
412
627
 
413
- export const encode = (obj: Partial<DialResponse>): Uint8Array => {
628
+ export interface DialResponseStatusFieldEvent {
629
+ field: '$.status'
630
+ value: DialResponse.ResponseStatus
631
+ }
632
+
633
+ export interface DialResponseAddrIdxFieldEvent {
634
+ field: '$.addrIdx'
635
+ value: number
636
+ }
637
+
638
+ export interface DialResponseDialStatusFieldEvent {
639
+ field: '$.dialStatus'
640
+ value: DialStatus
641
+ }
642
+
643
+ export function encode (obj: Partial<DialResponse>): Uint8Array {
414
644
  return encodeMessage(obj, DialResponse.codec())
415
645
  }
416
646
 
417
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialResponse>): DialResponse => {
647
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialResponse>): DialResponse {
418
648
  return decodeMessage(buf, DialResponse.codec(), opts)
419
649
  }
650
+
651
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialResponse>): Generator<DialResponseStatusFieldEvent | DialResponseAddrIdxFieldEvent | DialResponseDialStatusFieldEvent> {
652
+ return streamMessage(buf, DialResponse.codec(), opts)
653
+ }
420
654
  }
421
655
 
422
656
  export interface DialDataResponse {
@@ -464,19 +698,48 @@ export namespace DialDataResponse {
464
698
  }
465
699
 
466
700
  return obj
701
+ }, function * (reader, length, prefix, opts = {}) {
702
+ const end = length == null ? reader.len : reader.pos + length
703
+
704
+ while (reader.pos < end) {
705
+ const tag = reader.uint32()
706
+
707
+ switch (tag >>> 3) {
708
+ case 1: {
709
+ yield {
710
+ field: `${prefix}.data`,
711
+ value: reader.bytes()
712
+ }
713
+ break
714
+ }
715
+ default: {
716
+ reader.skipType(tag & 7)
717
+ break
718
+ }
719
+ }
720
+ }
467
721
  })
468
722
  }
469
723
 
470
724
  return _codec
471
725
  }
472
726
 
473
- export const encode = (obj: Partial<DialDataResponse>): Uint8Array => {
727
+ export interface DialDataResponseDataFieldEvent {
728
+ field: '$.data'
729
+ value: Uint8Array
730
+ }
731
+
732
+ export function encode (obj: Partial<DialDataResponse>): Uint8Array {
474
733
  return encodeMessage(obj, DialDataResponse.codec())
475
734
  }
476
735
 
477
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataResponse>): DialDataResponse => {
736
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataResponse>): DialDataResponse {
478
737
  return decodeMessage(buf, DialDataResponse.codec(), opts)
479
738
  }
739
+
740
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialDataResponse>): Generator<DialDataResponseDataFieldEvent> {
741
+ return streamMessage(buf, DialDataResponse.codec(), opts)
742
+ }
480
743
  }
481
744
 
482
745
  export interface DialBack {
@@ -524,19 +787,48 @@ export namespace DialBack {
524
787
  }
525
788
 
526
789
  return obj
790
+ }, function * (reader, length, prefix, opts = {}) {
791
+ const end = length == null ? reader.len : reader.pos + length
792
+
793
+ while (reader.pos < end) {
794
+ const tag = reader.uint32()
795
+
796
+ switch (tag >>> 3) {
797
+ case 1: {
798
+ yield {
799
+ field: `${prefix}.nonce`,
800
+ value: reader.fixed64()
801
+ }
802
+ break
803
+ }
804
+ default: {
805
+ reader.skipType(tag & 7)
806
+ break
807
+ }
808
+ }
809
+ }
527
810
  })
528
811
  }
529
812
 
530
813
  return _codec
531
814
  }
532
815
 
533
- export const encode = (obj: Partial<DialBack>): Uint8Array => {
816
+ export interface DialBackNonceFieldEvent {
817
+ field: '$.nonce'
818
+ value: bigint
819
+ }
820
+
821
+ export function encode (obj: Partial<DialBack>): Uint8Array {
534
822
  return encodeMessage(obj, DialBack.codec())
535
823
  }
536
824
 
537
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBack>): DialBack => {
825
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBack>): DialBack {
538
826
  return decodeMessage(buf, DialBack.codec(), opts)
539
827
  }
828
+
829
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBack>): Generator<DialBackNonceFieldEvent> {
830
+ return streamMessage(buf, DialBack.codec(), opts)
831
+ }
540
832
  }
541
833
 
542
834
  export interface DialBackResponse {
@@ -598,17 +890,46 @@ export namespace DialBackResponse {
598
890
  }
599
891
 
600
892
  return obj
893
+ }, function * (reader, length, prefix, opts = {}) {
894
+ const end = length == null ? reader.len : reader.pos + length
895
+
896
+ while (reader.pos < end) {
897
+ const tag = reader.uint32()
898
+
899
+ switch (tag >>> 3) {
900
+ case 1: {
901
+ yield {
902
+ field: `${prefix}.status`,
903
+ value: DialBackResponse.DialBackStatus.codec().decode(reader)
904
+ }
905
+ break
906
+ }
907
+ default: {
908
+ reader.skipType(tag & 7)
909
+ break
910
+ }
911
+ }
912
+ }
601
913
  })
602
914
  }
603
915
 
604
916
  return _codec
605
917
  }
606
918
 
607
- export const encode = (obj: Partial<DialBackResponse>): Uint8Array => {
919
+ export interface DialBackResponseStatusFieldEvent {
920
+ field: '$.status'
921
+ value: DialBackResponse.DialBackStatus
922
+ }
923
+
924
+ export function encode (obj: Partial<DialBackResponse>): Uint8Array {
608
925
  return encodeMessage(obj, DialBackResponse.codec())
609
926
  }
610
927
 
611
- export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBackResponse>): DialBackResponse => {
928
+ export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBackResponse>): DialBackResponse {
612
929
  return decodeMessage(buf, DialBackResponse.codec(), opts)
613
930
  }
931
+
932
+ export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<DialBackResponse>): Generator<DialBackResponseStatusFieldEvent> {
933
+ return streamMessage(buf, DialBackResponse.codec(), opts)
934
+ }
614
935
  }