@@ -162,6 +162,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
162
162
private readonly deny : Multiaddr [ ]
163
163
private readonly maxIncomingPendingConnections : number
164
164
private incomingPendingConnections : number
165
+ private outboundPendingConnections : number
165
166
private readonly maxConnections : number
166
167
167
168
public readonly dialQueue : DialQueue
@@ -200,6 +201,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
200
201
this . allow = ( init . allow ?? [ ] ) . map ( ma => multiaddr ( ma ) )
201
202
this . deny = ( init . deny ?? [ ] ) . map ( ma => multiaddr ( ma ) )
202
203
204
+ this . outboundPendingConnections = 0
203
205
this . incomingPendingConnections = 0
204
206
this . maxIncomingPendingConnections = init . maxIncomingPendingConnections ?? defaultOptions . maxIncomingPendingConnections
205
207
@@ -261,7 +263,9 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
261
263
calculate : ( ) => {
262
264
const metric = {
263
265
inbound : 0 ,
264
- outbound : 0
266
+ 'inbound pending' : this . incomingPendingConnections ,
267
+ outbound : 0 ,
268
+ 'outbound pending' : this . outboundPendingConnections
265
269
}
266
270
267
271
for ( const conns of this . connections . values ( ) ) {
@@ -462,48 +466,54 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
462
466
463
467
options . signal ?. throwIfAborted ( )
464
468
465
- const { peerId } = getPeerAddress ( peerIdOrMultiaddr )
469
+ try {
470
+ this . outboundPendingConnections ++
466
471
467
- if ( peerId != null && options . force !== true ) {
468
- this . log ( 'dial %p' , peerId )
469
- const existingConnection = this . getConnections ( peerId )
470
- . find ( conn => conn . limits == null )
472
+ const { peerId } = getPeerAddress ( peerIdOrMultiaddr )
471
473
472
- if ( existingConnection != null ) {
473
- this . log ( 'had an existing non-limited connection to %p' , peerId )
474
+ if ( peerId != null && options . force !== true ) {
475
+ this . log ( 'dial %p' , peerId )
476
+ const existingConnection = this . getConnections ( peerId )
477
+ . find ( conn => conn . limits == null )
474
478
475
- options . onProgress ?.( new CustomProgressEvent ( 'dial-queue:already-connected' ) )
476
- return existingConnection
479
+ if ( existingConnection != null ) {
480
+ this . log ( 'had an existing non-limited connection to %p' , peerId )
481
+
482
+ options . onProgress ?.( new CustomProgressEvent ( 'dial-queue:already-connected' ) )
483
+ return existingConnection
484
+ }
477
485
}
478
- }
479
486
480
- const connection = await this . dialQueue . dial ( peerIdOrMultiaddr , {
481
- ...options ,
482
- priority : options . priority ?? DEFAULT_DIAL_PRIORITY
483
- } )
484
- let peerConnections = this . connections . get ( connection . remotePeer )
487
+ const connection = await this . dialQueue . dial ( peerIdOrMultiaddr , {
488
+ ...options ,
489
+ priority : options . priority ?? DEFAULT_DIAL_PRIORITY
490
+ } )
491
+ let peerConnections = this . connections . get ( connection . remotePeer )
485
492
486
- if ( peerConnections == null ) {
487
- peerConnections = [ ]
488
- this . connections . set ( connection . remotePeer , peerConnections )
489
- }
493
+ if ( peerConnections == null ) {
494
+ peerConnections = [ ]
495
+ this . connections . set ( connection . remotePeer , peerConnections )
496
+ }
490
497
491
- // we get notified of connections via the Upgrader emitting "connection"
492
- // events, double check we aren't already tracking this connection before
493
- // storing it
494
- let trackedConnection = false
498
+ // we get notified of connections via the Upgrader emitting "connection"
499
+ // events, double check we aren't already tracking this connection before
500
+ // storing it
501
+ let trackedConnection = false
495
502
496
- for ( const conn of peerConnections ) {
497
- if ( conn . id === connection . id ) {
498
- trackedConnection = true
503
+ for ( const conn of peerConnections ) {
504
+ if ( conn . id === connection . id ) {
505
+ trackedConnection = true
506
+ }
499
507
}
500
- }
501
508
502
- if ( ! trackedConnection ) {
503
- peerConnections . push ( connection )
504
- }
509
+ if ( ! trackedConnection ) {
510
+ peerConnections . push ( connection )
511
+ }
505
512
506
- return connection
513
+ return connection
514
+ } finally {
515
+ this . outboundPendingConnections --
516
+ }
507
517
}
508
518
509
519
async closeConnections ( peerId : PeerId , options : AbortOptions = { } ) : Promise < void > {
0 commit comments