Skip to content

Commit

Permalink
fix(PeerStanding): Include lower bound in standing test
Browse files Browse the repository at this point in the history
An off-by-inclusion error caused peers that should have been banned
based on poor standing to successfully accept connections. The fix
involves including the lower bound on the standing in the standing
test.

Also: improve some log messages.

Closes #301.
  • Loading branch information
aszepieniec committed Jan 7, 2025
1 parent ac35685 commit 5c35dc1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/connect_to_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn check_if_connection_is_allowed(
// Disallow connection if peer is banned via CLI arguments
if cli_arguments.ban.contains(&peer_address.ip()) {
warn!(
"Banned peer {} attempted to connect. Disallowing.",
"Peer {}, banned via CLI argument, attempted to connect. Disallowing.",
peer_address.ip()
);
return InternalConnectionStatus::Refused(ConnectionRefusedReason::BadStanding);
Expand All @@ -95,7 +95,11 @@ async fn check_if_connection_is_allowed(
.get_peer_standing_from_database(peer_address.ip())
.await;

if standing.is_some() && standing.unwrap().standing < -(cli_arguments.peer_tolerance as i32) {
if standing.is_some() && standing.unwrap().standing <= -(cli_arguments.peer_tolerance as i32) {
warn!(
"Peer {}, banned because of bad standing, attempted to connect. Disallowing.",
peer_address.ip()
);
return InternalConnectionStatus::Refused(ConnectionRefusedReason::BadStanding);
}

Expand Down

0 comments on commit 5c35dc1

Please sign in to comment.