@libp2p/utils 3.0.12-8b0e6bef → 3.0.12-b1024c6c

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: Duplex<AsyncIterable<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>>;
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, options?: StreamOptions): MultiaddrConnection;
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,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACrD,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,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAA;CAErB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,CAAC,CAAA;IAClF,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,GAAE,aAAkB,GAAG,mBAAmB,CAoD/G"}
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, options = {}) {
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
- await close();
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: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource,
36
+ source: mapSource,
41
37
  remoteAddr,
42
38
  timeline: { open: Date.now(), close: undefined },
43
- async close() {
44
- await sink(async function* () {
45
- yield new Uint8Array(0);
46
- }());
47
- await close();
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
- async function close() {
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;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAMpD,MAAM,GAAG,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA;AA8B7C;;;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;IAE/B,MAAM,SAA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,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-8b0e6bef",
3
+ "version": "3.0.12-b1024c6c",
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-8b0e6bef",
90
- "@libp2p/logger": "2.1.1-8b0e6bef",
89
+ "@libp2p/interface": "0.0.1-b1024c6c",
90
+ "@libp2p/logger": "2.1.1-b1024c6c",
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.10",
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.3"
102
+ "uint8arrays": "^4.0.4"
104
103
  },
105
104
  "typedoc": {
106
105
  "entryPoint": "./src/index.ts"
@@ -1,36 +1,12 @@
1
1
  import { logger } from '@libp2p/logger'
2
- import { abortableSource } from 'abortable-iterator'
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: Duplex<AsyncIterable<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>>
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, options: StreamOptions = {}): MultiaddrConnection {
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
- await close()
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: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource,
47
+ source: mapSource,
76
48
  remoteAddr,
77
49
  timeline: { open: Date.now(), close: undefined },
78
- async close () {
79
- await sink(async function * () {
80
- yield new Uint8Array(0)
81
- }())
82
- await close()
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
- async function close (): Promise<void> {
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