@libp2p/utils 3.0.12-8b0e6bef → 3.0.12-a1ec46b5
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.
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import type { MultiaddrConnection } from '@libp2p/interface/connection';
|
|
1
|
+
import type { MultiaddrConnection, Stream } from '@libp2p/interface/connection';
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
-
import type { Duplex, Source } from 'it-stream-types';
|
|
4
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
-
export interface Timeline {
|
|
6
|
-
/**
|
|
7
|
-
* Connection opening timestamp
|
|
8
|
-
*/
|
|
9
|
-
open: number;
|
|
10
|
-
/**
|
|
11
|
-
* Connection upgraded timestamp
|
|
12
|
-
*/
|
|
13
|
-
upgraded?: number;
|
|
14
|
-
/**
|
|
15
|
-
* Connection closed timestamp
|
|
16
|
-
*/
|
|
17
|
-
close?: number;
|
|
18
|
-
}
|
|
19
|
-
export interface StreamOptions {
|
|
20
|
-
signal?: AbortSignal;
|
|
21
|
-
}
|
|
22
3
|
export interface StreamProperties {
|
|
23
|
-
stream:
|
|
4
|
+
stream: Stream;
|
|
24
5
|
remoteAddr: Multiaddr;
|
|
25
6
|
localAddr: Multiaddr;
|
|
26
7
|
}
|
|
@@ -28,5 +9,5 @@ export interface StreamProperties {
|
|
|
28
9
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
29
10
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
30
11
|
*/
|
|
31
|
-
export declare function streamToMaConnection(props: StreamProperties
|
|
12
|
+
export declare function streamToMaConnection(props: StreamProperties): MultiaddrConnection;
|
|
32
13
|
//# 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,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CAiDlF"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger';
|
|
2
|
-
import { abortableSource } from 'abortable-iterator';
|
|
3
2
|
const log = logger('libp2p:stream:converter');
|
|
4
3
|
/**
|
|
5
4
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
6
5
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
7
6
|
*/
|
|
8
|
-
export function streamToMaConnection(props
|
|
7
|
+
export function streamToMaConnection(props) {
|
|
9
8
|
const { stream, remoteAddr } = props;
|
|
10
9
|
const { sink, source } = stream;
|
|
11
10
|
const mapSource = (async function* () {
|
|
@@ -20,12 +19,9 @@ export function streamToMaConnection(props, options = {}) {
|
|
|
20
19
|
}());
|
|
21
20
|
const maConn = {
|
|
22
21
|
async sink(source) {
|
|
23
|
-
if (options.signal != null) {
|
|
24
|
-
source = abortableSource(source, options.signal);
|
|
25
|
-
}
|
|
26
22
|
try {
|
|
27
23
|
await sink(source);
|
|
28
|
-
|
|
24
|
+
close();
|
|
29
25
|
}
|
|
30
26
|
catch (err) {
|
|
31
27
|
// If aborted we can safely ignore
|
|
@@ -37,21 +33,22 @@ export function streamToMaConnection(props, options = {}) {
|
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
},
|
|
40
|
-
source:
|
|
36
|
+
source: mapSource,
|
|
41
37
|
remoteAddr,
|
|
42
38
|
timeline: { open: Date.now(), close: undefined },
|
|
43
|
-
async close() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
async close(options) {
|
|
40
|
+
close();
|
|
41
|
+
await stream.close(options);
|
|
42
|
+
},
|
|
43
|
+
abort(err) {
|
|
44
|
+
close();
|
|
45
|
+
stream.abort(err);
|
|
48
46
|
}
|
|
49
47
|
};
|
|
50
|
-
|
|
48
|
+
function close() {
|
|
51
49
|
if (maConn.timeline.close == null) {
|
|
52
50
|
maConn.timeline.close = Date.now();
|
|
53
51
|
}
|
|
54
|
-
await Promise.resolve();
|
|
55
52
|
}
|
|
56
53
|
return maConn;
|
|
57
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAKvC,MAAM,GAAG,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA;AAQ7C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IACpC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAE/B,MAAM,SAAS,GAAG,CAAC,KAAK,SAAU,CAAC;QACjC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;YAC/B,IAAI,IAAI,YAAY,UAAU,EAAE;gBAC9B,MAAM,IAAI,CAAA;aACX;iBAAM;gBACL,KAAM,CAAC,CAAC,IAAI,CAAA;aACb;SACF;IACH,CAAC,EAAE,CAAC,CAAA;IAEJ,MAAM,MAAM,GAAwB;QAClC,KAAK,CAAC,IAAI,CAAE,MAAM;YAChB,IAAI;gBACF,MAAM,IAAI,CAAC,MAAM,CAAC,CAAA;gBAClB,KAAK,EAAE,CAAA;aACR;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,SAAS;QACjB,UAAU;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;QAChD,KAAK,CAAC,KAAK,CAAE,OAAsB;YACjC,KAAK,EAAE,CAAA;YACP,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;QACD,KAAK,CAAE,GAAU;YACf,KAAK,EAAE,CAAA;YACP,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;KACF,CAAA;IAED,SAAS,KAAK;QACZ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE;YACjC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;SACnC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "3.0.12-
|
|
3
|
+
"version": "3.0.12-a1ec46b5",
|
|
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/master/packages/utils#readme",
|
|
@@ -86,21 +86,20 @@
|
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@achingbrain/ip-address": "^8.1.0",
|
|
89
|
-
"@libp2p/interface": "0.0.1-
|
|
90
|
-
"@libp2p/logger": "2.1.1-
|
|
89
|
+
"@libp2p/interface": "0.0.1-a1ec46b5",
|
|
90
|
+
"@libp2p/logger": "2.1.1-a1ec46b5",
|
|
91
91
|
"@multiformats/multiaddr": "^12.1.3",
|
|
92
|
-
"abortable-iterator": "^5.0.1",
|
|
93
92
|
"is-loopback-addr": "^2.0.1",
|
|
94
93
|
"it-stream-types": "^2.0.1",
|
|
95
94
|
"private-ip": "^3.0.0",
|
|
96
95
|
"uint8arraylist": "^2.4.3"
|
|
97
96
|
},
|
|
98
97
|
"devDependencies": {
|
|
99
|
-
"aegir": "^39.0.
|
|
98
|
+
"aegir": "^39.0.13",
|
|
100
99
|
"it-all": "^3.0.1",
|
|
101
100
|
"it-pair": "^2.0.6",
|
|
102
101
|
"it-pipe": "^3.0.1",
|
|
103
|
-
"uint8arrays": "^4.0.
|
|
102
|
+
"uint8arrays": "^4.0.4"
|
|
104
103
|
},
|
|
105
104
|
"typedoc": {
|
|
106
105
|
"entryPoint": "./src/index.ts"
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import {
|
|
3
|
-
import type { MultiaddrConnection } from '@libp2p/interface/connection'
|
|
2
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
3
|
+
import type { MultiaddrConnection, Stream } from '@libp2p/interface/connection'
|
|
4
4
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
|
-
import type { Duplex, Source } from 'it-stream-types'
|
|
6
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
7
5
|
|
|
8
6
|
const log = logger('libp2p:stream:converter')
|
|
9
7
|
|
|
10
|
-
export interface Timeline {
|
|
11
|
-
/**
|
|
12
|
-
* Connection opening timestamp
|
|
13
|
-
*/
|
|
14
|
-
open: number
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Connection upgraded timestamp
|
|
18
|
-
*/
|
|
19
|
-
upgraded?: number
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Connection closed timestamp
|
|
23
|
-
*/
|
|
24
|
-
close?: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface StreamOptions {
|
|
28
|
-
signal?: AbortSignal
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
8
|
export interface StreamProperties {
|
|
33
|
-
stream:
|
|
9
|
+
stream: Stream
|
|
34
10
|
remoteAddr: Multiaddr
|
|
35
11
|
localAddr: Multiaddr
|
|
36
12
|
}
|
|
@@ -39,7 +15,7 @@ export interface StreamProperties {
|
|
|
39
15
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
40
16
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
41
17
|
*/
|
|
42
|
-
export function streamToMaConnection (props: StreamProperties
|
|
18
|
+
export function streamToMaConnection (props: StreamProperties): MultiaddrConnection {
|
|
43
19
|
const { stream, remoteAddr } = props
|
|
44
20
|
const { sink, source } = stream
|
|
45
21
|
|
|
@@ -55,13 +31,9 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
|
|
|
55
31
|
|
|
56
32
|
const maConn: MultiaddrConnection = {
|
|
57
33
|
async sink (source) {
|
|
58
|
-
if (options.signal != null) {
|
|
59
|
-
source = abortableSource(source, options.signal)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
34
|
try {
|
|
63
35
|
await sink(source)
|
|
64
|
-
|
|
36
|
+
close()
|
|
65
37
|
} catch (err: any) {
|
|
66
38
|
// If aborted we can safely ignore
|
|
67
39
|
if (err.type !== 'aborted') {
|
|
@@ -72,22 +44,23 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
|
|
|
72
44
|
}
|
|
73
45
|
}
|
|
74
46
|
},
|
|
75
|
-
source:
|
|
47
|
+
source: mapSource,
|
|
76
48
|
remoteAddr,
|
|
77
49
|
timeline: { open: Date.now(), close: undefined },
|
|
78
|
-
async close () {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
async close (options?: AbortOptions) {
|
|
51
|
+
close()
|
|
52
|
+
await stream.close(options)
|
|
53
|
+
},
|
|
54
|
+
abort (err: Error): void {
|
|
55
|
+
close()
|
|
56
|
+
stream.abort(err)
|
|
83
57
|
}
|
|
84
58
|
}
|
|
85
59
|
|
|
86
|
-
|
|
60
|
+
function close (): void {
|
|
87
61
|
if (maConn.timeline.close == null) {
|
|
88
62
|
maConn.timeline.close = Date.now()
|
|
89
63
|
}
|
|
90
|
-
await Promise.resolve()
|
|
91
64
|
}
|
|
92
65
|
|
|
93
66
|
return maConn
|