@libp2p/utils 6.7.2 → 7.0.0-55b7e5fea
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 +16 -1
- package/dist/index.min.js +7 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/abstract-message-stream.d.ts +129 -0
- package/dist/src/abstract-message-stream.d.ts.map +1 -0
- package/dist/src/abstract-message-stream.js +393 -0
- package/dist/src/abstract-message-stream.js.map +1 -0
- package/dist/src/abstract-multiaddr-connection.d.ts +26 -0
- package/dist/src/abstract-multiaddr-connection.d.ts.map +1 -0
- package/dist/src/abstract-multiaddr-connection.js +66 -0
- package/dist/src/abstract-multiaddr-connection.js.map +1 -0
- package/dist/src/abstract-stream-muxer.d.ts +53 -0
- package/dist/src/abstract-stream-muxer.d.ts.map +1 -0
- package/dist/src/abstract-stream-muxer.js +169 -0
- package/dist/src/abstract-stream-muxer.js.map +1 -0
- package/dist/src/abstract-stream.d.ts +14 -130
- package/dist/src/abstract-stream.d.ts.map +1 -1
- package/dist/src/abstract-stream.js +39 -321
- package/dist/src/abstract-stream.js.map +1 -1
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +8 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/get-thin-waist-addresses.browser.d.ts +1 -1
- package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -1
- package/dist/src/get-thin-waist-addresses.browser.js +4 -3
- package/dist/src/get-thin-waist-addresses.browser.js.map +1 -1
- package/dist/src/get-thin-waist-addresses.d.ts +1 -1
- package/dist/src/get-thin-waist-addresses.d.ts.map +1 -1
- package/dist/src/get-thin-waist-addresses.js +7 -9
- package/dist/src/get-thin-waist-addresses.js.map +1 -1
- package/dist/src/index.d.ts +31 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +31 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/length-prefixed-decoder.d.ts +37 -0
- package/dist/src/length-prefixed-decoder.d.ts.map +1 -0
- package/dist/src/length-prefixed-decoder.js +64 -0
- package/dist/src/length-prefixed-decoder.js.map +1 -0
- package/dist/src/message-queue.d.ts +61 -0
- package/dist/src/message-queue.d.ts.map +1 -0
- package/dist/src/message-queue.js +93 -0
- package/dist/src/message-queue.js.map +1 -0
- package/dist/src/mock-muxer.d.ts +57 -0
- package/dist/src/mock-muxer.d.ts.map +1 -0
- package/dist/src/mock-muxer.js +204 -0
- package/dist/src/mock-muxer.js.map +1 -0
- package/dist/src/mock-stream.d.ts +31 -0
- package/dist/src/mock-stream.d.ts.map +1 -0
- package/dist/src/mock-stream.js +69 -0
- package/dist/src/mock-stream.js.map +1 -0
- package/dist/src/multiaddr/get-net-config.d.ts +55 -0
- package/dist/src/multiaddr/get-net-config.d.ts.map +1 -0
- package/dist/src/multiaddr/get-net-config.js +54 -0
- package/dist/src/multiaddr/get-net-config.js.map +1 -0
- package/dist/src/multiaddr/index.d.ts +7 -0
- package/dist/src/multiaddr/index.d.ts.map +1 -0
- package/dist/src/multiaddr/index.js +7 -0
- package/dist/src/multiaddr/index.js.map +1 -0
- package/dist/src/multiaddr/is-global-unicast.d.ts.map +1 -1
- package/dist/src/multiaddr/is-global-unicast.js +8 -9
- package/dist/src/multiaddr/is-global-unicast.js.map +1 -1
- package/dist/src/multiaddr/is-link-local.d.ts.map +1 -1
- package/dist/src/multiaddr/is-link-local.js +11 -16
- package/dist/src/multiaddr/is-link-local.js.map +1 -1
- package/dist/src/multiaddr/is-loopback.d.ts.map +1 -1
- package/dist/src/multiaddr/is-loopback.js +12 -5
- package/dist/src/multiaddr/is-loopback.js.map +1 -1
- package/dist/src/multiaddr/is-network-address.d.ts.map +1 -1
- package/dist/src/multiaddr/is-network-address.js +4 -16
- package/dist/src/multiaddr/is-network-address.js.map +1 -1
- package/dist/src/multiaddr/is-private.d.ts.map +1 -1
- package/dist/src/multiaddr/is-private.js +9 -10
- package/dist/src/multiaddr/is-private.js.map +1 -1
- package/dist/src/multiaddr/utils.d.ts +5 -0
- package/dist/src/multiaddr/utils.d.ts.map +1 -0
- package/dist/src/multiaddr/utils.js +32 -0
- package/dist/src/multiaddr/utils.js.map +1 -0
- package/dist/src/multiaddr-connection-pair.d.ts +25 -0
- package/dist/src/multiaddr-connection-pair.d.ts.map +1 -0
- package/dist/src/multiaddr-connection-pair.js +103 -0
- package/dist/src/multiaddr-connection-pair.js.map +1 -0
- package/dist/src/queue/index.d.ts +3 -6
- package/dist/src/queue/index.d.ts.map +1 -1
- package/dist/src/queue/index.js +20 -4
- package/dist/src/queue/index.js.map +1 -1
- package/dist/src/rate-limiter.d.ts +1 -15
- package/dist/src/rate-limiter.d.ts.map +1 -1
- package/dist/src/rate-limiter.js +1 -14
- package/dist/src/rate-limiter.js.map +1 -1
- package/dist/src/stream-pair.d.ts +42 -0
- package/dist/src/stream-pair.d.ts.map +1 -0
- package/dist/src/stream-pair.js +40 -0
- package/dist/src/stream-pair.js.map +1 -0
- package/dist/src/stream-utils.d.ts +191 -0
- package/dist/src/stream-utils.d.ts.map +1 -0
- package/dist/src/stream-utils.js +371 -0
- package/dist/src/stream-utils.js.map +1 -0
- package/package.json +15 -162
- package/src/abstract-message-stream.ts +553 -0
- package/src/abstract-multiaddr-connection.ts +93 -0
- package/src/abstract-stream-muxer.ts +239 -0
- package/src/abstract-stream.ts +51 -464
- package/src/errors.ts +10 -0
- package/src/get-thin-waist-addresses.browser.ts +5 -4
- package/src/get-thin-waist-addresses.ts +8 -12
- package/src/index.ts +31 -1
- package/src/length-prefixed-decoder.ts +98 -0
- package/src/message-queue.ts +156 -0
- package/src/mock-muxer.ts +304 -0
- package/src/mock-stream.ts +101 -0
- package/src/multiaddr/get-net-config.ts +112 -0
- package/src/multiaddr/index.ts +6 -0
- package/src/multiaddr/is-global-unicast.ts +8 -11
- package/src/multiaddr/is-link-local.ts +11 -20
- package/src/multiaddr/is-loopback.ts +12 -7
- package/src/multiaddr/is-network-address.ts +4 -19
- package/src/multiaddr/is-private.ts +9 -14
- package/src/multiaddr/utils.ts +46 -0
- package/src/multiaddr-connection-pair.ts +147 -0
- package/src/queue/index.ts +24 -11
- package/src/rate-limiter.ts +3 -30
- package/src/stream-pair.ts +90 -0
- package/src/stream-utils.ts +866 -0
- package/dist/src/abort-options.d.ts +0 -7
- package/dist/src/abort-options.d.ts.map +0 -1
- package/dist/src/abort-options.js +0 -14
- package/dist/src/abort-options.js.map +0 -1
- package/dist/src/array-equals.d.ts +0 -24
- package/dist/src/array-equals.d.ts.map +0 -1
- package/dist/src/array-equals.js +0 -31
- package/dist/src/array-equals.js.map +0 -1
- package/dist/src/close-source.d.ts +0 -4
- package/dist/src/close-source.d.ts.map +0 -1
- package/dist/src/close-source.js +0 -11
- package/dist/src/close-source.js.map +0 -1
- package/dist/src/close.d.ts +0 -21
- package/dist/src/close.d.ts.map +0 -1
- package/dist/src/close.js +0 -49
- package/dist/src/close.js.map +0 -1
- package/dist/src/merge-options.d.ts +0 -7
- package/dist/src/merge-options.d.ts.map +0 -1
- package/dist/src/merge-options.js +0 -128
- package/dist/src/merge-options.js.map +0 -1
- package/dist/src/multiaddr/is-ip-based.d.ts +0 -6
- package/dist/src/multiaddr/is-ip-based.d.ts.map +0 -1
- package/dist/src/multiaddr/is-ip-based.js +0 -18
- package/dist/src/multiaddr/is-ip-based.js.map +0 -1
- package/dist/src/stream-to-ma-conn.d.ts +0 -23
- package/dist/src/stream-to-ma-conn.d.ts.map +0 -1
- package/dist/src/stream-to-ma-conn.js +0 -75
- package/dist/src/stream-to-ma-conn.js.map +0 -1
- package/dist/typedoc-urls.json +0 -147
- package/src/abort-options.ts +0 -20
- package/src/array-equals.ts +0 -34
- package/src/close-source.ts +0 -14
- package/src/close.ts +0 -65
- package/src/merge-options.ts +0 -161
- package/src/multiaddr/is-ip-based.ts +0 -21
- package/src/stream-to-ma-conn.ts +0 -106
|
@@ -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"}
|
package/dist/src/array-equals.js
DELETED
|
@@ -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 +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"}
|
package/dist/src/close-source.js
DELETED
|
@@ -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"}
|
package/dist/src/close.d.ts
DELETED
|
@@ -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
|
package/dist/src/close.d.ts.map
DELETED
|
@@ -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
|
package/dist/src/close.js.map
DELETED
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-options.d.ts","sourceRoot":"","sources":["../../src/merge-options.ts"],"names":[],"mappings":"AA0IA;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,CAiB/D"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import isOptionObject from 'is-plain-obj';
|
|
2
|
-
const { hasOwnProperty } = Object.prototype;
|
|
3
|
-
const { propertyIsEnumerable } = Object;
|
|
4
|
-
const defineProperty = (object, name, value) => {
|
|
5
|
-
Object.defineProperty(object, name, {
|
|
6
|
-
value,
|
|
7
|
-
writable: true,
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
const globalThis = this;
|
|
13
|
-
const defaultMergeOptions = {
|
|
14
|
-
concatArrays: false,
|
|
15
|
-
ignoreUndefined: false
|
|
16
|
-
};
|
|
17
|
-
const getEnumerableOwnPropertyKeys = (value) => {
|
|
18
|
-
const keys = [];
|
|
19
|
-
for (const key in value) {
|
|
20
|
-
if (hasOwnProperty.call(value, key)) {
|
|
21
|
-
keys.push(key);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/* istanbul ignore else */
|
|
25
|
-
if (Object.getOwnPropertySymbols) {
|
|
26
|
-
const symbols = Object.getOwnPropertySymbols(value);
|
|
27
|
-
for (const symbol of symbols) {
|
|
28
|
-
if (propertyIsEnumerable.call(value, symbol)) {
|
|
29
|
-
keys.push(symbol);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return keys;
|
|
34
|
-
};
|
|
35
|
-
function clone(value) {
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
return cloneArray(value);
|
|
38
|
-
}
|
|
39
|
-
if (isOptionObject(value)) {
|
|
40
|
-
return cloneOptionObject(value);
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
function cloneArray(array) {
|
|
45
|
-
const result = array.slice(0, 0);
|
|
46
|
-
getEnumerableOwnPropertyKeys(array).forEach(key => {
|
|
47
|
-
defineProperty(result, key, clone(array[key]));
|
|
48
|
-
});
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
function cloneOptionObject(object) {
|
|
52
|
-
const result = Object.getPrototypeOf(object) === null ? Object.create(null) : {};
|
|
53
|
-
getEnumerableOwnPropertyKeys(object).forEach(key => {
|
|
54
|
-
defineProperty(result, key, clone(object[key]));
|
|
55
|
-
});
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
const mergeKeys = (merged, source, keys, config) => {
|
|
59
|
-
keys.forEach(key => {
|
|
60
|
-
if (typeof source[key] === 'undefined' && config.ignoreUndefined) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// Do not recurse into prototype chain of merged
|
|
64
|
-
if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
|
|
65
|
-
defineProperty(merged, key, merge(merged[key], source[key], config));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
defineProperty(merged, key, clone(source[key]));
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return merged;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
|
|
75
|
-
*/
|
|
76
|
-
const concatArrays = (merged, source, config) => {
|
|
77
|
-
let result = merged.slice(0, 0);
|
|
78
|
-
let resultIndex = 0;
|
|
79
|
-
[merged, source].forEach(array => {
|
|
80
|
-
const indices = [];
|
|
81
|
-
// `result.concat(array)` with cloning
|
|
82
|
-
for (let k = 0; k < array.length; k++) {
|
|
83
|
-
if (!hasOwnProperty.call(array, k)) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
indices.push(String(k));
|
|
87
|
-
if (array === merged) {
|
|
88
|
-
// Already cloned
|
|
89
|
-
defineProperty(result, resultIndex++, array[k]);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
defineProperty(result, resultIndex++, clone(array[k]));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// Merge non-index keys
|
|
96
|
-
result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter(key => !indices.includes(key)), config);
|
|
97
|
-
});
|
|
98
|
-
return result;
|
|
99
|
-
};
|
|
100
|
-
function merge(merged, source, config) {
|
|
101
|
-
if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
|
|
102
|
-
return concatArrays(merged, source, config);
|
|
103
|
-
}
|
|
104
|
-
if (!isOptionObject(source) || !isOptionObject(merged)) {
|
|
105
|
-
return clone(source);
|
|
106
|
-
}
|
|
107
|
-
return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Port of `merge-options` to typescript
|
|
111
|
-
*
|
|
112
|
-
* @see https://github.com/schnittstabil/merge-options/pull/28
|
|
113
|
-
*/
|
|
114
|
-
export function mergeOptions(...options) {
|
|
115
|
-
const config = merge(clone(defaultMergeOptions), (this !== globalThis && this) || {}, defaultMergeOptions);
|
|
116
|
-
let merged = { _: {} };
|
|
117
|
-
for (const option of options) {
|
|
118
|
-
if (option === undefined) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (!isOptionObject(option)) {
|
|
122
|
-
throw new TypeError('`' + option + '` is not an Option Object');
|
|
123
|
-
}
|
|
124
|
-
merged = merge(merged, { _: option }, config);
|
|
125
|
-
}
|
|
126
|
-
return merged._;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=merge-options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-options.js","sourceRoot":"","sources":["../../src/merge-options.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,cAAc,CAAA;AAEzC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC,SAAS,CAAA;AAC3C,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAA;AACvC,MAAM,cAAc,GAAG,CAAC,MAAW,EAAE,IAAS,EAAE,KAAU,EAAQ,EAAE;IAClE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE;QAClC,KAAK;QACL,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,mBAAmB,GAAG;IAC1B,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;CACvB,CAAA;AAED,MAAM,4BAA4B,GAAG,CAAC,KAAU,EAAS,EAAE;IACzD,MAAM,IAAI,GAAG,EAAE,CAAA;IAEf,KAAK,MAAM,GAAG,IAAI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IP4, CODE_IP6, CODE_IP6ZONE } from '@multiformats/multiaddr';
|
|
2
|
-
/**
|
|
3
|
-
* Check if a given multiaddr is IP-based
|
|
4
|
-
*/
|
|
5
|
-
export function isIpBased(ma) {
|
|
6
|
-
try {
|
|
7
|
-
for (const { code } of ma.getComponents()) {
|
|
8
|
-
if (code === CODE_IP6ZONE) {
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
return code === CODE_IP4 || code === CODE_IP6;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=is-ip-based.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-ip-based.js","sourceRoot":"","sources":["../../../src/multiaddr/is-ip-based.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAG1E;;GAEG;AACH,MAAM,UAAU,SAAS,CAAE,EAAa;IACtC,IAAI,CAAC;QACH,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC;YAC1C,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC1B,SAAQ;YACV,CAAC;YAED,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,CAAA;QAC/C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;IAET,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Logger, 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
|
-
log: Logger;
|
|
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,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC5E,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,GAAG,EAAE,MAAM,CAAA;IAEX;;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,CA8ElF"}
|
|
@@ -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, log, onDataRead, onDataWrite } = props;
|
|
9
|
-
let closedRead = false;
|
|
10
|
-
let closedWrite = false;
|
|
11
|
-
// piggyback on `stream.close` invocations to close multiaddr connection
|
|
12
|
-
const streamClose = stream.close.bind(stream);
|
|
13
|
-
stream.close = async (options) => {
|
|
14
|
-
await streamClose(options);
|
|
15
|
-
close(true);
|
|
16
|
-
};
|
|
17
|
-
// piggyback on `stream.abort` invocations to close multiaddr connection
|
|
18
|
-
const streamAbort = stream.abort.bind(stream);
|
|
19
|
-
stream.abort = (err) => {
|
|
20
|
-
streamAbort(err);
|
|
21
|
-
close(true);
|
|
22
|
-
};
|
|
23
|
-
// piggyback on `stream.sink` invocations to close multiaddr connection
|
|
24
|
-
const streamSink = stream.sink.bind(stream);
|
|
25
|
-
stream.sink = async (source) => {
|
|
26
|
-
try {
|
|
27
|
-
await streamSink(pipe(source, (source) => forEach(source, buf => onDataWrite?.(buf))));
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
maConn.log.error('errored - %e', 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
|
-
maConn.log.error('%s error in sink - %e', remoteAddr, err);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
closedWrite = true;
|
|
41
|
-
close();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const maConn = {
|
|
45
|
-
log: log.newScope('stream-to-maconn'),
|
|
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":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAsB9B;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,KAAK,CAAA;IAElE,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,WAAW,GAAG,KAAK,CAAA;IAEvB,wEAAwE;IACxE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,GAAG,KA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