libp2p 0.35.8 → 0.35.9-rc.0

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 (80) hide show
  1. package/dist/src/circuit/auto-relay.d.ts +8 -10
  2. package/dist/src/circuit/auto-relay.d.ts.map +1 -1
  3. package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
  4. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  5. package/dist/src/connection-manager/index.d.ts +1 -2
  6. package/dist/src/connection-manager/index.d.ts.map +1 -1
  7. package/dist/src/content-routing/utils.d.ts +3 -3
  8. package/dist/src/content-routing/utils.d.ts.map +1 -1
  9. package/dist/src/dialer/dial-request.d.ts.map +1 -1
  10. package/dist/src/dialer/index.d.ts +5 -5
  11. package/dist/src/dialer/index.d.ts.map +1 -1
  12. package/dist/src/identify/index.d.ts +4 -4
  13. package/dist/src/identify/index.d.ts.map +1 -1
  14. package/dist/src/index.d.ts +6 -6
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/peer-routing.d.ts +1 -1
  17. package/dist/src/peer-routing.d.ts.map +1 -1
  18. package/dist/src/peer-store/address-book.d.ts +28 -84
  19. package/dist/src/peer-store/address-book.d.ts.map +1 -1
  20. package/dist/src/peer-store/index.d.ts +25 -94
  21. package/dist/src/peer-store/index.d.ts.map +1 -1
  22. package/dist/src/peer-store/key-book.d.ts +31 -15
  23. package/dist/src/peer-store/key-book.d.ts.map +1 -1
  24. package/dist/src/peer-store/metadata-book.d.ts +33 -29
  25. package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
  26. package/dist/src/peer-store/pb/peer.d.ts +222 -0
  27. package/dist/src/peer-store/proto-book.d.ts +28 -29
  28. package/dist/src/peer-store/proto-book.d.ts.map +1 -1
  29. package/dist/src/peer-store/store.d.ts +46 -0
  30. package/dist/src/peer-store/store.d.ts.map +1 -0
  31. package/dist/src/peer-store/types.d.ts +199 -0
  32. package/dist/src/peer-store/types.d.ts.map +1 -0
  33. package/dist/src/ping/index.d.ts.map +1 -1
  34. package/dist/src/record/peer-record/index.d.ts +2 -2
  35. package/dist/src/record/peer-record/index.d.ts.map +1 -1
  36. package/dist/src/registrar.d.ts +5 -5
  37. package/dist/src/registrar.d.ts.map +1 -1
  38. package/dist/src/upgrader.d.ts.map +1 -1
  39. package/package.json +11 -16
  40. package/src/circuit/auto-relay.js +19 -19
  41. package/src/connection-manager/auto-dialler.js +6 -3
  42. package/src/connection-manager/index.js +29 -20
  43. package/src/content-routing/utils.js +4 -4
  44. package/src/dialer/dial-request.js +4 -1
  45. package/src/dialer/index.js +9 -6
  46. package/src/identify/index.js +28 -23
  47. package/src/index.js +33 -27
  48. package/src/peer-routing.js +4 -1
  49. package/src/peer-store/address-book.js +238 -227
  50. package/src/peer-store/index.js +77 -110
  51. package/src/peer-store/key-book.js +99 -54
  52. package/src/peer-store/metadata-book.js +171 -101
  53. package/src/peer-store/pb/peer.d.ts +222 -0
  54. package/src/peer-store/pb/peer.js +643 -0
  55. package/src/peer-store/pb/peer.proto +31 -0
  56. package/src/peer-store/proto-book.js +171 -105
  57. package/src/peer-store/store.js +250 -0
  58. package/src/peer-store/types.ts +245 -0
  59. package/src/ping/index.js +6 -0
  60. package/src/record/peer-record/index.js +1 -1
  61. package/src/record/utils.js +1 -1
  62. package/src/registrar.js +4 -4
  63. package/src/upgrader.js +3 -1
  64. package/dist/src/peer-store/book.d.ts +0 -81
  65. package/dist/src/peer-store/book.d.ts.map +0 -1
  66. package/dist/src/peer-store/persistent/consts.d.ts +0 -6
  67. package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
  68. package/dist/src/peer-store/persistent/index.d.ts +0 -129
  69. package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
  70. package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
  71. package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
  72. package/src/peer-store/book.js +0 -124
  73. package/src/peer-store/persistent/consts.js +0 -15
  74. package/src/peer-store/persistent/index.js +0 -408
  75. package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
  76. package/src/peer-store/persistent/pb/address-book.js +0 -522
  77. package/src/peer-store/persistent/pb/address-book.proto +0 -27
  78. package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
  79. package/src/peer-store/persistent/pb/proto-book.js +0 -157
  80. package/src/peer-store/persistent/pb/proto-book.proto +0 -5
@@ -14,12 +14,12 @@ const take = require('it-take')
14
14
  * Store the multiaddrs from every peer in the passed peer store
15
15
  *
16
16
  * @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source
17
- * @param {import('../peer-store')} peerStore
17
+ * @param {import('../peer-store/types').PeerStore} peerStore
18
18
  */
19
- function storeAddresses (source, peerStore) {
20
- return map(source, (peer) => {
19
+ async function * storeAddresses (source, peerStore) {
20
+ yield * map(source, async (peer) => {
21
21
  // ensure we have the addresses for a given peer
22
- peerStore.addressBook.add(peer.id, peer.multiaddrs)
22
+ await peerStore.addressBook.add(peer.id, peer.multiaddrs)
23
23
 
24
24
  return peer
25
25
  })
@@ -63,7 +63,10 @@ class DialRequest {
63
63
  tokens.forEach(token => tokenHolder.push(token))
64
64
  const dialAbortControllers = this.addrs.map(() => {
65
65
  const controller = new AbortController()
66
- setMaxListeners && setMaxListeners(Infinity, controller.signal)
66
+ try {
67
+ // fails on node < 15.4
68
+ setMaxListeners && setMaxListeners(Infinity, controller.signal)
69
+ } catch {}
67
70
 
68
71
  return controller
69
72
  })
@@ -30,8 +30,8 @@ const METRICS_PENDING_DIAL_TARGETS = 'pending-dial-targets'
30
30
  /**
31
31
  * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
32
32
  * @typedef {import('peer-id')} PeerId
33
- * @typedef {import('../peer-store')} PeerStore
34
- * @typedef {import('../peer-store/address-book').Address} Address
33
+ * @typedef {import('../peer-store/types').PeerStore} PeerStore
34
+ * @typedef {import('../peer-store/types').Address} Address
35
35
  * @typedef {import('../transport-manager')} TransportManager
36
36
  */
37
37
 
@@ -192,10 +192,10 @@ class Dialer {
192
192
  const { id, multiaddrs } = getPeer(peer)
193
193
 
194
194
  if (multiaddrs) {
195
- this.peerStore.addressBook.add(id, multiaddrs)
195
+ await this.peerStore.addressBook.add(id, multiaddrs)
196
196
  }
197
197
 
198
- let knownAddrs = this.peerStore.addressBook.getMultiaddrsForPeer(id, this.addressSorter) || []
198
+ let knownAddrs = await this.peerStore.addressBook.getMultiaddrsForPeer(id, this.addressSorter) || []
199
199
 
200
200
  // If received a multiaddr to dial, it should be the first to use
201
201
  // But, if we know other multiaddrs for the peer, we should try them too.
@@ -215,7 +215,7 @@ class Dialer {
215
215
  const supportedAddrs = addrs.filter(a => this.transportManager.transportForMultiaddr(a))
216
216
 
217
217
  if (supportedAddrs.length > this.maxAddrsToDial) {
218
- this.peerStore.delete(id)
218
+ await this.peerStore.delete(id)
219
219
  throw errCode(new Error('dial with more addresses than allowed'), codes.ERR_TOO_MANY_ADDRESSES)
220
220
  }
221
221
 
@@ -259,7 +259,10 @@ class Dialer {
259
259
 
260
260
  // this signal will potentially be used while dialing lots of
261
261
  // peers so prevent MaxListenersExceededWarning appearing in the console
262
- setMaxListeners && setMaxListeners(Infinity, signal)
262
+ try {
263
+ // fails on node < 15.4
264
+ setMaxListeners && setMaxListeners(Infinity, signal)
265
+ } catch {}
263
266
 
264
267
  const pendingDial = {
265
268
  dialRequest,
@@ -77,8 +77,6 @@ class IdentifyService {
77
77
  ...libp2p._options.host
78
78
  }
79
79
 
80
- this.peerStore.metadataBook.set(this.peerId, 'AgentVersion', uint8ArrayFromString(this._host.agentVersion))
81
- this.peerStore.metadataBook.set(this.peerId, 'ProtocolVersion', uint8ArrayFromString(this._host.protocolVersion))
82
80
  // When a new connection happens, trigger identify
83
81
  this.connectionManager.on('peer:connect', (connection) => {
84
82
  this.identify(connection).catch(log.error)
@@ -87,18 +85,27 @@ class IdentifyService {
87
85
  // When self multiaddrs change, trigger identify-push
88
86
  this.peerStore.on('change:multiaddrs', ({ peerId }) => {
89
87
  if (peerId.toString() === this.peerId.toString()) {
90
- this.pushToPeerStore()
88
+ this.pushToPeerStore().catch(err => log.error(err))
91
89
  }
92
90
  })
93
91
 
94
92
  // When self protocols change, trigger identify-push
95
93
  this.peerStore.on('change:protocols', ({ peerId }) => {
96
94
  if (peerId.toString() === this.peerId.toString()) {
97
- this.pushToPeerStore()
95
+ this.pushToPeerStore().catch(err => log.error(err))
98
96
  }
99
97
  })
100
98
  }
101
99
 
100
+ async start () {
101
+ await this.peerStore.metadataBook.setValue(this.peerId, 'AgentVersion', uint8ArrayFromString(this._host.agentVersion))
102
+ await this.peerStore.metadataBook.setValue(this.peerId, 'ProtocolVersion', uint8ArrayFromString(this._host.protocolVersion))
103
+ }
104
+
105
+ async stop () {
106
+
107
+ }
108
+
102
109
  /**
103
110
  * Send an Identify Push update to the list of connections
104
111
  *
@@ -108,7 +115,7 @@ class IdentifyService {
108
115
  async push (connections) {
109
116
  const signedPeerRecord = await this.peerStore.addressBook.getRawEnvelope(this.peerId)
110
117
  const listenAddrs = this._libp2p.multiaddrs.map((ma) => ma.bytes)
111
- const protocols = this.peerStore.protoBook.get(this.peerId) || []
118
+ const protocols = await this.peerStore.protoBook.get(this.peerId)
112
119
 
113
120
  const pushes = connections.map(async connection => {
114
121
  try {
@@ -135,10 +142,8 @@ class IdentifyService {
135
142
 
136
143
  /**
137
144
  * Calls `push` for all peers in the `peerStore` that are connected
138
- *
139
- * @returns {void}
140
145
  */
141
- pushToPeerStore () {
146
+ async pushToPeerStore () {
142
147
  // Do not try to push if libp2p node is not running
143
148
  if (!this._libp2p.isStarted()) {
144
149
  return
@@ -146,13 +151,13 @@ class IdentifyService {
146
151
 
147
152
  const connections = []
148
153
  let connection
149
- for (const peer of this.peerStore.peers.values()) {
154
+ for await (const peer of this.peerStore.getPeers()) {
150
155
  if (peer.protocols.includes(this.identifyPushProtocolStr) && (connection = this.connectionManager.get(peer.id))) {
151
156
  connections.push(connection)
152
157
  }
153
158
  }
154
159
 
155
- this.push(connections)
160
+ await this.push(connections)
156
161
  }
157
162
 
158
163
  /**
@@ -205,10 +210,10 @@ class IdentifyService {
205
210
 
206
211
  try {
207
212
  const envelope = await Envelope.openAndCertify(signedPeerRecord, PeerRecord.DOMAIN)
208
- if (this.peerStore.addressBook.consumePeerRecord(envelope)) {
209
- this.peerStore.protoBook.set(id, protocols)
210
- this.peerStore.metadataBook.set(id, 'AgentVersion', uint8ArrayFromString(message.agentVersion))
211
- this.peerStore.metadataBook.set(id, 'ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
213
+ if (await this.peerStore.addressBook.consumePeerRecord(envelope)) {
214
+ await this.peerStore.protoBook.set(id, protocols)
215
+ await this.peerStore.metadataBook.setValue(id, 'AgentVersion', uint8ArrayFromString(message.agentVersion))
216
+ await this.peerStore.metadataBook.setValue(id, 'ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
212
217
  return
213
218
  }
214
219
  } catch (/** @type {any} */ err) {
@@ -217,14 +222,14 @@ class IdentifyService {
217
222
 
218
223
  // LEGACY: Update peers data in PeerStore
219
224
  try {
220
- this.peerStore.addressBook.set(id, listenAddrs.map((addr) => new Multiaddr(addr)))
225
+ await this.peerStore.addressBook.set(id, listenAddrs.map((addr) => new Multiaddr(addr)))
221
226
  } catch (/** @type {any} */ err) {
222
227
  log.error('received invalid addrs', err)
223
228
  }
224
229
 
225
- this.peerStore.protoBook.set(id, protocols)
226
- this.peerStore.metadataBook.set(id, 'AgentVersion', uint8ArrayFromString(message.agentVersion))
227
- this.peerStore.metadataBook.set(id, 'ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
230
+ await this.peerStore.protoBook.set(id, protocols)
231
+ await this.peerStore.metadataBook.setValue(id, 'AgentVersion', uint8ArrayFromString(message.agentVersion))
232
+ await this.peerStore.metadataBook.setValue(id, 'ProtocolVersion', uint8ArrayFromString(message.protocolVersion))
228
233
 
229
234
  // TODO: Add and score our observed addr
230
235
  log('received observed address of %s', cleanObservedAddr)
@@ -268,7 +273,7 @@ class IdentifyService {
268
273
  }
269
274
 
270
275
  const signedPeerRecord = await this.peerStore.addressBook.getRawEnvelope(this.peerId)
271
- const protocols = this.peerStore.protoBook.get(this.peerId) || []
276
+ const protocols = await this.peerStore.protoBook.get(this.peerId)
272
277
 
273
278
  const message = Message.Identify.encode({
274
279
  protocolVersion: this._host.protocolVersion,
@@ -321,8 +326,8 @@ class IdentifyService {
321
326
 
322
327
  try {
323
328
  const envelope = await Envelope.openAndCertify(message.signedPeerRecord, PeerRecord.DOMAIN)
324
- if (this.peerStore.addressBook.consumePeerRecord(envelope)) {
325
- this.peerStore.protoBook.set(id, message.protocols)
329
+ if (await this.peerStore.addressBook.consumePeerRecord(envelope)) {
330
+ await this.peerStore.protoBook.set(id, message.protocols)
326
331
  return
327
332
  }
328
333
  } catch (/** @type {any} */ err) {
@@ -331,14 +336,14 @@ class IdentifyService {
331
336
 
332
337
  // LEGACY: Update peers data in PeerStore
333
338
  try {
334
- this.peerStore.addressBook.set(id,
339
+ await this.peerStore.addressBook.set(id,
335
340
  message.listenAddrs.map((addr) => new Multiaddr(addr)))
336
341
  } catch (/** @type {any} */ err) {
337
342
  log.error('received invalid addrs', err)
338
343
  }
339
344
 
340
345
  // Update the protocols
341
- this.peerStore.protoBook.set(id, message.protocols)
346
+ await this.peerStore.protoBook.set(id, message.protocols)
342
347
  }
343
348
 
344
349
  /**
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,7 +28,6 @@ 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
32
  const ping = require('./ping')
34
33
  const IdentifyService = require('./identify')
@@ -112,7 +111,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
112
111
  * @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
113
112
  * @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
114
113
  * @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
115
- * @property {PeerStoreOptions & PersistentPeerStoreOptions} [peerStore]
114
+ * @property {PeerStoreOptions} [peerStore]
116
115
  * @property {import('./transport-manager').TransportManagerOptions} [transportManager]
117
116
  * @property {Libp2pConfig} [config]
118
117
  *
@@ -172,13 +171,11 @@ class Libp2p extends EventEmitter {
172
171
  this.metrics = metrics
173
172
  }
174
173
 
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 })
174
+ /** @type {import('./peer-store/types').PeerStore} */
175
+ this.peerStore = new PeerStore({
176
+ peerId: this.peerId,
177
+ datastore: (this.datastore && this._options.peerStore.persistence) ? this.datastore : new MemoryDatastore()
178
+ })
182
179
 
183
180
  // Addresses {listen, announce, noAnnounce}
184
181
  this.addresses = this._options.addresses
@@ -290,7 +287,6 @@ class Libp2p extends EventEmitter {
290
287
 
291
288
  // Add the identify service since we can multiplex
292
289
  this.identifyService = new IdentifyService({ libp2p: this })
293
- this.handle(Object.values(IdentifyService.getProtocolStr(this)), this.identifyService.handleMessage)
294
290
  }
295
291
 
296
292
  // Attach private network protector
@@ -356,6 +352,10 @@ class Libp2p extends EventEmitter {
356
352
  async start () {
357
353
  log('libp2p is starting')
358
354
 
355
+ if (this.identifyService) {
356
+ await this.handle(Object.values(IdentifyService.getProtocolStr(this)), this.identifyService.handleMessage)
357
+ }
358
+
359
359
  try {
360
360
  await this._onStarting()
361
361
  await this._onDidStart()
@@ -380,9 +380,13 @@ class Libp2p extends EventEmitter {
380
380
  try {
381
381
  this._isStarted = false
382
382
 
383
+ if (this.identifyService) {
384
+ await this.identifyService.stop()
385
+ }
386
+
383
387
  this.relay && this.relay.stop()
384
388
  this.peerRouting.stop()
385
- this._autodialler.stop()
389
+ await this._autodialler.stop()
386
390
  await (this._dht && this._dht.stop())
387
391
 
388
392
  for (const service of this._discovery.values()) {
@@ -393,7 +397,6 @@ class Libp2p extends EventEmitter {
393
397
 
394
398
  this._discovery = new Map()
395
399
 
396
- await this.peerStore.stop()
397
400
  await this.connectionManager.stop()
398
401
 
399
402
  await Promise.all([
@@ -499,7 +502,7 @@ class Libp2p extends EventEmitter {
499
502
  if (!connection) {
500
503
  connection = await this.dialer.connectToPeer(peer, options)
501
504
  } else if (multiaddrs) {
502
- this.peerStore.addressBook.add(id, multiaddrs)
505
+ await this.peerStore.addressBook.add(id, multiaddrs)
503
506
  }
504
507
 
505
508
  return connection
@@ -579,14 +582,14 @@ class Libp2p extends EventEmitter {
579
582
  * @param {string[]|string} protocols
580
583
  * @param {(props: HandlerProps) => void} handler
581
584
  */
582
- handle (protocols, handler) {
585
+ async handle (protocols, handler) {
583
586
  protocols = Array.isArray(protocols) ? protocols : [protocols]
584
587
  protocols.forEach(protocol => {
585
588
  this.upgrader.protocols.set(protocol, handler)
586
589
  })
587
590
 
588
591
  // Add new protocols to self protocols in the Protobook
589
- this.peerStore.protoBook.add(this.peerId, protocols)
592
+ await this.peerStore.protoBook.add(this.peerId, protocols)
590
593
  }
591
594
 
592
595
  /**
@@ -595,14 +598,14 @@ class Libp2p extends EventEmitter {
595
598
  *
596
599
  * @param {string[]|string} protocols
597
600
  */
598
- unhandle (protocols) {
601
+ async unhandle (protocols) {
599
602
  protocols = Array.isArray(protocols) ? protocols : [protocols]
600
603
  protocols.forEach(protocol => {
601
604
  this.upgrader.protocols.delete(protocol)
602
605
  })
603
606
 
604
607
  // Remove protocols from self protocols in the Protobook
605
- this.peerStore.protoBook.remove(this.peerId, protocols)
608
+ await this.peerStore.protoBook.remove(this.peerId, protocols)
606
609
  }
607
610
 
608
611
  async _onStarting () {
@@ -613,11 +616,8 @@ class Libp2p extends EventEmitter {
613
616
  // Manage your NATs
614
617
  this.natManager.start()
615
618
 
616
- // Start PeerStore
617
- await this.peerStore.start()
618
-
619
619
  if (this._config.pubsub.enabled) {
620
- this.pubsub && this.pubsub.start()
620
+ this.pubsub && await this.pubsub.start()
621
621
  }
622
622
 
623
623
  // DHT subsystem
@@ -631,6 +631,10 @@ class Libp2p extends EventEmitter {
631
631
 
632
632
  // Start metrics if present
633
633
  this.metrics && this.metrics.start()
634
+
635
+ if (this.identifyService) {
636
+ await this.identifyService.start()
637
+ }
634
638
  }
635
639
 
636
640
  /**
@@ -643,17 +647,19 @@ class Libp2p extends EventEmitter {
643
647
 
644
648
  this.peerStore.on('peer', peerId => {
645
649
  this.emit('peer:discovery', peerId)
646
- this._maybeConnect(peerId)
650
+ this._maybeConnect(peerId).catch(err => {
651
+ log.error(err)
652
+ })
647
653
  })
648
654
 
649
655
  // Once we start, emit any peers we may have already discovered
650
656
  // TODO: this should be removed, as we already discovered these peers in the past
651
- for (const peer of this.peerStore.peers.values()) {
657
+ for await (const peer of this.peerStore.getPeers()) {
652
658
  this.emit('peer:discovery', peer.id)
653
659
  }
654
660
 
655
661
  this.connectionManager.start()
656
- this._autodialler.start()
662
+ await this._autodialler.start()
657
663
 
658
664
  // Peer discovery
659
665
  await this._setupPeerDiscovery()
@@ -677,8 +683,8 @@ class Libp2p extends EventEmitter {
677
683
  return
678
684
  }
679
685
 
680
- peer.multiaddrs && this.peerStore.addressBook.add(peer.id, peer.multiaddrs)
681
- peer.protocols && this.peerStore.protoBook.set(peer.id, peer.protocols)
686
+ peer.multiaddrs && this.peerStore.addressBook.add(peer.id, peer.multiaddrs).catch(err => log.error(err))
687
+ peer.protocols && this.peerStore.protoBook.set(peer.id, peer.protocols).catch(err => log.error(err))
682
688
  }
683
689
 
684
690
  /**
@@ -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
  }