2021-05-26 08:15:46 -07:00
|
|
|
use {
|
2023-04-21 08:39:16 -07:00
|
|
|
crate::{
|
|
|
|
contact_info::{
|
2023-06-13 12:34:59 -07:00
|
|
|
get_quic_socket, sanitize_quic_offset, sanitize_socket, ContactInfo, Error, Protocol,
|
|
|
|
SOCKET_ADDR_UNSPECIFIED,
|
2023-04-21 08:39:16 -07:00
|
|
|
},
|
|
|
|
crds_value::MAX_WALLCLOCK,
|
|
|
|
},
|
2021-05-26 08:15:46 -07:00
|
|
|
solana_sdk::{
|
|
|
|
pubkey::Pubkey,
|
|
|
|
sanitize::{Sanitize, SanitizeError},
|
|
|
|
timing::timestamp,
|
|
|
|
},
|
2021-07-23 08:25:03 -07:00
|
|
|
solana_streamer::socket::SocketAddrSpace,
|
2023-02-02 15:48:21 -08:00
|
|
|
std::net::{IpAddr, Ipv4Addr, SocketAddr},
|
2021-05-26 08:15:46 -07:00
|
|
|
};
|
2018-11-15 13:23:26 -08:00
|
|
|
|
|
|
|
/// Structure representing a node on the network
|
2022-05-26 05:45:53 -07:00
|
|
|
#[derive(
|
|
|
|
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, AbiExample, Deserialize, Serialize,
|
|
|
|
)]
|
2023-01-08 08:00:55 -08:00
|
|
|
pub struct LegacyContactInfo {
|
2023-04-28 05:05:15 -07:00
|
|
|
id: Pubkey,
|
2018-11-15 13:23:26 -08:00
|
|
|
/// gossip address
|
2023-04-21 08:39:16 -07:00
|
|
|
gossip: SocketAddr,
|
2018-11-15 13:23:26 -08:00
|
|
|
/// address to connect to for replication
|
2023-04-21 08:39:16 -07:00
|
|
|
tvu: SocketAddr,
|
2023-08-07 15:02:41 -07:00
|
|
|
/// TVU over QUIC protocol.
|
|
|
|
tvu_quic: SocketAddr,
|
2023-08-15 10:09:09 -07:00
|
|
|
/// repair service over QUIC protocol.
|
|
|
|
serve_repair_quic: SocketAddr,
|
2018-11-15 13:23:26 -08:00
|
|
|
/// transactions address
|
2023-04-21 08:39:16 -07:00
|
|
|
tpu: SocketAddr,
|
2019-03-11 12:46:30 -07:00
|
|
|
/// address to forward unprocessed transactions to
|
2023-04-21 08:39:16 -07:00
|
|
|
tpu_forwards: SocketAddr,
|
2020-08-07 07:45:17 -07:00
|
|
|
/// address to which to send bank state requests
|
2023-04-21 08:39:16 -07:00
|
|
|
tpu_vote: SocketAddr,
|
2018-11-15 13:23:26 -08:00
|
|
|
/// address to which to send JSON-RPC requests
|
2023-04-21 08:39:16 -07:00
|
|
|
rpc: SocketAddr,
|
2018-11-15 13:23:26 -08:00
|
|
|
/// websocket for JSON-RPC push notifications
|
2023-04-21 08:39:16 -07:00
|
|
|
rpc_pubsub: SocketAddr,
|
2020-01-31 14:23:51 -08:00
|
|
|
/// address to send repair requests to
|
2023-04-21 08:39:16 -07:00
|
|
|
serve_repair: SocketAddr,
|
2018-11-15 13:23:26 -08:00
|
|
|
/// latest wallclock picked
|
2023-04-22 13:18:39 -07:00
|
|
|
wallclock: u64,
|
2020-01-13 14:59:31 -08:00
|
|
|
/// node shred version
|
2023-04-24 08:19:33 -07:00
|
|
|
shred_version: u16,
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
|
|
|
|
2023-01-08 08:00:55 -08:00
|
|
|
impl Sanitize for LegacyContactInfo {
|
2020-04-27 11:06:00 -07:00
|
|
|
fn sanitize(&self) -> std::result::Result<(), SanitizeError> {
|
|
|
|
if self.wallclock >= MAX_WALLCLOCK {
|
2020-04-29 18:12:51 -07:00
|
|
|
return Err(SanitizeError::ValueOutOfBounds);
|
2020-04-27 11:06:00 -07:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 08:39:16 -07:00
|
|
|
macro_rules! get_socket {
|
|
|
|
($name:ident) => {
|
|
|
|
pub fn $name(&self) -> Result<SocketAddr, Error> {
|
|
|
|
let socket = &self.$name;
|
|
|
|
sanitize_socket(socket)?;
|
|
|
|
Ok(socket).copied()
|
|
|
|
}
|
|
|
|
};
|
2023-08-07 15:02:41 -07:00
|
|
|
($name:ident, $quic:ident) => {
|
|
|
|
pub fn $name(&self, protocol: Protocol) -> Result<SocketAddr, Error> {
|
|
|
|
let socket = match protocol {
|
|
|
|
Protocol::QUIC => &self.$quic,
|
|
|
|
Protocol::UDP => &self.$name,
|
|
|
|
};
|
|
|
|
sanitize_socket(socket)?;
|
|
|
|
Ok(socket).copied()
|
|
|
|
}
|
|
|
|
};
|
2023-05-12 09:16:20 -07:00
|
|
|
(@quic $name:ident) => {
|
|
|
|
pub fn $name(&self, protocol: Protocol) -> Result<SocketAddr, Error> {
|
|
|
|
let socket = &self.$name;
|
|
|
|
sanitize_socket(socket)?;
|
|
|
|
match protocol {
|
|
|
|
Protocol::QUIC => get_quic_socket(socket),
|
|
|
|
Protocol::UDP => Ok(socket).copied(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-04-21 08:39:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! set_socket {
|
|
|
|
($name:ident, $key:ident) => {
|
|
|
|
pub fn $name<T>(&mut self, socket: T) -> Result<(), Error>
|
|
|
|
where
|
|
|
|
SocketAddr: From<T>,
|
|
|
|
{
|
|
|
|
let socket = SocketAddr::from(socket);
|
|
|
|
sanitize_socket(&socket)?;
|
|
|
|
self.$key = socket;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! socketaddr {
|
|
|
|
($ip:expr, $port:expr) => {
|
2019-05-03 11:01:35 -07:00
|
|
|
std::net::SocketAddr::from((std::net::Ipv4Addr::from($ip), $port))
|
2018-11-15 13:23:26 -08:00
|
|
|
};
|
|
|
|
($str:expr) => {{
|
2021-05-19 13:56:10 -07:00
|
|
|
$str.parse::<std::net::SocketAddr>().unwrap()
|
2018-11-15 13:23:26 -08:00
|
|
|
}};
|
|
|
|
}
|
2023-02-02 15:48:21 -08:00
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! socketaddr_any {
|
|
|
|
() => {
|
2023-02-02 15:48:21 -08:00
|
|
|
socketaddr!(std::net::Ipv4Addr::UNSPECIFIED, 0)
|
2018-11-15 13:23:26 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-08 08:00:55 -08:00
|
|
|
impl Default for LegacyContactInfo {
|
2018-11-15 13:23:26 -08:00
|
|
|
fn default() -> Self {
|
2023-01-08 08:00:55 -08:00
|
|
|
LegacyContactInfo {
|
2018-11-15 13:23:26 -08:00
|
|
|
id: Pubkey::default(),
|
2018-12-06 12:52:47 -08:00
|
|
|
gossip: socketaddr_any!(),
|
2018-11-15 13:23:26 -08:00
|
|
|
tvu: socketaddr_any!(),
|
2023-08-07 15:02:41 -07:00
|
|
|
tvu_quic: socketaddr_any!(),
|
2023-08-15 10:09:09 -07:00
|
|
|
serve_repair_quic: socketaddr_any!(),
|
2018-11-15 13:23:26 -08:00
|
|
|
tpu: socketaddr_any!(),
|
2019-07-30 14:50:02 -07:00
|
|
|
tpu_forwards: socketaddr_any!(),
|
2021-10-07 02:38:23 -07:00
|
|
|
tpu_vote: socketaddr_any!(),
|
2018-11-15 13:23:26 -08:00
|
|
|
rpc: socketaddr_any!(),
|
|
|
|
rpc_pubsub: socketaddr_any!(),
|
2020-01-31 14:23:51 -08:00
|
|
|
serve_repair: socketaddr_any!(),
|
2018-11-15 13:23:26 -08:00
|
|
|
wallclock: 0,
|
2020-01-13 14:59:31 -08:00
|
|
|
shred_version: 0,
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 08:00:55 -08:00
|
|
|
impl LegacyContactInfo {
|
2020-02-12 12:58:51 -08:00
|
|
|
pub fn new_localhost(id: &Pubkey, now: u64) -> Self {
|
2019-03-08 17:15:08 -08:00
|
|
|
Self {
|
2019-03-09 19:28:43 -08:00
|
|
|
id: *id,
|
2023-02-02 15:48:21 -08:00
|
|
|
gossip: socketaddr!(Ipv4Addr::LOCALHOST, 1234),
|
|
|
|
tvu: socketaddr!(Ipv4Addr::LOCALHOST, 1235),
|
2023-08-07 15:02:41 -07:00
|
|
|
tvu_quic: socketaddr!(Ipv4Addr::LOCALHOST, 1236),
|
2023-08-15 10:09:09 -07:00
|
|
|
serve_repair_quic: socketaddr!(Ipv4Addr::LOCALHOST, 1237),
|
2023-02-02 15:48:21 -08:00
|
|
|
tpu: socketaddr!(Ipv4Addr::LOCALHOST, 1238),
|
|
|
|
tpu_forwards: socketaddr!(Ipv4Addr::LOCALHOST, 1239),
|
|
|
|
tpu_vote: socketaddr!(Ipv4Addr::LOCALHOST, 1240),
|
|
|
|
rpc: socketaddr!(Ipv4Addr::LOCALHOST, 1241),
|
|
|
|
rpc_pubsub: socketaddr!(Ipv4Addr::LOCALHOST, 1242),
|
|
|
|
serve_repair: socketaddr!(Ipv4Addr::LOCALHOST, 1243),
|
2018-11-15 13:23:26 -08:00
|
|
|
wallclock: now,
|
2020-01-13 14:59:31 -08:00
|
|
|
shred_version: 0,
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 08:00:55 -08:00
|
|
|
/// New random LegacyContactInfo for tests and simulations.
|
2021-07-06 17:35:25 -07:00
|
|
|
pub fn new_rand<R: rand::Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self {
|
2020-11-15 08:38:04 -08:00
|
|
|
let delay = 10 * 60 * 1000; // 10 minutes
|
2023-08-21 10:11:21 -07:00
|
|
|
let now = timestamp() - delay + rng.gen_range(0..2 * delay);
|
2020-11-15 08:38:04 -08:00
|
|
|
let pubkey = pubkey.unwrap_or_else(solana_sdk::pubkey::new_rand);
|
2023-01-08 08:00:55 -08:00
|
|
|
let mut node = LegacyContactInfo::new_localhost(&pubkey, now);
|
2023-08-21 10:11:21 -07:00
|
|
|
node.gossip.set_port(rng.gen_range(1024..u16::MAX));
|
2023-01-03 11:37:43 -08:00
|
|
|
node
|
2020-11-15 08:38:04 -08:00
|
|
|
}
|
|
|
|
|
2023-01-08 08:00:55 -08:00
|
|
|
// Construct a LegacyContactInfo that's only usable for gossip
|
2019-03-08 17:15:08 -08:00
|
|
|
pub fn new_gossip_entry_point(gossip_addr: &SocketAddr) -> Self {
|
2020-02-12 12:58:51 -08:00
|
|
|
Self {
|
|
|
|
id: Pubkey::default(),
|
|
|
|
gossip: *gossip_addr,
|
|
|
|
wallclock: timestamp(),
|
2023-01-08 08:00:55 -08:00
|
|
|
..LegacyContactInfo::default()
|
2020-02-12 12:58:51 -08:00
|
|
|
}
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
2019-04-12 18:17:34 -07:00
|
|
|
|
2023-04-28 05:05:15 -07:00
|
|
|
#[inline]
|
|
|
|
pub fn pubkey(&self) -> &Pubkey {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
2023-04-22 13:18:39 -07:00
|
|
|
#[inline]
|
|
|
|
pub fn wallclock(&self) -> u64 {
|
|
|
|
self.wallclock
|
|
|
|
}
|
|
|
|
|
2023-04-24 08:19:33 -07:00
|
|
|
#[inline]
|
|
|
|
pub fn shred_version(&self) -> u16 {
|
|
|
|
self.shred_version
|
|
|
|
}
|
|
|
|
|
2023-04-28 05:05:15 -07:00
|
|
|
pub fn set_pubkey(&mut self, pubkey: Pubkey) {
|
|
|
|
self.id = pubkey
|
|
|
|
}
|
|
|
|
|
2023-04-22 13:18:39 -07:00
|
|
|
pub fn set_wallclock(&mut self, wallclock: u64) {
|
|
|
|
self.wallclock = wallclock;
|
|
|
|
}
|
|
|
|
|
2023-04-24 08:19:33 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
pub(crate) fn set_shred_version(&mut self, shred_version: u16) {
|
|
|
|
self.shred_version = shred_version
|
|
|
|
}
|
|
|
|
|
2023-04-21 08:39:16 -07:00
|
|
|
get_socket!(gossip);
|
2023-08-07 15:02:41 -07:00
|
|
|
get_socket!(tvu, tvu_quic);
|
2023-05-12 09:16:20 -07:00
|
|
|
get_socket!(@quic tpu);
|
|
|
|
get_socket!(@quic tpu_forwards);
|
2023-04-21 08:39:16 -07:00
|
|
|
get_socket!(tpu_vote);
|
|
|
|
get_socket!(rpc);
|
|
|
|
get_socket!(rpc_pubsub);
|
2023-08-15 10:09:09 -07:00
|
|
|
get_socket!(serve_repair, serve_repair_quic);
|
2023-04-21 08:39:16 -07:00
|
|
|
|
|
|
|
set_socket!(set_gossip, gossip);
|
|
|
|
set_socket!(set_rpc, rpc);
|
2023-04-22 13:18:58 -07:00
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
fn is_valid_ip(addr: IpAddr) -> bool {
|
|
|
|
!(addr.is_unspecified() || addr.is_multicast())
|
|
|
|
// || (addr.is_loopback() && !cfg_test))
|
|
|
|
// TODO: boot loopback in production networks
|
|
|
|
}
|
2019-04-12 18:17:34 -07:00
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
/// port must not be 0
|
2020-06-17 20:54:52 -07:00
|
|
|
/// ip must be specified and not multicast
|
2018-11-15 13:23:26 -08:00
|
|
|
/// loopback ip is only allowed in tests
|
2021-07-23 08:25:03 -07:00
|
|
|
// TODO: Replace this entirely with streamer SocketAddrSpace.
|
|
|
|
pub fn is_valid_address(addr: &SocketAddr, socket_addr_space: &SocketAddrSpace) -> bool {
|
2023-01-08 14:53:45 -08:00
|
|
|
addr.port() != 0u16 && Self::is_valid_ip(addr.ip()) && socket_addr_space.check(addr)
|
2021-07-16 10:41:01 -07:00
|
|
|
}
|
|
|
|
|
2023-02-01 05:07:42 -08:00
|
|
|
pub(crate) fn valid_client_facing_addr(
|
2021-07-23 08:25:03 -07:00
|
|
|
&self,
|
2023-05-09 06:46:17 -07:00
|
|
|
protocol: Protocol,
|
2021-07-23 08:25:03 -07:00
|
|
|
socket_addr_space: &SocketAddrSpace,
|
|
|
|
) -> Option<(SocketAddr, SocketAddr)> {
|
2023-05-12 09:16:20 -07:00
|
|
|
Some((
|
|
|
|
self.rpc()
|
|
|
|
.ok()
|
|
|
|
.filter(|addr| socket_addr_space.check(addr))?,
|
|
|
|
self.tpu(protocol)
|
|
|
|
.ok()
|
|
|
|
.filter(|addr| socket_addr_space.check(addr))?,
|
|
|
|
))
|
2019-05-01 17:14:01 -07:00
|
|
|
}
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
|
|
|
|
2023-04-21 08:39:16 -07:00
|
|
|
impl TryFrom<&ContactInfo> for LegacyContactInfo {
|
|
|
|
type Error = Error;
|
|
|
|
|
|
|
|
fn try_from(node: &ContactInfo) -> Result<Self, Self::Error> {
|
|
|
|
macro_rules! unwrap_socket {
|
|
|
|
($name:ident) => {
|
2023-06-13 12:34:59 -07:00
|
|
|
node.$name().ok().unwrap_or(SOCKET_ADDR_UNSPECIFIED)
|
2023-04-21 08:39:16 -07:00
|
|
|
};
|
2023-05-12 09:16:20 -07:00
|
|
|
($name:ident, $protocol:expr) => {
|
|
|
|
node.$name($protocol)
|
|
|
|
.ok()
|
2023-06-13 12:34:59 -07:00
|
|
|
.unwrap_or(SOCKET_ADDR_UNSPECIFIED)
|
2023-05-12 09:16:20 -07:00
|
|
|
};
|
2023-04-21 08:39:16 -07:00
|
|
|
}
|
2023-05-12 09:16:20 -07:00
|
|
|
sanitize_quic_offset(
|
|
|
|
&node.tpu(Protocol::UDP).ok(),
|
|
|
|
&node.tpu(Protocol::QUIC).ok(),
|
|
|
|
)?;
|
|
|
|
sanitize_quic_offset(
|
|
|
|
&node.tpu_forwards(Protocol::UDP).ok(),
|
|
|
|
&node.tpu_forwards(Protocol::QUIC).ok(),
|
|
|
|
)?;
|
2023-04-21 08:39:16 -07:00
|
|
|
Ok(Self {
|
|
|
|
id: *node.pubkey(),
|
|
|
|
gossip: unwrap_socket!(gossip),
|
2023-05-15 08:13:21 -07:00
|
|
|
tvu: unwrap_socket!(tvu, Protocol::UDP),
|
2023-08-07 15:02:41 -07:00
|
|
|
tvu_quic: unwrap_socket!(tvu, Protocol::QUIC),
|
2023-08-15 10:09:09 -07:00
|
|
|
serve_repair_quic: unwrap_socket!(serve_repair, Protocol::QUIC),
|
2023-05-12 09:16:20 -07:00
|
|
|
tpu: unwrap_socket!(tpu, Protocol::UDP),
|
|
|
|
tpu_forwards: unwrap_socket!(tpu_forwards, Protocol::UDP),
|
2023-04-21 08:39:16 -07:00
|
|
|
tpu_vote: unwrap_socket!(tpu_vote),
|
|
|
|
rpc: unwrap_socket!(rpc),
|
|
|
|
rpc_pubsub: unwrap_socket!(rpc_pubsub),
|
2023-08-15 10:09:09 -07:00
|
|
|
serve_repair: unwrap_socket!(serve_repair, Protocol::UDP),
|
2023-04-21 08:39:16 -07:00
|
|
|
wallclock: node.wallclock(),
|
|
|
|
shred_version: node.shred_version(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-02-10 12:07:45 -08:00
|
|
|
use super::*;
|
2018-11-15 13:23:26 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_is_valid_address() {
|
2023-02-02 15:48:21 -08:00
|
|
|
let bad_address_port = socketaddr!(Ipv4Addr::LOCALHOST, 0);
|
2023-01-08 08:00:55 -08:00
|
|
|
assert!(!LegacyContactInfo::is_valid_address(
|
2021-07-23 08:25:03 -07:00
|
|
|
&bad_address_port,
|
|
|
|
&SocketAddrSpace::Unspecified
|
|
|
|
));
|
2023-02-02 15:48:21 -08:00
|
|
|
let bad_address_unspecified = socketaddr!(Ipv4Addr::UNSPECIFIED, 1234);
|
2023-01-08 08:00:55 -08:00
|
|
|
assert!(!LegacyContactInfo::is_valid_address(
|
2021-07-23 08:25:03 -07:00
|
|
|
&bad_address_unspecified,
|
|
|
|
&SocketAddrSpace::Unspecified
|
|
|
|
));
|
2018-11-15 13:23:26 -08:00
|
|
|
let bad_address_multicast = socketaddr!([224, 254, 0, 0], 1234);
|
2023-01-08 08:00:55 -08:00
|
|
|
assert!(!LegacyContactInfo::is_valid_address(
|
2021-07-23 08:25:03 -07:00
|
|
|
&bad_address_multicast,
|
|
|
|
&SocketAddrSpace::Unspecified
|
|
|
|
));
|
2023-02-02 15:48:21 -08:00
|
|
|
let loopback = socketaddr!(Ipv4Addr::LOCALHOST, 1234);
|
2023-01-08 08:00:55 -08:00
|
|
|
assert!(LegacyContactInfo::is_valid_address(
|
2021-07-23 08:25:03 -07:00
|
|
|
&loopback,
|
|
|
|
&SocketAddrSpace::Unspecified
|
|
|
|
));
|
2023-01-08 08:00:55 -08:00
|
|
|
// assert!(!LegacyContactInfo::is_valid_ip_internal(loopback.ip(), false));
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
2019-05-01 17:14:01 -07:00
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
#[test]
|
|
|
|
fn test_default() {
|
2023-01-08 08:00:55 -08:00
|
|
|
let ci = LegacyContactInfo::default();
|
2018-12-06 12:52:47 -08:00
|
|
|
assert!(ci.gossip.ip().is_unspecified());
|
2018-11-15 13:23:26 -08:00
|
|
|
assert!(ci.tvu.ip().is_unspecified());
|
2019-07-30 14:50:02 -07:00
|
|
|
assert!(ci.tpu_forwards.ip().is_unspecified());
|
2018-11-15 13:23:26 -08:00
|
|
|
assert!(ci.rpc.ip().is_unspecified());
|
|
|
|
assert!(ci.rpc_pubsub.ip().is_unspecified());
|
|
|
|
assert!(ci.tpu.ip().is_unspecified());
|
2021-10-07 02:38:23 -07:00
|
|
|
assert!(ci.tpu_vote.ip().is_unspecified());
|
2020-01-31 14:23:51 -08:00
|
|
|
assert!(ci.serve_repair.ip().is_unspecified());
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
2023-02-01 05:07:42 -08:00
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
#[test]
|
|
|
|
fn test_entry_point() {
|
2023-02-02 15:48:21 -08:00
|
|
|
let addr = socketaddr!(Ipv4Addr::LOCALHOST, 10);
|
2023-01-08 08:00:55 -08:00
|
|
|
let ci = LegacyContactInfo::new_gossip_entry_point(&addr);
|
2018-12-06 12:52:47 -08:00
|
|
|
assert_eq!(ci.gossip, addr);
|
2018-11-15 13:23:26 -08:00
|
|
|
assert!(ci.tvu.ip().is_unspecified());
|
2019-07-30 14:50:02 -07:00
|
|
|
assert!(ci.tpu_forwards.ip().is_unspecified());
|
2018-11-15 13:23:26 -08:00
|
|
|
assert!(ci.rpc.ip().is_unspecified());
|
|
|
|
assert!(ci.rpc_pubsub.ip().is_unspecified());
|
|
|
|
assert!(ci.tpu.ip().is_unspecified());
|
2021-10-07 02:38:23 -07:00
|
|
|
assert!(ci.tpu_vote.ip().is_unspecified());
|
2020-01-31 14:23:51 -08:00
|
|
|
assert!(ci.serve_repair.ip().is_unspecified());
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|
2019-05-01 17:14:01 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_valid_client_facing() {
|
2023-01-08 08:00:55 -08:00
|
|
|
let mut ci = LegacyContactInfo::default();
|
2021-07-23 08:25:03 -07:00
|
|
|
assert_eq!(
|
2023-05-09 06:46:17 -07:00
|
|
|
ci.valid_client_facing_addr(Protocol::QUIC, &SocketAddrSpace::Unspecified),
|
2021-07-23 08:25:03 -07:00
|
|
|
None
|
|
|
|
);
|
2023-02-02 15:48:21 -08:00
|
|
|
ci.tpu = socketaddr!(Ipv4Addr::LOCALHOST, 123);
|
2021-07-23 08:25:03 -07:00
|
|
|
assert_eq!(
|
2023-05-09 06:46:17 -07:00
|
|
|
ci.valid_client_facing_addr(Protocol::QUIC, &SocketAddrSpace::Unspecified),
|
2021-07-23 08:25:03 -07:00
|
|
|
None
|
|
|
|
);
|
2023-02-02 15:48:21 -08:00
|
|
|
ci.rpc = socketaddr!(Ipv4Addr::LOCALHOST, 234);
|
2021-07-23 08:25:03 -07:00
|
|
|
assert!(ci
|
2023-05-09 06:46:17 -07:00
|
|
|
.valid_client_facing_addr(Protocol::QUIC, &SocketAddrSpace::Unspecified)
|
2021-07-23 08:25:03 -07:00
|
|
|
.is_some());
|
2019-05-01 17:14:01 -07:00
|
|
|
}
|
2020-04-29 18:12:51 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sanitize() {
|
2023-01-08 08:00:55 -08:00
|
|
|
let mut ci = LegacyContactInfo::default();
|
2020-04-29 18:12:51 -07:00
|
|
|
assert_eq!(ci.sanitize(), Ok(()));
|
|
|
|
ci.wallclock = MAX_WALLCLOCK;
|
|
|
|
assert_eq!(ci.sanitize(), Err(SanitizeError::ValueOutOfBounds));
|
|
|
|
}
|
2018-11-15 13:23:26 -08:00
|
|
|
}
|