Skip to content

Commit

Permalink
fix(connection-pool): fixed logging (#1463)
Browse files Browse the repository at this point in the history
* fix: fixed logging

* fmt
  • Loading branch information
gurinderu committed Feb 13, 2023
1 parent 563d84d commit 66e364e
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions connection-pool/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,7 @@ impl ConnectionPoolBehaviour {
})
}

fn fail_address(&mut self, peer_id: Option<&PeerId>, addr: &Multiaddr) {
log::warn!(
"failed to connect to {} {}",
addr,
peer_id.map_or("unknown".to_string(), |id| id.to_string())
);

fn cleanup_address(&mut self, peer_id: Option<&PeerId>, addr: &Multiaddr) {
// Notify those who waits for address dial
if let Some(outs) = self.dialing.remove(addr) {
for out in outs {
Expand All @@ -400,7 +394,7 @@ impl ConnectionPoolBehaviour {
if contact.connected.is_empty() && contact.dialing.is_empty() {
self.remove_contact(
peer_id,
"no more connected or dialed addresses after 'fail_address' call",
"no more connected or dialed addresses after 'cleanup_address' call",
);
}
};
Expand Down Expand Up @@ -437,7 +431,9 @@ impl NetworkBehaviour for ConnectionPoolBehaviour {
// mark failed addresses as such
if let Some(failed_addresses) = failed_addresses {
for addr in failed_addresses {
self.fail_address(Some(peer_id), addr)
log::warn!("failed to connect to {} {}", addr, peer_id);

self.cleanup_address(Some(peer_id), addr)
}
}

Expand Down Expand Up @@ -487,7 +483,7 @@ impl NetworkBehaviour for ConnectionPoolBehaviour {
)
}

self.fail_address(Some(peer_id), multiaddr);
self.cleanup_address(Some(peer_id), multiaddr);
}

fn inject_dial_failure(
Expand Down Expand Up @@ -523,11 +519,11 @@ impl NetworkBehaviour for ConnectionPoolBehaviour {
ConnectedPoint::Dialer { address, .. } => address,
ConnectedPoint::Listener { send_back_addr, .. } => send_back_addr,
};
self.fail_address(peer_id.as_ref(), addr);
self.cleanup_address(peer_id.as_ref(), addr);
}
DialError::Transport(addrs) => {
for (addr, _) in addrs {
self.fail_address(peer_id.as_ref(), addr);
self.cleanup_address(peer_id.as_ref(), addr);
}
}
_ => {}
Expand Down

0 comments on commit 66e364e

Please sign in to comment.