Move get_clients into gossip_service (#4109)
This commit is contained in:
@ -210,6 +210,14 @@ impl ContactInfo {
|
||||
pub fn client_facing_addr(&self) -> (SocketAddr, SocketAddr) {
|
||||
(self.rpc, self.tpu)
|
||||
}
|
||||
|
||||
pub fn valid_client_facing_addr(&self) -> Option<(SocketAddr, SocketAddr)> {
|
||||
if ContactInfo::is_valid_address(&self.rpc) && ContactInfo::is_valid_address(&self.tpu) {
|
||||
Some((self.rpc, self.tpu))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Signable for ContactInfo {
|
||||
@ -272,6 +280,7 @@ mod tests {
|
||||
assert!(ContactInfo::is_valid_address(&loopback));
|
||||
// assert!(!ContactInfo::is_valid_ip_internal(loopback.ip(), false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let ci = ContactInfo::default();
|
||||
@ -333,4 +342,14 @@ mod tests {
|
||||
assert_eq!(d1.rpc, socketaddr!("127.0.0.1:8899"));
|
||||
assert_eq!(d1.rpc_pubsub, socketaddr!("127.0.0.1:8900"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_valid_client_facing() {
|
||||
let mut ci = ContactInfo::default();
|
||||
assert_eq!(ci.valid_client_facing_addr(), None);
|
||||
ci.tpu = socketaddr!("127.0.0.1:123");
|
||||
assert_eq!(ci.valid_client_facing_addr(), None);
|
||||
ci.rpc = socketaddr!("127.0.0.1:234");
|
||||
assert!(ci.valid_client_facing_addr().is_some());
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,11 @@
|
||||
use crate::bank_forks::BankForks;
|
||||
use crate::blocktree::Blocktree;
|
||||
use crate::cluster_info::ClusterInfo;
|
||||
use crate::cluster_info::FULLNODE_PORT_RANGE;
|
||||
use crate::contact_info::ContactInfo;
|
||||
use crate::service::Service;
|
||||
use crate::streamer;
|
||||
use solana_client::thin_client::{create_client, ThinClient};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use std::net::SocketAddr;
|
||||
@ -105,6 +107,14 @@ pub fn discover(
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get_clients(nodes: &[ContactInfo]) -> Vec<ThinClient> {
|
||||
nodes
|
||||
.iter()
|
||||
.filter_map(ContactInfo::valid_client_facing_addr)
|
||||
.map(|addrs| create_client(addrs, FULLNODE_PORT_RANGE))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn spy(
|
||||
spy_ref: Arc<RwLock<ClusterInfo>>,
|
||||
num_nodes: Option<usize>,
|
||||
|
Reference in New Issue
Block a user