Skip to content

Commit

Permalink
refactor gossip_addr out from spy and rpc methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcusack committed Jun 17, 2024
1 parent 5417d9e commit 6e1171f
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions gossip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,8 @@ fn process_spy(matches: &ArgMatches, socket_addr_space: SocketAddrSpace) -> std:
let pubkeys = pubkeys_of(matches, "node_pubkey");
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 gossip_addr = get_gossip_address(matches, entrypoint_addr);

let discover_timeout = Duration::from_secs(timeout.unwrap_or(u64::MAX));
let (_all_peers, validators) = discover(
Expand Down Expand Up @@ -285,22 +272,10 @@ fn process_rpc_url(
) -> 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 entrypoint_addr = parse_entrypoint(matches);
let gossip_addr = get_gossip_address(matches, entrypoint_addr);

let (_all_peers, validators) = discover(
None, // keypair
Expand Down Expand Up @@ -342,6 +317,20 @@ fn process_rpc_url(
Ok(())
}

fn get_gossip_address(matches: &ArgMatches, entrypoint_addr: Option<SocketAddr>) -> SocketAddr {
let gossip_host = parse_gossip_host(matches, entrypoint_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")
}),
)
}

fn main() -> Result<(), Box<dyn error::Error>> {
solana_logger::setup_with_default_filter();

Expand Down

0 comments on commit 6e1171f

Please sign in to comment.