libp2p 0.46.19-fb8a6f188 → 0.46.19

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.
Files changed (67) hide show
  1. package/dist/index.min.js +22 -22
  2. package/dist/src/components.d.ts +1 -3
  3. package/dist/src/components.d.ts.map +1 -1
  4. package/dist/src/components.js +0 -4
  5. package/dist/src/components.js.map +1 -1
  6. package/dist/src/connection/index.d.ts +1 -3
  7. package/dist/src/connection/index.d.ts.map +1 -1
  8. package/dist/src/connection/index.js +9 -9
  9. package/dist/src/connection/index.js.map +1 -1
  10. package/dist/src/connection-manager/auto-dial.d.ts +1 -3
  11. package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
  12. package/dist/src/connection-manager/auto-dial.js +20 -20
  13. package/dist/src/connection-manager/auto-dial.js.map +1 -1
  14. package/dist/src/connection-manager/connection-pruner.d.ts +1 -3
  15. package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
  16. package/dist/src/connection-manager/connection-pruner.js +8 -8
  17. package/dist/src/connection-manager/connection-pruner.js.map +1 -1
  18. package/dist/src/connection-manager/dial-queue.d.ts +1 -3
  19. package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
  20. package/dist/src/connection-manager/dial-queue.js +23 -26
  21. package/dist/src/connection-manager/dial-queue.js.map +1 -1
  22. package/dist/src/connection-manager/index.d.ts +1 -3
  23. package/dist/src/connection-manager/index.d.ts.map +1 -1
  24. package/dist/src/connection-manager/index.js +18 -21
  25. package/dist/src/connection-manager/index.js.map +1 -1
  26. package/dist/src/connection-manager/utils.d.ts +1 -2
  27. package/dist/src/connection-manager/utils.d.ts.map +1 -1
  28. package/dist/src/connection-manager/utils.js +4 -2
  29. package/dist/src/connection-manager/utils.js.map +1 -1
  30. package/dist/src/identify/consts.d.ts +1 -1
  31. package/dist/src/identify/consts.d.ts.map +1 -1
  32. package/dist/src/identify/identify.d.ts.map +1 -1
  33. package/dist/src/identify/identify.js +20 -20
  34. package/dist/src/identify/identify.js.map +1 -1
  35. package/dist/src/identify/index.d.ts +1 -2
  36. package/dist/src/identify/index.d.ts.map +1 -1
  37. package/dist/src/identify/index.js.map +1 -1
  38. package/dist/src/index.d.ts +1 -21
  39. package/dist/src/index.d.ts.map +1 -1
  40. package/dist/src/index.js.map +1 -1
  41. package/dist/src/libp2p.d.ts +1 -2
  42. package/dist/src/libp2p.d.ts.map +1 -1
  43. package/dist/src/libp2p.js +16 -20
  44. package/dist/src/libp2p.js.map +1 -1
  45. package/dist/src/upgrader.d.ts +1 -3
  46. package/dist/src/upgrader.d.ts.map +1 -1
  47. package/dist/src/upgrader.js +29 -30
  48. package/dist/src/upgrader.js.map +1 -1
  49. package/dist/src/version.d.ts +1 -1
  50. package/dist/src/version.d.ts.map +1 -1
  51. package/dist/src/version.js +1 -1
  52. package/dist/src/version.js.map +1 -1
  53. package/dist/typedoc-urls.json +71 -0
  54. package/package.json +21 -21
  55. package/src/components.ts +1 -8
  56. package/src/connection/index.ts +11 -12
  57. package/src/connection-manager/auto-dial.ts +22 -22
  58. package/src/connection-manager/connection-pruner.ts +10 -10
  59. package/src/connection-manager/dial-queue.ts +25 -28
  60. package/src/connection-manager/index.ts +20 -23
  61. package/src/connection-manager/utils.ts +7 -5
  62. package/src/identify/identify.ts +22 -21
  63. package/src/identify/index.ts +1 -2
  64. package/src/index.ts +1 -22
  65. package/src/libp2p.ts +18 -21
  66. package/src/upgrader.ts +31 -32
  67. package/src/version.ts +1 -1
package/src/upgrader.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { CodeError } from '@libp2p/interface/errors'
2
2
  import { setMaxListeners } from '@libp2p/interface/events'
3
+ import { logger } from '@libp2p/logger'
3
4
  import * as mss from '@libp2p/multistream-select'
4
5
  import { peerIdFromString } from '@libp2p/peer-id'
5
6
  import { createConnection } from './connection/index.js'
6
7
  import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
7
8
  import { codes } from './errors.js'
8
9
  import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
9
- import type { Libp2pEvents, AbortOptions, ComponentLogger, Logger } from '@libp2p/interface'
10
+ import type { Libp2pEvents, AbortOptions } from '@libp2p/interface'
10
11
  import type { MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions } from '@libp2p/interface/connection'
11
12
  import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface/connection-encrypter'
12
13
  import type { ConnectionGater } from '@libp2p/interface/connection-gater'
@@ -20,6 +21,8 @@ import type { ConnectionManager } from '@libp2p/interface-internal/connection-ma
20
21
  import type { Registrar } from '@libp2p/interface-internal/registrar'
21
22
  import type { Duplex, Source } from 'it-stream-types'
22
23
 
24
+ const log = logger('libp2p:upgrader')
25
+
23
26
  interface CreateConnectionOptions {
24
27
  cryptoProtocol: string
25
28
  direction: 'inbound' | 'outbound'
@@ -102,7 +105,6 @@ export interface DefaultUpgraderComponents {
102
105
  registrar: Registrar
103
106
  peerStore: PeerStore
104
107
  events: TypedEventTarget<Libp2pEvents>
105
- logger: ComponentLogger
106
108
  }
107
109
 
108
110
  type EncryptedConn = Duplex<AsyncGenerator<Uint8Array, any, unknown>, Source<Uint8Array>, Promise<void>>
@@ -115,12 +117,10 @@ export class DefaultUpgrader implements Upgrader {
115
117
  private readonly muxers: Map<string, StreamMuxerFactory>
116
118
  private readonly inboundUpgradeTimeout: number
117
119
  private readonly events: TypedEventTarget<Libp2pEvents>
118
- readonly #log: Logger
119
120
 
120
121
  constructor (components: DefaultUpgraderComponents, init: UpgraderInit) {
121
122
  this.components = components
122
123
  this.connectionEncryption = new Map()
123
- this.#log = components.logger.forComponent('libp2p:upgrader')
124
124
 
125
125
  init.connectionEncryption.forEach(encrypter => {
126
126
  this.connectionEncryption.set(encrypter.protocol, encrypter)
@@ -179,7 +179,7 @@ export class DefaultUpgrader implements Upgrader {
179
179
 
180
180
  this.components.metrics?.trackMultiaddrConnection(maConn)
181
181
 
182
- this.#log('starting the inbound connection upgrade')
182
+ log('starting the inbound connection upgrade')
183
183
 
184
184
  // Protect
185
185
  let protectedConn = maConn
@@ -188,7 +188,7 @@ export class DefaultUpgrader implements Upgrader {
188
188
  const protector = this.components.connectionProtector
189
189
 
190
190
  if (protector != null) {
191
- this.#log('protecting the inbound connection')
191
+ log('protecting the inbound connection')
192
192
  protectedConn = await protector.protect(maConn)
193
193
  }
194
194
  }
@@ -235,13 +235,13 @@ export class DefaultUpgrader implements Upgrader {
235
235
  upgradedConn = multiplexed.stream
236
236
  }
237
237
  } catch (err: any) {
238
- this.#log.error('Failed to upgrade inbound connection', err)
238
+ log.error('Failed to upgrade inbound connection', err)
239
239
  throw err
240
240
  }
241
241
 
242
242
  await this.shouldBlockConnection(remotePeer, maConn, 'denyInboundUpgradedConnection')
243
243
 
244
- this.#log('Successfully upgraded inbound connection')
244
+ log('Successfully upgraded inbound connection')
245
245
 
246
246
  return this._createConnection({
247
247
  cryptoProtocol,
@@ -280,7 +280,7 @@ export class DefaultUpgrader implements Upgrader {
280
280
 
281
281
  this.components.metrics?.trackMultiaddrConnection(maConn)
282
282
 
283
- this.#log('Starting the outbound connection upgrade')
283
+ log('Starting the outbound connection upgrade')
284
284
 
285
285
  // If the transport natively supports encryption, skip connection
286
286
  // protector and encryption
@@ -333,14 +333,14 @@ export class DefaultUpgrader implements Upgrader {
333
333
  upgradedConn = multiplexed.stream
334
334
  }
335
335
  } catch (err: any) {
336
- this.#log.error('Failed to upgrade outbound connection', err)
336
+ log.error('Failed to upgrade outbound connection', err)
337
337
  await maConn.close(err)
338
338
  throw err
339
339
  }
340
340
 
341
341
  await this.shouldBlockConnection(remotePeer, maConn, 'denyOutboundUpgradedConnection')
342
342
 
343
- this.#log('Successfully upgraded outbound connection')
343
+ log('Successfully upgraded outbound connection')
344
344
 
345
345
  return this._createConnection({
346
346
  cryptoProtocol,
@@ -385,7 +385,7 @@ export class DefaultUpgrader implements Upgrader {
385
385
  .then(async () => {
386
386
  const protocols = this.components.registrar.getProtocols()
387
387
  const { stream, protocol } = await mss.handle(muxedStream, protocols)
388
- this.#log('%s: incoming stream opened on %s', direction, protocol)
388
+ log('%s: incoming stream opened on %s', direction, protocol)
389
389
 
390
390
  if (connection == null) {
391
391
  return
@@ -418,7 +418,7 @@ export class DefaultUpgrader implements Upgrader {
418
418
  this._onStream({ connection, stream: muxedStream, protocol })
419
419
  })
420
420
  .catch(async err => {
421
- this.#log.error(err)
421
+ log.error(err)
422
422
 
423
423
  if (muxedStream.timeline.close == null) {
424
424
  await muxedStream.close()
@@ -432,12 +432,12 @@ export class DefaultUpgrader implements Upgrader {
432
432
  throw new CodeError('Stream is not multiplexed', codes.ERR_MUXER_UNAVAILABLE)
433
433
  }
434
434
 
435
- this.#log('%s-%s: starting new stream on %s', connection.id, direction, protocols)
435
+ log('%s-%s: starting new stream on %s', connection.id, direction, protocols)
436
436
  const muxedStream = await muxer.newStream()
437
437
 
438
438
  try {
439
439
  if (options.signal == null) {
440
- this.#log('No abort signal was passed while trying to negotiate protocols %s falling back to default timeout', protocols)
440
+ log('No abort signal was passed while trying to negotiate protocols %s falling back to default timeout', protocols)
441
441
 
442
442
  options.signal = AbortSignal.timeout(30000)
443
443
 
@@ -472,7 +472,7 @@ export class DefaultUpgrader implements Upgrader {
472
472
 
473
473
  return muxedStream
474
474
  } catch (err: any) {
475
- this.#log.error('could not create new stream for protocols %s on connection with address %a', protocols, connection.remoteAddr, err)
475
+ log.error('could not create new stream for protocols %s on connection with address %a', protocols, connection.remoteAddr, err)
476
476
 
477
477
  if (muxedStream.timeline.close == null) {
478
478
  muxedStream.abort(err)
@@ -491,7 +491,7 @@ export class DefaultUpgrader implements Upgrader {
491
491
  muxer.sink(upgradedConn.source),
492
492
  upgradedConn.sink(muxer.source)
493
493
  ]).catch(err => {
494
- this.#log.error(err)
494
+ log.error(err)
495
495
  })
496
496
  }
497
497
 
@@ -506,14 +506,14 @@ export class DefaultUpgrader implements Upgrader {
506
506
  await connection.close()
507
507
  }
508
508
  } catch (err: any) {
509
- this.#log.error(err)
509
+ log.error(err)
510
510
  } finally {
511
511
  this.events.safeDispatchEvent('connection:close', {
512
512
  detail: connection
513
513
  })
514
514
  }
515
515
  })().catch(err => {
516
- this.#log.error(err)
516
+ log.error(err)
517
517
  })
518
518
  }
519
519
 
@@ -536,20 +536,19 @@ export class DefaultUpgrader implements Upgrader {
536
536
  multiplexer: muxer?.protocol,
537
537
  encryption: cryptoProtocol,
538
538
  transient,
539
- logger: this.components.logger,
540
539
  newStream: newStream ?? errConnectionNotMultiplexed,
541
540
  getStreams: () => { if (muxer != null) { return muxer.streams } else { return [] } },
542
541
  close: async (options?: AbortOptions) => {
543
542
  // Ensure remaining streams are closed gracefully
544
543
  if (muxer != null) {
545
- this.#log.trace('close muxer')
544
+ log.trace('close muxer')
546
545
  await muxer.close(options)
547
546
  }
548
547
 
549
- this.#log.trace('close maconn')
548
+ log.trace('close maconn')
550
549
  // close the underlying transport
551
550
  await maConn.close(options)
552
- this.#log.trace('closed maconn')
551
+ log.trace('closed maconn')
553
552
  },
554
553
  abort: (err) => {
555
554
  maConn.abort(err)
@@ -586,7 +585,7 @@ export class DefaultUpgrader implements Upgrader {
586
585
  */
587
586
  async _encryptInbound (connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>>): Promise<CryptoResult> {
588
587
  const protocols = Array.from(this.connectionEncryption.keys())
589
- this.#log('handling inbound crypto protocol selection', protocols)
588
+ log('handling inbound crypto protocol selection', protocols)
590
589
 
591
590
  try {
592
591
  const { stream, protocol } = await mss.handle(connection, protocols, {
@@ -598,7 +597,7 @@ export class DefaultUpgrader implements Upgrader {
598
597
  throw new Error(`no crypto module found for ${protocol}`)
599
598
  }
600
599
 
601
- this.#log('encrypting inbound connection...')
600
+ log('encrypting inbound connection...')
602
601
 
603
602
  return {
604
603
  ...await encrypter.secureInbound(this.components.peerId, stream),
@@ -615,7 +614,7 @@ export class DefaultUpgrader implements Upgrader {
615
614
  */
616
615
  async _encryptOutbound (connection: MultiaddrConnection, remotePeerId?: PeerId): Promise<CryptoResult> {
617
616
  const protocols = Array.from(this.connectionEncryption.keys())
618
- this.#log('selecting outbound crypto protocol', protocols)
617
+ log('selecting outbound crypto protocol', protocols)
619
618
 
620
619
  try {
621
620
  const { stream, protocol } = await mss.select(connection, protocols, {
@@ -627,7 +626,7 @@ export class DefaultUpgrader implements Upgrader {
627
626
  throw new Error(`no crypto module found for ${protocol}`)
628
627
  }
629
628
 
630
- this.#log('encrypting outbound connection to %p', remotePeerId)
629
+ log('encrypting outbound connection to %p', remotePeerId)
631
630
 
632
631
  return {
633
632
  ...await encrypter.secureOutbound(this.components.peerId, stream, remotePeerId),
@@ -644,17 +643,17 @@ export class DefaultUpgrader implements Upgrader {
644
643
  */
645
644
  async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
646
645
  const protocols = Array.from(muxers.keys())
647
- this.#log('outbound selecting muxer %s', protocols)
646
+ log('outbound selecting muxer %s', protocols)
648
647
  try {
649
648
  const { stream, protocol } = await mss.select(connection, protocols, {
650
649
  writeBytes: true
651
650
  })
652
- this.#log('%s selected as muxer protocol', protocol)
651
+ log('%s selected as muxer protocol', protocol)
653
652
  const muxerFactory = muxers.get(protocol)
654
653
 
655
654
  return { stream, muxerFactory }
656
655
  } catch (err: any) {
657
- this.#log.error('error multiplexing outbound stream', err)
656
+ log.error('error multiplexing outbound stream', err)
658
657
  throw new CodeError(String(err), codes.ERR_MUXER_UNAVAILABLE)
659
658
  }
660
659
  }
@@ -665,7 +664,7 @@ export class DefaultUpgrader implements Upgrader {
665
664
  */
666
665
  async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, muxerFactory?: StreamMuxerFactory }> {
667
666
  const protocols = Array.from(muxers.keys())
668
- this.#log('inbound handling muxers %s', protocols)
667
+ log('inbound handling muxers %s', protocols)
669
668
  try {
670
669
  const { stream, protocol } = await mss.handle(connection, protocols, {
671
670
  writeBytes: true
@@ -674,7 +673,7 @@ export class DefaultUpgrader implements Upgrader {
674
673
 
675
674
  return { stream, muxerFactory }
676
675
  } catch (err: any) {
677
- this.#log.error('error multiplexing inbound stream', err)
676
+ log.error('error multiplexing inbound stream', err)
678
677
  throw new CodeError(String(err), codes.ERR_MUXER_UNAVAILABLE)
679
678
  }
680
679
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '0.46.19-fb8a6f188'
1
+ export const version = '0.46.19'
2
2
  export const name = 'libp2p'