Skip to content

Commit

Permalink
Merge pull request ProvableHQ#3002 from AleoHQ/fix/peer_request
Browse files Browse the repository at this point in the history
Filter peer response for requester's IP before sending it
  • Loading branch information
howardwu authored Feb 20, 2024
2 parents cf20012 + 00b1da8 commit 0e096ff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions node/router/src/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,15 @@ pub trait Inbound<N: Network>: Reading + Outbound<N> {
// Filter out invalid addresses.
let peers = match self.router().is_dev() {
// In development mode, relax the validity requirements to make operating devnets more flexible.
true => peers.into_iter().filter(|ip| !is_bogon_ip(ip.ip())).take(u8::MAX as usize).collect(),
true => {
peers.into_iter().filter(|ip| *ip != peer_ip && !is_bogon_ip(ip.ip())).take(u8::MAX as usize).collect()
}
// In production mode, ensure the peer IPs are valid.
false => peers.into_iter().filter(|ip| self.router().is_valid_peer_ip(ip)).take(u8::MAX as usize).collect(),
false => peers
.into_iter()
.filter(|ip| *ip != peer_ip && self.router().is_valid_peer_ip(ip))
.take(u8::MAX as usize)
.collect(),
};
// Send a `PeerResponse` message to the peer.
self.send(peer_ip, Message::PeerResponse(PeerResponse { peers }));
Expand Down

0 comments on commit 0e096ff

Please sign in to comment.