Skip to content

Commit

Permalink
clean up fullnode cmdline
Browse files Browse the repository at this point in the history
 * fix documentation, other opt parameters
 * add support for a named output file, remove hardcoded "leader.log"
 * resurrect stdout as the default output
  • Loading branch information
rob-solana committed Jun 15, 2018
1 parent d30670e commit 7fe1fd2
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/bin/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use solana::server::Server;
use solana::transaction::Instruction;
use std::env;
use std::fs::File;
use std::io::{stdin, Read};
use std::io::{stdin, stdout, Read, Write};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use std::process::exit;
use std::sync::atomic::AtomicBool;
Expand All @@ -35,14 +35,16 @@ fn print_usage(program: &str, opts: Options) {
fn main() {
env_logger::init();
let mut opts = Options::new();
opts.optopt("l", "", "load", "load my identity to path.json");
opts.optflag("h", "help", "print help");
opts.optopt("l", "", "run with the identity found in FILE", "FILE");
opts.optopt("v", "", "validate; find leader's identity in FILE", "FILE");
opts.optopt(
"v",
"o",
"",
"validator",
"run as replicate with path to leader.json",
"output log to FILE, defaults to stdout (ignored by validators)",
"FILE",
);

let args: Vec<String> = env::args().collect();
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Expand Down Expand Up @@ -137,7 +139,16 @@ fn main() {
} else {
eprintln!("starting leader... {}", repl_data.requests_addr);
repl_data.current_leader_id = repl_data.id.clone();
let file = File::create("leader.log").expect("leader.log create");

let outfile: Box<Write + Send + 'static> = if matches.opt_present("o") {
let path = matches.opt_str("o").unwrap();
Box::new(
File::create(&path).expect(&format!("unable to open output file \"{}\"", path)),
)
} else {
Box::new(stdout())
};

let server = Server::new_leader(
bank,
//Some(Duration::from_millis(1000)),
Expand All @@ -149,7 +160,7 @@ fn main() {
UdpSocket::bind("0.0.0.0:0").unwrap(),
UdpSocket::bind(repl_data.gossip_addr).unwrap(),
exit.clone(),
file,
outfile,
);
server.thread_hdls
};
Expand Down

0 comments on commit 7fe1fd2

Please sign in to comment.