@libp2p/utils 6.7.1 → 6.7.2-a02cb0461

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.
Files changed (120) hide show
  1. package/README.md +16 -1
  2. package/dist/index.min.js +6 -1
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/abstract-message-stream.d.ts +129 -0
  5. package/dist/src/abstract-message-stream.d.ts.map +1 -0
  6. package/dist/src/abstract-message-stream.js +389 -0
  7. package/dist/src/abstract-message-stream.js.map +1 -0
  8. package/dist/src/abstract-multiaddr-connection.d.ts +26 -0
  9. package/dist/src/abstract-multiaddr-connection.d.ts.map +1 -0
  10. package/dist/src/abstract-multiaddr-connection.js +66 -0
  11. package/dist/src/abstract-multiaddr-connection.js.map +1 -0
  12. package/dist/src/abstract-stream-muxer.d.ts +53 -0
  13. package/dist/src/abstract-stream-muxer.d.ts.map +1 -0
  14. package/dist/src/abstract-stream-muxer.js +169 -0
  15. package/dist/src/abstract-stream-muxer.js.map +1 -0
  16. package/dist/src/abstract-stream.d.ts +14 -130
  17. package/dist/src/abstract-stream.d.ts.map +1 -1
  18. package/dist/src/abstract-stream.js +39 -321
  19. package/dist/src/abstract-stream.js.map +1 -1
  20. package/dist/src/errors.d.ts +8 -0
  21. package/dist/src/errors.d.ts.map +1 -1
  22. package/dist/src/errors.js +8 -0
  23. package/dist/src/errors.js.map +1 -1
  24. package/dist/src/index.d.ts +33 -1
  25. package/dist/src/index.d.ts.map +1 -1
  26. package/dist/src/index.js +33 -1
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/src/length-prefixed-decoder.d.ts +37 -0
  29. package/dist/src/length-prefixed-decoder.d.ts.map +1 -0
  30. package/dist/src/length-prefixed-decoder.js +64 -0
  31. package/dist/src/length-prefixed-decoder.js.map +1 -0
  32. package/dist/src/message-queue.d.ts +61 -0
  33. package/dist/src/message-queue.d.ts.map +1 -0
  34. package/dist/src/message-queue.js +93 -0
  35. package/dist/src/message-queue.js.map +1 -0
  36. package/dist/src/mock-muxer.d.ts +57 -0
  37. package/dist/src/mock-muxer.d.ts.map +1 -0
  38. package/dist/src/mock-muxer.js +204 -0
  39. package/dist/src/mock-muxer.js.map +1 -0
  40. package/dist/src/mock-stream.d.ts +31 -0
  41. package/dist/src/mock-stream.d.ts.map +1 -0
  42. package/dist/src/mock-stream.js +69 -0
  43. package/dist/src/mock-stream.js.map +1 -0
  44. package/dist/src/multiaddr/index.d.ts +7 -0
  45. package/dist/src/multiaddr/index.d.ts.map +1 -0
  46. package/dist/src/multiaddr/index.js +7 -0
  47. package/dist/src/multiaddr/index.js.map +1 -0
  48. package/dist/src/multiaddr-connection-pair.d.ts +25 -0
  49. package/dist/src/multiaddr-connection-pair.d.ts.map +1 -0
  50. package/dist/src/multiaddr-connection-pair.js +103 -0
  51. package/dist/src/multiaddr-connection-pair.js.map +1 -0
  52. package/dist/src/queue/index.d.ts +5 -0
  53. package/dist/src/queue/index.d.ts.map +1 -1
  54. package/dist/src/queue/index.js +24 -9
  55. package/dist/src/queue/index.js.map +1 -1
  56. package/dist/src/rate-limiter.d.ts +1 -15
  57. package/dist/src/rate-limiter.d.ts.map +1 -1
  58. package/dist/src/rate-limiter.js +1 -14
  59. package/dist/src/rate-limiter.js.map +1 -1
  60. package/dist/src/socket-writer.browser.d.ts +2 -0
  61. package/dist/src/socket-writer.browser.d.ts.map +1 -0
  62. package/dist/src/socket-writer.browser.js +4 -0
  63. package/dist/src/socket-writer.browser.js.map +1 -0
  64. package/dist/src/socket-writer.d.ts +19 -0
  65. package/dist/src/socket-writer.d.ts.map +1 -0
  66. package/dist/src/socket-writer.js +43 -0
  67. package/dist/src/socket-writer.js.map +1 -0
  68. package/dist/src/stream-pair.d.ts +42 -0
  69. package/dist/src/stream-pair.d.ts.map +1 -0
  70. package/dist/src/stream-pair.js +40 -0
  71. package/dist/src/stream-pair.js.map +1 -0
  72. package/dist/src/stream-utils.d.ts +199 -0
  73. package/dist/src/stream-utils.d.ts.map +1 -0
  74. package/dist/src/stream-utils.js +369 -0
  75. package/dist/src/stream-utils.js.map +1 -0
  76. package/package.json +19 -163
  77. package/src/abstract-message-stream.ts +549 -0
  78. package/src/abstract-multiaddr-connection.ts +93 -0
  79. package/src/abstract-stream-muxer.ts +239 -0
  80. package/src/abstract-stream.ts +51 -464
  81. package/src/errors.ts +10 -0
  82. package/src/index.ts +33 -1
  83. package/src/length-prefixed-decoder.ts +98 -0
  84. package/src/message-queue.ts +156 -0
  85. package/src/mock-muxer.ts +304 -0
  86. package/src/mock-stream.ts +101 -0
  87. package/src/multiaddr/index.ts +6 -0
  88. package/src/multiaddr-connection-pair.ts +147 -0
  89. package/src/queue/index.ts +30 -9
  90. package/src/rate-limiter.ts +3 -30
  91. package/src/socket-writer.browser.ts +3 -0
  92. package/src/socket-writer.ts +64 -0
  93. package/src/stream-pair.ts +90 -0
  94. package/src/stream-utils.ts +874 -0
  95. package/dist/src/abort-options.d.ts +0 -7
  96. package/dist/src/abort-options.d.ts.map +0 -1
  97. package/dist/src/abort-options.js +0 -14
  98. package/dist/src/abort-options.js.map +0 -1
  99. package/dist/src/array-equals.d.ts +0 -24
  100. package/dist/src/array-equals.d.ts.map +0 -1
  101. package/dist/src/array-equals.js +0 -31
  102. package/dist/src/array-equals.js.map +0 -1
  103. package/dist/src/close-source.d.ts +0 -4
  104. package/dist/src/close-source.d.ts.map +0 -1
  105. package/dist/src/close-source.js +0 -11
  106. package/dist/src/close-source.js.map +0 -1
  107. package/dist/src/close.d.ts +0 -21
  108. package/dist/src/close.d.ts.map +0 -1
  109. package/dist/src/close.js +0 -49
  110. package/dist/src/close.js.map +0 -1
  111. package/dist/src/stream-to-ma-conn.d.ts +0 -23
  112. package/dist/src/stream-to-ma-conn.d.ts.map +0 -1
  113. package/dist/src/stream-to-ma-conn.js +0 -75
  114. package/dist/src/stream-to-ma-conn.js.map +0 -1
  115. package/dist/typedoc-urls.json +0 -147
  116. package/src/abort-options.ts +0 -20
  117. package/src/array-equals.ts +0 -34
  118. package/src/close-source.ts +0 -14
  119. package/src/close.ts +0 -65
  120. package/src/stream-to-ma-conn.ts +0 -105
@@ -1,7 +0,0 @@
1
- import type { AbortOptions } from '@libp2p/interface';
2
- import type { ClearableSignal } from 'any-signal';
3
- export declare function createTimeoutOptions(timeout: number): AbortOptions;
4
- export declare function createTimeoutOptions(timeout: number, ...existingSignals: AbortSignal[]): {
5
- signal: ClearableSignal;
6
- };
7
- //# sourceMappingURL=abort-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abort-options.d.ts","sourceRoot":"","sources":["../../src/abort-options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,wBAAgB,oBAAoB,CAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAAA;AACpE,wBAAgB,oBAAoB,CAAE,OAAO,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE,WAAW,EAAE,GAAG;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,CAAA"}
@@ -1,14 +0,0 @@
1
- import { anySignal } from 'any-signal';
2
- import { setMaxListeners } from 'main-event';
3
- export function createTimeoutOptions(timeout, ...existingSignals) {
4
- let signal = AbortSignal.timeout(timeout);
5
- setMaxListeners(Infinity, signal);
6
- if (existingSignals.length > 0) {
7
- signal = anySignal([signal, ...existingSignals]);
8
- setMaxListeners(Infinity, signal);
9
- }
10
- return {
11
- signal
12
- };
13
- }
14
- //# sourceMappingURL=abort-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abort-options.js","sourceRoot":"","sources":["../../src/abort-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAM5C,MAAM,UAAU,oBAAoB,CAAE,OAAe,EAAE,GAAG,eAA8B;IACtF,IAAI,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACzC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAEjC,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,GAAG,SAAS,CAAC,CAAC,MAAM,EAAE,GAAG,eAAe,CAAC,CAAC,CAAA;QAChD,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,OAAO;QACL,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -1,24 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies ensure arrays are equivalent.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { arrayEquals } from '@libp2p/utils/array-equals'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
- * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
- *
15
- * console.info(arrayEquals([ma1], [ma1])) // true
16
- * console.info(arrayEquals([ma1], [ma2])) // false
17
- * ```
18
- */
19
- /**
20
- * Verify if two arrays of non primitive types with the "equals" function are equal.
21
- * Compatible with multiaddr, peer-id and others.
22
- */
23
- export declare function arrayEquals(a: any[], b: any[]): boolean;
24
- //# sourceMappingURL=array-equals.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array-equals.d.ts","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,wBAAgB,WAAW,CAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAUxD"}
@@ -1,31 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies ensure arrays are equivalent.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { arrayEquals } from '@libp2p/utils/array-equals'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
- * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
- *
15
- * console.info(arrayEquals([ma1], [ma1])) // true
16
- * console.info(arrayEquals([ma1], [ma2])) // false
17
- * ```
18
- */
19
- /**
20
- * Verify if two arrays of non primitive types with the "equals" function are equal.
21
- * Compatible with multiaddr, peer-id and others.
22
- */
23
- export function arrayEquals(a, b) {
24
- const sort = (a, b) => a.toString().localeCompare(b.toString());
25
- if (a.length !== b.length) {
26
- return false;
27
- }
28
- b.sort(sort);
29
- return a.sort(sort).every((item, index) => b[index].equals(item));
30
- }
31
- //# sourceMappingURL=array-equals.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array-equals.js","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,CAAQ,EAAE,CAAQ;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAM,EAAE,CAAM,EAAU,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEjF,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEZ,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AACnE,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { Logger } from '@libp2p/logger';
2
- import type { Source } from 'it-stream-types';
3
- export declare function closeSource(source: Source<unknown>, log: Logger): void;
4
- //# sourceMappingURL=close-source.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"close-source.d.ts","sourceRoot":"","sources":["../../src/close-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAE7C,wBAAgB,WAAW,CAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAQvE"}
@@ -1,11 +0,0 @@
1
- import { getIterator } from 'get-iterator';
2
- import { isPromise } from './is-promise.js';
3
- export function closeSource(source, log) {
4
- const res = getIterator(source).return?.();
5
- if (isPromise(res)) {
6
- res.catch(err => {
7
- log.error('could not cause iterator to return', err);
8
- });
9
- }
10
- }
11
- //# sourceMappingURL=close-source.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"close-source.js","sourceRoot":"","sources":["../../src/close-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAI3C,MAAM,UAAU,WAAW,CAAE,MAAuB,EAAE,GAAW;IAC/D,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAA;IAE1C,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YACd,GAAG,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
@@ -1,21 +0,0 @@
1
- import type { Connection, Stream, AbortOptions } from '@libp2p/interface';
2
- /**
3
- * Close the passed stream, falling back to aborting the stream if closing
4
- * cleanly fails.
5
- */
6
- export declare function safelyCloseStream(stream?: Stream, options?: AbortOptions): Promise<void>;
7
- export interface SafelyCloseConnectionOptions extends AbortOptions {
8
- /**
9
- * Only close the stream if it either has no protocol streams open or only
10
- * ones in this list.
11
- *
12
- * @default ['/ipfs/id/1.0.0']
13
- */
14
- closableProtocols?: string[];
15
- }
16
- /**
17
- * Close the passed connection if it has no streams, or only closable protocol
18
- * streams, falling back to aborting the connection if closing it cleanly fails.
19
- */
20
- export declare function safelyCloseConnectionIfUnused(connection?: Connection, options?: SafelyCloseConnectionOptions): Promise<void>;
21
- //# sourceMappingURL=close.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"close.d.ts","sourceRoot":"","sources":["../../src/close.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEzE;;;GAGG;AACH,wBAAsB,iBAAiB,CAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAM/F;AAuBD,MAAM,WAAW,4BAA6B,SAAQ,YAAY;IAChE;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED;;;GAGG;AACH,wBAAsB,6BAA6B,CAAE,UAAU,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAenI"}
package/dist/src/close.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Close the passed stream, falling back to aborting the stream if closing
3
- * cleanly fails.
4
- */
5
- export async function safelyCloseStream(stream, options) {
6
- try {
7
- await stream?.close(options);
8
- }
9
- catch (err) {
10
- stream?.abort(err);
11
- }
12
- }
13
- /**
14
- * These are speculative protocols that are run automatically on connection open
15
- * so are usually not the reason the connection was opened.
16
- *
17
- * Consequently when requested it should be safe to close connections that only
18
- * have these protocol streams open.
19
- */
20
- const DEFAULT_CLOSABLE_PROTOCOLS = [
21
- // identify
22
- '/ipfs/id/1.0.0',
23
- // identify-push
24
- '/ipfs/id/push/1.0.0',
25
- // autonat
26
- '/libp2p/autonat/1.0.0',
27
- // dcutr
28
- '/libp2p/dcutr'
29
- ];
30
- /**
31
- * Close the passed connection if it has no streams, or only closable protocol
32
- * streams, falling back to aborting the connection if closing it cleanly fails.
33
- */
34
- export async function safelyCloseConnectionIfUnused(connection, options) {
35
- const streamProtocols = connection?.streams?.map(stream => stream.protocol) ?? [];
36
- const closableProtocols = options?.closableProtocols ?? DEFAULT_CLOSABLE_PROTOCOLS;
37
- // if the connection has protocols not in the closable protocols list, do not
38
- // close the connection
39
- if (streamProtocols.filter(proto => proto != null && !closableProtocols.includes(proto)).length > 0) {
40
- return;
41
- }
42
- try {
43
- await connection?.close(options);
44
- }
45
- catch (err) {
46
- connection?.abort(err);
47
- }
48
- }
49
- //# sourceMappingURL=close.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"close.js","sourceRoot":"","sources":["../../src/close.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAE,MAAe,EAAE,OAAsB;IAC9E,IAAI,CAAC;QACH,MAAM,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACpB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;IACjC,WAAW;IACX,gBAAgB;IAEhB,gBAAgB;IAChB,qBAAqB;IAErB,UAAU;IACV,uBAAuB;IAEvB,QAAQ;IACR,eAAe;CAChB,CAAA;AAYD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAAE,UAAuB,EAAE,OAAsC;IAClH,MAAM,eAAe,GAAG,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IACjF,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,0BAA0B,CAAA;IAElF,6EAA6E;IAC7E,uBAAuB;IACvB,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpG,OAAM;IACR,CAAC;IAED,IAAI,CAAC;QACH,MAAM,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,UAAU,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;AACH,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { ComponentLogger, MultiaddrConnection, Stream } from '@libp2p/interface';
2
- import type { Multiaddr } from '@multiformats/multiaddr';
3
- import type { Uint8ArrayList } from 'uint8arraylist';
4
- export interface StreamProperties {
5
- stream: Stream;
6
- remoteAddr: Multiaddr;
7
- localAddr: Multiaddr;
8
- logger: ComponentLogger;
9
- /**
10
- * A callback invoked when data is read from the stream
11
- */
12
- onDataRead?(buf: Uint8ArrayList | Uint8Array): void;
13
- /**
14
- * A callback invoked when data is written to the stream
15
- */
16
- onDataWrite?(buf: Uint8ArrayList | Uint8Array): void;
17
- }
18
- /**
19
- * Convert a duplex iterable into a MultiaddrConnection.
20
- * https://github.com/libp2p/interface-transport#multiaddrconnection
21
- */
22
- export declare function streamToMaConnection(props: StreamProperties): MultiaddrConnection;
23
- //# sourceMappingURL=stream-to-ma-conn.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,eAAe,CAAA;IAEvB;;OAEG;IACH,UAAU,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,IAAI,CAAA;IAEnD;;OAEG;IACH,WAAW,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,IAAI,CAAA;CACrD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CA6ElF"}
@@ -1,75 +0,0 @@
1
- import forEach from 'it-foreach';
2
- import { pipe } from 'it-pipe';
3
- /**
4
- * Convert a duplex iterable into a MultiaddrConnection.
5
- * https://github.com/libp2p/interface-transport#multiaddrconnection
6
- */
7
- export function streamToMaConnection(props) {
8
- const { stream, remoteAddr, logger, onDataRead, onDataWrite } = props;
9
- const log = logger.forComponent('libp2p:stream:converter');
10
- let closedRead = false;
11
- let closedWrite = false;
12
- // piggyback on `stream.close` invocations to close multiaddr connection
13
- const streamClose = stream.close.bind(stream);
14
- stream.close = async (options) => {
15
- await streamClose(options);
16
- close(true);
17
- };
18
- // piggyback on `stream.abort` invocations to close multiaddr connection
19
- const streamAbort = stream.abort.bind(stream);
20
- stream.abort = (err) => {
21
- streamAbort(err);
22
- close(true);
23
- };
24
- // piggyback on `stream.sink` invocations to close multiaddr connection
25
- const streamSink = stream.sink.bind(stream);
26
- stream.sink = async (source) => {
27
- try {
28
- await streamSink(pipe(source, (source) => forEach(source, buf => onDataWrite?.(buf))));
29
- }
30
- catch (err) {
31
- // If aborted we can safely ignore
32
- if (err.type !== 'aborted') {
33
- // If the source errored the socket will already have been destroyed by
34
- // toIterable.duplex(). If the socket errored it will already be
35
- // destroyed. There's nothing to do here except log the error & return.
36
- log.error('%s error in sink', remoteAddr, err);
37
- }
38
- }
39
- finally {
40
- closedWrite = true;
41
- close();
42
- }
43
- };
44
- const maConn = {
45
- log,
46
- sink: stream.sink,
47
- source: (async function* () {
48
- try {
49
- for await (const buf of stream.source) {
50
- onDataRead?.(buf);
51
- yield buf;
52
- }
53
- }
54
- finally {
55
- closedRead = true;
56
- close();
57
- }
58
- }()),
59
- remoteAddr,
60
- timeline: { open: Date.now(), close: undefined },
61
- close: stream.close,
62
- abort: stream.abort
63
- };
64
- function close(force) {
65
- if (force === true) {
66
- closedRead = true;
67
- closedWrite = true;
68
- }
69
- if (closedRead && closedWrite && maConn.timeline.close == null) {
70
- maConn.timeline.close = Date.now();
71
- }
72
- }
73
- return maConn;
74
- }
75
- //# sourceMappingURL=stream-to-ma-conn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"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"}
@@ -1,147 +0,0 @@
1
- {
2
- "createTimeoutOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.abort-options.createTimeoutOptions.html",
3
- "./abort-options:createTimeoutOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.abort-options.createTimeoutOptions.html",
4
- "AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.abstract-stream.AbstractStream.html",
5
- "./abstract-stream:AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.abstract-stream.AbstractStream.html",
6
- "AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.abstract-stream.AbstractStreamInit.html",
7
- "./abstract-stream:AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.abstract-stream.AbstractStreamInit.html",
8
- "AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.adaptive-timeout.AdaptiveTimeout.html",
9
- "./adaptive-timeout:AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.adaptive-timeout.AdaptiveTimeout.html",
10
- "AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutInit.html",
11
- "./adaptive-timeout:AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutInit.html",
12
- "AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutSignal.html",
13
- "./adaptive-timeout:AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutSignal.html",
14
- "GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.GetTimeoutSignalOptions.html",
15
- "./adaptive-timeout:GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.GetTimeoutSignalOptions.html",
16
- "DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_FAILURE_MULTIPLIER.html",
17
- "./adaptive-timeout:DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_FAILURE_MULTIPLIER.html",
18
- "DEFAULT_INTERVAL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_INTERVAL.html",
19
- "./adaptive-timeout:DEFAULT_INTERVAL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_INTERVAL.html",
20
- "DEFAULT_MAX_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MAX_TIMEOUT.html",
21
- "./adaptive-timeout:DEFAULT_MAX_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MAX_TIMEOUT.html",
22
- "DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MIN_TIMEOUT.html",
23
- "./adaptive-timeout:DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MIN_TIMEOUT.html",
24
- "DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
25
- "./adaptive-timeout:DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
26
- "arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array-equals.arrayEquals.html",
27
- "./array-equals:arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array-equals.arrayEquals.html",
28
- "SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
29
- "./close:SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
30
- "safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
31
- "./close:safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
32
- "safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
33
- "./close:safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
34
- "closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close-source.closeSource.html",
35
- "./close-source:closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close-source.closeSource.html",
36
- "DebouncedFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.debounce.DebouncedFunction.html",
37
- "./debounce:DebouncedFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.debounce.DebouncedFunction.html",
38
- "debounce": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.debounce.debounce.html",
39
- "./debounce:debounce": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.debounce.debounce.html",
40
- "BloomFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.BloomFilter.html",
41
- "Bucket": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.Bucket.html",
42
- "CuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.CuckooFilter.html",
43
- "Fingerprint": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.Fingerprint.html",
44
- "ScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.ScalableCuckooFilter.html",
45
- "BloomFilterOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.BloomFilterOptions.html",
46
- "CuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.CuckooFilterInit.html",
47
- "Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Filter.html",
48
- "./filters:Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Filter.html",
49
- "Hash": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Hash.html",
50
- "ScalableCuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.ScalableCuckooFilterInit.html",
51
- "createBloomFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createBloomFilter.html",
52
- "createCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createCuckooFilter.html",
53
- "createScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createScalableCuckooFilter.html",
54
- "getThinWaistAddresses": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.get-thin-waist-addresses.getThinWaistAddresses.html",
55
- "./get-thin-waist-addresses:getThinWaistAddresses": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.get-thin-waist-addresses.getThinWaistAddresses.html",
56
- "isGlobalUnicastIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.global-unicast-ip.isGlobalUnicastIp.html",
57
- "./global-unicast-ip:isGlobalUnicastIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.global-unicast-ip.isGlobalUnicastIp.html",
58
- "ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip-port-to-multiaddr.ipPortToMultiaddr.html",
59
- "./ip-port-to-multiaddr:ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip-port-to-multiaddr.ipPortToMultiaddr.html",
60
- "isAsyncGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-async-generator.isAsyncGenerator.html",
61
- "./is-async-generator:isAsyncGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-async-generator.isAsyncGenerator.html",
62
- "isGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-generator.isGenerator.html",
63
- "./is-generator:isGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-generator.isGenerator.html",
64
- "isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-promise.isPromise.html",
65
- "./is-promise:isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-promise.isPromise.html",
66
- "isLinkLocalIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.link-local-ip.isLinkLocalIp.html",
67
- "./link-local-ip:isLinkLocalIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.link-local-ip.isLinkLocalIp.html",
68
- "mergeOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.merge-options.mergeOptions.html",
69
- "./merge-options:mergeOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.merge-options.mergeOptions.html",
70
- "MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving-average.MovingAverage.html",
71
- "./moving-average:MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving-average.MovingAverage.html",
72
- "isGlobalUnicast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-global-unicast.isGlobalUnicast.html",
73
- "./multiaddr/is-global-unicast:isGlobalUnicast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-global-unicast.isGlobalUnicast.html",
74
- "isIpBased": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-ip-based.isIpBased.html",
75
- "./multiaddr/is-ip-based:isIpBased": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-ip-based.isIpBased.html",
76
- "isLinkLocal": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-link-local.isLinkLocal.html",
77
- "./multiaddr/is-link-local:isLinkLocal": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-link-local.isLinkLocal.html",
78
- "isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-loopback.isLoopback.html",
79
- "./multiaddr/is-loopback:isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-loopback.isLoopback.html",
80
- "isNetworkAddress": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-network-address.isNetworkAddress.html",
81
- "./multiaddr/is-network-address:isNetworkAddress": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-network-address.isNetworkAddress.html",
82
- "isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-private.isPrivate.html",
83
- "./multiaddr/is-private:isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-private.isPrivate.html",
84
- "PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer-queue.PeerQueue.html",
85
- "./peer-queue:PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer-queue.PeerQueue.html",
86
- "PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer-queue.PeerQueueJobOptions.html",
87
- "./peer-queue:PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer-queue.PeerQueueJobOptions.html",
88
- "PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority-queue.PriorityQueue.html",
89
- "./priority-queue:PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority-queue.PriorityQueue.html",
90
- "PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority-queue.PriorityQueueJobOptions.html",
91
- "./priority-queue:PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority-queue.PriorityQueueJobOptions.html",
92
- "isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private-ip.isPrivateIp.html",
93
- "./private-ip:isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private-ip.isPrivateIp.html",
94
- "Job": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Job.html",
95
- "JobRecipient": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.JobRecipient.html",
96
- "Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
97
- "./queue:Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
98
- "Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
99
- "./queue:Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
100
- "JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
101
- "./queue:JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
102
- "JobTimeline": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobTimeline.html",
103
- "QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
104
- "./queue:QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
105
- "QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
106
- "./queue:QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
107
- "QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
108
- "./queue:QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
109
- "QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
110
- "./queue:QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
111
- "RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
112
- "./queue:RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
113
- "JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
114
- "./queue:JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
115
- "MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.MemoryStorage.html",
116
- "./rate-limiter:MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.MemoryStorage.html",
117
- "RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.RateLimiter.html",
118
- "./rate-limiter:RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.RateLimiter.html",
119
- "GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.GetKeySecDurationOptions.html",
120
- "./rate-limiter:GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.GetKeySecDurationOptions.html",
121
- "RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterInit.html",
122
- "./rate-limiter:RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterInit.html",
123
- "RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterResult.html",
124
- "./rate-limiter:RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterResult.html",
125
- "RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateRecord.html",
126
- "./rate-limiter:RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateRecord.html",
127
- "RepeatingTask": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTask.html",
128
- "./repeating-task:RepeatingTask": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTask.html",
129
- "RepeatingTaskOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTaskOptions.html",
130
- "./repeating-task:RepeatingTaskOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTaskOptions.html",
131
- "repeatingTask": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.repeating-task.repeatingTask.html",
132
- "./repeating-task:repeatingTask": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.repeating-task.repeatingTask.html",
133
- "StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream-to-ma-conn.StreamProperties.html",
134
- "./stream-to-ma-conn:StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream-to-ma-conn.StreamProperties.html",
135
- "streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream-to-ma-conn.streamToMaConnection.html",
136
- "./stream-to-ma-conn:streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream-to-ma-conn.streamToMaConnection.html",
137
- "CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-list.CreateTrackedListInit.html",
138
- "./tracked-list:CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-list.CreateTrackedListInit.html",
139
- "trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-list.trackedList.html",
140
- "./tracked-list:trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-list.trackedList.html",
141
- "CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.CreateTrackedMapInit.html",
142
- "./tracked-map:CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.CreateTrackedMapInit.html",
143
- "TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.TrackedMapInit.html",
144
- "./tracked-map:TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.TrackedMapInit.html",
145
- "trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-map.trackedMap.html",
146
- "./tracked-map:trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-map.trackedMap.html"
147
- }
@@ -1,20 +0,0 @@
1
- import { anySignal } from 'any-signal'
2
- import { setMaxListeners } from 'main-event'
3
- import type { AbortOptions } from '@libp2p/interface'
4
- import type { ClearableSignal } from 'any-signal'
5
-
6
- export function createTimeoutOptions (timeout: number): AbortOptions
7
- export function createTimeoutOptions (timeout: number, ...existingSignals: AbortSignal[]): { signal: ClearableSignal }
8
- export function createTimeoutOptions (timeout: number, ...existingSignals: AbortSignal[]): AbortOptions {
9
- let signal = AbortSignal.timeout(timeout)
10
- setMaxListeners(Infinity, signal)
11
-
12
- if (existingSignals.length > 0) {
13
- signal = anySignal([signal, ...existingSignals])
14
- setMaxListeners(Infinity, signal)
15
- }
16
-
17
- return {
18
- signal
19
- }
20
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies ensure arrays are equivalent.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { arrayEquals } from '@libp2p/utils/array-equals'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
- * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
- *
15
- * console.info(arrayEquals([ma1], [ma1])) // true
16
- * console.info(arrayEquals([ma1], [ma2])) // false
17
- * ```
18
- */
19
-
20
- /**
21
- * Verify if two arrays of non primitive types with the "equals" function are equal.
22
- * Compatible with multiaddr, peer-id and others.
23
- */
24
- export function arrayEquals (a: any[], b: any[]): boolean {
25
- const sort = (a: any, b: any): number => a.toString().localeCompare(b.toString())
26
-
27
- if (a.length !== b.length) {
28
- return false
29
- }
30
-
31
- b.sort(sort)
32
-
33
- return a.sort(sort).every((item, index) => b[index].equals(item))
34
- }
@@ -1,14 +0,0 @@
1
- import { getIterator } from 'get-iterator'
2
- import { isPromise } from './is-promise.js'
3
- import type { Logger } from '@libp2p/logger'
4
- import type { Source } from 'it-stream-types'
5
-
6
- export function closeSource (source: Source<unknown>, log: Logger): void {
7
- const res = getIterator(source).return?.()
8
-
9
- if (isPromise(res)) {
10
- res.catch(err => {
11
- log.error('could not cause iterator to return', err)
12
- })
13
- }
14
- }
package/src/close.ts DELETED
@@ -1,65 +0,0 @@
1
- import type { Connection, Stream, AbortOptions } from '@libp2p/interface'
2
-
3
- /**
4
- * Close the passed stream, falling back to aborting the stream if closing
5
- * cleanly fails.
6
- */
7
- export async function safelyCloseStream (stream?: Stream, options?: AbortOptions): Promise<void> {
8
- try {
9
- await stream?.close(options)
10
- } catch (err: any) {
11
- stream?.abort(err)
12
- }
13
- }
14
-
15
- /**
16
- * These are speculative protocols that are run automatically on connection open
17
- * so are usually not the reason the connection was opened.
18
- *
19
- * Consequently when requested it should be safe to close connections that only
20
- * have these protocol streams open.
21
- */
22
- const DEFAULT_CLOSABLE_PROTOCOLS = [
23
- // identify
24
- '/ipfs/id/1.0.0',
25
-
26
- // identify-push
27
- '/ipfs/id/push/1.0.0',
28
-
29
- // autonat
30
- '/libp2p/autonat/1.0.0',
31
-
32
- // dcutr
33
- '/libp2p/dcutr'
34
- ]
35
-
36
- export interface SafelyCloseConnectionOptions extends AbortOptions {
37
- /**
38
- * Only close the stream if it either has no protocol streams open or only
39
- * ones in this list.
40
- *
41
- * @default ['/ipfs/id/1.0.0']
42
- */
43
- closableProtocols?: string[]
44
- }
45
-
46
- /**
47
- * Close the passed connection if it has no streams, or only closable protocol
48
- * streams, falling back to aborting the connection if closing it cleanly fails.
49
- */
50
- export async function safelyCloseConnectionIfUnused (connection?: Connection, options?: SafelyCloseConnectionOptions): Promise<void> {
51
- const streamProtocols = connection?.streams?.map(stream => stream.protocol) ?? []
52
- const closableProtocols = options?.closableProtocols ?? DEFAULT_CLOSABLE_PROTOCOLS
53
-
54
- // if the connection has protocols not in the closable protocols list, do not
55
- // close the connection
56
- if (streamProtocols.filter(proto => proto != null && !closableProtocols.includes(proto)).length > 0) {
57
- return
58
- }
59
-
60
- try {
61
- await connection?.close(options)
62
- } catch (err: any) {
63
- connection?.abort(err)
64
- }
65
- }