Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comms+dht): mark peers as online inbound connection,join #5741

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions comms/core/src/connection_manager/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ pub(super) fn create_or_update_peer_from_validated_peer_identity(
peer_identity_claim: peer_identity.claim.clone(),
});

peer.addresses
.mark_all_addresses_as_last_seen_now(&peer_identity.claim.addresses);

peer.features = peer_identity.claim.features;
peer.supported_protocols = peer_identity.metadata.supported_protocols.clone();
peer.user_agent = peer_identity.metadata.user_agent.clone();
Expand Down
4 changes: 2 additions & 2 deletions comms/core/src/connectivity/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl ConnectivityManagerActor {
}
}

fn mark_peer_succeeded(&mut self, node_id: NodeId) {
fn mark_connection_success(&mut self, node_id: NodeId) {
let entry = self.get_connection_stat_mut(node_id);
entry.set_connection_success();
}
Expand Down Expand Up @@ -635,7 +635,7 @@ impl ConnectivityManagerActor {
match (old_status, new_status) {
(_, Connected) => match self.pool.get_connection(&node_id).cloned() {
Some(conn) => {
self.mark_peer_succeeded(node_id.clone());
self.mark_connection_success(conn.peer_node_id().clone());
self.publish_event(ConnectivityEvent::PeerConnected(conn.into()));
},
None => unreachable!(
Expand Down
15 changes: 15 additions & 0 deletions comms/core/src/net_address/mutliaddresses_with_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ impl MultiaddressesWithStats {
}
}

/// Mark all addresses as seen. Returns true if all addresses are contained in this instance, otherwise false
pub fn mark_all_addresses_as_last_seen_now(&mut self, addresses: &[Multiaddr]) -> bool {
let mut all_exist = true;
for address in addresses {
match self.find_address_mut(address) {
Some(addr) => {
addr.mark_last_seen_now().mark_last_attempted_now();
},
None => all_exist = false,
}
}
self.sort_addresses();
all_exist
}

/// Mark that a connection could not be established with the specified net address
///
/// Returns true if the address is contained in this instance, otherwise false
Expand Down
7 changes: 2 additions & 5 deletions comms/dht/src/connectivity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,6 @@ impl DhtConnectivity {
}

async fn handle_new_peer_connected(&mut self, conn: PeerConnection) -> Result<(), DhtConnectivityError> {
// We can only mark the peer as seen if we know which address we are were about to connect to (Outbound).
if let Some(addr) = conn.known_address() {
self.peer_manager.mark_last_seen(conn.peer_node_id(), addr).await?;
}
if conn.peer_features().is_client() {
debug!(
target: LOG_TARGET,
Expand Down Expand Up @@ -749,6 +745,7 @@ impl DhtConnectivity {
let peer_manager = &self.peer_manager;
let node_id = self.node_identity.node_id();
let connected = self.connected_peers_iter().collect::<Vec<_>>();

// Fetch to all n nearest neighbour Communication Nodes
// which are eligible for connection.
// Currently that means:
Expand Down Expand Up @@ -779,7 +776,7 @@ 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() {
if peer.last_connect_attempt().is_some() && peer.last_seen().is_none() {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions comms/dht/src/peer_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl<'a> PeerValidator<'a> {
peer.update_addresses(&claim.addresses, &PeerAddressSource::FromDiscovery {
peer_identity_claim: claim.clone(),
});
peer.addresses.mark_all_addresses_as_last_seen_now(&claim.addresses);
}

Ok(peer)
Expand Down