excludes private ip addresses

This commit is contained in:
behzad nouri
2021-07-16 13:41:01 -04:00
committed by Trent Nelson
parent 919c3ae6ec
commit e316586516
6 changed files with 62 additions and 8 deletions

View File

@ -64,6 +64,7 @@ use {
solana_streamer::{
packet,
sendmmsg::{multi_target_send, SendPktsError},
socket::is_global,
streamer::{PacketReceiver, PacketSender},
},
solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY,
@ -1178,7 +1179,7 @@ impl ClusterInfo {
.filter(|node| {
node.id != self_pubkey
&& node.shred_version == self_shred_version
&& ContactInfo::is_valid_address(&node.tvu)
&& ContactInfo::is_valid_tvu_address(&node.tvu)
})
.cloned()
.collect()
@ -1235,9 +1236,14 @@ impl ClusterInfo {
.iter()
.map(|peer| &peer.tvu_forwards)
.filter(|addr| ContactInfo::is_valid_address(addr))
.filter(|addr| is_global(addr))
.collect()
} else {
peers.iter().map(|peer| &peer.tvu).collect()
peers
.iter()
.map(|peer| &peer.tvu)
.filter(|addr| is_global(addr))
.collect()
};
let data = &packet.data[..packet.meta.size];

View File

@ -193,10 +193,17 @@ impl ContactInfo {
/// port must not be 0
/// ip must be specified and not multicast
/// loopback ip is only allowed in tests
pub fn is_valid_address(addr: &SocketAddr) -> bool {
// Keeping this for now not to break tvu-peers and turbine shuffle order of
// nodes when arranging nodes on retransmit tree. Private IP addresses in
// turbine are filtered out just before sending packets.
pub(crate) fn is_valid_tvu_address(addr: &SocketAddr) -> bool {
(addr.port() != 0) && Self::is_valid_ip(addr.ip())
}
pub fn is_valid_address(addr: &SocketAddr) -> bool {
Self::is_valid_tvu_address(addr) && solana_streamer::socket::is_global(addr)
}
pub fn client_facing_addr(&self) -> (SocketAddr, SocketAddr) {
(self.rpc, self.tpu)
}