Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
wip: re-add code fragment to handle dial failure
Browse files Browse the repository at this point in the history
  • Loading branch information
rand0m-cloud authored and koivunej committed Apr 1, 2022
1 parent 77291ee commit 888e6f1
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/p2p/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,27 @@ impl NetworkBehaviour for SwarmApi {
handler,
});
}
}

if let Some(peer_id) = peer_id {
match self.pending_connections.entry(peer_id) {
Entry::Occupied(mut oe) => {
let addresses = oe.get_mut();
let addr = MultiaddrWithPeerId::try_from(addr.clone())
.expect("dialed address contains peerid in libp2p 0.38");
let pos = addresses.iter().position(|a| *a == addr);

if let Some(pos) = pos {
addresses.swap_remove(pos);
self.connect_registry
.finish_subscription(addr.into(), Err(error.to_string()));
}

// this should not be executed once, but probably will be in case unsupported addresses or something
// surprising happens.
for failed in self
.pending_connections
.remove(&peer_id)
.unwrap_or_default()
{
self.connect_registry
.finish_subscription(failed.into(), Err("addresses exhausted".into()));
if addresses.is_empty() {
oe.remove();
}
}
Entry::Vacant(_) => {}
}
}
}
Expand Down

0 comments on commit 888e6f1

Please sign in to comment.