|solana-gossip spy| no longer requires an entrypoint (#6999)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
//! A command-line executable for monitoring a cluster's gossip plane.
|
||||
|
||||
use clap::{crate_description, crate_name, value_t_or_exit, App, AppSettings, Arg, SubCommand};
|
||||
use clap::{
|
||||
crate_description, crate_name, value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
|
||||
};
|
||||
use solana_clap_utils::input_validators::is_pubkey;
|
||||
use solana_client::rpc_client::RpcClient;
|
||||
use solana_core::{contact_info::ContactInfo, gossip_service::discover};
|
||||
use solana_core::{contact_info::ContactInfo, gossip_service::discover, socketaddr};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use std::error;
|
||||
use std::net::SocketAddr;
|
||||
@@ -12,26 +14,23 @@ use std::process::exit;
|
||||
fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
solana_logger::setup_with_filter("solana=info");
|
||||
|
||||
let mut entrypoint_addr = SocketAddr::from(([127, 0, 0, 1], 8001));
|
||||
let entrypoint_string = entrypoint_addr.to_string();
|
||||
let matches = App::new(crate_name!())
|
||||
.about(crate_description!())
|
||||
.version(solana_clap_utils::version!())
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.arg(
|
||||
Arg::with_name("entrypoint")
|
||||
.short("n")
|
||||
.long("entrypoint")
|
||||
.value_name("HOST:PORT")
|
||||
.takes_value(true)
|
||||
.default_value(&entrypoint_string)
|
||||
.validator(solana_net_utils::is_host_port)
|
||||
.global(true)
|
||||
.help("Rendezvous with the cluster at this entry point"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("get-rpc-url")
|
||||
.about("Get an RPC URL for the cluster")
|
||||
.arg(
|
||||
Arg::with_name("entrypoint")
|
||||
.short("n")
|
||||
.long("entrypoint")
|
||||
.value_name("HOST:PORT")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.validator(solana_net_utils::is_host_port)
|
||||
.help("Rendezvous with the cluster at this entry point"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("all")
|
||||
.long("all")
|
||||
@@ -52,12 +51,21 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
SubCommand::with_name("spy")
|
||||
.about("Monitor the gossip entrypoint")
|
||||
.setting(AppSettings::DisableVersion)
|
||||
.arg(
|
||||
Arg::with_name("entrypoint")
|
||||
.short("n")
|
||||
.long("entrypoint")
|
||||
.value_name("HOST:PORT")
|
||||
.takes_value(true)
|
||||
.required_unless("gossip_port")
|
||||
.validator(solana_net_utils::is_host_port)
|
||||
.help("Rendezvous with the cluster at this entry point"),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::with_name("gossip_port")
|
||||
.long("gossip-port")
|
||||
.value_name("PORT")
|
||||
.value_name("HOST:PORT")
|
||||
.takes_value(true)
|
||||
.default_value("0")
|
||||
.help("Gossip port number for the node"),
|
||||
)
|
||||
.arg(
|
||||
@@ -98,6 +106,16 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
SubCommand::with_name("stop")
|
||||
.about("Send stop request to a node")
|
||||
.setting(AppSettings::DisableVersion)
|
||||
.arg(
|
||||
Arg::with_name("entrypoint")
|
||||
.short("n")
|
||||
.long("entrypoint")
|
||||
.value_name("HOST:PORT")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.validator(solana_net_utils::is_host_port)
|
||||
.help("Rendezvous with the cluster at this entry point"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("node_pubkey")
|
||||
.index(1)
|
||||
@@ -109,11 +127,13 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if let Some(addr) = matches.value_of("entrypoint") {
|
||||
entrypoint_addr = solana_net_utils::parse_host_port(addr).unwrap_or_else(|e| {
|
||||
eprintln!("failed to parse entrypoint address: {}", e);
|
||||
exit(1);
|
||||
});
|
||||
fn parse_entrypoint(matches: &ArgMatches) -> Option<SocketAddr> {
|
||||
matches.value_of("entrypoint").map(|entrypoint| {
|
||||
solana_net_utils::parse_host_port(entrypoint).unwrap_or_else(|e| {
|
||||
eprintln!("failed to parse entrypoint address: {}", e);
|
||||
exit(1);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
match matches.subcommand() {
|
||||
@@ -132,16 +152,30 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
.value_of("node_pubkey")
|
||||
.map(|pubkey_str| pubkey_str.parse::<Pubkey>().unwrap());
|
||||
|
||||
let gossip_addr = SocketAddr::new(
|
||||
solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
||||
eprintln!("failed to contact {}: {}", entrypoint_addr, err);
|
||||
exit(1);
|
||||
}),
|
||||
value_t_or_exit!(matches, "gossip_port", u16),
|
||||
let mut gossip_addr = solana_net_utils::parse_port_or_addr(
|
||||
matches.value_of("gossip_port"),
|
||||
socketaddr!(
|
||||
[127, 0, 0, 1],
|
||||
solana_net_utils::find_available_port_in_range((0, 1))
|
||||
.expect("unable to find an available gossip port")
|
||||
),
|
||||
);
|
||||
|
||||
let entrypoint_addr = parse_entrypoint(&matches);
|
||||
if let Some(entrypoint_addr) = entrypoint_addr {
|
||||
gossip_addr.set_ip(
|
||||
solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
||||
eprintln!(
|
||||
"Failed to contact cluster entrypoint {}: {}",
|
||||
entrypoint_addr, err
|
||||
);
|
||||
exit(1);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let (nodes, _archivers) = discover(
|
||||
&entrypoint_addr,
|
||||
entrypoint_addr.as_ref(),
|
||||
num_nodes,
|
||||
timeout,
|
||||
pubkey,
|
||||
@@ -182,20 +216,21 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
}
|
||||
}
|
||||
("get-rpc-url", Some(matches)) => {
|
||||
let entrypoint_addr = parse_entrypoint(&matches);
|
||||
let timeout = value_t_or_exit!(matches, "timeout", u64);
|
||||
let (nodes, _archivers) = discover(
|
||||
&entrypoint_addr,
|
||||
entrypoint_addr.as_ref(),
|
||||
Some(1),
|
||||
Some(timeout),
|
||||
None,
|
||||
Some(entrypoint_addr),
|
||||
entrypoint_addr.as_ref(),
|
||||
None,
|
||||
)?;
|
||||
|
||||
let rpc_addrs: Vec<_> = nodes
|
||||
.iter()
|
||||
.filter_map(|contact_info| {
|
||||
if (matches.is_present("all") || contact_info.gossip == entrypoint_addr)
|
||||
if (matches.is_present("all") || Some(contact_info.gossip) == entrypoint_addr)
|
||||
&& ContactInfo::is_valid_address(&contact_info.rpc)
|
||||
{
|
||||
return Some(contact_info.rpc);
|
||||
@@ -214,13 +249,20 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
}
|
||||
}
|
||||
("stop", Some(matches)) => {
|
||||
let entrypoint_addr = parse_entrypoint(&matches);
|
||||
let pubkey = matches
|
||||
.value_of("node_pubkey")
|
||||
.unwrap()
|
||||
.parse::<Pubkey>()
|
||||
.unwrap();
|
||||
let (nodes, _archivers) =
|
||||
discover(&entrypoint_addr, None, None, Some(pubkey), None, None)?;
|
||||
let (nodes, _archivers) = discover(
|
||||
entrypoint_addr.as_ref(),
|
||||
None,
|
||||
None,
|
||||
Some(pubkey),
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
let node = nodes.iter().find(|x| x.id == pubkey).unwrap();
|
||||
|
||||
if !ContactInfo::is_valid_address(&node.rpc) {
|
||||
|
Reference in New Issue
Block a user