mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-24 18:12:14 +00:00
fix: specify max stream args separately (#1254)
This commit is contained in:
parent
d4dd664071
commit
5371729646
@ -2,6 +2,7 @@ import { logger } from '@libp2p/logger'
|
||||
import errCode from 'err-code'
|
||||
import { codes } from './errors.js'
|
||||
import { isTopology, StreamHandlerOptions, StreamHandlerRecord } from '@libp2p/interface-registrar'
|
||||
import merge from 'merge-options'
|
||||
import type { Registrar, StreamHandler, Topology } from '@libp2p/interface-registrar'
|
||||
import type { PeerProtocolsChangeData } from '@libp2p/interface-peer-store'
|
||||
import type { Connection } from '@libp2p/interface-connection'
|
||||
@ -9,6 +10,9 @@ import type { Components } from '@libp2p/components'
|
||||
|
||||
const log = logger('libp2p:registrar')
|
||||
|
||||
const DEFAULT_MAX_INCOMING_STREAMS = 1
|
||||
const DEFAULT_MAX_OUTGOING_STREAMS = 1
|
||||
|
||||
/**
|
||||
* Responsible for notifying registered protocols of events in the network.
|
||||
*/
|
||||
@ -63,11 +67,16 @@ export class DefaultRegistrar implements Registrar {
|
||||
/**
|
||||
* Registers the `handler` for each protocol
|
||||
*/
|
||||
async handle (protocol: string, handler: StreamHandler, options: StreamHandlerOptions = { maxConcurrentStreams: 1 }): Promise<void> {
|
||||
async handle (protocol: string, handler: StreamHandler, opts?: StreamHandlerOptions): Promise<void> {
|
||||
if (this.handlers.has(protocol)) {
|
||||
throw errCode(new Error(`Handler already registered for protocol ${protocol}`), codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED)
|
||||
}
|
||||
|
||||
const options = merge({
|
||||
maxIncomingStreams: DEFAULT_MAX_INCOMING_STREAMS,
|
||||
maxOutgoingStreams: DEFAULT_MAX_OUTGOING_STREAMS
|
||||
}, opts)
|
||||
|
||||
this.handlers.set(protocol, {
|
||||
handler,
|
||||
options
|
||||
|
Loading…
x
Reference in New Issue
Block a user