summaryrefslogtreecommitdiffstats
path: root/src/transport
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-28 13:27:43 +0100
committertv <tv@krebsco.de>2026-10-28 13:41:22 +0100
commita5a27eb4699fc5c3fa9fbcc5886f06b88e068bfd (patch)
treebd36f77947eb98e6e17b28f375f4cb4f22a0c65d /src/transport
parentae92c0da76e7c5c84b4cbad0812d75b2e9c43073 (diff)
libp2p: remove duplicate close line
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/libp2p.rs14
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,