solana/src/bin/fullnode.rs

85 lines
2.7 KiB
Rust
Raw Normal View History

2018-06-13 18:42:30 -07:00
extern crate atty;
extern crate clap;
2018-03-26 21:07:11 -07:00
extern crate env_logger;
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};
use clap::{App, Arg};
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};
use solana::service::Service;
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;
//use std::time::Duration;
2018-02-28 17:04:35 -08:00
2018-07-02 11:23:20 -07:00
fn main() -> () {
env_logger::init();
let matches = App::new("fullnode")
.arg(
Arg::with_name("identity")
.short("l")
.long("local")
.value_name("FILE")
.takes_value(true)
.help("run with the identity found in FILE"),
)
.arg(
Arg::with_name("testnet")
.short("t")
.long("testnet")
.value_name("HOST:PORT")
.takes_value(true)
.help("testnet; connect to the network at this gossip entry point"),
)
.arg(
Arg::with_name("output")
.short("o")
.long("output")
.value_name("FILE")
.takes_value(true)
.help("output log to FILE, defaults to stdout (ignored by validators)"),
)
.get_matches();
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);
let mut repl_data = ReplicatedData::new_leader(&bind_addr);
if let Some(l) = matches.value_of("identity") {
let path = l.to_string();
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 {
eprintln!("failed to parse {}", path);
exit(1);
2018-05-30 07:17:04 -07:00
}
2018-06-15 15:29:43 -07:00
} else {
eprintln!("failed to read {}", path);
exit(1);
}
}
2018-07-02 14:46:23 -07:00
let mut node = TestNode::new_with_bind_addr(repl_data, bind_addr);
let fullnode = if let Some(t) = matches.value_of("testnet") {
let testnet_address_string = t.to_string();
2018-06-23 17:01:38 -07:00
let testnet_addr = testnet_address_string.parse().unwrap();
2018-07-09 13:53:18 -07:00
FullNode::new(node, false, InFile::StdIn, Some(testnet_addr), None)
} else {
2018-07-02 14:46:23 -07:00
node.data.current_leader_id = node.data.id.clone();
let outfile = if let Some(o) = matches.value_of("output") {
OutFile::Path(o.to_string())
} else {
2018-07-03 10:20:02 -07:00
OutFile::StdOut
};
2018-07-09 13:53:18 -07:00
FullNode::new(node, true, InFile::StdIn, None, Some(outfile))
};
fullnode.join().expect("join");
}