@libp2p/utils 4.0.7-9ad8f8686 → 4.0.7-9c67c5b3d

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 +1 @@
1
- {"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CAkDlF"}
1
+ {"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,eAAe,CAAA;CACxB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CAiElF"}
@@ -6,21 +6,28 @@ export function streamToMaConnection(props) {
6
6
  const { stream, remoteAddr, logger } = props;
7
7
  const { sink, source } = stream;
8
8
  const log = logger.forComponent('libp2p:stream:converter');
9
+ let closedRead = false;
10
+ let closedWrite = false;
9
11
  const mapSource = (async function* () {
10
- for await (const list of source) {
11
- if (list instanceof Uint8Array) {
12
- yield list;
13
- }
14
- else {
15
- yield* list;
12
+ try {
13
+ for await (const list of source) {
14
+ if (list instanceof Uint8Array) {
15
+ yield list;
16
+ }
17
+ else {
18
+ yield* list;
19
+ }
16
20
  }
17
21
  }
22
+ finally {
23
+ closedRead = true;
24
+ close();
25
+ }
18
26
  }());
19
27
  const maConn = {
20
28
  async sink(source) {
21
29
  try {
22
30
  await sink(source);
23
- close();
24
31
  }
25
32
  catch (err) {
26
33
  // If aborted we can safely ignore
@@ -31,21 +38,29 @@ export function streamToMaConnection(props) {
31
38
  log(err);
32
39
  }
33
40
  }
41
+ finally {
42
+ closedWrite = true;
43
+ close();
44
+ }
34
45
  },
35
46
  source: mapSource,
36
47
  remoteAddr,
37
48
  timeline: { open: Date.now(), close: undefined },
38
49
  async close(options) {
39
- close();
50
+ close(true);
40
51
  await stream.close(options);
41
52
  },
42
53
  abort(err) {
43
- close();
54
+ close(true);
44
55
  stream.abort(err);
45
56
  }
46
57
  };
47
- function close() {
48
- if (maConn.timeline.close == null) {
58
+ function close(force) {
59
+ if (force === true) {
60
+ closedRead = true;
61
+ closedWrite = true;
62
+ }
63
+ if (closedRead && closedWrite && maConn.timeline.close == null) {
49
64
  maConn.timeline.close = Date.now();
50
65
  }
51
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,KAAK,CAAA;IAC5C,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAC/B,MAAM,GAA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,KAAK,EAAE,SAAS,EAAE;QAChD,KAAK,CAAC,KAAK,CAAE,OAAsB;YACjC,KAAK,CAAC,IAAI,CAAC,CAAA;YACX,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;QACD,KAAK,CAAE,GAAU;YACf,KAAK,CAAC,IAAI,CAAC,CAAA;YACX,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;KACF,CAAA;IAED,SAAS,KAAK,CAAE,KAAe;QAC7B,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,UAAU,GAAG,IAAI,CAAA;YACjB,WAAW,GAAG,IAAI,CAAA;SACnB;QAED,IAAI,UAAU,IAAI,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE;YAC9D,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": "4.0.7-9ad8f8686",
3
+ "version": "4.0.7-9c67c5b3d",
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",
@@ -91,7 +91,7 @@
91
91
  },
92
92
  "dependencies": {
93
93
  "@chainsafe/is-ip": "^2.0.2",
94
- "@libp2p/interface": "0.1.6-9ad8f8686",
94
+ "@libp2p/interface": "0.1.6-9c67c5b3d",
95
95
  "@multiformats/multiaddr": "^12.1.10",
96
96
  "@multiformats/multiaddr-matcher": "^1.1.0",
97
97
  "is-loopback-addr": "^2.0.1",
@@ -101,8 +101,8 @@
101
101
  "uint8arraylist": "^2.4.3"
102
102
  },
103
103
  "devDependencies": {
104
- "@libp2p/logger": "3.1.0-9ad8f8686",
105
- "@libp2p/peer-id-factory": "3.0.8-9ad8f8686",
104
+ "@libp2p/logger": "3.1.0-9c67c5b3d",
105
+ "@libp2p/peer-id-factory": "3.0.8-9c67c5b3d",
106
106
  "aegir": "^41.0.2",
107
107
  "it-all": "^3.0.3",
108
108
  "it-pair": "^2.0.6",
@@ -18,13 +18,21 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
18
18
  const { sink, source } = stream
19
19
  const log = logger.forComponent('libp2p:stream:converter')
20
20
 
21
+ let closedRead = false
22
+ let closedWrite = false
23
+
21
24
  const mapSource = (async function * () {
22
- for await (const list of source) {
23
- if (list instanceof Uint8Array) {
24
- yield list
25
- } else {
26
- yield * list
25
+ try {
26
+ for await (const list of source) {
27
+ if (list instanceof Uint8Array) {
28
+ yield list
29
+ } else {
30
+ yield * list
31
+ }
27
32
  }
33
+ } finally {
34
+ closedRead = true
35
+ close()
28
36
  }
29
37
  }())
30
38
 
@@ -32,7 +40,6 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
32
40
  async sink (source) {
33
41
  try {
34
42
  await sink(source)
35
- close()
36
43
  } catch (err: any) {
37
44
  // If aborted we can safely ignore
38
45
  if (err.type !== 'aborted') {
@@ -41,23 +48,31 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
41
48
  // destroyed. There's nothing to do here except log the error & return.
42
49
  log(err)
43
50
  }
51
+ } finally {
52
+ closedWrite = true
53
+ close()
44
54
  }
45
55
  },
46
56
  source: mapSource,
47
57
  remoteAddr,
48
58
  timeline: { open: Date.now(), close: undefined },
49
59
  async close (options?: AbortOptions) {
50
- close()
60
+ close(true)
51
61
  await stream.close(options)
52
62
  },
53
63
  abort (err: Error): void {
54
- close()
64
+ close(true)
55
65
  stream.abort(err)
56
66
  }
57
67
  }
58
68
 
59
- function close (): void {
60
- if (maConn.timeline.close == null) {
69
+ function close (force?: boolean): void {
70
+ if (force === true) {
71
+ closedRead = true
72
+ closedWrite = true
73
+ }
74
+
75
+ if (closedRead && closedWrite && maConn.timeline.close == null) {
61
76
  maConn.timeline.close = Date.now()
62
77
  }
63
78
  }