diff options
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/libp2p.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/transport/libp2p.rs b/src/transport/libp2p.rs index ebf50b4..ee5bb56 100644 --- a/src/transport/libp2p.rs +++ b/src/transport/libp2p.rs @@ -972,6 +972,9 @@ async fn run( // Peers that may have several connections, and when to cut them to one. Only the // side with the smaller peer ID does that, so the two never close different ones. let mut dedupe_due: HashMap<PeerId, tokio::time::Instant> = HashMap::new(); + // Connections closed as duplicates, until they are: their "Connection closed" says so. + let mut closing_duplicates: std::collections::HashSet<ConnectionId> = + std::collections::HashSet::new(); let mut dedupe = tokio::time::interval(DEDUPE_EVERY); dedupe.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay); loop { @@ -987,8 +990,9 @@ async fn run( dedupe_due.remove(&peer); let duplicates = lock(&book).duplicates(&peer); for connection in duplicates { - debug!(peer = %peer, connection = %connection, "Closing a duplicate connection"); - swarm.close_connection(connection); + if swarm.close_connection(connection) { + closing_duplicates.insert(connection); + } } } } @@ -1127,6 +1131,12 @@ async fn run( } SwarmEvent::ConnectionClosed { peer_id, connection_id, cause, .. } => { lock(&book).connections.remove(&connection_id); + let cause = match cause { + _ if closing_duplicates.remove(&connection_id) => "a duplicate".to_owned(), + // By us, or idle: libp2p doesn't tell which. + None => "closed here".to_owned(), + Some(error) => error.to_string(), + }; debug!( peer = %peer_id, connection = %connection_id, |
