From 73df636a2af97cb8b61bdae56b2742cdc18fe452 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 14 Jun 2023 15:52:20 +0200 Subject: [PATCH] fix: add maxOutboundStreams option to connection.newStream When no handler has been registered for a protocol, the upgrader falls back to the default limit of 64 streams for the protocol on the current connection. This PR adds a `maxOutboundStreams` option to `connection.newStream` that gives the user a way to override the default outgoing stream count without having to register a dummy handler. --- packages/interface-connection/src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/interface-connection/src/index.ts b/packages/interface-connection/src/index.ts index ee087d30a..ea5d9296d 100644 --- a/packages/interface-connection/src/index.ts +++ b/packages/interface-connection/src/index.ts @@ -158,6 +158,15 @@ export interface Stream extends Duplex, Source } +export interface NewStreamOptions extends AbortOptions { + /** + * If specified, and no handler has been registered with the registrar for the + * successfully negotiated protocol, use this as the max outbound stream limit + * for the protocol + */ + maxOutboundStreams?: number +} + /** * A Connection is a high-level representation of a connection * to a remote peer that may have been secured by encryption and @@ -172,7 +181,7 @@ export interface Connection { tags: string[] streams: Stream[] - newStream: (multicodecs: string | string[], options?: AbortOptions) => Promise + newStream: (multicodecs: string | string[], options?: NewStreamOptions) => Promise addStream: (stream: Stream) => void removeStream: (id: string) => void close: () => Promise