@libp2p/utils 3.0.0 → 3.0.2
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 +2 -2
- package/dist/src/array-equals.d.ts.map +1 -1
- package/dist/src/array-equals.js +5 -1
- package/dist/src/array-equals.js.map +1 -1
- package/dist/src/ip-port-to-multiaddr.d.ts +1 -2
- package/dist/src/ip-port-to-multiaddr.d.ts.map +1 -1
- package/dist/src/ip-port-to-multiaddr.js +4 -4
- package/dist/src/ip-port-to-multiaddr.js.map +1 -1
- package/dist/src/stream-to-ma-conn.d.ts +2 -1
- package/dist/src/stream-to-ma-conn.d.ts.map +1 -1
- package/dist/src/stream-to-ma-conn.js +6 -1
- package/dist/src/stream-to-ma-conn.js.map +1 -1
- package/package.json +16 -9
- package/src/array-equals.ts +8 -1
- package/src/ip-port-to-multiaddr.ts +4 -4
- package/src/stream-to-ma-conn.ts +10 -2
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
- [Usage](#usage)
|
|
16
16
|
- [Contribute](#contribute)
|
|
17
17
|
- [License](#license)
|
|
18
|
-
- [
|
|
18
|
+
- [Contribute](#contribute-1)
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
@@ -59,6 +59,6 @@ Licensed under either of
|
|
|
59
59
|
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
60
60
|
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
61
61
|
|
|
62
|
-
##
|
|
62
|
+
## Contribute
|
|
63
63
|
|
|
64
64
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-equals.d.ts","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"array-equals.d.ts","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,WAU9C"}
|
package/dist/src/array-equals.js
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export function arrayEquals(a, b) {
|
|
6
6
|
const sort = (a, b) => a.toString().localeCompare(b.toString());
|
|
7
|
-
|
|
7
|
+
if (a.length !== b.length) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
b.sort(sort);
|
|
11
|
+
return a.sort(sort).every((item, index) => b[index].equals(item));
|
|
8
12
|
}
|
|
9
13
|
//# sourceMappingURL=array-equals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-equals.js","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,CAAQ,EAAE,CAAQ;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"array-equals.js","sourceRoot":"","sources":["../../src/array-equals.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAE,CAAQ,EAAE,CAAQ;IAC7C,MAAM,IAAI,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEzE,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;QACzB,OAAO,KAAK,CAAA;KACb;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,4 +1,3 @@
|
|
|
1
|
-
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
1
|
export declare const Errors: {
|
|
3
2
|
ERR_INVALID_IP_PARAMETER: string;
|
|
4
3
|
ERR_INVALID_PORT_PARAMETER: string;
|
|
@@ -7,5 +6,5 @@ export declare const Errors: {
|
|
|
7
6
|
/**
|
|
8
7
|
* Transform an IP, Port pair into a multiaddr
|
|
9
8
|
*/
|
|
10
|
-
export declare function ipPortToMultiaddr(ip: string, port: number | string): Multiaddr;
|
|
9
|
+
export declare function ipPortToMultiaddr(ip: string, port: number | string): import("@multiformats/multiaddr").Multiaddr;
|
|
11
10
|
//# sourceMappingURL=ip-port-to-multiaddr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.d.ts","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,MAAM;;;;CAIlB,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,+CA8BnE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger';
|
|
2
|
-
import {
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import errCode from 'err-code';
|
|
4
4
|
import { Address4, Address6 } from '@achingbrain/ip-address';
|
|
5
5
|
const log = logger('libp2p:ip-port-to-multiaddr');
|
|
@@ -24,15 +24,15 @@ export function ipPortToMultiaddr(ip, port) {
|
|
|
24
24
|
try {
|
|
25
25
|
// Test valid IPv4
|
|
26
26
|
new Address4(ip); // eslint-disable-line no-new
|
|
27
|
-
return
|
|
27
|
+
return multiaddr(`/ip4/${ip}/tcp/${port}`);
|
|
28
28
|
}
|
|
29
29
|
catch { }
|
|
30
30
|
try {
|
|
31
31
|
// Test valid IPv6
|
|
32
32
|
const ip6 = new Address6(ip);
|
|
33
33
|
return ip6.is4()
|
|
34
|
-
?
|
|
35
|
-
:
|
|
34
|
+
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
|
|
35
|
+
: multiaddr(`/ip6/${ip}/tcp/${port}`);
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
38
|
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`;
|
|
@@ -1 +1 @@
|
|
|
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;I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EAAuE;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,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC3C;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,SAAS,CAAC,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC;YAC1D,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KACxC;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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
import type { MultiaddrConnection } from '@libp2p/interface-connection';
|
|
3
3
|
import type { Duplex } from 'it-stream-types';
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
4
5
|
export interface Timeline {
|
|
5
6
|
/**
|
|
6
7
|
* Connection opening timestamp
|
|
@@ -19,7 +20,7 @@ interface StreamOptions {
|
|
|
19
20
|
signal?: AbortSignal;
|
|
20
21
|
}
|
|
21
22
|
interface StreamProperties {
|
|
22
|
-
stream: Duplex<Uint8Array>;
|
|
23
|
+
stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>;
|
|
23
24
|
remoteAddr: Multiaddr;
|
|
24
25
|
localAddr: Multiaddr;
|
|
25
26
|
}
|
|
@@ -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,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;
|
|
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;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,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,cAAc,EAAE,cAAc,GAAG,UAAU,CAAC,CAAA;IAC3D,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,uBAiDzF"}
|
|
@@ -8,6 +8,11 @@ const log = logger('libp2p:stream:converter');
|
|
|
8
8
|
export function streamToMaConnection(props, options = {}) {
|
|
9
9
|
const { stream, remoteAddr } = props;
|
|
10
10
|
const { sink, source } = stream;
|
|
11
|
+
const mapSource = (async function* () {
|
|
12
|
+
for await (const list of source) {
|
|
13
|
+
yield* list;
|
|
14
|
+
}
|
|
15
|
+
}());
|
|
11
16
|
const maConn = {
|
|
12
17
|
async sink(source) {
|
|
13
18
|
if (options.signal != null) {
|
|
@@ -27,7 +32,7 @@ export function streamToMaConnection(props, options = {}) {
|
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
|
-
source: (options.signal != null) ? abortableSource(
|
|
35
|
+
source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource,
|
|
31
36
|
remoteAddr,
|
|
32
37
|
/** @type {Timeline} */
|
|
33
38
|
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,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,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,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAMvC,MAAM,GAAG,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA;AA8B7C;;;GAGG;AACH,MAAM,UAAU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AAM,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": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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",
|
|
@@ -102,15 +102,15 @@
|
|
|
102
102
|
"release": "patch"
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
"type": "
|
|
105
|
+
"type": "docs",
|
|
106
106
|
"release": "patch"
|
|
107
107
|
},
|
|
108
108
|
{
|
|
109
|
-
"type": "
|
|
109
|
+
"type": "test",
|
|
110
110
|
"release": "patch"
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
"type": "
|
|
113
|
+
"type": "deps",
|
|
114
114
|
"release": "patch"
|
|
115
115
|
},
|
|
116
116
|
{
|
|
@@ -140,7 +140,11 @@
|
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"type": "docs",
|
|
143
|
-
"section": "
|
|
143
|
+
"section": "Documentation"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "deps",
|
|
147
|
+
"section": "Dependencies"
|
|
144
148
|
},
|
|
145
149
|
{
|
|
146
150
|
"type": "test",
|
|
@@ -172,21 +176,24 @@
|
|
|
172
176
|
},
|
|
173
177
|
"dependencies": {
|
|
174
178
|
"@achingbrain/ip-address": "^8.1.0",
|
|
175
|
-
"@libp2p/interface-connection": "^
|
|
176
|
-
"@libp2p/interface-peer-store": "^1.
|
|
179
|
+
"@libp2p/interface-connection": "^3.0.2",
|
|
180
|
+
"@libp2p/interface-peer-store": "^1.2.1",
|
|
177
181
|
"@libp2p/logger": "^2.0.0",
|
|
178
|
-
"@multiformats/multiaddr": "^
|
|
182
|
+
"@multiformats/multiaddr": "^11.0.0",
|
|
179
183
|
"abortable-iterator": "^4.0.2",
|
|
180
184
|
"err-code": "^3.0.1",
|
|
181
185
|
"is-loopback-addr": "^2.0.1",
|
|
182
186
|
"it-stream-types": "^1.0.4",
|
|
183
|
-
"private-ip": "^2.1.1"
|
|
187
|
+
"private-ip": "^2.1.1",
|
|
188
|
+
"uint8arraylist": "^2.3.2"
|
|
184
189
|
},
|
|
185
190
|
"devDependencies": {
|
|
186
191
|
"aegir": "^37.2.0",
|
|
187
192
|
"it-all": "^1.0.6",
|
|
193
|
+
"it-map": "^1.0.6",
|
|
188
194
|
"it-pair": "^2.0.2",
|
|
189
195
|
"it-pipe": "^2.0.2",
|
|
196
|
+
"p-defer": "^4.0.0",
|
|
190
197
|
"uint8arrays": "^3.0.0"
|
|
191
198
|
}
|
|
192
199
|
}
|
package/src/array-equals.ts
CHANGED
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export function arrayEquals (a: any[], b: any[]) {
|
|
6
6
|
const sort = (a: any, b: any) => a.toString().localeCompare(b.toString())
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
if (a.length !== b.length) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
b.sort(sort)
|
|
13
|
+
|
|
14
|
+
return a.sort(sort).every((item, index) => b[index].equals(item))
|
|
8
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import {
|
|
2
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import errCode from 'err-code'
|
|
4
4
|
import { Address4, Address6 } from '@achingbrain/ip-address'
|
|
5
5
|
|
|
@@ -30,15 +30,15 @@ export function ipPortToMultiaddr (ip: string, port: number | string) {
|
|
|
30
30
|
try {
|
|
31
31
|
// Test valid IPv4
|
|
32
32
|
new Address4(ip) // eslint-disable-line no-new
|
|
33
|
-
return
|
|
33
|
+
return multiaddr(`/ip4/${ip}/tcp/${port}`)
|
|
34
34
|
} catch {}
|
|
35
35
|
|
|
36
36
|
try {
|
|
37
37
|
// Test valid IPv6
|
|
38
38
|
const ip6 = new Address6(ip)
|
|
39
39
|
return ip6.is4()
|
|
40
|
-
?
|
|
41
|
-
:
|
|
40
|
+
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`)
|
|
41
|
+
: multiaddr(`/ip6/${ip}/tcp/${port}`)
|
|
42
42
|
} catch (err) {
|
|
43
43
|
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
|
|
44
44
|
log.error(errMsg)
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { logger } from '@libp2p/logger'
|
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import type { MultiaddrConnection } from '@libp2p/interface-connection'
|
|
5
5
|
import type { Duplex } from 'it-stream-types'
|
|
6
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
6
7
|
|
|
7
8
|
const log = logger('libp2p:stream:converter')
|
|
8
9
|
|
|
@@ -29,7 +30,7 @@ interface StreamOptions {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
interface StreamProperties {
|
|
32
|
-
stream: Duplex<Uint8Array>
|
|
33
|
+
stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>
|
|
33
34
|
remoteAddr: Multiaddr
|
|
34
35
|
localAddr: Multiaddr
|
|
35
36
|
}
|
|
@@ -41,6 +42,13 @@ interface StreamProperties {
|
|
|
41
42
|
export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}) {
|
|
42
43
|
const { stream, remoteAddr } = props
|
|
43
44
|
const { sink, source } = stream
|
|
45
|
+
|
|
46
|
+
const mapSource = (async function * () {
|
|
47
|
+
for await (const list of source) {
|
|
48
|
+
yield * list
|
|
49
|
+
}
|
|
50
|
+
}())
|
|
51
|
+
|
|
44
52
|
const maConn: MultiaddrConnection = {
|
|
45
53
|
async sink (source) {
|
|
46
54
|
if (options.signal != null) {
|
|
@@ -60,7 +68,7 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
|
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
},
|
|
63
|
-
source: (options.signal != null) ? abortableSource(
|
|
71
|
+
source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource,
|
|
64
72
|
remoteAddr,
|
|
65
73
|
/** @type {Timeline} */
|
|
66
74
|
timeline: { open: Date.now(), close: undefined },
|