lighthouse/src/main.rs

68 lines
2.0 KiB
Rust
Raw Normal View History

2018-07-28 00:02:45 +00:00
#[macro_use]
extern crate slog;
extern crate slog_term;
extern crate slog_async;
extern crate clap;
extern crate libp2p_peerstore;
pub mod p2p;
pub mod pubkeystore;
pub mod state;
2018-08-06 23:13:24 +00:00
pub mod sync;
2018-07-28 00:02:45 +00:00
pub mod utils;
2018-08-06 23:13:24 +00:00
pub mod config;
2018-07-28 00:02:45 +00:00
use std::path::PathBuf;
2018-07-28 00:02:45 +00:00
use slog::Drain;
use clap::{ Arg, App };
2018-08-06 23:13:24 +00:00
use config::LighthouseConfig;
2018-08-04 03:45:02 +00:00
use p2p::service::NetworkService;
2018-07-29 05:06:42 +00:00
use p2p::state::NetworkState;
2018-08-06 23:13:24 +00:00
use sync::sync_start;
2018-07-28 00:02:45 +00:00
fn main() {
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();
let log = slog::Logger::root(drain, o!());
let matches = App::new("Lighthouse")
.version("0.0.1")
.author("Sigma Prime <paul@sigmaprime.io>")
2018-07-28 00:02:45 +00:00
.about("Eth 2.0 Client")
.arg(Arg::with_name("datadir")
.long("datadir")
.value_name("DIR")
.help("Data directory for keys and databases.")
.takes_value(true))
.arg(Arg::with_name("port")
.long("port")
.value_name("PORT")
.help("Network listen port for p2p connections.")
.takes_value(true))
2018-07-28 00:02:45 +00:00
.get_matches();
2018-08-06 23:13:24 +00:00
let mut config = LighthouseConfig::default();
// Custom datadir
if let Some(dir) = matches.value_of("datadir") {
config.data_dir = PathBuf::from(dir.to_string());
}
2018-08-06 23:13:24 +00:00
// Custom p2p listen port
if let Some(port) = matches.value_of("port") {
2018-08-06 23:13:24 +00:00
config.p2p_listen_port = port.to_string();
}
info!(log, ""; "data_dir" => &config.data_dir.to_str());
2018-07-28 00:02:45 +00:00
if let Some(_) = matches.subcommand_matches("generate-keys") {
2018-07-29 05:06:42 +00:00
// keys::generate_keys(&log).expect("Failed to generate keys");
2018-07-28 00:02:45 +00:00
} else {
let mut state = NetworkState::new(config, &log).expect("setup failed");
2018-08-06 23:13:24 +00:00
let (service, net_rx) = NetworkService::new(state, log.new(o!()));
sync_start(service, net_rx, log.new(o!()));
2018-07-28 00:02:45 +00:00
}
info!(log, "Exiting.");
}