@@ -57,17 +57,34 @@ export interface ConnectionManagerInit {
57
57
/**
58
58
* How long a dial attempt is allowed to take, including DNS resolution
59
59
* of the multiaddr, opening a socket and upgrading it to a Connection.
60
+ *
61
+ * @default 5000
60
62
*/
61
63
dialTimeout ?: number
62
64
63
65
/**
64
- * When a new inbound connection is opened, the upgrade process (e.g. protect,
65
- * encrypt, multiplex etc) must complete within this number of ms.
66
+ * When a new incoming connection is opened, the upgrade process (e.g.
67
+ * protect, encrypt, multiplex etc) must complete within this number of ms.
66
68
*
67
- * @default 30000
69
+ * @default 3000
68
70
*/
69
71
inboundUpgradeTimeout ?: number
70
72
73
+ /**
74
+ * When a new outbound connection is opened, the upgrade process (e.g.
75
+ * protect, encrypt, multiplex etc) must complete within this number of ms.
76
+ *
77
+ * @default 3000
78
+ */
79
+ outboundUpgradeTimeout ?: number
80
+
81
+ /**
82
+ * Protocol negotiation must complete within this number of ms
83
+ *
84
+ * @default 2000
85
+ */
86
+ protocolNegotiationTimeout ?: number
87
+
71
88
/**
72
89
* Multiaddr resolvers to use when dialling
73
90
*/
@@ -164,7 +181,6 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
164
181
private readonly deny : Multiaddr [ ]
165
182
private readonly maxIncomingPendingConnections : number
166
183
private incomingPendingConnections : number
167
- private outboundPendingConnections : number
168
184
private readonly maxConnections : number
169
185
170
186
public readonly dialQueue : DialQueue
@@ -203,7 +219,6 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
203
219
this . allow = ( init . allow ?? [ ] ) . map ( ma => multiaddr ( ma ) )
204
220
this . deny = ( init . deny ?? [ ] ) . map ( ma => multiaddr ( ma ) )
205
221
206
- this . outboundPendingConnections = 0
207
222
this . incomingPendingConnections = 0
208
223
this . maxIncomingPendingConnections = init . maxIncomingPendingConnections ?? defaultOptions . maxIncomingPendingConnections
209
224
@@ -266,8 +281,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
266
281
const metric = {
267
282
inbound : 0 ,
268
283
'inbound pending' : this . incomingPendingConnections ,
269
- outbound : 0 ,
270
- 'outbound pending' : this . outboundPendingConnections
284
+ outbound : 0
271
285
}
272
286
273
287
for ( const conns of this . connections . values ( ) ) {
@@ -468,54 +482,48 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
468
482
469
483
options . signal ?. throwIfAborted ( )
470
484
471
- try {
472
- this . outboundPendingConnections ++
485
+ const { peerId } = getPeerAddress ( peerIdOrMultiaddr )
473
486
474
- const { peerId } = getPeerAddress ( peerIdOrMultiaddr )
487
+ if ( peerId != null && options . force !== true ) {
488
+ this . log ( 'dial %p' , peerId )
489
+ const existingConnection = this . getConnections ( peerId )
490
+ . find ( conn => conn . limits == null )
475
491
476
- if ( peerId != null && options . force !== true ) {
477
- this . log ( 'dial %p' , peerId )
478
- const existingConnection = this . getConnections ( peerId )
479
- . find ( conn => conn . limits == null )
492
+ if ( existingConnection != null ) {
493
+ this . log ( 'had an existing non-limited connection to %p' , peerId )
480
494
481
- if ( existingConnection != null ) {
482
- this . log ( 'had an existing non-limited connection to %p' , peerId )
483
-
484
- options . onProgress ?.( new CustomProgressEvent ( 'dial-queue:already-connected' ) )
485
- return existingConnection
486
- }
495
+ options . onProgress ?.( new CustomProgressEvent ( 'dial-queue:already-connected' ) )
496
+ return existingConnection
487
497
}
498
+ }
488
499
489
- const connection = await this . dialQueue . dial ( peerIdOrMultiaddr , {
490
- ...options ,
491
- priority : options . priority ?? DEFAULT_DIAL_PRIORITY
492
- } )
493
- let peerConnections = this . connections . get ( connection . remotePeer )
494
-
495
- if ( peerConnections == null ) {
496
- peerConnections = [ ]
497
- this . connections . set ( connection . remotePeer , peerConnections )
498
- }
500
+ const connection = await this . dialQueue . dial ( peerIdOrMultiaddr , {
501
+ ...options ,
502
+ priority : options . priority ?? DEFAULT_DIAL_PRIORITY
503
+ } )
504
+ let peerConnections = this . connections . get ( connection . remotePeer )
499
505
500
- // we get notified of connections via the Upgrader emitting "connection"
501
- // events, double check we aren't already tracking this connection before
502
- // storing it
503
- let trackedConnection = false
506
+ if ( peerConnections == null ) {
507
+ peerConnections = [ ]
508
+ this . connections . set ( connection . remotePeer , peerConnections )
509
+ }
504
510
505
- for ( const conn of peerConnections ) {
506
- if ( conn . id === connection . id ) {
507
- trackedConnection = true
508
- }
509
- }
511
+ // we get notified of connections via the Upgrader emitting "connection"
512
+ // events, double check we aren't already tracking this connection before
513
+ // storing it
514
+ let trackedConnection = false
510
515
511
- if ( ! trackedConnection ) {
512
- peerConnections . push ( connection )
516
+ for ( const conn of peerConnections ) {
517
+ if ( conn . id === connection . id ) {
518
+ trackedConnection = true
513
519
}
520
+ }
514
521
515
- return connection
516
- } finally {
517
- this . outboundPendingConnections --
522
+ if ( ! trackedConnection ) {
523
+ peerConnections . push ( connection )
518
524
}
525
+
526
+ return connection
519
527
}
520
528
521
529
async closeConnections ( peerId : PeerId , options : AbortOptions = { } ) : Promise < void > {
0 commit comments