@libp2p/utils 6.7.1-57e7fa441 → 6.7.1-79473c99a

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,11 +1,11 @@
1
- import type { ComponentLogger, MultiaddrConnection, Stream } from '@libp2p/interface';
1
+ import type { Logger, MultiaddrConnection, Stream } from '@libp2p/interface';
2
2
  import type { Multiaddr } from '@multiformats/multiaddr';
3
3
  import type { Uint8ArrayList } from 'uint8arraylist';
4
4
  export interface StreamProperties {
5
5
  stream: Stream;
6
6
  remoteAddr: Multiaddr;
7
7
  localAddr: Multiaddr;
8
- logger: ComponentLogger;
8
+ log: Logger;
9
9
  /**
10
10
  * A callback invoked when data is read from the stream
11
11
  */
@@ -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,eAAe,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;IACpB,MAAM,EAAE,eAAe,CAAA;IAEvB;;OAEG;IACH,UAAU,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,IAAI,CAAA;IAEnD;;OAEG;IACH,WAAW,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,IAAI,CAAA;CACrD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CA6ElF"}
1
+ {"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,UAAU,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,IAAI,CAAA;IAEnD;;OAEG;IACH,WAAW,CAAC,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,IAAI,CAAA;CACrD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CA8ElF"}
@@ -5,8 +5,7 @@ import { pipe } from 'it-pipe';
5
5
  * https://github.com/libp2p/interface-transport#multiaddrconnection
6
6
  */
7
7
  export function streamToMaConnection(props) {
8
- const { stream, remoteAddr, logger, onDataRead, onDataWrite } = props;
9
- const log = logger.forComponent('libp2p:stream:converter');
8
+ const { stream, remoteAddr, log, onDataRead, onDataWrite } = props;
10
9
  let closedRead = false;
11
10
  let closedWrite = false;
12
11
  // piggyback on `stream.close` invocations to close multiaddr connection
@@ -28,12 +27,13 @@ export function streamToMaConnection(props) {
28
27
  await streamSink(pipe(source, (source) => forEach(source, buf => onDataWrite?.(buf))));
29
28
  }
30
29
  catch (err) {
30
+ maConn.log.error('errored - %e', err);
31
31
  // If aborted we can safely ignore
32
32
  if (err.type !== 'aborted') {
33
33
  // If the source errored the socket will already have been destroyed by
34
34
  // toIterable.duplex(). If the socket errored it will already be
35
35
  // destroyed. There's nothing to do here except log the error & return.
36
- log.error('%s error in sink', remoteAddr, err);
36
+ maConn.log.error('%s error in sink - %e', remoteAddr, err);
37
37
  }
38
38
  }
39
39
  finally {
@@ -42,7 +42,7 @@ export function streamToMaConnection(props) {
42
42
  }
43
43
  };
44
44
  const maConn = {
45
- log,
45
+ log: log.newScope('stream-to-maconn'),
46
46
  sink: stream.sink,
47
47
  source: (async function* () {
48
48
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAsB9B;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,KAAK,CAAA;IACrE,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAA;IAE1D,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,WAAW,GAAG,KAAK,CAAA;IAEvB,wEAAwE;IACxE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,GAAG,KAAK,EAAE,OAAO,EAAiB,EAAE;QAC9C,MAAM,WAAW,CAAC,OAAO,CAAC,CAAA;QAC1B,KAAK,CAAC,IAAI,CAAC,CAAA;IACb,CAAC,CAAA;IAED,wEAAwE;IACxE,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,EAAQ,EAAE;QAC3B,WAAW,CAAC,GAAG,CAAC,CAAA;QAChB,KAAK,CAAC,IAAI,CAAC,CAAA;IACb,CAAC,CAAA;IAED,uEAAuE;IACvE,MAAM,UAAU,GAAG,MAA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AAC;QACH,CAAC,EAAE,CAAC;QACJ,UAAU;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;QAChD,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAA;IAED,SAAS,KAAK,CAAE,KAAe;QAC7B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,UAAU,GAAG,IAAI,CAAA;YACjB,WAAW,GAAG,IAAI,CAAA;QACpB,CAAC;QAED,IAAI,UAAU,IAAI,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YAC/D,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACpC,CAAC;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": "6.7.1-57e7fa441",
3
+ "version": "6.7.1-79473c99a",
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/main/packages/utils#readme",
@@ -191,9 +191,9 @@
191
191
  "dependencies": {
192
192
  "@chainsafe/is-ip": "^2.1.0",
193
193
  "@chainsafe/netmask": "^2.0.0",
194
- "@libp2p/crypto": "5.1.7-57e7fa441",
195
- "@libp2p/interface": "2.10.5-57e7fa441",
196
- "@libp2p/logger": "5.1.21-57e7fa441",
194
+ "@libp2p/crypto": "5.1.7-79473c99a",
195
+ "@libp2p/interface": "2.10.5-79473c99a",
196
+ "@libp2p/logger": "5.1.21-79473c99a",
197
197
  "@multiformats/multiaddr": "^12.4.4",
198
198
  "@sindresorhus/fnv1a": "^3.1.0",
199
199
  "any-signal": "^4.1.1",
@@ -214,7 +214,7 @@
214
214
  "uint8arrays": "^5.1.0"
215
215
  },
216
216
  "devDependencies": {
217
- "@libp2p/peer-id": "5.1.8-57e7fa441",
217
+ "@libp2p/peer-id": "5.1.8-79473c99a",
218
218
  "@types/netmask": "^2.0.5",
219
219
  "aegir": "^47.0.14",
220
220
  "benchmark": "^2.1.4",
@@ -1,6 +1,6 @@
1
1
  import forEach from 'it-foreach'
2
2
  import { pipe } from 'it-pipe'
3
- import type { ComponentLogger, MultiaddrConnection, Stream } from '@libp2p/interface'
3
+ import type { Logger, MultiaddrConnection, Stream } from '@libp2p/interface'
4
4
  import type { Multiaddr } from '@multiformats/multiaddr'
5
5
  import type { Uint8ArrayList } from 'uint8arraylist'
6
6
 
@@ -8,7 +8,7 @@ export interface StreamProperties {
8
8
  stream: Stream
9
9
  remoteAddr: Multiaddr
10
10
  localAddr: Multiaddr
11
- logger: ComponentLogger
11
+ log: Logger
12
12
 
13
13
  /**
14
14
  * A callback invoked when data is read from the stream
@@ -26,8 +26,7 @@ export interface StreamProperties {
26
26
  * https://github.com/libp2p/interface-transport#multiaddrconnection
27
27
  */
28
28
  export function streamToMaConnection (props: StreamProperties): MultiaddrConnection {
29
- const { stream, remoteAddr, logger, onDataRead, onDataWrite } = props
30
- const log = logger.forComponent('libp2p:stream:converter')
29
+ const { stream, remoteAddr, log, onDataRead, onDataWrite } = props
31
30
 
32
31
  let closedRead = false
33
32
  let closedWrite = false
@@ -57,12 +56,14 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
57
56
  )
58
57
  )
59
58
  } catch (err: any) {
59
+ maConn.log.error('errored - %e', err)
60
+
60
61
  // If aborted we can safely ignore
61
62
  if (err.type !== 'aborted') {
62
63
  // If the source errored the socket will already have been destroyed by
63
64
  // toIterable.duplex(). If the socket errored it will already be
64
65
  // destroyed. There's nothing to do here except log the error & return.
65
- log.error('%s error in sink', remoteAddr, err)
66
+ maConn.log.error('%s error in sink - %e', remoteAddr, err)
66
67
  }
67
68
  } finally {
68
69
  closedWrite = true
@@ -71,7 +72,7 @@ export function streamToMaConnection (props: StreamProperties): MultiaddrConnect
71
72
  }
72
73
 
73
74
  const maConn: MultiaddrConnection = {
74
- log,
75
+ log: log.newScope('stream-to-maconn'),
75
76
  sink: stream.sink,
76
77
  source: (async function * (): AsyncGenerator<Uint8ArrayList> {
77
78
  try {