Skip to content

Commit

Permalink
fix(external_address): limit some of the incoming error from affectin…
Browse files Browse the repository at this point in the history
…g the score
  • Loading branch information
RolandSherwin committed Jan 17, 2025
1 parent 819d69b commit 0979e80
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ant-networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,19 @@ impl SwarmDriver {
// giving time for ConnectionEstablished to be hopefully processed.
// And since we don't do anything critical with this event, the order and time of processing is
// not critical.
if self.should_we_log_incoming_connection_error(connection_id, &send_back_addr) {
if self.is_incoming_connection_error_valid(connection_id, &send_back_addr) {
error!("IncomingConnectionError from local_addr:?{local_addr:?}, send_back_addr {send_back_addr:?} on {connection_id:?} with error {error:?}");

// This is best approximation that we can do to prevent harmless errors from affecting the external
// address health.
if let Some(external_addr_manager) = self.external_address_manager.as_mut() {
external_addr_manager
.on_incoming_connection_error(local_addr.clone(), &mut self.swarm);
}
} else {
debug!("IncomingConnectionError from local_addr:?{local_addr:?}, send_back_addr {send_back_addr:?} on {connection_id:?} with error {error:?}");
}
if let Some(external_addr_manager) = self.external_address_manager.as_mut() {
external_addr_manager
.on_incoming_connection_error(local_addr.clone(), &mut self.swarm);
}

let _ = self.live_connected_peers.remove(&connection_id);
self.record_connection_metrics();
}
Expand Down Expand Up @@ -787,7 +791,7 @@ impl SwarmDriver {
}

// Do not log IncomingConnectionError if the ConnectionId is adjacent to an already established connection.
fn should_we_log_incoming_connection_error(&self, id: ConnectionId, addr: &Multiaddr) -> bool {
fn is_incoming_connection_error_valid(&self, id: ConnectionId, addr: &Multiaddr) -> bool {
let Ok(id) = format!("{id}").parse::<usize>() else {
return true;
};
Expand Down

0 comments on commit 0979e80

Please sign in to comment.