@@ -323,27 +323,33 @@ impl DriaP2PClient {
323
323
cause,
324
324
..
325
325
} => {
326
- let cause = cause
327
- . map ( |c| c. to_string ( ) )
328
- . unwrap_or ( "Unknown" . to_string ( ) ) ;
326
+ // we only care about the connections that we have dialed
329
327
if endpoint. is_dialer ( ) {
330
- // we only care about logs about the ones that we have dialed
331
- log:: warn!( "Connection ({connection_id}) closed for {peer_id}\n Cause: {cause}" ) ;
328
+ // if we know the cause, it may be a good idea to re-dial
329
+ if let Some ( cause) = cause {
330
+ log:: warn!(
331
+ "Connection ({connection_id}) closed for {peer_id} due to {cause}"
332
+ ) ;
332
333
333
- let addr = endpoint. get_remote_address ( ) ;
334
- log:: info!( "Dialing {} again at {}" , peer_id, addr) ;
335
- if let Err ( err) = self . swarm . dial (
336
- DialOpts :: peer_id ( peer_id)
337
- . addresses ( vec ! [ addr. clone( ) ] )
338
- . condition ( PeerCondition :: DisconnectedAndNotDialing )
339
- . build ( ) ,
340
- ) {
341
- log:: error!( "Could not dial peer {peer_id}: {err:?}" ) ;
334
+ let addr = endpoint. get_remote_address ( ) ;
335
+ log:: info!( "Dialing {} again at {}" , peer_id, addr) ;
336
+ if let Err ( err) = self . swarm . dial (
337
+ DialOpts :: peer_id ( peer_id)
338
+ . addresses ( vec ! [ addr. clone( ) ] )
339
+ . condition ( PeerCondition :: DisconnectedAndNotDialing )
340
+ . build ( ) ,
341
+ ) {
342
+ log:: error!( "Could not dial peer {peer_id}: {err:?}" ) ;
343
+ }
344
+ } else {
345
+ // if we don't know the cause, we don't want to re-dial,
346
+ // because the cause is `None` if the other side closed the connection manually
347
+ log:: warn!(
348
+ "Connection ({connection_id}) closed for {peer_id} without a cause, will not re-dial!"
349
+ ) ;
342
350
}
343
351
} else {
344
- log:: debug!(
345
- "Connection ({connection_id}) closed for {peer_id}\n Cause: {cause}"
346
- ) ;
352
+ log:: debug!( "Connection ({connection_id}) closed for {peer_id}: {cause:?}" , ) ;
347
353
}
348
354
}
349
355
0 commit comments