fix: specify max stream args separately (#1254)

This commit is contained in:
Alex Potsides 2022-06-16 08:37:58 +01:00 committed by GitHub
parent d4dd664071
commit 5371729646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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