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

Commit

Permalink
fix: apply review suggestions and fix clippy lints
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 1cee67d commit 897c16f
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/p2p/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ impl NetworkBehaviour for SwarmApi {
_handler: Self::ConnectionHandler,
error: &DialError,
) {
// TODO: there might be additional connections we should attempt
// (i.e) a new MultiAddr was found after sending the existing ones
// off to dial
if let Some(peer_id) = peer_id {
match self.pending_connections.entry(peer_id) {
Entry::Occupied(mut oe) => {
Expand All @@ -342,23 +345,17 @@ impl NetworkBehaviour for SwarmApi {
for (addr, error) in multiaddrs {
let addr = MultiaddrWithPeerId::try_from(addr.clone())
.expect("to recieve an MultiAddrWithPeerId from DialError");
self.connect_registry
.finish_subscription(addr.into(), Err(error.to_string()));
}

let peer_ids = multiaddrs
.into_iter()
.map(|(addr, _err)| {
MultiaddrWithPeerId::try_from(addr.clone()).unwrap()
})
.collect::<Vec<_>>();
self.connect_registry.finish_subscription(
addr.clone().into(),
Err(error.to_string()),
);

addresses.retain(|peer_id| !peer_ids.iter().any(|id| peer_id == id));
if let Some(pos) = addresses.iter().position(|a| *a == addr) {
addresses.swap_remove(pos);
}
}
}
DialError::WrongPeerId {
obtained: _,
endpoint: _,
} => {
DialError::WrongPeerId { .. } => {
for addr in addresses.iter() {
self.connect_registry.finish_subscription(
addr.clone().into(),
Expand All @@ -368,7 +365,12 @@ impl NetworkBehaviour for SwarmApi {

addresses.clear();
}
err => trace!("unhandled DialError {}", err),
error => {
warn!(
?error,
"unexpected DialError; some futures might never complete"
);
}
}

if addresses.is_empty() {
Expand Down

0 comments on commit 897c16f

Please sign in to comment.