libp2p 0.45.8 → 0.45.9-5a9fb4d6

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.
package/src/upgrader.ts CHANGED
@@ -9,7 +9,7 @@ import { createConnection } from './connection/index.js'
9
9
  import { INBOUND_UPGRADE_TIMEOUT } from './connection-manager/constants.js'
10
10
  import { codes } from './errors.js'
11
11
  import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.js'
12
- import type { MultiaddrConnection, Connection, Stream, ConnectionProtector } from '@libp2p/interface-connection'
12
+ import type { MultiaddrConnection, Connection, Stream, ConnectionProtector, NewStreamOptions } from '@libp2p/interface-connection'
13
13
  import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
14
14
  import type { ConnectionGater } from '@libp2p/interface-connection-gater'
15
15
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
@@ -70,17 +70,20 @@ function findIncomingStreamLimit (protocol: string, registrar: Registrar): numbe
70
70
  return DEFAULT_MAX_INBOUND_STREAMS
71
71
  }
72
72
 
73
- function findOutgoingStreamLimit (protocol: string, registrar: Registrar): number | undefined {
73
+ function findOutgoingStreamLimit (protocol: string, registrar: Registrar, options: NewStreamOptions = {}): number {
74
74
  try {
75
75
  const { options } = registrar.getHandler(protocol)
76
- return options.maxOutboundStreams
76
+
77
+ if (options.maxOutboundStreams != null) {
78
+ return options.maxOutboundStreams
79
+ }
77
80
  } catch (err: any) {
78
81
  if (err.code !== codes.ERR_NO_HANDLER_FOR_PROTOCOL) {
79
82
  throw err
80
83
  }
81
84
  }
82
85
 
83
- return DEFAULT_MAX_OUTBOUND_STREAMS
86
+ return options.maxOutboundStreams ?? DEFAULT_MAX_OUTBOUND_STREAMS
84
87
  }
85
88
 
86
89
  function countStreams (protocol: string, direction: 'inbound' | 'outbound', connection: Connection): number {
@@ -428,7 +431,7 @@ export class DefaultUpgrader implements Upgrader {
428
431
  }
429
432
  })
430
433
 
431
- newStream = async (protocols: string[], options: AbortOptions = {}): Promise<Stream> => {
434
+ newStream = async (protocols: string[], options: NewStreamOptions = {}): Promise<Stream> => {
432
435
  if (muxer == null) {
433
436
  throw new CodeError('Stream is not multiplexed', codes.ERR_MUXER_UNAVAILABLE)
434
437
  }
@@ -450,10 +453,10 @@ export class DefaultUpgrader implements Upgrader {
450
453
 
451
454
  const { stream, protocol } = await mss.select(muxedStream, protocols, options)
452
455
 
453
- const outgoingLimit = findOutgoingStreamLimit(protocol, this.components.registrar)
456
+ const outgoingLimit = findOutgoingStreamLimit(protocol, this.components.registrar, options)
454
457
  const streamCount = countStreams(protocol, 'outbound', connection)
455
458
 
456
- if (streamCount === outgoingLimit) {
459
+ if (streamCount >= outgoingLimit) {
457
460
  const err = new CodeError(`Too many outbound protocol streams for protocol "${protocol}" - limit ${outgoingLimit}`, codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS)
458
461
  muxedStream.abort(err)
459
462
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '0.45.8'
1
+ export const version = '0.45.9-5a9fb4d6'
2
2
  export const name = 'libp2p'