@libp2p/utils 2.0.0 → 3.0.1
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,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,oBAA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AC,eAAe,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;QACzF,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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",
|
|
@@ -172,23 +172,24 @@
|
|
|
172
172
|
},
|
|
173
173
|
"dependencies": {
|
|
174
174
|
"@achingbrain/ip-address": "^8.1.0",
|
|
175
|
-
"@libp2p/interface-connection": "^
|
|
175
|
+
"@libp2p/interface-connection": "^3.0.1",
|
|
176
176
|
"@libp2p/interface-peer-store": "^1.0.0",
|
|
177
|
-
"@libp2p/interface-transport": "^1.0.0",
|
|
178
177
|
"@libp2p/logger": "^2.0.0",
|
|
179
178
|
"@multiformats/multiaddr": "^10.1.1",
|
|
180
179
|
"abortable-iterator": "^4.0.2",
|
|
181
180
|
"err-code": "^3.0.1",
|
|
182
181
|
"is-loopback-addr": "^2.0.1",
|
|
183
182
|
"it-stream-types": "^1.0.4",
|
|
184
|
-
"private-ip": "^2.1.1"
|
|
183
|
+
"private-ip": "^2.1.1",
|
|
184
|
+
"uint8arraylist": "^2.3.2"
|
|
185
185
|
},
|
|
186
186
|
"devDependencies": {
|
|
187
|
-
"@libp2p/interfaces": "^1.0.3",
|
|
188
187
|
"aegir": "^37.2.0",
|
|
189
188
|
"it-all": "^1.0.6",
|
|
189
|
+
"it-map": "^1.0.6",
|
|
190
190
|
"it-pair": "^2.0.2",
|
|
191
191
|
"it-pipe": "^2.0.2",
|
|
192
|
+
"p-defer": "^4.0.0",
|
|
192
193
|
"uint8arrays": "^3.0.0"
|
|
193
194
|
}
|
|
194
195
|
}
|
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 },
|