2018-06-13 18:42:30 -07:00
|
|
|
extern crate atty;
|
2018-07-09 18:04:49 -07:00
|
|
|
extern crate clap;
|
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-07-09 18:04:49 -07:00
|
|
|
use clap::{App, Arg};
|
2018-07-11 00:18:48 -07:00
|
|
|
use solana::crdt::{NodeInfo, TestNode};
|
2018-07-05 12:01:40 -07:00
|
|
|
use solana::fullnode::{Config, FullNode, InFile, OutFile};
|
2018-07-03 21:14:08 -07:00
|
|
|
use solana::service::Service;
|
2018-07-05 12:01:40 -07:00
|
|
|
use solana::signature::{KeyPair, KeyPairUtil};
|
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-24 23:18:41 -07:00
|
|
|
//use std::time::Duration;
|
2018-02-28 17:04:35 -08:00
|
|
|
|
2018-07-02 11:23:20 -07:00
|
|
|
fn main() -> () {
|
2018-06-14 15:45:14 -07:00
|
|
|
env_logger::init();
|
2018-07-09 18:04:49 -07:00
|
|
|
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);
|
2018-07-05 12:01:40 -07:00
|
|
|
let mut keypair = KeyPair::new();
|
2018-07-11 00:18:48 -07:00
|
|
|
let mut repl_data = NodeInfo::new_leader_with_pubkey(keypair.pubkey(), &bind_addr);
|
2018-07-09 18:04:49 -07:00
|
|
|
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()) {
|
2018-07-05 12:01:40 -07:00
|
|
|
let parse: serde_json::Result<Config> = serde_json::from_reader(file);
|
|
|
|
if let Ok(data) = parse {
|
|
|
|
keypair = data.keypair();
|
2018-07-10 12:02:51 -07:00
|
|
|
repl_data = data.node_info;
|
2018-05-30 07:17:04 -07:00
|
|
|
} 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-07-09 18:04:49 -07:00
|
|
|
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-10 22:35:58 -07:00
|
|
|
FullNode::new(
|
|
|
|
node,
|
|
|
|
false,
|
|
|
|
InFile::StdIn,
|
|
|
|
Some(keypair),
|
|
|
|
Some(testnet_addr),
|
|
|
|
None,
|
|
|
|
)
|
2018-05-23 13:03:19 -07:00
|
|
|
} else {
|
2018-07-11 00:18:48 -07:00
|
|
|
node.data.leader_id = node.data.id.clone();
|
2018-06-14 22:47:08 -07:00
|
|
|
|
2018-07-09 18:04:49 -07:00
|
|
|
let outfile = if let Some(o) = matches.value_of("output") {
|
|
|
|
OutFile::Path(o.to_string())
|
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-10 22:35:58 -07:00
|
|
|
FullNode::new(node, true, InFile::StdIn, None, None, Some(outfile))
|
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
|
|
|
}
|