solana/replicator/src/main.rs

91 lines
2.7 KiB
Rust
Raw Normal View History

use clap::{crate_description, crate_name, crate_version, App, Arg};
use solana::cluster_info::{Node, FULLNODE_PORT_RANGE};
2019-03-08 17:23:07 -08:00
use solana::contact_info::ContactInfo;
use solana::replicator::Replicator;
use solana::socketaddr;
2019-03-04 14:27:06 -08:00
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
use std::process::exit;
use std::sync::Arc;
fn main() {
solana_logger::setup();
let matches = App::new(crate_name!())
.about(crate_description!())
.version(crate_version!())
.arg(
Arg::with_name("identity")
.short("i")
.long("identity")
.value_name("PATH")
.takes_value(true)
2019-03-04 14:27:06 -08:00
.help("File containing an identity (keypair)"),
)
.arg(
Arg::with_name("network")
.short("n")
.long("network")
.value_name("HOST:PORT")
.takes_value(true)
.required(true)
.help("Rendezvous with the network at this gossip entry point"),
)
.arg(
Arg::with_name("ledger")
.short("l")
.long("ledger")
.value_name("DIR")
.takes_value(true)
.required(true)
.help("use DIR as persistent ledger location"),
)
.get_matches();
2019-01-31 12:44:09 -08:00
let ledger_path = matches.value_of("ledger").unwrap();
2019-03-04 14:27:06 -08:00
let keypair = if let Some(identity) = matches.value_of("identity") {
read_keypair(identity).unwrap_or_else(|err| {
eprintln!("{}: Unable to open keypair file: {}", err, identity);
exit(1);
2019-03-04 14:27:06 -08:00
})
} else {
2019-03-04 14:27:06 -08:00
Keypair::new()
};
let network_addr = matches
.value_of("network")
.map(|network| {
solana_netutil::parse_host_port(network).expect("failed to parse network address")
})
.unwrap();
2019-03-04 14:27:06 -08:00
let gossip_addr = {
let mut addr = socketaddr!([127, 0, 0, 1], 8700);
addr.set_ip(solana_netutil::get_public_ip_addr(&network_addr).unwrap());
2019-03-04 14:27:06 -08:00
addr
};
let node =
Node::new_replicator_with_external_ip(&keypair.pubkey(), &gossip_addr, FULLNODE_PORT_RANGE);
println!(
2019-03-04 14:27:06 -08:00
"replicating the data with keypair={:?} gossip_addr={:?}",
keypair.pubkey(),
2019-03-04 14:27:06 -08:00
gossip_addr
);
2019-03-08 17:23:07 -08:00
let leader_info = ContactInfo::new_gossip_entry_point(&network_addr);
let storage_keypair = Arc::new(Keypair::new());
let mut replicator = Replicator::new(
ledger_path,
node,
leader_info,
Arc::new(keypair),
storage_keypair,
None,
)
.unwrap();
replicator.run();
replicator.close();
}