Move binaries from src/bin into their own crate

This commit is contained in:
Michael Vines
2018-12-13 21:11:09 -08:00
parent 092edabd2d
commit 0fe6d61036
19 changed files with 234 additions and 40 deletions

19
replicator/Cargo.toml Normal file
View File

@@ -0,0 +1,19 @@
[package]
authors = ["Solana Maintainers <maintainers@solana.com>"]
edition = "2018"
name = "solana-replicator"
version = "0.11.0"
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
[dependencies]
clap = "2.32.0"
dirs = "1.0.2"
serde_json = "1.0.10"
solana = { path = "..", version = "0.11.0" }
solana-sdk = { path = "../sdk", version = "0.11.0" }
[features]
chacha = ["solana/chacha"]
cuda = ["solana/cuda"]

88
replicator/src/main.rs Normal file
View File

@@ -0,0 +1,88 @@
#[macro_use]
extern crate clap;
use serde_json;
#[macro_use]
extern crate solana;
use clap::{App, Arg};
use solana::cluster_info::{Node, NodeInfo};
use solana::fullnode::Config;
use solana::logger;
use solana::replicator::Replicator;
use solana_sdk::signature::{Keypair, KeypairUtil};
use std::fs::File;
use std::net::{Ipv4Addr, SocketAddr};
use std::process::exit;
fn main() {
logger::setup();
let matches = App::new("replicator")
.version(crate_version!())
.arg(
Arg::with_name("identity")
.short("i")
.long("identity")
.value_name("PATH")
.takes_value(true)
.help("Run with the identity found in FILE"),
)
.arg(
Arg::with_name("network")
.short("n")
.long("network")
.value_name("HOST:PORT")
.takes_value(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();
let ledger_path = matches.value_of("ledger");
let (keypair, gossip) = if let Some(i) = matches.value_of("identity") {
let path = i.to_string();
if let Ok(file) = File::open(path.clone()) {
let parse: serde_json::Result<Config> = serde_json::from_reader(file);
if let Ok(data) = parse {
(data.keypair(), data.node_info.gossip)
} else {
eprintln!("failed to parse {}", path);
exit(1);
}
} else {
eprintln!("failed to read {}", path);
exit(1);
}
} else {
(Keypair::new(), socketaddr!([127, 0, 0, 1], 8700))
};
let node = Node::new_with_external_ip(keypair.pubkey(), &gossip);
println!(
"replicating the data with keypair: {:?} gossip:{:?}",
keypair.pubkey(),
gossip
);
let network_addr = matches
.value_of("network")
.map(|network| network.parse().expect("failed to parse network address"))
.unwrap();
let leader_info = NodeInfo::new_entry_point(&network_addr);
let replicator = Replicator::new(ledger_path, node, &leader_info, &keypair).unwrap();
replicator.join();
}