@@ -38,7 +38,7 @@ export class ConnectionManager
38
38
private dialAttemptsForPeer : Map < string , number > = new Map ( ) ;
39
39
private dialErrorsForPeer : Map < string , any > = new Map ( ) ;
40
40
41
- private currentActiveDialCount = 0 ;
41
+ private currentActiveParallelDialCount = 0 ;
42
42
private pendingPeerDialQueue : Array < PeerId > = [ ] ;
43
43
44
44
public static create (
@@ -181,7 +181,7 @@ export class ConnectionManager
181
181
}
182
182
183
183
private async dialPeer ( peerId : PeerId ) : Promise < void > {
184
- this . currentActiveDialCount += 1 ;
184
+ this . currentActiveParallelDialCount += 1 ;
185
185
let dialAttempt = 0 ;
186
186
while ( dialAttempt < this . options . maxDialAttemptsForPeer ) {
187
187
try {
@@ -195,9 +195,9 @@ export class ConnectionManager
195
195
conn . tags = Array . from ( new Set ( [ ...conn . tags , ...tags ] ) ) ;
196
196
} ) ;
197
197
198
- // instead of deleting the peer from the peer store, we set the dial attempt to 0
198
+ // instead of deleting the peer from the peer store, we set the dial attempt to Infinity
199
199
// this helps us keep track of peers that have been dialed before
200
- this . dialAttemptsForPeer . set ( peerId . toString ( ) , 0 ) ;
200
+ this . dialAttemptsForPeer . set ( peerId . toString ( ) , Infinity ) ;
201
201
202
202
// Dialing succeeded, break the loop
203
203
break ;
@@ -221,7 +221,7 @@ export class ConnectionManager
221
221
}
222
222
223
223
// Always decrease the active dial count and process the dial queue
224
- this . currentActiveDialCount -- ;
224
+ this . currentActiveParallelDialCount -- ;
225
225
this . processDialQueue ( ) ;
226
226
227
227
// If max dial attempts reached and dialing failed, delete the peer
@@ -273,7 +273,7 @@ export class ConnectionManager
273
273
private processDialQueue ( ) : void {
274
274
if (
275
275
this . pendingPeerDialQueue . length > 0 &&
276
- this . currentActiveDialCount < this . options . maxParallelDials
276
+ this . currentActiveParallelDialCount < this . options . maxParallelDials
277
277
) {
278
278
const peerId = this . pendingPeerDialQueue . shift ( ) ;
279
279
if ( ! peerId ) return ;
@@ -319,7 +319,7 @@ export class ConnectionManager
319
319
private async attemptDial ( peerId : PeerId ) : Promise < void > {
320
320
if ( ! ( await this . shouldDialPeer ( peerId ) ) ) return ;
321
321
322
- if ( this . currentActiveDialCount >= this . options . maxParallelDials ) {
322
+ if ( this . currentActiveParallelDialCount >= this . options . maxParallelDials ) {
323
323
this . pendingPeerDialQueue . push ( peerId ) ;
324
324
return ;
325
325
}
@@ -438,7 +438,7 @@ export class ConnectionManager
438
438
// If the peer is already in the peer store or has an active dial attempt, don't dial it
439
439
if (
440
440
this . dialAttemptsForPeer . has ( peerId . toString ( ) ) &&
441
- this . dialAttemptsForPeer . get ( peerId . toString ( ) ) === 0
441
+ this . dialAttemptsForPeer . get ( peerId . toString ( ) ) === Infinity
442
442
) {
443
443
log (
444
444
`Peer ${ peerId . toString ( ) } has already been attempted dial before, or already has a dial attempt in progress, skipping dial`
0 commit comments