2018-06-13 18:42:30 -07:00
|
|
|
extern crate atty;
|
2018-03-26 21:07:11 -07:00
|
|
|
extern crate env_logger;
|
2018-04-09 11:28:54 -07:00
|
|
|
extern crate getopts;
|
2018-06-18 15:49:41 -07:00
|
|
|
extern crate log;
|
2018-03-03 23:13:40 -08:00
|
|
|
extern crate serde_json;
|
2018-03-27 15:24:05 -07:00
|
|
|
extern crate solana;
|
2018-02-28 17:04:35 -08:00
|
|
|
|
2018-06-13 15:07:36 -07:00
|
|
|
use atty::{is, Stream};
|
2018-06-13 18:42:30 -07:00
|
|
|
use getopts::Options;
|
2018-07-02 11:20:35 -07:00
|
|
|
use solana::crdt::{ReplicatedData, TestNode};
|
2018-07-03 10:20:02 -07:00
|
|
|
use solana::fullnode::{FullNode, InFile, OutFile};
|
2018-07-03 21:14:08 -07:00
|
|
|
use solana::service::Service;
|
2018-04-11 19:24:14 -07:00
|
|
|
use std::env;
|
2018-05-23 13:03:19 -07:00
|
|
|
use std::fs::File;
|
2018-07-02 11:20:35 -07:00
|
|
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
2018-04-19 07:06:19 -07:00
|
|
|
use std::process::exit;
|
2018-05-11 12:06:05 -07:00
|
|
|
use std::sync::atomic::AtomicBool;
|
2018-07-02 14:46:23 -07:00
|
|
|
use std::sync::Arc;
|
2018-05-24 23:18:41 -07:00
|
|
|
//use std::time::Duration;
|
2018-02-28 17:04:35 -08:00
|
|
|
|
2018-04-19 10:16:20 -07:00
|
|
|
fn print_usage(program: &str, opts: Options) {
|
|
|
|
let mut brief = format!("Usage: cat <transaction.log> | {} [options]\n\n", program);
|
|
|
|
brief += " Run a Solana node to handle transactions and\n";
|
|
|
|
brief += " write a new transaction log to stdout.\n";
|
|
|
|
brief += " Takes existing transaction log from stdin.";
|
|
|
|
|
|
|
|
print!("{}", opts.usage(&brief));
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:23:20 -07:00
|
|
|
fn main() -> () {
|
2018-06-14 15:45:14 -07:00
|
|
|
env_logger::init();
|
2018-04-09 11:28:54 -07:00
|
|
|
let mut opts = Options::new();
|
2018-04-19 10:16:20 -07:00
|
|
|
opts.optflag("h", "help", "print help");
|
2018-06-14 22:47:08 -07:00
|
|
|
opts.optopt("l", "", "run with the identity found in FILE", "FILE");
|
2018-06-23 16:08:53 -07:00
|
|
|
opts.optopt(
|
|
|
|
"t",
|
|
|
|
"",
|
2018-06-23 16:44:56 -07:00
|
|
|
"testnet; connect to the network at this gossip entry point",
|
2018-06-23 16:43:26 -07:00
|
|
|
"HOST:PORT",
|
2018-06-23 16:08:53 -07:00
|
|
|
);
|
2018-05-23 13:03:19 -07:00
|
|
|
opts.optopt(
|
2018-06-14 22:47:08 -07:00
|
|
|
"o",
|
2018-05-23 13:03:19 -07:00
|
|
|
"",
|
2018-06-14 22:47:08 -07:00
|
|
|
"output log to FILE, defaults to stdout (ignored by validators)",
|
|
|
|
"FILE",
|
2018-05-23 13:03:19 -07:00
|
|
|
);
|
2018-06-14 22:47:08 -07:00
|
|
|
|
2018-04-09 11:28:54 -07:00
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
let matches = match opts.parse(&args[1..]) {
|
|
|
|
Ok(m) => m,
|
2018-04-19 07:06:19 -07:00
|
|
|
Err(e) => {
|
|
|
|
eprintln!("{}", e);
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-04-09 11:28:54 -07:00
|
|
|
};
|
2018-04-19 10:16:20 -07:00
|
|
|
if matches.opt_present("h") {
|
|
|
|
let program = args[0].clone();
|
|
|
|
print_usage(&program, opts);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-13 15:07:36 -07:00
|
|
|
if is(Stream::Stdin) {
|
2018-04-21 06:12:57 -07:00
|
|
|
eprintln!("nothing found on stdin, expected a log file");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:06:04 -07:00
|
|
|
let bind_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8000);
|
2018-05-31 14:11:16 -07:00
|
|
|
let mut repl_data = ReplicatedData::new_leader(&bind_addr);
|
2018-05-24 23:18:41 -07:00
|
|
|
if matches.opt_present("l") {
|
|
|
|
let path = matches.opt_str("l").unwrap();
|
2018-05-30 07:17:04 -07:00
|
|
|
if let Ok(file) = File::open(path.clone()) {
|
|
|
|
if let Ok(data) = serde_json::from_reader(file) {
|
|
|
|
repl_data = data;
|
|
|
|
} else {
|
2018-06-16 09:35:30 -07:00
|
|
|
eprintln!("failed to parse {}", path);
|
|
|
|
exit(1);
|
2018-05-30 07:17:04 -07:00
|
|
|
}
|
2018-06-15 15:29:43 -07:00
|
|
|
} else {
|
2018-06-16 09:35:30 -07:00
|
|
|
eprintln!("failed to read {}", path);
|
|
|
|
exit(1);
|
2018-05-24 23:18:41 -07:00
|
|
|
}
|
|
|
|
}
|
2018-07-02 14:46:23 -07:00
|
|
|
let mut node = TestNode::new_with_bind_addr(repl_data, bind_addr);
|
2018-06-16 09:35:30 -07:00
|
|
|
let exit = Arc::new(AtomicBool::new(false));
|
2018-07-02 15:24:40 -07:00
|
|
|
let fullnode = if matches.opt_present("t") {
|
2018-06-23 17:01:38 -07:00
|
|
|
let testnet_address_string = matches.opt_str("t").unwrap();
|
|
|
|
let testnet_addr = testnet_address_string.parse().unwrap();
|
2018-07-03 10:20:02 -07:00
|
|
|
FullNode::new(node, false, InFile::StdIn, Some(testnet_addr), None, exit)
|
2018-05-23 13:03:19 -07:00
|
|
|
} else {
|
2018-07-02 14:46:23 -07:00
|
|
|
node.data.current_leader_id = node.data.id.clone();
|
2018-06-14 22:47:08 -07:00
|
|
|
|
2018-06-28 14:51:53 -07:00
|
|
|
let outfile = if let Some(f) = matches.opt_str("o") {
|
2018-07-03 10:20:02 -07:00
|
|
|
OutFile::Path(f)
|
2018-06-28 14:51:53 -07:00
|
|
|
} else {
|
2018-07-03 10:20:02 -07:00
|
|
|
OutFile::StdOut
|
2018-06-28 14:51:53 -07:00
|
|
|
};
|
2018-07-03 10:20:02 -07:00
|
|
|
FullNode::new(node, true, InFile::StdIn, None, Some(outfile), exit)
|
2018-05-23 13:03:19 -07:00
|
|
|
};
|
2018-07-03 21:14:08 -07:00
|
|
|
fullnode.join().expect("join");
|
2018-05-23 13:03:19 -07:00
|
|
|
}
|