@@ -17,11 +17,11 @@ import {
17
17
} from "@waku/interfaces" ;
18
18
import { Libp2p , Tags } from "@waku/interfaces" ;
19
19
import { shardInfoToPubSubTopics } from "@waku/utils" ;
20
- import debug from "debug " ;
20
+ import { Logger } from "@waku/utils " ;
21
21
22
22
import { KeepAliveManager } from "./keep_alive_manager.js" ;
23
23
24
- const log = debug ( "waku: connection-manager") ;
24
+ const log = new Logger ( " connection-manager") ;
25
25
26
26
export const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1 ;
27
27
export const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3 ;
@@ -128,14 +128,16 @@ export class ConnectionManager
128
128
this . keepAliveManager = new KeepAliveManager ( keepAliveOptions , relay ) ;
129
129
130
130
this . run ( )
131
- . then ( ( ) => log ( `Connection Manager is now running` ) )
132
- . catch ( ( error ) => log ( `Unexpected error while running service` , error ) ) ;
131
+ . then ( ( ) => log . info ( `Connection Manager is now running` ) )
132
+ . catch ( ( error ) =>
133
+ log . error ( `Unexpected error while running service` , error )
134
+ ) ;
133
135
134
136
// libp2p emits `peer:discovery` events during its initialization
135
137
// which means that before the ConnectionManager is initialized, some peers may have been discovered
136
138
// we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
137
139
this . dialPeerStorePeers ( ) . catch ( ( error ) =>
138
- log ( `Unexpected error while dialing peer store peers` , error )
140
+ log . error ( `Unexpected error while dialing peer store peers` , error )
139
141
) ;
140
142
}
141
143
@@ -153,7 +155,7 @@ export class ConnectionManager
153
155
try {
154
156
await Promise . all ( dialPromises ) ;
155
157
} catch ( error ) {
156
- log ( `Unexpected error while dialing peer store peers` , error ) ;
158
+ log . error ( `Unexpected error while dialing peer store peers` , error ) ;
157
159
}
158
160
}
159
161
@@ -185,7 +187,9 @@ export class ConnectionManager
185
187
let dialAttempt = 0 ;
186
188
while ( dialAttempt < this . options . maxDialAttemptsForPeer ) {
187
189
try {
188
- log ( `Dialing peer ${ peerId . toString ( ) } on attempt ${ dialAttempt + 1 } ` ) ;
190
+ log . info (
191
+ `Dialing peer ${ peerId . toString ( ) } on attempt ${ dialAttempt + 1 } `
192
+ ) ;
189
193
await this . libp2p . dial ( peerId ) ;
190
194
191
195
const tags = await this . getTagNamesForPeer ( peerId ) ;
@@ -201,10 +205,12 @@ export class ConnectionManager
201
205
} catch ( error ) {
202
206
if ( error instanceof AggregateError ) {
203
207
// Handle AggregateError
204
- log ( `Error dialing peer ${ peerId . toString ( ) } - ${ error . errors } ` ) ;
208
+ log . error (
209
+ `Error dialing peer ${ peerId . toString ( ) } - ${ error . errors } `
210
+ ) ;
205
211
} else {
206
212
// Handle generic error
207
- log (
213
+ log . error (
208
214
`Error dialing peer ${ peerId . toString ( ) } - ${
209
215
( error as any ) . message
210
216
} `
@@ -230,18 +236,18 @@ export class ConnectionManager
230
236
let errorMessage ;
231
237
if ( error instanceof AggregateError ) {
232
238
if ( ! error . errors ) {
233
- log ( `No errors array found for AggregateError` ) ;
239
+ log . warn ( `No errors array found for AggregateError` ) ;
234
240
} else if ( error . errors . length === 0 ) {
235
- log ( `Errors array is empty for AggregateError` ) ;
241
+ log . warn ( `Errors array is empty for AggregateError` ) ;
236
242
} else {
237
243
errorMessage = JSON . stringify ( error . errors [ 0 ] ) ;
238
244
}
239
245
} else {
240
246
errorMessage = error . message ;
241
247
}
242
248
243
- log (
244
- `Deleting undialable peer ${ peerId . toString ( ) } from peer store. Error : ${ errorMessage } `
249
+ log . info (
250
+ `Deleting undialable peer ${ peerId . toString ( ) } from peer store. Reason : ${ errorMessage } `
245
251
) ;
246
252
}
247
253
@@ -259,9 +265,9 @@ export class ConnectionManager
259
265
try {
260
266
this . keepAliveManager . stop ( peerId ) ;
261
267
await this . libp2p . hangUp ( peerId ) ;
262
- log ( `Dropped connection with peer ${ peerId . toString ( ) } ` ) ;
268
+ log . info ( `Dropped connection with peer ${ peerId . toString ( ) } ` ) ;
263
269
} catch ( error ) {
264
- log (
270
+ log . error (
265
271
`Error dropping connection with peer ${ peerId . toString ( ) } - ${ error } `
266
272
) ;
267
273
}
@@ -275,7 +281,7 @@ export class ConnectionManager
275
281
const peerId = this . pendingPeerDialQueue . shift ( ) ;
276
282
if ( ! peerId ) return ;
277
283
this . attemptDial ( peerId ) . catch ( ( error ) => {
278
- log ( error ) ;
284
+ log . error ( error ) ;
279
285
} ) ;
280
286
}
281
287
}
@@ -322,7 +328,7 @@ export class ConnectionManager
322
328
}
323
329
324
330
this . dialPeer ( peerId ) . catch ( ( err ) => {
325
- log ( `Error dialing peer ${ peerId . toString ( ) } : ${ err } ` ) ;
331
+ log . error ( `Error dialing peer ${ peerId . toString ( ) } : ${ err } ` ) ;
326
332
} ) ;
327
333
}
328
334
@@ -336,7 +342,7 @@ export class ConnectionManager
336
342
try {
337
343
await this . attemptDial ( peerId ) ;
338
344
} catch ( error ) {
339
- log ( `Error dialing peer ${ peerId . toString ( ) } : ${ error } ` ) ;
345
+ log . error ( `Error dialing peer ${ peerId . toString ( ) } : ${ error } ` ) ;
340
346
}
341
347
} ) ( ) ;
342
348
} ,
@@ -404,7 +410,7 @@ export class ConnectionManager
404
410
// if we're already connected to the peer, don't dial
405
411
const isConnected = this . libp2p . getConnections ( peerId ) . length > 0 ;
406
412
if ( isConnected ) {
407
- log ( `Already connected to peer ${ peerId . toString ( ) } . Not dialing.` ) ;
413
+ log . warn ( `Already connected to peer ${ peerId . toString ( ) } . Not dialing.` ) ;
408
414
return false ;
409
415
}
410
416
@@ -414,7 +420,7 @@ export class ConnectionManager
414
420
peerId ,
415
421
this . libp2p . peerStore
416
422
) ;
417
- log (
423
+ log . warn (
418
424
`Discovered peer ${ peerId . toString ( ) } with ShardInfo ${ shardInfo } is not part of any of the configured pubsub topics (${
419
425
this . configuredPubSubTopics
420
426
} ).
@@ -425,7 +431,7 @@ export class ConnectionManager
425
431
426
432
// if the peer is not dialable based on bootstrap status, don't dial
427
433
if ( ! ( await this . isPeerDialableBasedOnBootstrapStatus ( peerId ) ) ) {
428
- log (
434
+ log . warn (
429
435
`Peer ${ peerId . toString ( ) } is not dialable based on bootstrap status. Not dialing.`
430
436
) ;
431
437
return false ;
@@ -486,7 +492,7 @@ export class ConnectionManager
486
492
const peer = await this . libp2p . peerStore . get ( peerId ) ;
487
493
return Array . from ( peer . tags . keys ( ) ) ;
488
494
} catch ( error ) {
489
- log ( `Failed to get peer ${ peerId } , error: ${ error } ` ) ;
495
+ log . error ( `Failed to get peer ${ peerId } , error: ${ error } ` ) ;
490
496
return [ ] ;
491
497
}
492
498
}
0 commit comments