@libp2p/utils 1.0.6 → 1.0.9
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/dist/src/address-sort.d.ts +4 -8
- package/dist/src/address-sort.d.ts.map +1 -1
- package/dist/src/address-sort.js +2 -18
- package/dist/src/address-sort.js.map +1 -1
- package/dist/src/stream-to-ma-conn.d.ts +2 -8
- package/dist/src/stream-to-ma-conn.d.ts.map +1 -1
- package/dist/src/stream-to-ma-conn.js.map +1 -1
- package/package.json +4 -3
- package/src/address-sort.ts +3 -26
- package/src/stream-to-ma-conn.ts +2 -9
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
interface Address {
|
|
3
|
-
multiaddr: Multiaddr;
|
|
4
|
-
isCertified: boolean;
|
|
5
|
-
}
|
|
1
|
+
import type { Address } from '@libp2p/interfaces/peer-store';
|
|
6
2
|
/**
|
|
7
|
-
*
|
|
3
|
+
* Compare function for array.sort().
|
|
4
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
8
5
|
* In case of equality, a certified address will come first.
|
|
9
6
|
*/
|
|
10
|
-
export declare function publicAddressesFirst(
|
|
11
|
-
export {};
|
|
7
|
+
export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
12
8
|
//# sourceMappingURL=address-sort.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAG5D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAiBxE"}
|
package/dist/src/address-sort.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { isPrivate } from './multiaddr/is-private.js';
|
|
2
|
-
/**
|
|
3
|
-
* @typedef {Object} Address
|
|
4
|
-
* @property {Multiaddr} multiaddr peer multiaddr.
|
|
5
|
-
* @property {boolean} isCertified obtained from a signed peer record.
|
|
6
|
-
*/
|
|
7
2
|
/**
|
|
8
3
|
* Compare function for array.sort().
|
|
9
|
-
* This sort aims to move the private
|
|
4
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
10
5
|
* In case of equality, a certified address will come first.
|
|
11
|
-
*
|
|
12
|
-
* @param {Address} a
|
|
13
|
-
* @param {Address} b
|
|
14
|
-
* @returns {number}
|
|
15
6
|
*/
|
|
16
|
-
function
|
|
7
|
+
export function publicAddressesFirst(a, b) {
|
|
17
8
|
const isAPrivate = isPrivate(a.multiaddr);
|
|
18
9
|
const isBPrivate = isPrivate(b.multiaddr);
|
|
19
10
|
if (isAPrivate && !isBPrivate) {
|
|
@@ -31,11 +22,4 @@ function addressesPublicFirstCompareFunction(a, b) {
|
|
|
31
22
|
}
|
|
32
23
|
return 0;
|
|
33
24
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Sort given addresses by putting public addresses first.
|
|
36
|
-
* In case of equality, a certified address will come first.
|
|
37
|
-
*/
|
|
38
|
-
export function publicAddressesFirst(addresses) {
|
|
39
|
-
return [...addresses].sort(addressesPublicFirstCompareFunction);
|
|
40
|
-
}
|
|
41
25
|
//# sourceMappingURL=address-sort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD;;;;GAIG;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;QAC7B,OAAO,CAAC,CAAA;KACT;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE;QACpC,OAAO,CAAC,CAAC,CAAA;KACV;IACD,mBAAmB;IACnB,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;QACnC,OAAO,CAAC,CAAC,CAAA;KACV;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE;QAC1C,OAAO,CAAC,CAAA;KACT;IAED,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type { Stream } from '@libp2p/interfaces/connection';
|
|
2
1
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
2
|
import type { MultiaddrConnection } from '@libp2p/interfaces/transport';
|
|
4
|
-
|
|
5
|
-
* @typedef {Object} Timeline
|
|
6
|
-
* @property {number} open -
|
|
7
|
-
* @property {number} [upgraded] - .
|
|
8
|
-
* @property {number} [close]
|
|
9
|
-
*/
|
|
3
|
+
import type { Duplex } from 'it-stream-types';
|
|
10
4
|
export interface Timeline {
|
|
11
5
|
/**
|
|
12
6
|
* Connection opening timestamp
|
|
@@ -25,7 +19,7 @@ interface StreamOptions {
|
|
|
25
19
|
signal?: AbortSignal;
|
|
26
20
|
}
|
|
27
21
|
interface StreamProperties {
|
|
28
|
-
stream:
|
|
22
|
+
stream: Duplex<Uint8Array>;
|
|
29
23
|
remoteAddr: Multiaddr;
|
|
30
24
|
localAddr: Multiaddr;
|
|
31
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAI7C,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,UAAU,aAAa;IACrB,MAAM,CAAC,EAAE,WAAW,CAAA;CAErB;AAED,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IAC1B,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,uBA0CzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAKvC,MAAM,GAAG,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAA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CAAA;YACJ,MAAM,KAAK,EAAE,CAAA;QACf,CAAC;KACF,CAAA;IAED,KAAK,UAAU,KAAK;QAClB,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE;YACjC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;SACnC;QACD,OAAO,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;IAChC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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-utils#readme",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"types": "./dist/src/multiaddr/is-private.d.ts"
|
|
65
65
|
},
|
|
66
66
|
"./stream-to-ma-conn": {
|
|
67
|
-
"import": "./dist/src/stream-to-ma-
|
|
68
|
-
"types": "./dist/src/stream-to-ma-
|
|
67
|
+
"import": "./dist/src/stream-to-ma-conn.js",
|
|
68
|
+
"types": "./dist/src/stream-to-ma-conn.d.ts"
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"eslintConfig": {
|
|
@@ -176,6 +176,7 @@
|
|
|
176
176
|
"abortable-iterator": "^4.0.2",
|
|
177
177
|
"err-code": "^3.0.1",
|
|
178
178
|
"is-loopback-addr": "^2.0.1",
|
|
179
|
+
"it-stream-types": "^1.0.4",
|
|
179
180
|
"private-ip": "^2.1.1"
|
|
180
181
|
},
|
|
181
182
|
"devDependencies": {
|
package/src/address-sort.ts
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Address } from '@libp2p/interfaces/peer-store'
|
|
2
2
|
import { isPrivate } from './multiaddr/is-private.js'
|
|
3
3
|
|
|
4
|
-
interface Address {
|
|
5
|
-
multiaddr: Multiaddr
|
|
6
|
-
isCertified: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {Object} Address
|
|
11
|
-
* @property {Multiaddr} multiaddr peer multiaddr.
|
|
12
|
-
* @property {boolean} isCertified obtained from a signed peer record.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
4
|
/**
|
|
16
5
|
* Compare function for array.sort().
|
|
17
|
-
* This sort aims to move the private
|
|
6
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
18
7
|
* In case of equality, a certified address will come first.
|
|
19
|
-
*
|
|
20
|
-
* @param {Address} a
|
|
21
|
-
* @param {Address} b
|
|
22
|
-
* @returns {number}
|
|
23
8
|
*/
|
|
24
|
-
function
|
|
9
|
+
export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
25
10
|
const isAPrivate = isPrivate(a.multiaddr)
|
|
26
11
|
const isBPrivate = isPrivate(b.multiaddr)
|
|
27
12
|
|
|
@@ -39,11 +24,3 @@ function addressesPublicFirstCompareFunction (a: Address, b: Address) {
|
|
|
39
24
|
|
|
40
25
|
return 0
|
|
41
26
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Sort given addresses by putting public addresses first.
|
|
45
|
-
* In case of equality, a certified address will come first.
|
|
46
|
-
*/
|
|
47
|
-
export function publicAddressesFirst (addresses: Address[]) {
|
|
48
|
-
return [...addresses].sort(addressesPublicFirstCompareFunction)
|
|
49
|
-
}
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { abortableSource } from 'abortable-iterator'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import type { Stream } from '@libp2p/interfaces/connection'
|
|
4
3
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
4
|
import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
5
|
+
import type { Duplex } from 'it-stream-types'
|
|
6
6
|
|
|
7
7
|
const log = logger('libp2p:stream:converter')
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {Object} Timeline
|
|
11
|
-
* @property {number} open -
|
|
12
|
-
* @property {number} [upgraded] - .
|
|
13
|
-
* @property {number} [close]
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
9
|
export interface Timeline {
|
|
17
10
|
/**
|
|
18
11
|
* Connection opening timestamp
|
|
@@ -36,7 +29,7 @@ interface StreamOptions {
|
|
|
36
29
|
}
|
|
37
30
|
|
|
38
31
|
interface StreamProperties {
|
|
39
|
-
stream:
|
|
32
|
+
stream: Duplex<Uint8Array>
|
|
40
33
|
remoteAddr: Multiaddr
|
|
41
34
|
localAddr: Multiaddr
|
|
42
35
|
}
|