2019-03-13 20:54:30 -07:00
|
|
|
use clap::{crate_description, crate_name, crate_version, App, Arg};
|
2019-04-12 18:17:34 -07:00
|
|
|
use solana::cluster_info::{Node, FULLNODE_PORT_RANGE};
|
2019-03-08 17:23:07 -08:00
|
|
|
use solana::contact_info::ContactInfo;
|
2018-11-02 08:40:29 -07:00
|
|
|
use solana::replicator::Replicator;
|
2018-12-14 17:42:46 -08:00
|
|
|
use solana::socketaddr;
|
2019-03-04 14:27:06 -08:00
|
|
|
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
|
2018-09-21 15:32:15 -07:00
|
|
|
use std::process::exit;
|
2019-03-06 19:09:37 -08:00
|
|
|
use std::sync::Arc;
|
2018-09-21 15:32:15 -07:00
|
|
|
|
|
|
|
fn main() {
|
2018-12-14 12:36:50 -08:00
|
|
|
solana_logger::setup();
|
2018-09-27 10:48:40 -07:00
|
|
|
|
2019-05-03 11:01:35 -07:00
|
|
|
let matches = App::new(crate_name!())
|
|
|
|
.about(crate_description!())
|
2018-09-21 15:32:15 -07:00
|
|
|
.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)"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2019-05-03 15:00:19 -07:00
|
|
|
Arg::with_name("entrypoint")
|
2018-09-21 15:32:15 -07:00
|
|
|
.short("n")
|
2019-05-03 15:00:19 -07:00
|
|
|
.long("entrypoint")
|
2018-09-21 15:32:15 -07:00
|
|
|
.value_name("HOST:PORT")
|
|
|
|
.takes_value(true)
|
2019-01-02 11:02:15 -08:00
|
|
|
.required(true)
|
2019-05-03 15:00:19 -07:00
|
|
|
.help("Rendezvous with the cluster at this entry point"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2018-09-21 15:32:15 -07:00
|
|
|
Arg::with_name("ledger")
|
|
|
|
.short("l")
|
|
|
|
.long("ledger")
|
|
|
|
.value_name("DIR")
|
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("use DIR as persistent ledger location"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
2019-05-09 13:43:39 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("storage_keypair")
|
|
|
|
.short("s")
|
2019-05-15 15:19:29 -07:00
|
|
|
.long("storage-keypair")
|
|
|
|
.value_name("PATH")
|
2019-05-09 13:43:39 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
|
|
|
.help("File containing the storage account keypair"),
|
|
|
|
)
|
2018-12-07 19:01:28 -08:00
|
|
|
.get_matches();
|
2018-09-21 15:32:15 -07:00
|
|
|
|
2019-01-31 12:44:09 -08:00
|
|
|
let ledger_path = matches.value_of("ledger").unwrap();
|
2018-09-21 15:32:15 -07:00
|
|
|
|
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);
|
2018-09-21 15:32:15 -07:00
|
|
|
exit(1);
|
2019-03-04 14:27:06 -08:00
|
|
|
})
|
2018-09-21 15:32:15 -07:00
|
|
|
} else {
|
2019-03-04 14:27:06 -08:00
|
|
|
Keypair::new()
|
2018-09-21 15:32:15 -07:00
|
|
|
};
|
2019-05-09 13:43:39 -07:00
|
|
|
let storage_keypair = if let Some(storage_keypair) = matches.value_of("storage_keypair") {
|
|
|
|
read_keypair(storage_keypair).unwrap_or_else(|err| {
|
|
|
|
eprintln!("{}: Unable to open keypair file: {}", err, storage_keypair);
|
|
|
|
exit(1);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
Keypair::new()
|
|
|
|
};
|
2018-09-21 15:32:15 -07:00
|
|
|
|
2019-05-03 15:00:19 -07:00
|
|
|
let entrypoint_addr = matches
|
|
|
|
.value_of("entrypoint")
|
|
|
|
.map(|entrypoint| {
|
|
|
|
solana_netutil::parse_host_port(entrypoint).expect("failed to parse entrypoint address")
|
2019-05-03 11:01:35 -07:00
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
2019-03-04 14:27:06 -08:00
|
|
|
let gossip_addr = {
|
|
|
|
let mut addr = socketaddr!([127, 0, 0, 1], 8700);
|
2019-05-03 15:00:19 -07:00
|
|
|
addr.set_ip(solana_netutil::get_public_ip_addr(&entrypoint_addr).unwrap());
|
2019-03-04 14:27:06 -08:00
|
|
|
addr
|
|
|
|
};
|
2019-04-12 18:17:34 -07:00
|
|
|
let node =
|
|
|
|
Node::new_replicator_with_external_ip(&keypair.pubkey(), &gossip_addr, FULLNODE_PORT_RANGE);
|
2018-09-21 15:32:15 -07:00
|
|
|
|
|
|
|
println!(
|
2019-03-04 14:27:06 -08:00
|
|
|
"replicating the data with keypair={:?} gossip_addr={:?}",
|
2018-09-21 15:32:15 -07:00
|
|
|
keypair.pubkey(),
|
2019-03-04 14:27:06 -08:00
|
|
|
gossip_addr
|
2018-09-21 15:32:15 -07:00
|
|
|
);
|
|
|
|
|
2019-05-03 15:00:19 -07:00
|
|
|
let entrypoint_info = ContactInfo::new_gossip_entry_point(&entrypoint_addr);
|
2019-03-27 15:54:09 -07:00
|
|
|
let mut replicator = Replicator::new(
|
|
|
|
ledger_path,
|
|
|
|
node,
|
2019-05-03 15:00:19 -07:00
|
|
|
entrypoint_info,
|
2019-03-27 15:54:09 -07:00
|
|
|
Arc::new(keypair),
|
2019-05-09 13:43:39 -07:00
|
|
|
Arc::new(storage_keypair),
|
2019-03-27 15:54:09 -07:00
|
|
|
)
|
|
|
|
.unwrap();
|
2018-10-02 11:47:51 -07:00
|
|
|
|
2019-03-12 11:37:48 -07:00
|
|
|
replicator.run();
|
|
|
|
replicator.close();
|
2018-09-21 15:32:15 -07:00
|
|
|
}
|