@libp2p/utils 6.0.5 → 6.0.6-32c176fd5
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/utils",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.6-32c176fd5",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme",
|
|
@@ -56,10 +56,6 @@
|
|
|
56
56
|
"types": "./dist/src/adaptive-timeout.d.ts",
|
|
57
57
|
"import": "./dist/src/adaptive-timeout.js"
|
|
58
58
|
},
|
|
59
|
-
"./address-sort": {
|
|
60
|
-
"types": "./dist/src/address-sort.d.ts",
|
|
61
|
-
"import": "./dist/src/address-sort.js"
|
|
62
|
-
},
|
|
63
59
|
"./array-equals": {
|
|
64
60
|
"types": "./dist/src/array-equals.d.ts",
|
|
65
61
|
"import": "./dist/src/array-equals.js"
|
|
@@ -152,11 +148,10 @@
|
|
|
152
148
|
},
|
|
153
149
|
"dependencies": {
|
|
154
150
|
"@chainsafe/is-ip": "^2.0.2",
|
|
155
|
-
"@libp2p/crypto": "
|
|
156
|
-
"@libp2p/interface": "
|
|
157
|
-
"@libp2p/logger": "
|
|
151
|
+
"@libp2p/crypto": "5.0.4-32c176fd5",
|
|
152
|
+
"@libp2p/interface": "2.1.2-32c176fd5",
|
|
153
|
+
"@libp2p/logger": "5.1.0-32c176fd5",
|
|
158
154
|
"@multiformats/multiaddr": "^12.2.3",
|
|
159
|
-
"@multiformats/multiaddr-matcher": "^1.2.1",
|
|
160
155
|
"@sindresorhus/fnv1a": "^3.1.0",
|
|
161
156
|
"@types/murmurhash3js-revisited": "^3.0.3",
|
|
162
157
|
"any-signal": "^4.1.1",
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* Provides strategies to sort a list of multiaddrs.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { publicAddressesFirst } from '@libp2p/utils/address-sort'
|
|
10
|
-
* import { multiaddr } from '@multformats/multiaddr'
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* const addresses = [
|
|
14
|
-
* multiaddr('/ip4/127.0.0.1/tcp/9000'),
|
|
15
|
-
* multiaddr('/ip4/82.41.53.1/tcp/9000')
|
|
16
|
-
* ].sort(publicAddressesFirst)
|
|
17
|
-
*
|
|
18
|
-
* console.info(addresses)
|
|
19
|
-
* // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
import type { Address } from '@libp2p/interface';
|
|
23
|
-
/**
|
|
24
|
-
* Compare function for array.sort() that moves public addresses to the start
|
|
25
|
-
* of the array.
|
|
26
|
-
*/
|
|
27
|
-
export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
28
|
-
/**
|
|
29
|
-
* Compare function for array.sort() that moves certified addresses to the start
|
|
30
|
-
* of the array.
|
|
31
|
-
*/
|
|
32
|
-
export declare function certifiedAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
33
|
-
/**
|
|
34
|
-
* Compare function for array.sort() that moves circuit relay addresses to the
|
|
35
|
-
* start of the array.
|
|
36
|
-
*/
|
|
37
|
-
export declare function circuitRelayAddressesLast(a: Address, b: Address): -1 | 0 | 1;
|
|
38
|
-
export declare function defaultAddressSort(a: Address, b: Address): -1 | 0 | 1;
|
|
39
|
-
//# sourceMappingURL=address-sort.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAWxE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQ3E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAW7E;AAED,wBAAgB,kBAAkB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAgBtE"}
|
package/dist/src/address-sort.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* Provides strategies to sort a list of multiaddrs.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { publicAddressesFirst } from '@libp2p/utils/address-sort'
|
|
10
|
-
* import { multiaddr } from '@multformats/multiaddr'
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* const addresses = [
|
|
14
|
-
* multiaddr('/ip4/127.0.0.1/tcp/9000'),
|
|
15
|
-
* multiaddr('/ip4/82.41.53.1/tcp/9000')
|
|
16
|
-
* ].sort(publicAddressesFirst)
|
|
17
|
-
*
|
|
18
|
-
* console.info(addresses)
|
|
19
|
-
* // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
import { Circuit } from '@multiformats/multiaddr-matcher';
|
|
23
|
-
import { isPrivate } from './multiaddr/is-private.js';
|
|
24
|
-
/**
|
|
25
|
-
* Compare function for array.sort() that moves public addresses to the start
|
|
26
|
-
* of the array.
|
|
27
|
-
*/
|
|
28
|
-
export function publicAddressesFirst(a, b) {
|
|
29
|
-
const isAPrivate = isPrivate(a.multiaddr);
|
|
30
|
-
const isBPrivate = isPrivate(b.multiaddr);
|
|
31
|
-
if (isAPrivate && !isBPrivate) {
|
|
32
|
-
return 1;
|
|
33
|
-
}
|
|
34
|
-
else if (!isAPrivate && isBPrivate) {
|
|
35
|
-
return -1;
|
|
36
|
-
}
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Compare function for array.sort() that moves certified addresses to the start
|
|
41
|
-
* of the array.
|
|
42
|
-
*/
|
|
43
|
-
export function certifiedAddressesFirst(a, b) {
|
|
44
|
-
if (a.isCertified && !b.isCertified) {
|
|
45
|
-
return -1;
|
|
46
|
-
}
|
|
47
|
-
else if (!a.isCertified && b.isCertified) {
|
|
48
|
-
return 1;
|
|
49
|
-
}
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Compare function for array.sort() that moves circuit relay addresses to the
|
|
54
|
-
* start of the array.
|
|
55
|
-
*/
|
|
56
|
-
export function circuitRelayAddressesLast(a, b) {
|
|
57
|
-
const isACircuit = Circuit.exactMatch(a.multiaddr);
|
|
58
|
-
const isBCircuit = Circuit.exactMatch(b.multiaddr);
|
|
59
|
-
if (isACircuit && !isBCircuit) {
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
else if (!isACircuit && isBCircuit) {
|
|
63
|
-
return -1;
|
|
64
|
-
}
|
|
65
|
-
return 0;
|
|
66
|
-
}
|
|
67
|
-
export function defaultAddressSort(a, b) {
|
|
68
|
-
const publicResult = publicAddressesFirst(a, b);
|
|
69
|
-
if (publicResult !== 0) {
|
|
70
|
-
return publicResult;
|
|
71
|
-
}
|
|
72
|
-
const relayResult = circuitRelayAddressesLast(a, b);
|
|
73
|
-
if (relayResult !== 0) {
|
|
74
|
-
return relayResult;
|
|
75
|
-
}
|
|
76
|
-
const certifiedResult = certifiedAddressesFirst(a, b);
|
|
77
|
-
return certifiedResult;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=address-sort.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAGrD;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,CAAU,EAAE,CAAU;IAC1D,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEzC,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAA;IACV,CAAC;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE,CAAC;QACrC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAE,CAAU,EAAE,CAAU;IAC7D,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAE,CAAU,EAAE,CAAU;IAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAElD,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAA;IACV,CAAC;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE,CAAC;QACrC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAE,CAAU,EAAE,CAAU;IACxD,MAAM,YAAY,GAAG,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAE/C,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,MAAM,WAAW,GAAG,yBAAyB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEnD,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,MAAM,eAAe,GAAG,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAErD,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,121 +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_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_MIN_TIMEOUT.html",
|
|
19
|
-
"./adaptive-timeout:DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_MIN_TIMEOUT.html",
|
|
20
|
-
"DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
|
|
21
|
-
"./adaptive-timeout:DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
|
|
22
|
-
"certifiedAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.certifiedAddressesFirst.html",
|
|
23
|
-
"./address-sort:certifiedAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.certifiedAddressesFirst.html",
|
|
24
|
-
"circuitRelayAddressesLast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.circuitRelayAddressesLast.html",
|
|
25
|
-
"./address-sort:circuitRelayAddressesLast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.circuitRelayAddressesLast.html",
|
|
26
|
-
"defaultAddressSort": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.defaultAddressSort.html",
|
|
27
|
-
"./address-sort:defaultAddressSort": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.defaultAddressSort.html",
|
|
28
|
-
"publicAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.publicAddressesFirst.html",
|
|
29
|
-
"./address-sort:publicAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.publicAddressesFirst.html",
|
|
30
|
-
"arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array_equals.arrayEquals.html",
|
|
31
|
-
"./array-equals:arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array_equals.arrayEquals.html",
|
|
32
|
-
"SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
|
|
33
|
-
"./close:SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
|
|
34
|
-
"safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
|
|
35
|
-
"./close:safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
|
|
36
|
-
"safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
|
|
37
|
-
"./close:safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
|
|
38
|
-
"closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close_source.closeSource.html",
|
|
39
|
-
"./close-source:closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close_source.closeSource.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
|
-
"ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip_port_to_multiaddr.ipPortToMultiaddr.html",
|
|
55
|
-
"./ip-port-to-multiaddr:ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip_port_to_multiaddr.ipPortToMultiaddr.html",
|
|
56
|
-
"isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is_promise.isPromise.html",
|
|
57
|
-
"./is-promise:isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is_promise.isPromise.html",
|
|
58
|
-
"MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving_average.MovingAverage.html",
|
|
59
|
-
"./moving-average:MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving_average.MovingAverage.html",
|
|
60
|
-
"isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_loopback.isLoopback.html",
|
|
61
|
-
"./multiaddr/is-loopback:isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_loopback.isLoopback.html",
|
|
62
|
-
"isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_private.isPrivate.html",
|
|
63
|
-
"./multiaddr/is-private:isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_private.isPrivate.html",
|
|
64
|
-
"PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer_queue.PeerQueue.html",
|
|
65
|
-
"./peer-queue:PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer_queue.PeerQueue.html",
|
|
66
|
-
"PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer_queue.PeerQueueJobOptions.html",
|
|
67
|
-
"./peer-queue:PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer_queue.PeerQueueJobOptions.html",
|
|
68
|
-
"PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority_queue.PriorityQueue.html",
|
|
69
|
-
"./priority-queue:PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority_queue.PriorityQueue.html",
|
|
70
|
-
"PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority_queue.PriorityQueueJobOptions.html",
|
|
71
|
-
"./priority-queue:PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority_queue.PriorityQueueJobOptions.html",
|
|
72
|
-
"isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private_ip.isPrivateIp.html",
|
|
73
|
-
"./private-ip:isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private_ip.isPrivateIp.html",
|
|
74
|
-
"Job": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Job.html",
|
|
75
|
-
"JobRecipient": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.JobRecipient.html",
|
|
76
|
-
"Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
|
|
77
|
-
"./queue:Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
|
|
78
|
-
"Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
|
|
79
|
-
"./queue:Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
|
|
80
|
-
"JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
|
|
81
|
-
"./queue:JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
|
|
82
|
-
"JobTimeline": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobTimeline.html",
|
|
83
|
-
"QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
|
|
84
|
-
"./queue:QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
|
|
85
|
-
"QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
|
|
86
|
-
"./queue:QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
|
|
87
|
-
"QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
|
|
88
|
-
"./queue:QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
|
|
89
|
-
"QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
|
|
90
|
-
"./queue:QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
|
|
91
|
-
"RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
|
|
92
|
-
"./queue:RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
|
|
93
|
-
"JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
|
|
94
|
-
"./queue:JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
|
|
95
|
-
"MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.MemoryStorage.html",
|
|
96
|
-
"./rate-limiter:MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.MemoryStorage.html",
|
|
97
|
-
"RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.RateLimiter.html",
|
|
98
|
-
"./rate-limiter:RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.RateLimiter.html",
|
|
99
|
-
"GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.GetKeySecDurationOptions.html",
|
|
100
|
-
"./rate-limiter:GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.GetKeySecDurationOptions.html",
|
|
101
|
-
"RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterInit.html",
|
|
102
|
-
"./rate-limiter:RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterInit.html",
|
|
103
|
-
"RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterResult.html",
|
|
104
|
-
"./rate-limiter:RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterResult.html",
|
|
105
|
-
"RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateRecord.html",
|
|
106
|
-
"./rate-limiter:RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateRecord.html",
|
|
107
|
-
"StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream_to_ma_conn.StreamProperties.html",
|
|
108
|
-
"./stream-to-ma-conn:StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream_to_ma_conn.StreamProperties.html",
|
|
109
|
-
"streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream_to_ma_conn.streamToMaConnection.html",
|
|
110
|
-
"./stream-to-ma-conn:streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream_to_ma_conn.streamToMaConnection.html",
|
|
111
|
-
"CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_list.CreateTrackedListInit.html",
|
|
112
|
-
"./tracked-list:CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_list.CreateTrackedListInit.html",
|
|
113
|
-
"trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_list.trackedList.html",
|
|
114
|
-
"./tracked-list:trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_list.trackedList.html",
|
|
115
|
-
"CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.CreateTrackedMapInit.html",
|
|
116
|
-
"./tracked-map:CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.CreateTrackedMapInit.html",
|
|
117
|
-
"TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.TrackedMapInit.html",
|
|
118
|
-
"./tracked-map:TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.TrackedMapInit.html",
|
|
119
|
-
"trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_map.trackedMap.html",
|
|
120
|
-
"./tracked-map:trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_map.trackedMap.html"
|
|
121
|
-
}
|
package/src/address-sort.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* Provides strategies to sort a list of multiaddrs.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { publicAddressesFirst } from '@libp2p/utils/address-sort'
|
|
10
|
-
* import { multiaddr } from '@multformats/multiaddr'
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* const addresses = [
|
|
14
|
-
* multiaddr('/ip4/127.0.0.1/tcp/9000'),
|
|
15
|
-
* multiaddr('/ip4/82.41.53.1/tcp/9000')
|
|
16
|
-
* ].sort(publicAddressesFirst)
|
|
17
|
-
*
|
|
18
|
-
* console.info(addresses)
|
|
19
|
-
* // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { Circuit } from '@multiformats/multiaddr-matcher'
|
|
24
|
-
import { isPrivate } from './multiaddr/is-private.js'
|
|
25
|
-
import type { Address } from '@libp2p/interface'
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Compare function for array.sort() that moves public addresses to the start
|
|
29
|
-
* of the array.
|
|
30
|
-
*/
|
|
31
|
-
export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
32
|
-
const isAPrivate = isPrivate(a.multiaddr)
|
|
33
|
-
const isBPrivate = isPrivate(b.multiaddr)
|
|
34
|
-
|
|
35
|
-
if (isAPrivate && !isBPrivate) {
|
|
36
|
-
return 1
|
|
37
|
-
} else if (!isAPrivate && isBPrivate) {
|
|
38
|
-
return -1
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return 0
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Compare function for array.sort() that moves certified addresses to the start
|
|
46
|
-
* of the array.
|
|
47
|
-
*/
|
|
48
|
-
export function certifiedAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
49
|
-
if (a.isCertified && !b.isCertified) {
|
|
50
|
-
return -1
|
|
51
|
-
} else if (!a.isCertified && b.isCertified) {
|
|
52
|
-
return 1
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return 0
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Compare function for array.sort() that moves circuit relay addresses to the
|
|
60
|
-
* start of the array.
|
|
61
|
-
*/
|
|
62
|
-
export function circuitRelayAddressesLast (a: Address, b: Address): -1 | 0 | 1 {
|
|
63
|
-
const isACircuit = Circuit.exactMatch(a.multiaddr)
|
|
64
|
-
const isBCircuit = Circuit.exactMatch(b.multiaddr)
|
|
65
|
-
|
|
66
|
-
if (isACircuit && !isBCircuit) {
|
|
67
|
-
return 1
|
|
68
|
-
} else if (!isACircuit && isBCircuit) {
|
|
69
|
-
return -1
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return 0
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function defaultAddressSort (a: Address, b: Address): -1 | 0 | 1 {
|
|
76
|
-
const publicResult = publicAddressesFirst(a, b)
|
|
77
|
-
|
|
78
|
-
if (publicResult !== 0) {
|
|
79
|
-
return publicResult
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const relayResult = circuitRelayAddressesLast(a, b)
|
|
83
|
-
|
|
84
|
-
if (relayResult !== 0) {
|
|
85
|
-
return relayResult
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const certifiedResult = certifiedAddressesFirst(a, b)
|
|
89
|
-
|
|
90
|
-
return certifiedResult
|
|
91
|
-
}
|