diff --git a/comms/core/src/peer_manager/peer.rs b/comms/core/src/peer_manager/peer.rs index 933a5627e0..b21fb14e23 100644 --- a/comms/core/src/peer_manager/peer.rs +++ b/comms/core/src/peer_manager/peer.rs @@ -158,6 +158,23 @@ impl Peer { &self.supported_protocols } + pub fn last_connect_attempt(&self) -> Option { + let mut last_connected_attempt = None; + for address in self.addresses.addresses() { + if let Some(address_time) = address.last_attempted { + match last_connected_attempt { + Some(last_time) => { + if last_time < address_time { + last_connected_attempt = address.last_attempted + } + }, + None => last_connected_attempt = address.last_attempted, + } + } + } + last_connected_attempt + } + /// Returns true if the peer is marked as offline pub fn is_offline(&self) -> bool { self.addresses.offline_at().is_some() diff --git a/comms/dht/src/connectivity/mod.rs b/comms/dht/src/connectivity/mod.rs index 9eaf9b2677..37ab6f5bf8 100644 --- a/comms/dht/src/connectivity/mod.rs +++ b/comms/dht/src/connectivity/mod.rs @@ -793,6 +793,10 @@ impl DhtConnectivity { { return false; } + // we have tried to connect to this peer, and we have never made a successful attempt at connection + if peer.offline_since().is_none() && peer.last_connect_attempt().is_some() { + return false; + } let is_excluded = excluded.contains(&peer.node_id); if is_excluded {