2016-09-30 05:44:50 -07:00
|
|
|
//! Parity bitcoin client.
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
2016-10-19 05:17:18 -07:00
|
|
|
extern crate env_logger;
|
2016-09-30 05:44:50 -07:00
|
|
|
|
|
|
|
extern crate keys;
|
|
|
|
extern crate script;
|
2016-10-03 07:29:07 -07:00
|
|
|
extern crate message;
|
2016-09-30 05:59:16 -07:00
|
|
|
extern crate p2p;
|
2016-10-24 07:38:33 -07:00
|
|
|
extern crate sync;
|
2016-09-30 05:59:16 -07:00
|
|
|
|
2016-10-02 18:01:46 -07:00
|
|
|
mod config;
|
2016-09-30 05:44:50 -07:00
|
|
|
|
2016-10-03 06:44:35 -07:00
|
|
|
use std::net::SocketAddr;
|
2016-10-24 01:14:01 -07:00
|
|
|
use p2p::{P2P, event_loop, forever, NetConfig};
|
2016-10-24 07:38:33 -07:00
|
|
|
use sync::local_node::LocalNode;
|
|
|
|
use sync::inbound_connection_factory::InboundConnectionFactory;
|
2016-10-03 06:44:35 -07:00
|
|
|
|
2016-09-30 05:44:50 -07:00
|
|
|
fn main() {
|
2016-10-19 05:17:18 -07:00
|
|
|
env_logger::init().unwrap();
|
2016-10-02 18:01:46 -07:00
|
|
|
match run() {
|
|
|
|
Err(err) => println!("{}", err),
|
|
|
|
Ok(_) => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run() -> Result<(), String> {
|
2016-09-30 05:44:50 -07:00
|
|
|
let yaml = load_yaml!("cli.yml");
|
|
|
|
let matches = clap::App::from_yaml(yaml).get_matches();
|
2016-10-02 18:01:46 -07:00
|
|
|
let cfg = try!(config::parse(&matches));
|
2016-09-30 07:25:28 -07:00
|
|
|
|
2016-10-03 06:44:35 -07:00
|
|
|
let mut el = event_loop();
|
2016-10-02 18:01:46 -07:00
|
|
|
|
2016-10-04 03:33:23 -07:00
|
|
|
let p2p_cfg = p2p::Config {
|
2016-10-17 16:44:52 -07:00
|
|
|
threads: 4,
|
|
|
|
protocol_minimum: 70001,
|
|
|
|
protocol_maximum: 70017,
|
|
|
|
inbound_connections: 10,
|
|
|
|
outbound_connections: 10,
|
2016-10-24 01:14:01 -07:00
|
|
|
connection: NetConfig {
|
2016-10-04 03:33:23 -07:00
|
|
|
magic: cfg.magic,
|
|
|
|
local_address: SocketAddr::new("127.0.0.1".parse().unwrap(), cfg.port),
|
|
|
|
services: Default::default(),
|
|
|
|
user_agent: "pbtc".into(),
|
|
|
|
start_height: 0,
|
|
|
|
relay: false,
|
|
|
|
},
|
2016-10-17 16:44:52 -07:00
|
|
|
peers: cfg.connect.map_or_else(|| vec![], |x| vec![x]),
|
|
|
|
seeds: cfg.seednode.map_or_else(|| vec![], |x| vec![x]),
|
2016-10-03 06:44:35 -07:00
|
|
|
};
|
|
|
|
|
2016-10-24 07:38:33 -07:00
|
|
|
let local_sync_node = LocalNode::new();
|
|
|
|
let local_sync_factory = InboundConnectionFactory::with_local_node(local_sync_node.clone());
|
|
|
|
|
|
|
|
let p2p = P2P::new(p2p_cfg, local_sync_factory, el.handle());
|
2016-10-13 00:17:29 -07:00
|
|
|
try!(p2p.run().map_err(|_| "Failed to start p2p module"));
|
|
|
|
el.run(forever()).unwrap();
|
2016-10-02 18:01:46 -07:00
|
|
|
Ok(())
|
2016-09-30 05:44:50 -07:00
|
|
|
}
|
2016-10-02 18:01:46 -07:00
|
|
|
|