Skip to content

Commit

Permalink
fix: specify max stream args separately (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jun 16, 2022
1 parent d4dd664 commit 5371729
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/registrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ 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'
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.
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5371729

Please sign in to comment.