Skip to content

Commit

Permalink
send actual gossip ip:port when running solana-gossip rpc-url
Browse files Browse the repository at this point in the history
a
  • Loading branch information
gregcusack committed Jun 15, 2024
1 parent 5241bf0 commit 54b3d1f
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions gossip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ fn parse_matches() -> ArgMatches<'static> {
.value_name("HOST")
.takes_value(true)
.validator(solana_net_utils::is_host)
.help("Gossip DNS name or IP address for the node to advertise in gossip \
[default: ask --entrypoint, or 127.0.0.1 when --entrypoint is not provided]");

.help(
"Gossip DNS name or IP address for the node to advertise in gossip \
[default: ask --entrypoint, or 127.0.0.1 when --entrypoint is not provided]",
);

App::new(crate_name!())
.about(crate_description!())
Expand Down Expand Up @@ -215,7 +216,7 @@ fn process_spy_results(
}
}

fn process_spy(matches: &ArgMatches, socket_addr_space: SocketAddrSpace, entrypoint_addr: Option<SocketAddr>, gossip_addr: &SocketAddr) -> std::io::Result<()> {
fn process_spy(matches: &ArgMatches, socket_addr_space: SocketAddrSpace) -> std::io::Result<()> {
let num_nodes_exactly = matches
.value_of("num_nodes_exactly")
.map(|num| num.to_string().parse().unwrap());
Expand All @@ -230,6 +231,21 @@ fn process_spy(matches: &ArgMatches, socket_addr_space: SocketAddrSpace, entrypo
let shred_version = value_t_or_exit!(matches, "shred_version", u16);
let identity_keypair = keypair_of(matches, "identity");

let entrypoint_addr = parse_entrypoint(matches);

let gossip_host = parse_gossip_host(matches, entrypoint_addr);

let gossip_addr = SocketAddr::new(
gossip_host,
value_t!(matches, "gossip_port", u16).unwrap_or_else(|_| {
solana_net_utils::find_available_port_in_range(
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
(0, 1),
)
.expect("unable to find an available gossip port")
}),
);

let discover_timeout = Duration::from_secs(timeout.unwrap_or(u64::MAX));
let (_all_peers, validators) = discover(
identity_keypair,
Expand All @@ -238,7 +254,7 @@ fn process_spy(matches: &ArgMatches, socket_addr_space: SocketAddrSpace, entrypo
discover_timeout,
pubkeys.as_deref(), // find_nodes_by_pubkey
None, // find_node_by_gossip_addr
Some(gossip_addr), // my_gossip_addr
Some(&gossip_addr), // my_gossip_addr
shred_version,
socket_addr_space,
)?;
Expand Down Expand Up @@ -266,22 +282,34 @@ fn parse_entrypoint(matches: &ArgMatches) -> Option<SocketAddr> {
fn process_rpc_url(
matches: &ArgMatches,
socket_addr_space: SocketAddrSpace,
entrypoint_addr: Option<SocketAddr>,
gossip_addr: &SocketAddr,
) -> std::io::Result<()> {
let any = matches.is_present("any");
let all = matches.is_present("all");
let entrypoint_addr = parse_entrypoint(matches);
let timeout = value_t_or_exit!(matches, "timeout", u64);
let shred_version = value_t_or_exit!(matches, "shred_version", u16);

let gossip_host = parse_gossip_host(matches, entrypoint_addr);

let gossip_addr = SocketAddr::new(
gossip_host,
value_t!(matches, "gossip_port", u16).unwrap_or_else(|_| {
solana_net_utils::find_available_port_in_range(
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
(0, 1),
)
.expect("unable to find an available gossip port")
}),
);

let (_all_peers, validators) = discover(
None, // keypair
entrypoint_addr.as_ref(),
Some(1), // num_nodes
Duration::from_secs(timeout),
None, // find_nodes_by_pubkey
entrypoint_addr.as_ref(), // find_node_by_gossip_addr
Some(gossip_addr), // my_gossip_addr
Some(&gossip_addr), // my_gossip_addr
shred_version,
socket_addr_space,
)?;
Expand Down Expand Up @@ -319,28 +347,12 @@ fn main() -> Result<(), Box<dyn error::Error>> {

let matches = parse_matches();
let socket_addr_space = SocketAddrSpace::new(matches.is_present("allow_private_addr"));

let entrypoint_addr = parse_entrypoint(&matches);
let gossip_host = parse_gossip_host(&matches, entrypoint_addr);
let gossip_addr = SocketAddr::new(
gossip_host,
value_t!(matches, "gossip_port", u16).unwrap_or_else(|_| {
solana_net_utils::find_available_port_in_range(
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
(0, 1),
)
.expect("unable to find an available gossip port")
}),
);

println!("entrypoint, gossip host, gossip addr: {:?}, {:?}, {:?}", entrypoint_addr, gossip_host, gosisp_addr);

match matches.subcommand() {
("spy", Some(matches)) => {
process_spy(matches, socket_addr_space, entrypoint_addr, &gossip_addr)?;
process_spy(matches, socket_addr_space)?;
}
("rpc-url", Some(matches)) => {
process_rpc_url(matches, socket_addr_space, entrypoint_addr, &gossip_addr,)?;
process_rpc_url(matches, socket_addr_space)?;
}
_ => unreachable!(),
}
Expand Down

0 comments on commit 54b3d1f

Please sign in to comment.