libp2p 0.35.8 → 0.36.0-d44bd90

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 (108) hide show
  1. package/dist/index.min.js +55 -0
  2. package/dist/src/circuit/auto-relay.d.ts +8 -10
  3. package/dist/src/circuit/auto-relay.d.ts.map +1 -1
  4. package/dist/src/config.d.ts +2 -0
  5. package/dist/src/config.d.ts.map +1 -1
  6. package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
  7. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  8. package/dist/src/connection-manager/index.d.ts +1 -2
  9. package/dist/src/connection-manager/index.d.ts.map +1 -1
  10. package/dist/src/content-routing/utils.d.ts +3 -3
  11. package/dist/src/content-routing/utils.d.ts.map +1 -1
  12. package/dist/src/dialer/dial-request.d.ts.map +1 -1
  13. package/dist/src/dialer/index.d.ts +12 -7
  14. package/dist/src/dialer/index.d.ts.map +1 -1
  15. package/dist/src/errors.d.ts +2 -0
  16. package/dist/src/fetch/constants.d.ts +2 -0
  17. package/dist/src/fetch/constants.d.ts.map +1 -0
  18. package/dist/src/fetch/index.d.ts +76 -0
  19. package/dist/src/fetch/index.d.ts.map +1 -0
  20. package/dist/src/fetch/proto.d.ts +134 -0
  21. package/dist/src/identify/index.d.ts +4 -4
  22. package/dist/src/identify/index.d.ts.map +1 -1
  23. package/dist/src/index.d.ts +26 -7
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/metrics/index.d.ts +9 -4
  26. package/dist/src/metrics/index.d.ts.map +1 -1
  27. package/dist/src/metrics/tracked-map.d.ts +6 -1
  28. package/dist/src/metrics/tracked-map.d.ts.map +1 -1
  29. package/dist/src/peer-routing.d.ts +1 -1
  30. package/dist/src/peer-routing.d.ts.map +1 -1
  31. package/dist/src/peer-store/address-book.d.ts +30 -84
  32. package/dist/src/peer-store/address-book.d.ts.map +1 -1
  33. package/dist/src/peer-store/index.d.ts +28 -94
  34. package/dist/src/peer-store/index.d.ts.map +1 -1
  35. package/dist/src/peer-store/key-book.d.ts +31 -15
  36. package/dist/src/peer-store/key-book.d.ts.map +1 -1
  37. package/dist/src/peer-store/metadata-book.d.ts +33 -29
  38. package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
  39. package/dist/src/peer-store/pb/peer.d.ts +222 -0
  40. package/dist/src/peer-store/proto-book.d.ts +27 -28
  41. package/dist/src/peer-store/proto-book.d.ts.map +1 -1
  42. package/dist/src/peer-store/store.d.ts +73 -0
  43. package/dist/src/peer-store/store.d.ts.map +1 -0
  44. package/dist/src/peer-store/types.d.ts +202 -0
  45. package/dist/src/peer-store/types.d.ts.map +1 -0
  46. package/dist/src/ping/index.d.ts +32 -25
  47. package/dist/src/ping/index.d.ts.map +1 -1
  48. package/dist/src/record/peer-record/index.d.ts +2 -2
  49. package/dist/src/record/peer-record/index.d.ts.map +1 -1
  50. package/dist/src/registrar.d.ts +5 -5
  51. package/dist/src/registrar.d.ts.map +1 -1
  52. package/dist/src/types.d.ts +90 -0
  53. package/dist/src/types.d.ts.map +1 -0
  54. package/dist/src/upgrader.d.ts +8 -2
  55. package/dist/src/upgrader.d.ts.map +1 -1
  56. package/package.json +23 -26
  57. package/src/circuit/auto-relay.js +52 -38
  58. package/src/config.js +2 -0
  59. package/src/connection-manager/auto-dialler.js +20 -8
  60. package/src/connection-manager/index.js +42 -22
  61. package/src/content-routing/utils.js +4 -4
  62. package/src/dialer/dial-request.js +4 -1
  63. package/src/dialer/index.js +38 -8
  64. package/src/errors.js +2 -0
  65. package/src/fetch/README.md +36 -0
  66. package/src/fetch/constants.js +6 -0
  67. package/src/fetch/index.js +159 -0
  68. package/src/fetch/proto.d.ts +134 -0
  69. package/src/fetch/proto.js +333 -0
  70. package/src/fetch/proto.proto +15 -0
  71. package/src/identify/index.js +47 -38
  72. package/src/index.js +81 -34
  73. package/src/metrics/index.js +15 -8
  74. package/src/metrics/tracked-map.js +40 -14
  75. package/src/peer-routing.js +4 -1
  76. package/src/peer-store/address-book.js +254 -226
  77. package/src/peer-store/index.js +79 -110
  78. package/src/peer-store/key-book.js +99 -54
  79. package/src/peer-store/metadata-book.js +171 -101
  80. package/src/peer-store/pb/peer.d.ts +222 -0
  81. package/src/peer-store/pb/peer.js +643 -0
  82. package/src/peer-store/pb/peer.proto +31 -0
  83. package/src/peer-store/proto-book.js +171 -105
  84. package/src/peer-store/store.js +263 -0
  85. package/src/peer-store/types.ts +245 -0
  86. package/src/ping/index.js +51 -46
  87. package/src/record/peer-record/index.js +1 -1
  88. package/src/record/utils.js +1 -1
  89. package/src/registrar.js +4 -4
  90. package/src/types.ts +98 -0
  91. package/src/upgrader.js +32 -2
  92. package/dist/src/peer-store/book.d.ts +0 -81
  93. package/dist/src/peer-store/book.d.ts.map +0 -1
  94. package/dist/src/peer-store/persistent/consts.d.ts +0 -6
  95. package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
  96. package/dist/src/peer-store/persistent/index.d.ts +0 -129
  97. package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
  98. package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
  99. package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
  100. package/src/peer-store/book.js +0 -124
  101. package/src/peer-store/persistent/consts.js +0 -15
  102. package/src/peer-store/persistent/index.js +0 -408
  103. package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
  104. package/src/peer-store/persistent/pb/address-book.js +0 -522
  105. package/src/peer-store/persistent/pb/address-book.proto +0 -27
  106. package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
  107. package/src/peer-store/persistent/pb/proto-book.js +0 -157
  108. package/src/peer-store/persistent/pb/proto-book.proto +0 -5
package/src/index.js CHANGED
@@ -9,7 +9,7 @@ const { EventEmitter } = require('events')
9
9
  const errCode = require('err-code')
10
10
  const PeerId = require('peer-id')
11
11
  const { Multiaddr } = require('multiaddr')
12
-
12
+ const { MemoryDatastore } = require('datastore-core/memory')
13
13
  const PeerRouting = require('./peer-routing')
14
14
  const ContentRouting = require('./content-routing')
15
15
  const getPeer = require('./get-peer')
@@ -28,10 +28,10 @@ const TransportManager = require('./transport-manager')
28
28
  const Upgrader = require('./upgrader')
29
29
  const PeerStore = require('./peer-store')
30
30
  const PubsubAdapter = require('./pubsub-adapter')
31
- const PersistentPeerStore = require('./peer-store/persistent')
32
31
  const Registrar = require('./registrar')
33
- const ping = require('./ping')
34
32
  const IdentifyService = require('./identify')
33
+ const FetchService = require('./fetch')
34
+ const PingService = require('./ping')
35
35
  const NatManager = require('./nat-manager')
36
36
  const { updateSelfPeerRecord } = require('./record/utils')
37
37
 
@@ -48,6 +48,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
48
48
  * @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
49
49
  * @typedef {import('interface-datastore').Datastore} Datastore
50
50
  * @typedef {import('./pnet')} Protector
51
+ * @typedef {import('./types').ConnectionGater} ConnectionGater
51
52
  * @typedef {Object} PersistentPeerStoreOptions
52
53
  * @property {number} [threshold]
53
54
  */
@@ -106,13 +107,14 @@ const { updateSelfPeerRecord } = require('./record/utils')
106
107
  * @property {Libp2pModules} modules libp2p modules to use
107
108
  * @property {import('./address-manager').AddressManagerOptions} [addresses]
108
109
  * @property {import('./connection-manager').ConnectionManagerOptions} [connectionManager]
110
+ * @property {Partial<import('./types').ConnectionGater>} [connectionGater]
109
111
  * @property {Datastore} [datastore]
110
112
  * @property {import('./dialer').DialerOptions} [dialer]
111
113
  * @property {import('./identify/index').HostProperties} [host] libp2p host
112
114
  * @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
113
115
  * @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
114
116
  * @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
115
- * @property {PeerStoreOptions & PersistentPeerStoreOptions} [peerStore]
117
+ * @property {PeerStoreOptions} [peerStore]
116
118
  * @property {import('./transport-manager').TransportManagerOptions} [transportManager]
117
119
  * @property {Libp2pConfig} [config]
118
120
  *
@@ -172,13 +174,26 @@ class Libp2p extends EventEmitter {
172
174
  this.metrics = metrics
173
175
  }
174
176
 
175
- this.peerStore = (this.datastore && this._options.peerStore.persistence)
176
- ? new PersistentPeerStore({
177
- peerId: this.peerId,
178
- datastore: this.datastore,
179
- ...this._options.peerStore
180
- })
181
- : new PeerStore({ peerId: this.peerId })
177
+ /** @type {ConnectionGater} */
178
+ this.connectionGater = {
179
+ denyDialPeer: async () => Promise.resolve(false),
180
+ denyDialMultiaddr: async () => Promise.resolve(false),
181
+ denyInboundConnection: async () => Promise.resolve(false),
182
+ denyOutboundConnection: async () => Promise.resolve(false),
183
+ denyInboundEncryptedConnection: async () => Promise.resolve(false),
184
+ denyOutboundEncryptedConnection: async () => Promise.resolve(false),
185
+ denyInboundUpgradedConnection: async () => Promise.resolve(false),
186
+ denyOutboundUpgradedConnection: async () => Promise.resolve(false),
187
+ filterMultiaddrForPeer: async () => Promise.resolve(true),
188
+ ...this._options.connectionGater
189
+ }
190
+
191
+ /** @type {import('./peer-store/types').PeerStore} */
192
+ this.peerStore = new PeerStore({
193
+ peerId: this.peerId,
194
+ datastore: (this.datastore && this._options.peerStore.persistence) ? this.datastore : new MemoryDatastore(),
195
+ addressFilter: this.connectionGater.filterMultiaddrForPeer
196
+ })
182
197
 
183
198
  // Addresses {listen, announce, noAnnounce}
184
199
  this.addresses = this._options.addresses
@@ -222,6 +237,7 @@ class Libp2p extends EventEmitter {
222
237
 
223
238
  // Setup the Upgrader
224
239
  this.upgrader = new Upgrader({
240
+ connectionGater: this.connectionGater,
225
241
  localPeer: this.peerId,
226
242
  metrics: this.metrics,
227
243
  onConnection: (connection) => this.connectionManager.onConnect(connection),
@@ -264,6 +280,7 @@ class Libp2p extends EventEmitter {
264
280
 
265
281
  this.dialer = new Dialer({
266
282
  transportManager: this.transportManager,
283
+ connectionGater: this.connectionGater,
267
284
  peerStore: this.peerStore,
268
285
  metrics: this.metrics,
269
286
  ...this._options.dialer
@@ -290,7 +307,6 @@ class Libp2p extends EventEmitter {
290
307
 
291
308
  // Add the identify service since we can multiplex
292
309
  this.identifyService = new IdentifyService({ libp2p: this })
293
- this.handle(Object.values(IdentifyService.getProtocolStr(this)), this.identifyService.handleMessage)
294
310
  }
295
311
 
296
312
  // Attach private network protector
@@ -323,10 +339,10 @@ class Libp2p extends EventEmitter {
323
339
  this.peerRouting = new PeerRouting(this)
324
340
  this.contentRouting = new ContentRouting(this)
325
341
 
326
- // Mount default protocols
327
- ping.mount(this)
328
-
329
342
  this._onDiscoveryPeer = this._onDiscoveryPeer.bind(this)
343
+
344
+ this.fetchService = new FetchService(this)
345
+ this.pingService = new PingService(this)
330
346
  }
331
347
 
332
348
  /**
@@ -356,6 +372,18 @@ class Libp2p extends EventEmitter {
356
372
  async start () {
357
373
  log('libp2p is starting')
358
374
 
375
+ if (this.identifyService) {
376
+ await this.handle(Object.values(IdentifyService.getProtocolStr(this)), this.identifyService.handleMessage)
377
+ }
378
+
379
+ if (this.fetchService) {
380
+ await this.handle(FetchService.PROTOCOL, this.fetchService.handleMessage)
381
+ }
382
+
383
+ if (this.pingService) {
384
+ await this.handle(PingService.getProtocolStr(this), this.pingService.handleMessage)
385
+ }
386
+
359
387
  try {
360
388
  await this._onStarting()
361
389
  await this._onDidStart()
@@ -380,9 +408,13 @@ class Libp2p extends EventEmitter {
380
408
  try {
381
409
  this._isStarted = false
382
410
 
411
+ if (this.identifyService) {
412
+ await this.identifyService.stop()
413
+ }
414
+
383
415
  this.relay && this.relay.stop()
384
416
  this.peerRouting.stop()
385
- this._autodialler.stop()
417
+ await this._autodialler.stop()
386
418
  await (this._dht && this._dht.stop())
387
419
 
388
420
  for (const service of this._discovery.values()) {
@@ -393,7 +425,6 @@ class Libp2p extends EventEmitter {
393
425
 
394
426
  this._discovery = new Map()
395
427
 
396
- await this.peerStore.stop()
397
428
  await this.connectionManager.stop()
398
429
 
399
430
  await Promise.all([
@@ -404,7 +435,9 @@ class Libp2p extends EventEmitter {
404
435
  await this.natManager.stop()
405
436
  await this.transportManager.close()
406
437
 
407
- ping.unmount(this)
438
+ await this.unhandle(FetchService.PROTOCOL)
439
+ await this.unhandle(PingService.getProtocolStr(this))
440
+
408
441
  this.dialer.destroy()
409
442
  } catch (/** @type {any} */ err) {
410
443
  if (err) {
@@ -499,7 +532,7 @@ class Libp2p extends EventEmitter {
499
532
  if (!connection) {
500
533
  connection = await this.dialer.connectToPeer(peer, options)
501
534
  } else if (multiaddrs) {
502
- this.peerStore.addressBook.add(id, multiaddrs)
535
+ await this.peerStore.addressBook.add(id, multiaddrs)
503
536
  }
504
537
 
505
538
  return connection
@@ -556,6 +589,17 @@ class Libp2p extends EventEmitter {
556
589
  )
557
590
  }
558
591
 
592
+ /**
593
+ * Sends a request to fetch the value associated with the given key from the given peer.
594
+ *
595
+ * @param {PeerId|Multiaddr} peer
596
+ * @param {string} key
597
+ * @returns {Promise<Uint8Array | null>}
598
+ */
599
+ fetch (peer, key) {
600
+ return this.fetchService.fetch(peer, key)
601
+ }
602
+
559
603
  /**
560
604
  * Pings the given peer in order to obtain the operation latency.
561
605
  *
@@ -567,10 +611,10 @@ class Libp2p extends EventEmitter {
567
611
 
568
612
  // If received multiaddr, ping it
569
613
  if (multiaddrs) {
570
- return ping(this, multiaddrs[0])
614
+ return this.pingService.ping(multiaddrs[0])
571
615
  }
572
616
 
573
- return ping(this, id)
617
+ return this.pingService.ping(id)
574
618
  }
575
619
 
576
620
  /**
@@ -579,14 +623,14 @@ class Libp2p extends EventEmitter {
579
623
  * @param {string[]|string} protocols
580
624
  * @param {(props: HandlerProps) => void} handler
581
625
  */
582
- handle (protocols, handler) {
626
+ async handle (protocols, handler) {
583
627
  protocols = Array.isArray(protocols) ? protocols : [protocols]
584
628
  protocols.forEach(protocol => {
585
629
  this.upgrader.protocols.set(protocol, handler)
586
630
  })
587
631
 
588
632
  // Add new protocols to self protocols in the Protobook
589
- this.peerStore.protoBook.add(this.peerId, protocols)
633
+ await this.peerStore.protoBook.add(this.peerId, protocols)
590
634
  }
591
635
 
592
636
  /**
@@ -595,14 +639,14 @@ class Libp2p extends EventEmitter {
595
639
  *
596
640
  * @param {string[]|string} protocols
597
641
  */
598
- unhandle (protocols) {
642
+ async unhandle (protocols) {
599
643
  protocols = Array.isArray(protocols) ? protocols : [protocols]
600
644
  protocols.forEach(protocol => {
601
645
  this.upgrader.protocols.delete(protocol)
602
646
  })
603
647
 
604
648
  // Remove protocols from self protocols in the Protobook
605
- this.peerStore.protoBook.remove(this.peerId, protocols)
649
+ await this.peerStore.protoBook.remove(this.peerId, protocols)
606
650
  }
607
651
 
608
652
  async _onStarting () {
@@ -613,11 +657,8 @@ class Libp2p extends EventEmitter {
613
657
  // Manage your NATs
614
658
  this.natManager.start()
615
659
 
616
- // Start PeerStore
617
- await this.peerStore.start()
618
-
619
660
  if (this._config.pubsub.enabled) {
620
- this.pubsub && this.pubsub.start()
661
+ this.pubsub && await this.pubsub.start()
621
662
  }
622
663
 
623
664
  // DHT subsystem
@@ -631,6 +672,10 @@ class Libp2p extends EventEmitter {
631
672
 
632
673
  // Start metrics if present
633
674
  this.metrics && this.metrics.start()
675
+
676
+ if (this.identifyService) {
677
+ await this.identifyService.start()
678
+ }
634
679
  }
635
680
 
636
681
  /**
@@ -643,17 +688,19 @@ class Libp2p extends EventEmitter {
643
688
 
644
689
  this.peerStore.on('peer', peerId => {
645
690
  this.emit('peer:discovery', peerId)
646
- this._maybeConnect(peerId)
691
+ this._maybeConnect(peerId).catch(err => {
692
+ log.error(err)
693
+ })
647
694
  })
648
695
 
649
696
  // Once we start, emit any peers we may have already discovered
650
697
  // TODO: this should be removed, as we already discovered these peers in the past
651
- for (const peer of this.peerStore.peers.values()) {
698
+ for await (const peer of this.peerStore.getPeers()) {
652
699
  this.emit('peer:discovery', peer.id)
653
700
  }
654
701
 
655
702
  this.connectionManager.start()
656
- this._autodialler.start()
703
+ await this._autodialler.start()
657
704
 
658
705
  // Peer discovery
659
706
  await this._setupPeerDiscovery()
@@ -677,8 +724,8 @@ class Libp2p extends EventEmitter {
677
724
  return
678
725
  }
679
726
 
680
- peer.multiaddrs && this.peerStore.addressBook.add(peer.id, peer.multiaddrs)
681
- peer.protocols && this.peerStore.protoBook.set(peer.id, peer.protocols)
727
+ peer.multiaddrs && this.peerStore.addressBook.add(peer.id, peer.multiaddrs).catch(err => log.error(err))
728
+ peer.protocols && this.peerStore.protoBook.set(peer.id, peer.protocols).catch(err => log.error(err))
682
729
  }
683
730
 
684
731
  /**
@@ -44,7 +44,7 @@ class Metrics {
44
44
  this._oldPeers = oldPeerLRU(this._options.maxOldPeersRetention)
45
45
  this._running = false
46
46
  this._onMessage = this._onMessage.bind(this)
47
- this._componentMetrics = new Map()
47
+ this._systems = new Map()
48
48
  }
49
49
 
50
50
  /**
@@ -89,19 +89,26 @@ class Metrics {
89
89
  }
90
90
 
91
91
  /**
92
- * @returns {Map}
92
+ * @returns {Map<string, Map<string, Map<string, any>>>}
93
93
  */
94
94
  getComponentMetrics () {
95
- return this._componentMetrics
95
+ return this._systems
96
96
  }
97
97
 
98
- updateComponentMetric (component, metric, value) {
99
- if (!this._componentMetrics.has(component)) {
100
- this._componentMetrics.set(component, new Map())
98
+ updateComponentMetric ({ system = 'libp2p', component, metric, value }) {
99
+ if (!this._systems.has(system)) {
100
+ this._systems.set(system, new Map())
101
101
  }
102
102
 
103
- const map = this._componentMetrics.get(component)
104
- map.set(metric, value)
103
+ const systemMetrics = this._systems.get(system)
104
+
105
+ if (!systemMetrics.has(component)) {
106
+ systemMetrics.set(component, new Map())
107
+ }
108
+
109
+ const componentMetrics = systemMetrics.get(component)
110
+
111
+ componentMetrics.set(metric, value)
105
112
  }
106
113
 
107
114
  /**
@@ -6,18 +6,27 @@
6
6
  */
7
7
  class TrackedMap extends Map {
8
8
  /**
9
- * @param {string} component
10
- * @param {string} name
11
- * @param {import('.')} metrics
9
+ * @param {object} options
10
+ * @param {string} options.system
11
+ * @param {string} options.component
12
+ * @param {string} options.metric
13
+ * @param {import('.')} options.metrics
12
14
  */
13
- constructor (component, name, metrics) {
15
+ constructor (options) {
14
16
  super()
15
17
 
18
+ const { system, component, metric, metrics } = options
19
+ this._system = system
16
20
  this._component = component
17
- this._name = name
21
+ this._metric = metric
18
22
  this._metrics = metrics
19
23
 
20
- this._metrics.updateComponentMetric(this._component, this._name, this.size)
24
+ this._metrics.updateComponentMetric({
25
+ system: this._system,
26
+ component: this._component,
27
+ metric: this._metric,
28
+ value: this.size
29
+ })
21
30
  }
22
31
 
23
32
  /**
@@ -26,7 +35,12 @@ class TrackedMap extends Map {
26
35
  */
27
36
  set (key, value) {
28
37
  super.set(key, value)
29
- this._metrics.updateComponentMetric(this._component, this._name, this.size)
38
+ this._metrics.updateComponentMetric({
39
+ system: this._system,
40
+ component: this._component,
41
+ metric: this._metric,
42
+ value: this.size
43
+ })
30
44
  return this
31
45
  }
32
46
 
@@ -35,31 +49,43 @@ class TrackedMap extends Map {
35
49
  */
36
50
  delete (key) {
37
51
  const deleted = super.delete(key)
38
- this._metrics.updateComponentMetric(this._component, this._name, this.size)
52
+ this._metrics.updateComponentMetric({
53
+ system: this._system,
54
+ component: this._component,
55
+ metric: this._metric,
56
+ value: this.size
57
+ })
39
58
  return deleted
40
59
  }
41
60
 
42
61
  clear () {
43
62
  super.clear()
44
63
 
45
- this._metrics.updateComponentMetric(this._component, this._name, this.size)
64
+ this._metrics.updateComponentMetric({
65
+ system: this._system,
66
+ component: this._component,
67
+ metric: this._metric,
68
+ value: this.size
69
+ })
46
70
  }
47
71
  }
48
72
 
49
73
  /**
50
74
  * @template K
51
75
  * @template V
52
- * @param {string} component
53
- * @param {string} name
54
- * @param {import('.')} [metrics]
76
+ * @param {object} options
77
+ * @param {string} [options.system]
78
+ * @param {string} options.component
79
+ * @param {string} options.metric
80
+ * @param {import('.')} [options.metrics]
55
81
  * @returns {Map<K, V>}
56
82
  */
57
- module.exports = (component, name, metrics) => {
83
+ module.exports = ({ system = 'libp2p', component, metric, metrics }) => {
58
84
  /** @type {Map<K, V>} */
59
85
  let map
60
86
 
61
87
  if (metrics) {
62
- map = new TrackedMap(component, name, metrics)
88
+ map = new TrackedMap({ system, component, metric, metrics })
63
89
  } else {
64
90
  map = new Map()
65
91
  }
@@ -154,7 +154,10 @@ class PeerRouting {
154
154
  const controller = new TimeoutController(options.timeout)
155
155
  // this controller will potentially be used while dialing lots of
156
156
  // peers so prevent MaxListenersExceededWarning appearing in the console
157
- setMaxListeners && setMaxListeners(Infinity, controller.signal)
157
+ try {
158
+ // fails on node < 15.4
159
+ setMaxListeners && setMaxListeners(Infinity, controller.signal)
160
+ } catch {}
158
161
 
159
162
  options.signal = controller.signal
160
163
  }