@@ -65,6 +65,8 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
65
65
66
66
private _registrarTopologyIds : string [ ] | undefined
67
67
protected enabled : boolean
68
+ private readonly maxInboundStreams : number
69
+ private readonly maxOutboundStreams : number
68
70
69
71
constructor ( props : PubSubInit ) {
70
72
super ( )
@@ -74,7 +76,9 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
74
76
globalSignaturePolicy = 'StrictSign' ,
75
77
canRelayMessage = false ,
76
78
emitSelf = false ,
77
- messageProcessingConcurrency = 10
79
+ messageProcessingConcurrency = 10 ,
80
+ maxInboundStreams = 1 ,
81
+ maxOutboundStreams = 1
78
82
} = props
79
83
80
84
this . multicodecs = ensureArray ( multicodecs )
@@ -88,6 +92,8 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
88
92
this . emitSelf = emitSelf
89
93
this . topicValidators = new Map ( )
90
94
this . queue = new Queue ( { concurrency : messageProcessingConcurrency } )
95
+ this . maxInboundStreams = maxInboundStreams
96
+ this . maxOutboundStreams = maxOutboundStreams
91
97
92
98
this . _onIncomingStream = this . _onIncomingStream . bind ( this )
93
99
this . _onPeerConnected = this . _onPeerConnected . bind ( this )
@@ -115,7 +121,10 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
115
121
const registrar = this . components . getRegistrar ( )
116
122
// Incoming streams
117
123
// Called after a peer dials us
118
- await Promise . all ( this . multicodecs . map ( async multicodec => await registrar . handle ( multicodec , this . _onIncomingStream ) ) )
124
+ await Promise . all ( this . multicodecs . map ( async multicodec => await registrar . handle ( multicodec , this . _onIncomingStream , {
125
+ maxInboundStreams : this . maxInboundStreams ,
126
+ maxOutboundStreams : this . maxOutboundStreams
127
+ } ) ) )
119
128
120
129
// register protocol with topology
121
130
// Topology callbacks called on connection manager changes
0 commit comments