@libp2p/utils 1.0.2 → 1.0.6
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/LICENSE +3 -1
- package/dist/src/ip-port-to-multiaddr.d.ts.map +1 -1
- package/dist/src/ip-port-to-multiaddr.js +2 -4
- package/dist/src/ip-port-to-multiaddr.js.map +1 -1
- package/dist/src/multiaddr/is-loopback.d.ts +1 -1
- package/dist/src/multiaddr/is-loopback.d.ts.map +1 -1
- package/dist/src/multiaddr/is-loopback.js +1 -2
- package/dist/src/multiaddr/is-loopback.js.map +1 -1
- package/dist/src/stream-to-ma-conn.d.ts +3 -3
- package/dist/src/stream-to-ma-conn.d.ts.map +1 -1
- package/dist/src/stream-to-ma-conn.js +6 -8
- package/dist/src/stream-to-ma-conn.js.map +1 -1
- package/package.json +81 -64
- package/src/ip-port-to-multiaddr.ts +2 -4
- package/src/multiaddr/is-loopback.ts +1 -2
- package/src/stream-to-ma-conn.ts +8 -10
package/LICENSE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAMnD,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,aA8BnE"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { logger } from '@libp2p/logger';
|
|
2
2
|
import { Multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import errCode from 'err-code';
|
|
4
4
|
import { Address4, Address6 } from '@achingbrain/ip-address';
|
|
5
|
-
const log =
|
|
6
|
-
error: debug('libp2p:ip-port-to-multiaddr:err')
|
|
7
|
-
});
|
|
5
|
+
const log = logger('libp2p:ip-port-to-multiaddr');
|
|
8
6
|
export const Errors = {
|
|
9
7
|
ERR_INVALID_IP_PARAMETER: 'ERR_INVALID_IP_PARAMETER',
|
|
10
8
|
ERR_INVALID_PORT_PARAMETER: 'ERR_INVALID_PORT_PARAMETER',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.js","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.js","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAE5D,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,wBAAwB,EAAE,0BAA0B;IACpD,0BAA0B,EAAE,4BAA4B;IACxD,cAAc,EAAE,gBAAgB;CACjC,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,EAAU,EAAE,IAAqB;IAClE,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC1B,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,wBAAwB,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,wBAAwB,CAAC,CAAA,CAAC,uEAAuE;KAChK;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;KACtB;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAA;KAC9F;IAED,IAAI;QACF,kBAAkB;QAClB,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA,CAAC,6BAA6B;QAC9C,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC/C;IAAC,MAAM,GAAE;IAEV,IAAI;QACF,kBAAkB;QAClB,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC5B,OAAO,GAAG,CAAC,GAAG,EAAE;YACd,CAAC,CAAC,IAAI,SAAS,CAAC,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC;YAC9D,CAAC,CAAC,IAAI,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC5C;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,MAAM,GAAG,6CAA6C,EAAE,IAAI,IAAI,EAAE,CAAA;QACxE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACjB,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;KACxD;AACH,CAAC"}
|
|
@@ -2,5 +2,5 @@ import type { Multiaddr } from '@multiformats/multiaddr';
|
|
|
2
2
|
/**
|
|
3
3
|
* Check if a given multiaddr is a loopback address.
|
|
4
4
|
*/
|
|
5
|
-
export declare function isLoopback(ma: Multiaddr):
|
|
5
|
+
export declare function isLoopback(ma: Multiaddr): boolean;
|
|
6
6
|
//# sourceMappingURL=is-loopback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-loopback.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-loopback.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-loopback.d.ts","sourceRoot":"","sources":["../../../src/multiaddr/is-loopback.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,UAAU,CAAE,EAAE,EAAE,SAAS,WAIxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-loopback.js","sourceRoot":"","sources":["../../../src/multiaddr/is-loopback.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"is-loopback.js","sourceRoot":"","sources":["../../../src/multiaddr/is-loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAE,EAAa;IACvC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAA;IAEpC,OAAO,cAAc,CAAC,OAAO,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Stream } from '@libp2p/interfaces/connection';
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import type { MultiaddrConnection } from '@libp2p/interfaces/transport';
|
|
4
4
|
/**
|
|
@@ -25,7 +25,7 @@ interface StreamOptions {
|
|
|
25
25
|
signal?: AbortSignal;
|
|
26
26
|
}
|
|
27
27
|
interface StreamProperties {
|
|
28
|
-
stream:
|
|
28
|
+
stream: Stream;
|
|
29
29
|
remoteAddr: Multiaddr;
|
|
30
30
|
localAddr: Multiaddr;
|
|
31
31
|
}
|
|
@@ -33,6 +33,6 @@ interface StreamProperties {
|
|
|
33
33
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
34
34
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
35
35
|
*/
|
|
36
|
-
export declare function streamToMaConnection(props: StreamProperties, options?: StreamOptions): MultiaddrConnection
|
|
36
|
+
export declare function streamToMaConnection(props: StreamProperties, options?: StreamOptions): MultiaddrConnection;
|
|
37
37
|
export {};
|
|
38
38
|
//# sourceMappingURL=stream-to-ma-conn.d.ts.map
|
|
@@ -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,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAIvE;;;;;GAKG;AAEH,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,CAAA;IACd,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,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
const log =
|
|
1
|
+
import { abortableSource } from 'abortable-iterator';
|
|
2
|
+
import { logger } from '@libp2p/logger';
|
|
3
|
+
const log = logger('libp2p:stream:converter');
|
|
4
4
|
/**
|
|
5
5
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
6
6
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
7
7
|
*/
|
|
8
8
|
export function streamToMaConnection(props, options = {}) {
|
|
9
|
-
const { stream, remoteAddr
|
|
9
|
+
const { stream, remoteAddr } = props;
|
|
10
10
|
const { sink, source } = stream;
|
|
11
11
|
const maConn = {
|
|
12
12
|
async sink(source) {
|
|
13
13
|
if (options.signal != null) {
|
|
14
|
-
source =
|
|
14
|
+
source = abortableSource(source, options.signal);
|
|
15
15
|
}
|
|
16
16
|
try {
|
|
17
17
|
await sink(source);
|
|
@@ -27,9 +27,7 @@ export function streamToMaConnection(props, options = {}) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
-
source: (options.signal != null) ?
|
|
31
|
-
conn: stream,
|
|
32
|
-
localAddr,
|
|
30
|
+
source: (options.signal != null) ? abortableSource(source, options.signal) : source,
|
|
33
31
|
remoteAddr,
|
|
34
32
|
/** @type {Timeline} */
|
|
35
33
|
timeline: { open: Date.now(), close: undefined },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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;AAqC7C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB,EAAE,UAAyB,EAAE;IACxF,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IACpC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAC/B,MAAM,MAAM,GAAwB;QAClC,KAAK,CAAC,IAAI,CAAE,MAAM;YAChB,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE;gBAC1B,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;aACjD;YAED,IAAI;gBACF,MAAM,IAAI,CAAC,MAAM,CAAC,CAAA;gBAClB,MAAM,KAAK,EAAE,CAAA;aACd;YAAC,OAAO,GAAQ,EAAE;gBACjB,kCAAkC;gBAClC,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;oBAC1B,uEAAuE;oBACvE,gEAAgE;oBAChE,uEAAuE;oBACvE,GAAG,CAAC,GAAG,CAAC,CAAA;iBACT;aACF;QACH,CAAC;QACD,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;QACnF,UAAU;QACV,uBAAuB;QACvB,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;QAChD,KAAK,CAAC,KAAK;YACT,MAAM,IAAI,CAAC,KAAK,SAAU,CAAC;gBACzB,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;YACzB,CAAC,EAAE,CAAC,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,17 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
|
-
"
|
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p-utils#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p-utils.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p-utils/issues"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=16.0.0",
|
|
16
|
+
"npm": ">=7.0.0"
|
|
17
|
+
},
|
|
6
18
|
"type": "module",
|
|
19
|
+
"types": "./dist/src/index.d.ts",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
"*": [
|
|
23
|
+
"*",
|
|
24
|
+
"dist/*",
|
|
25
|
+
"dist/src/*",
|
|
26
|
+
"dist/src/*/index"
|
|
27
|
+
],
|
|
28
|
+
"src/*": [
|
|
29
|
+
"*",
|
|
30
|
+
"dist/*",
|
|
31
|
+
"dist/src/*",
|
|
32
|
+
"dist/src/*/index"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src",
|
|
38
|
+
"dist/src",
|
|
39
|
+
"!dist/test",
|
|
40
|
+
"!**/*.tsbuildinfo"
|
|
41
|
+
],
|
|
7
42
|
"exports": {
|
|
8
|
-
"
|
|
9
|
-
"import": "./dist/src/
|
|
10
|
-
"types": "./dist/src/multiaddr/is-loopback.d.ts"
|
|
11
|
-
},
|
|
12
|
-
"./multiaddr/is-private": {
|
|
13
|
-
"import": "./dist/src/multiaddr/is-private.js",
|
|
14
|
-
"types": "./dist/src/multiaddr/is-private.d.ts"
|
|
43
|
+
".": {
|
|
44
|
+
"import": "./dist/src/index.js"
|
|
15
45
|
},
|
|
16
46
|
"./address-sort": {
|
|
17
47
|
"import": "./dist/src/address-sort.js",
|
|
@@ -25,68 +55,25 @@
|
|
|
25
55
|
"import": "./dist/src/ip-port-to-multiaddr.js",
|
|
26
56
|
"types": "./dist/src/ip-port-to-multiaddr.d.ts"
|
|
27
57
|
},
|
|
58
|
+
"./multiaddr/is-loopback": {
|
|
59
|
+
"import": "./dist/src/multiaddr/is-loopback.js",
|
|
60
|
+
"types": "./dist/src/multiaddr/is-loopback.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./multiaddr/is-private": {
|
|
63
|
+
"import": "./dist/src/multiaddr/is-private.js",
|
|
64
|
+
"types": "./dist/src/multiaddr/is-private.d.ts"
|
|
65
|
+
},
|
|
28
66
|
"./stream-to-ma-conn": {
|
|
29
67
|
"import": "./dist/src/stream-to-ma-connr.js",
|
|
30
68
|
"types": "./dist/src/stream-to-ma-connr.d.ts"
|
|
31
69
|
}
|
|
32
70
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"dist/src/*/index"
|
|
38
|
-
],
|
|
39
|
-
"src/*": [
|
|
40
|
-
"dist/src/*",
|
|
41
|
-
"dist/src/*/index"
|
|
42
|
-
]
|
|
71
|
+
"eslintConfig": {
|
|
72
|
+
"extends": "ipfs",
|
|
73
|
+
"parserOptions": {
|
|
74
|
+
"sourceType": "module"
|
|
43
75
|
}
|
|
44
76
|
},
|
|
45
|
-
"files": [
|
|
46
|
-
"src",
|
|
47
|
-
"dist/src"
|
|
48
|
-
],
|
|
49
|
-
"scripts": {
|
|
50
|
-
"lint": "aegir lint",
|
|
51
|
-
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
|
|
52
|
-
"build": "tsc",
|
|
53
|
-
"pretest": "npm run build",
|
|
54
|
-
"test": "aegir test -f ./dist/test/**/*.js",
|
|
55
|
-
"test:chrome": "npm run test -- -t browser",
|
|
56
|
-
"test:chrome-webworker": "npm run test -- -t webworker",
|
|
57
|
-
"test:firefox": "npm run test -- -t browser -- --browser firefox",
|
|
58
|
-
"test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
|
|
59
|
-
"test:node": "npm run test -- -t node --cov",
|
|
60
|
-
"test:electron-main": "npm run test -- -t electron-main",
|
|
61
|
-
"release": "semantic-release"
|
|
62
|
-
},
|
|
63
|
-
"repository": {
|
|
64
|
-
"type": "git",
|
|
65
|
-
"url": "git+https://github.com/libp2p/js-libp2p-utils.git"
|
|
66
|
-
},
|
|
67
|
-
"license": "Apache-2.0 OR MIT",
|
|
68
|
-
"bugs": {
|
|
69
|
-
"url": "https://github.com/libp2p/js-libp2p-utils/issues"
|
|
70
|
-
},
|
|
71
|
-
"homepage": "https://github.com/libp2p/js-libp2p-utils#readme",
|
|
72
|
-
"devDependencies": {
|
|
73
|
-
"@libp2p/interfaces": "^0.2.0",
|
|
74
|
-
"@types/debug": "^4.1.5",
|
|
75
|
-
"aegir": "^36.1.2",
|
|
76
|
-
"it-pair": "^1.0.0",
|
|
77
|
-
"it-pipe": "^1.1.0",
|
|
78
|
-
"streaming-iterables": "^6.0.0",
|
|
79
|
-
"util": "^0.12.3"
|
|
80
|
-
},
|
|
81
|
-
"dependencies": {
|
|
82
|
-
"@achingbrain/ip-address": "^8.1.0",
|
|
83
|
-
"@multiformats/multiaddr": "^10.1.1",
|
|
84
|
-
"abortable-iterator": "^3.0.0",
|
|
85
|
-
"debug": "^4.3.0",
|
|
86
|
-
"err-code": "^3.0.1",
|
|
87
|
-
"is-loopback-addr": "^1.0.0",
|
|
88
|
-
"private-ip": "^2.1.1"
|
|
89
|
-
},
|
|
90
77
|
"release": {
|
|
91
78
|
"branches": [
|
|
92
79
|
"master"
|
|
@@ -167,5 +154,35 @@
|
|
|
167
154
|
"@semantic-release/github",
|
|
168
155
|
"@semantic-release/git"
|
|
169
156
|
]
|
|
157
|
+
},
|
|
158
|
+
"scripts": {
|
|
159
|
+
"lint": "aegir lint",
|
|
160
|
+
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
|
|
161
|
+
"build": "tsc",
|
|
162
|
+
"pretest": "npm run build",
|
|
163
|
+
"test": "aegir test -f ./dist/test/*.js -f ./dist/test/**/*.js",
|
|
164
|
+
"test:chrome": "npm run test -- -t browser --cov",
|
|
165
|
+
"test:chrome-webworker": "npm run test -- -t webworker",
|
|
166
|
+
"test:firefox": "npm run test -- -t browser -- --browser firefox",
|
|
167
|
+
"test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
|
|
168
|
+
"test:node": "npm run test -- -t node --cov",
|
|
169
|
+
"test:electron-main": "npm run test -- -t electron-main",
|
|
170
|
+
"release": "semantic-release"
|
|
171
|
+
},
|
|
172
|
+
"dependencies": {
|
|
173
|
+
"@achingbrain/ip-address": "^8.1.0",
|
|
174
|
+
"@libp2p/logger": "^1.0.1",
|
|
175
|
+
"@multiformats/multiaddr": "^10.1.1",
|
|
176
|
+
"abortable-iterator": "^4.0.2",
|
|
177
|
+
"err-code": "^3.0.1",
|
|
178
|
+
"is-loopback-addr": "^2.0.1",
|
|
179
|
+
"private-ip": "^2.1.1"
|
|
180
|
+
},
|
|
181
|
+
"devDependencies": {
|
|
182
|
+
"@libp2p/interfaces": "^1.0.3",
|
|
183
|
+
"aegir": "^36.1.2",
|
|
184
|
+
"it-all": "^1.0.6",
|
|
185
|
+
"it-pair": "^2.0.2",
|
|
186
|
+
"it-pipe": "^2.0.2"
|
|
170
187
|
}
|
|
171
188
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { logger } from '@libp2p/logger'
|
|
2
2
|
import { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import errCode from 'err-code'
|
|
4
4
|
import { Address4, Address6 } from '@achingbrain/ip-address'
|
|
5
5
|
|
|
6
|
-
const log =
|
|
7
|
-
error: debug('libp2p:ip-port-to-multiaddr:err')
|
|
8
|
-
})
|
|
6
|
+
const log = logger('libp2p:ip-port-to-multiaddr')
|
|
9
7
|
|
|
10
8
|
export const Errors = {
|
|
11
9
|
ERR_INVALID_IP_PARAMETER: 'ERR_INVALID_IP_PARAMETER',
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
1
|
+
import { abortableSource } from 'abortable-iterator'
|
|
2
|
+
import { logger } from '@libp2p/logger'
|
|
3
|
+
import type { Stream } from '@libp2p/interfaces/connection'
|
|
4
4
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
5
|
import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
|
|
6
6
|
|
|
7
|
-
const log =
|
|
7
|
+
const log = logger('libp2p:stream:converter')
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {Object} Timeline
|
|
@@ -36,7 +36,7 @@ interface StreamOptions {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
interface StreamProperties {
|
|
39
|
-
stream:
|
|
39
|
+
stream: Stream
|
|
40
40
|
remoteAddr: Multiaddr
|
|
41
41
|
localAddr: Multiaddr
|
|
42
42
|
}
|
|
@@ -46,12 +46,12 @@ interface StreamProperties {
|
|
|
46
46
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
47
47
|
*/
|
|
48
48
|
export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) {
|
|
49
|
-
const { stream, remoteAddr
|
|
49
|
+
const { stream, remoteAddr } = props
|
|
50
50
|
const { sink, source } = stream
|
|
51
51
|
const maConn: MultiaddrConnection = {
|
|
52
52
|
async sink (source) {
|
|
53
53
|
if (options.signal != null) {
|
|
54
|
-
source =
|
|
54
|
+
source = abortableSource(source, options.signal)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
try {
|
|
@@ -67,9 +67,7 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
source: (options.signal != null) ?
|
|
71
|
-
conn: stream,
|
|
72
|
-
localAddr,
|
|
70
|
+
source: (options.signal != null) ? abortableSource(source, options.signal) : source,
|
|
73
71
|
remoteAddr,
|
|
74
72
|
/** @type {Timeline} */
|
|
75
73
|
timeline: { open: Date.now(), close: undefined },
|