libp2p 0.37.3-e6f646e → 0.38.0-0e7096d

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 (125) hide show
  1. package/README.md +0 -2
  2. package/dist/src/circuit/circuit/hop.d.ts +5 -3
  3. package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
  4. package/dist/src/circuit/circuit/hop.js +8 -4
  5. package/dist/src/circuit/circuit/hop.js.map +1 -1
  6. package/dist/src/circuit/circuit/stop.d.ts +5 -3
  7. package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
  8. package/dist/src/circuit/circuit/stop.js +4 -2
  9. package/dist/src/circuit/circuit/stop.js.map +1 -1
  10. package/dist/src/circuit/circuit/stream-handler.d.ts +2 -1
  11. package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
  12. package/dist/src/circuit/circuit/stream-handler.js +2 -2
  13. package/dist/src/circuit/circuit/stream-handler.js.map +1 -1
  14. package/dist/src/circuit/index.d.ts +2 -10
  15. package/dist/src/circuit/index.d.ts.map +1 -1
  16. package/dist/src/circuit/index.js.map +1 -1
  17. package/dist/src/circuit/pb/index.d.ts +5 -4
  18. package/dist/src/circuit/pb/index.d.ts.map +1 -1
  19. package/dist/src/circuit/pb/index.js +107 -11
  20. package/dist/src/circuit/pb/index.js.map +1 -1
  21. package/dist/src/circuit/transport.d.ts +3 -0
  22. package/dist/src/circuit/transport.d.ts.map +1 -1
  23. package/dist/src/circuit/transport.js +79 -57
  24. package/dist/src/circuit/transport.js.map +1 -1
  25. package/dist/src/config.d.ts.map +1 -1
  26. package/dist/src/config.js +19 -4
  27. package/dist/src/config.js.map +1 -1
  28. package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -1
  29. package/dist/src/connection-manager/dialer/auto-dialer.js +6 -0
  30. package/dist/src/connection-manager/dialer/auto-dialer.js.map +1 -1
  31. package/dist/src/connection-manager/dialer/index.d.ts +4 -4
  32. package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
  33. package/dist/src/connection-manager/dialer/index.js +10 -10
  34. package/dist/src/connection-manager/dialer/index.js.map +1 -1
  35. package/dist/src/connection-manager/index.d.ts +8 -1
  36. package/dist/src/connection-manager/index.d.ts.map +1 -1
  37. package/dist/src/connection-manager/index.js +42 -16
  38. package/dist/src/connection-manager/index.js.map +1 -1
  39. package/dist/src/constants.d.ts +4 -0
  40. package/dist/src/constants.d.ts.map +1 -1
  41. package/dist/src/constants.js +4 -0
  42. package/dist/src/constants.js.map +1 -1
  43. package/dist/src/fetch/index.d.ts +4 -0
  44. package/dist/src/fetch/index.d.ts.map +1 -1
  45. package/dist/src/fetch/index.js +25 -6
  46. package/dist/src/fetch/index.js.map +1 -1
  47. package/dist/src/fetch/pb/proto.d.ts +4 -3
  48. package/dist/src/fetch/pb/proto.d.ts.map +1 -1
  49. package/dist/src/fetch/pb/proto.js +88 -8
  50. package/dist/src/fetch/pb/proto.js.map +1 -1
  51. package/dist/src/identify/index.d.ts +1 -1
  52. package/dist/src/identify/index.d.ts.map +1 -1
  53. package/dist/src/identify/index.js +35 -12
  54. package/dist/src/identify/index.js.map +1 -1
  55. package/dist/src/identify/pb/message.d.ts +2 -1
  56. package/dist/src/identify/pb/message.d.ts.map +1 -1
  57. package/dist/src/identify/pb/message.js +94 -10
  58. package/dist/src/identify/pb/message.js.map +1 -1
  59. package/dist/src/index.d.ts +1 -5
  60. package/dist/src/index.d.ts.map +1 -1
  61. package/dist/src/index.js.map +1 -1
  62. package/dist/src/insecure/index.d.ts.map +1 -1
  63. package/dist/src/insecure/index.js +7 -3
  64. package/dist/src/insecure/index.js.map +1 -1
  65. package/dist/src/insecure/pb/proto.d.ts +4 -3
  66. package/dist/src/insecure/pb/proto.d.ts.map +1 -1
  67. package/dist/src/insecure/pb/proto.js +89 -9
  68. package/dist/src/insecure/pb/proto.js.map +1 -1
  69. package/dist/src/keychain/index.d.ts +6 -1
  70. package/dist/src/keychain/index.d.ts.map +1 -1
  71. package/dist/src/keychain/index.js +19 -2
  72. package/dist/src/keychain/index.js.map +1 -1
  73. package/dist/src/libp2p.d.ts +0 -5
  74. package/dist/src/libp2p.d.ts.map +1 -1
  75. package/dist/src/libp2p.js +3 -17
  76. package/dist/src/libp2p.js.map +1 -1
  77. package/dist/src/metrics/index.d.ts +1 -2
  78. package/dist/src/metrics/index.d.ts.map +1 -1
  79. package/dist/src/metrics/index.js +3 -4
  80. package/dist/src/metrics/index.js.map +1 -1
  81. package/dist/src/ping/index.d.ts +4 -0
  82. package/dist/src/ping/index.d.ts.map +1 -1
  83. package/dist/src/ping/index.js +27 -8
  84. package/dist/src/ping/index.js.map +1 -1
  85. package/dist/src/pnet/index.d.ts.map +1 -1
  86. package/dist/src/pnet/index.js +2 -1
  87. package/dist/src/pnet/index.js.map +1 -1
  88. package/dist/src/registrar.d.ts +2 -2
  89. package/dist/src/registrar.d.ts.map +1 -1
  90. package/dist/src/registrar.js +2 -2
  91. package/dist/src/registrar.js.map +1 -1
  92. package/dist/src/upgrader.d.ts +6 -0
  93. package/dist/src/upgrader.d.ts.map +1 -1
  94. package/dist/src/upgrader.js +121 -75
  95. package/dist/src/upgrader.js.map +1 -1
  96. package/dist/src/version.d.ts.map +1 -1
  97. package/dist/src/version.js.map +1 -1
  98. package/package.json +48 -47
  99. package/src/circuit/README.md +2 -2
  100. package/src/circuit/circuit/hop.ts +18 -9
  101. package/src/circuit/circuit/stop.ts +9 -4
  102. package/src/circuit/circuit/stream-handler.ts +5 -4
  103. package/src/circuit/index.ts +2 -11
  104. package/src/circuit/pb/index.ts +133 -15
  105. package/src/circuit/transport.ts +87 -58
  106. package/src/config.ts +19 -4
  107. package/src/connection-manager/dialer/auto-dialer.ts +6 -0
  108. package/src/connection-manager/dialer/index.ts +10 -10
  109. package/src/connection-manager/index.ts +54 -19
  110. package/src/constants.ts +5 -0
  111. package/src/fetch/index.ts +34 -8
  112. package/src/fetch/pb/proto.ts +109 -11
  113. package/src/identify/index.ts +41 -19
  114. package/src/identify/pb/message.ts +111 -11
  115. package/src/index.ts +1 -6
  116. package/src/insecure/index.ts +8 -3
  117. package/src/insecure/pb/proto.ts +111 -12
  118. package/src/keychain/index.ts +27 -3
  119. package/src/libp2p.ts +3 -18
  120. package/src/metrics/index.ts +4 -7
  121. package/src/ping/index.ts +37 -11
  122. package/src/pnet/index.ts +2 -0
  123. package/src/registrar.ts +2 -2
  124. package/src/upgrader.ts +138 -78
  125. package/src/version.ts +1 -2
package/src/upgrader.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { logger } from '@libp2p/logger'
2
2
  import errCode from 'err-code'
3
- import { Dialer, Listener } from '@libp2p/multistream-select'
3
+ import * as mss from '@libp2p/multistream-select'
4
4
  import { pipe } from 'it-pipe'
5
5
  // @ts-expect-error mutable-proxy does not export types
6
6
  import mutableProxy from 'mutable-proxy'
@@ -18,6 +18,9 @@ import { Components, isInitializable } from '@libp2p/components'
18
18
  import type { AbortOptions } from '@libp2p/interfaces'
19
19
  import type { Registrar } from '@libp2p/interface-registrar'
20
20
  import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
21
+ import { TimeoutController } from 'timeout-abort-controller'
22
+ import { abortableDuplex } from 'abortable-iterator'
23
+ import { setMaxListeners } from 'events'
21
24
 
22
25
  const log = logger('libp2p:upgrader')
23
26
 
@@ -43,6 +46,12 @@ export interface CryptoResult extends SecuredConnection {
43
46
  export interface UpgraderInit {
44
47
  connectionEncryption: ConnectionEncrypter[]
45
48
  muxers: StreamMuxerFactory[]
49
+
50
+ /**
51
+ * An amount of ms by which an inbound connection upgrade
52
+ * must complete
53
+ */
54
+ inboundUpgradeTimeout: number
46
55
  }
47
56
 
48
57
  function findIncomingStreamLimit (protocol: string, registrar: Registrar) {
@@ -89,6 +98,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
89
98
  private readonly components: Components
90
99
  private readonly connectionEncryption: Map<string, ConnectionEncrypter>
91
100
  private readonly muxers: Map<string, StreamMuxerFactory>
101
+ private readonly inboundUpgradeTimeout: number
92
102
 
93
103
  constructor (components: Components, init: UpgraderInit) {
94
104
  super()
@@ -105,6 +115,8 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
105
115
  init.muxers.forEach(muxer => {
106
116
  this.muxers.set(muxer.protocol, muxer)
107
117
  })
118
+
119
+ this.inboundUpgradeTimeout = init.inboundUpgradeTimeout
108
120
  }
109
121
 
110
122
  /**
@@ -120,82 +132,97 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
120
132
  let proxyPeer
121
133
  const metrics = this.components.getMetrics()
122
134
 
123
- if (await this.components.getConnectionGater().denyInboundConnection(maConn)) {
124
- throw errCode(new Error('The multiaddr connection is blocked by gater.acceptConnection'), codes.ERR_CONNECTION_INTERCEPTED)
125
- }
135
+ const timeoutController = new TimeoutController(this.inboundUpgradeTimeout)
126
136
 
127
- if (metrics != null) {
128
- ({ setTarget: setPeer, proxy: proxyPeer } = mutableProxy())
129
- const idString = `${(Math.random() * 1e9).toString(36)}${Date.now()}`
130
- setPeer({ toString: () => idString })
131
- maConn = metrics.trackStream({ stream: maConn, remotePeer: proxyPeer })
132
- }
137
+ try {
138
+ // fails on node < 15.4
139
+ setMaxListeners?.(Infinity, timeoutController.signal)
140
+ } catch {}
133
141
 
134
- log('starting the inbound connection upgrade')
142
+ try {
143
+ const abortableStream = abortableDuplex(maConn, timeoutController.signal)
144
+ maConn.source = abortableStream.source
145
+ maConn.sink = abortableStream.sink
135
146
 
136
- // Protect
137
- let protectedConn = maConn
138
- const protector = this.components.getConnectionProtector()
147
+ if (await this.components.getConnectionGater().denyInboundConnection(maConn)) {
148
+ throw errCode(new Error('The multiaddr connection is blocked by gater.acceptConnection'), codes.ERR_CONNECTION_INTERCEPTED)
149
+ }
139
150
 
140
- if (protector != null) {
141
- log('protecting the inbound connection')
142
- protectedConn = await protector.protect(maConn)
143
- }
151
+ if (metrics != null) {
152
+ ({ setTarget: setPeer, proxy: proxyPeer } = mutableProxy())
153
+ const idString = `${(Math.random() * 1e9).toString(36)}${Date.now()}`
154
+ setPeer({ toString: () => idString })
155
+ metrics.trackStream({ stream: maConn, remotePeer: proxyPeer })
156
+ }
144
157
 
145
- try {
146
- // Encrypt the connection
147
- ({
148
- conn: encryptedConn,
149
- remotePeer,
150
- protocol: cryptoProtocol
151
- } = await this._encryptInbound(protectedConn))
158
+ log('starting the inbound connection upgrade')
159
+
160
+ // Protect
161
+ let protectedConn = maConn
162
+ const protector = this.components.getConnectionProtector()
152
163
 
153
- if (await this.components.getConnectionGater().denyInboundEncryptedConnection(remotePeer, {
164
+ if (protector != null) {
165
+ log('protecting the inbound connection')
166
+ protectedConn = await protector.protect(maConn)
167
+ }
168
+
169
+ try {
170
+ // Encrypt the connection
171
+ ({
172
+ conn: encryptedConn,
173
+ remotePeer,
174
+ protocol: cryptoProtocol
175
+ } = await this._encryptInbound(protectedConn))
176
+
177
+ if (await this.components.getConnectionGater().denyInboundEncryptedConnection(remotePeer, {
178
+ ...protectedConn,
179
+ ...encryptedConn
180
+ })) {
181
+ throw errCode(new Error('The multiaddr connection is blocked by gater.acceptEncryptedConnection'), codes.ERR_CONNECTION_INTERCEPTED)
182
+ }
183
+
184
+ // Multiplex the connection
185
+ if (this.muxers.size > 0) {
186
+ const multiplexed = await this._multiplexInbound({
187
+ ...protectedConn,
188
+ ...encryptedConn
189
+ }, this.muxers)
190
+ muxerFactory = multiplexed.muxerFactory
191
+ upgradedConn = multiplexed.stream
192
+ } else {
193
+ upgradedConn = encryptedConn
194
+ }
195
+ } catch (err: any) {
196
+ log.error('Failed to upgrade inbound connection', err)
197
+ await maConn.close(err)
198
+ throw err
199
+ }
200
+
201
+ if (await this.components.getConnectionGater().denyInboundUpgradedConnection(remotePeer, {
154
202
  ...protectedConn,
155
203
  ...encryptedConn
156
204
  })) {
157
205
  throw errCode(new Error('The multiaddr connection is blocked by gater.acceptEncryptedConnection'), codes.ERR_CONNECTION_INTERCEPTED)
158
206
  }
159
207
 
160
- // Multiplex the connection
161
- if (this.muxers.size > 0) {
162
- const multiplexed = await this._multiplexInbound({
163
- ...protectedConn,
164
- ...encryptedConn
165
- }, this.muxers)
166
- muxerFactory = multiplexed.muxerFactory
167
- upgradedConn = multiplexed.stream
168
- } else {
169
- upgradedConn = encryptedConn
208
+ if (metrics != null) {
209
+ metrics.updatePlaceholder(proxyPeer, remotePeer)
210
+ setPeer(remotePeer)
170
211
  }
171
- } catch (err: any) {
172
- log.error('Failed to upgrade inbound connection', err)
173
- await maConn.close(err)
174
- throw err
175
- }
176
212
 
177
- if (await this.components.getConnectionGater().denyInboundUpgradedConnection(remotePeer, {
178
- ...protectedConn,
179
- ...encryptedConn
180
- })) {
181
- throw errCode(new Error('The multiaddr connection is blocked by gater.acceptEncryptedConnection'), codes.ERR_CONNECTION_INTERCEPTED)
182
- }
213
+ log('Successfully upgraded inbound connection')
183
214
 
184
- if (metrics != null) {
185
- metrics.updatePlaceholder(proxyPeer, remotePeer)
186
- setPeer(remotePeer)
215
+ return this._createConnection({
216
+ cryptoProtocol,
217
+ direction: 'inbound',
218
+ maConn,
219
+ upgradedConn,
220
+ muxerFactory,
221
+ remotePeer
222
+ })
223
+ } finally {
224
+ timeoutController.clear()
187
225
  }
188
-
189
- log('Successfully upgraded inbound connection')
190
-
191
- return this._createConnection({
192
- cryptoProtocol,
193
- direction: 'inbound',
194
- maConn,
195
- upgradedConn,
196
- muxerFactory,
197
- remotePeer
198
- })
199
226
  }
200
227
 
201
228
  /**
@@ -226,7 +253,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
226
253
  ({ setTarget: setPeer, proxy: proxyPeer } = mutableProxy())
227
254
  const idString = `${(Math.random() * 1e9).toString(36)}${Date.now()}`
228
255
  setPeer({ toB58String: () => idString })
229
- maConn = metrics.trackStream({ stream: maConn, remotePeer: proxyPeer })
256
+ metrics.trackStream({ stream: maConn, remotePeer: proxyPeer })
230
257
  }
231
258
 
232
259
  log('Starting the outbound connection upgrade')
@@ -315,6 +342,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
315
342
  if (muxerFactory != null) {
316
343
  // Create the muxer
317
344
  muxer = muxerFactory.createStreamMuxer({
345
+ direction,
318
346
  // Run anytime a remote stream is created
319
347
  onIncomingStream: muxedStream => {
320
348
  if (connection == null) {
@@ -323,9 +351,8 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
323
351
 
324
352
  void Promise.resolve()
325
353
  .then(async () => {
326
- const mss = new Listener(muxedStream)
327
354
  const protocols = this.components.getRegistrar().getProtocols()
328
- const { stream, protocol } = await mss.handle(protocols)
355
+ const { stream, protocol } = await mss.handle(muxedStream, protocols)
329
356
  log('%s: incoming stream opened on %s', direction, protocol)
330
357
 
331
358
  const metrics = this.components.getMetrics()
@@ -342,11 +369,17 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
342
369
  const streamCount = countStreams(protocol, 'inbound', connection)
343
370
 
344
371
  if (streamCount === incomingLimit) {
345
- throw errCode(new Error('Too many incoming protocol streams'), codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS)
372
+ muxedStream.abort(errCode(new Error(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`), codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS))
373
+
374
+ return
346
375
  }
347
376
 
348
377
  muxedStream.stat.protocol = protocol
349
378
 
379
+ // If a protocol stream has been successfully negotiated and is to be passed to the application,
380
+ // the peerstore should ensure that the peer is registered with that protocol
381
+ this.components.getPeerStore().protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))
382
+
350
383
  connection.addStream(muxedStream)
351
384
  this._onStream({ connection, stream: { ...muxedStream, ...stream }, protocol })
352
385
  })
@@ -375,25 +408,44 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
375
408
 
376
409
  log('%s: starting new stream on %s', direction, protocols)
377
410
  const muxedStream = muxer.newStream()
378
- const mss = new Dialer(muxedStream)
379
411
  const metrics = this.components.getMetrics()
412
+ let controller: TimeoutController | undefined
380
413
 
381
414
  try {
382
- let { stream, protocol } = await mss.select(protocols, options)
415
+ if (options.signal == null) {
416
+ log('No abort signal was passed while trying to negotiate protocols %s falling back to default timeout', protocols)
417
+
418
+ controller = new TimeoutController(30000)
419
+ options.signal = controller.signal
420
+
421
+ try {
422
+ // fails on node < 15.4
423
+ setMaxListeners?.(Infinity, controller.signal)
424
+ } catch {}
425
+ }
426
+
427
+ const { stream, protocol } = await mss.select(muxedStream, protocols, options)
383
428
 
384
429
  if (metrics != null) {
385
- stream = metrics.trackStream({ stream, remotePeer, protocol })
430
+ metrics.trackStream({ stream, remotePeer, protocol })
386
431
  }
387
432
 
388
433
  const outgoingLimit = findOutgoingStreamLimit(protocol, this.components.getRegistrar())
389
434
  const streamCount = countStreams(protocol, 'outbound', connection)
390
435
 
391
436
  if (streamCount === outgoingLimit) {
392
- throw errCode(new Error('Too many outgoing protocol streams'), codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS)
437
+ const err = errCode(new Error(`Too many outbound protocol streams for protocol "${protocol}" - limit ${outgoingLimit}`), codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS)
438
+ muxedStream.abort(err)
439
+
440
+ throw err
393
441
  }
394
442
 
395
443
  muxedStream.stat.protocol = protocol
396
444
 
445
+ // If a protocol stream has been successfully negotiated and is to be passed to the application,
446
+ // the peerstore should ensure that the peer is registered with that protocol
447
+ this.components.getPeerStore().protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))
448
+
397
449
  return {
398
450
  ...muxedStream,
399
451
  ...stream,
@@ -414,6 +466,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
414
466
  }
415
467
 
416
468
  throw errCode(err, codes.ERR_UNSUPPORTED_PROTOCOL)
469
+ } finally {
470
+ if (controller != null) {
471
+ controller.clear()
472
+ }
417
473
  }
418
474
  }
419
475
 
@@ -469,7 +525,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
469
525
  await maConn.close()
470
526
  // Ensure remaining streams are closed
471
527
  if (muxer != null) {
472
- muxer.streams.forEach(s => s.close())
528
+ muxer.close()
473
529
  }
474
530
  }
475
531
  })
@@ -495,12 +551,13 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
495
551
  * Attempts to encrypt the incoming `connection` with the provided `cryptos`
496
552
  */
497
553
  async _encryptInbound (connection: Duplex<Uint8Array>): Promise<CryptoResult> {
498
- const mss = new Listener(connection)
499
554
  const protocols = Array.from(this.connectionEncryption.keys())
500
555
  log('handling inbound crypto protocol selection', protocols)
501
556
 
502
557
  try {
503
- const { stream, protocol } = await mss.handle(protocols)
558
+ const { stream, protocol } = await mss.handle(connection, protocols, {
559
+ writeBytes: true
560
+ })
504
561
  const encrypter = this.connectionEncryption.get(protocol)
505
562
 
506
563
  if (encrypter == null) {
@@ -523,12 +580,13 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
523
580
  * The first `ConnectionEncrypter` module to succeed will be used
524
581
  */
525
582
  async _encryptOutbound (connection: MultiaddrConnection, remotePeerId: PeerId): Promise<CryptoResult> {
526
- const mss = new Dialer(connection)
527
583
  const protocols = Array.from(this.connectionEncryption.keys())
528
584
  log('selecting outbound crypto protocol', protocols)
529
585
 
530
586
  try {
531
- const { stream, protocol } = await mss.select(protocols)
587
+ const { stream, protocol } = await mss.select(connection, protocols, {
588
+ writeBytes: true
589
+ })
532
590
  const encrypter = this.connectionEncryption.get(protocol)
533
591
 
534
592
  if (encrypter == null) {
@@ -551,11 +609,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
551
609
  * muxer will be used for all future streams on the connection.
552
610
  */
553
611
  async _multiplexOutbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory}> {
554
- const dialer = new Dialer(connection)
555
612
  const protocols = Array.from(muxers.keys())
556
613
  log('outbound selecting muxer %s', protocols)
557
614
  try {
558
- const { stream, protocol } = await dialer.select(protocols)
615
+ const { stream, protocol } = await mss.select(connection, protocols, {
616
+ writeBytes: true
617
+ })
559
618
  log('%s selected as muxer protocol', protocol)
560
619
  const muxerFactory = muxers.get(protocol)
561
620
  return { stream, muxerFactory }
@@ -570,11 +629,12 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
570
629
  * selected muxer will be used for all future streams on the connection.
571
630
  */
572
631
  async _multiplexInbound (connection: MultiaddrConnection, muxers: Map<string, StreamMuxerFactory>): Promise<{ stream: Duplex<Uint8Array>, muxerFactory?: StreamMuxerFactory}> {
573
- const listener = new Listener(connection)
574
632
  const protocols = Array.from(muxers.keys())
575
633
  log('inbound handling muxers %s', protocols)
576
634
  try {
577
- const { stream, protocol } = await listener.handle(protocols)
635
+ const { stream, protocol } = await mss.handle(connection, protocols, {
636
+ writeBytes: true
637
+ })
578
638
  const muxerFactory = muxers.get(protocol)
579
639
  return { stream, muxerFactory }
580
640
  } catch (err: any) {
package/src/version.ts CHANGED
@@ -1,3 +1,2 @@
1
-
2
- export const version = '0.0.0'
1
+ export const version = '0.38.0-0e7096d'
3
2
  export const name = 'libp2p'