2018-03-27 13:59:38 -07:00
|
|
|
//! Example of a consensus node that uses the `hbbft::node::Node` struct for
|
|
|
|
//! running the distributed consensus state machine.
|
2018-05-05 06:39:32 -07:00
|
|
|
extern crate crossbeam;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate crossbeam_channel;
|
2018-03-27 13:59:38 -07:00
|
|
|
extern crate docopt;
|
2018-05-08 07:20:32 -07:00
|
|
|
extern crate env_logger;
|
2018-03-27 13:59:38 -07:00
|
|
|
extern crate hbbft;
|
2018-05-05 06:39:32 -07:00
|
|
|
#[macro_use]
|
2018-04-30 08:55:51 -07:00
|
|
|
extern crate log;
|
2018-06-13 02:47:33 -07:00
|
|
|
extern crate pairing;
|
2018-05-10 08:50:07 -07:00
|
|
|
extern crate protobuf;
|
2018-06-13 02:47:33 -07:00
|
|
|
extern crate rand;
|
2018-03-27 13:59:38 -07:00
|
|
|
|
2018-05-05 06:39:32 -07:00
|
|
|
mod network;
|
|
|
|
|
2018-03-27 13:59:38 -07:00
|
|
|
use docopt::Docopt;
|
2018-05-05 06:39:32 -07:00
|
|
|
use network::node::Node;
|
2018-04-01 14:29:12 -07:00
|
|
|
use std::collections::HashSet;
|
2018-03-27 13:59:38 -07:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
use std::vec::Vec;
|
|
|
|
|
2018-04-29 06:27:40 -07:00
|
|
|
const VERSION: &str = "0.1.0";
|
|
|
|
const USAGE: &str = "
|
2018-03-27 13:59:38 -07:00
|
|
|
Consensus node example
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
consensus-node --bind-address=<host:port> [--value=VALUE] [--remote-address=<host:port>]...
|
|
|
|
consensus-node (--help | -h)
|
|
|
|
consensus-node --version
|
|
|
|
";
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Args {
|
|
|
|
bind_address: SocketAddr,
|
2018-04-01 14:29:12 -07:00
|
|
|
remote_addresses: HashSet<SocketAddr>,
|
2018-03-27 13:59:38 -07:00
|
|
|
value: Option<Vec<u8>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_args() -> Args {
|
|
|
|
let args = Docopt::new(USAGE)
|
|
|
|
.unwrap_or_else(|e| e.exit())
|
|
|
|
.version(Some(VERSION.to_owned()))
|
|
|
|
.parse()
|
|
|
|
.unwrap_or_else(|e| e.exit());
|
|
|
|
Args {
|
|
|
|
value: if args.get_count("--value") > 0 {
|
|
|
|
Some(args.get_str("--value").as_bytes().to_vec())
|
2018-04-30 08:55:51 -07:00
|
|
|
} else {
|
2018-03-27 13:59:38 -07:00
|
|
|
None
|
|
|
|
},
|
|
|
|
bind_address: args.get_str("--bind-address").parse().unwrap(),
|
2018-05-21 02:01:49 -07:00
|
|
|
remote_addresses: args
|
|
|
|
.get_vec("--remote-address")
|
2018-03-27 13:59:38 -07:00
|
|
|
.iter()
|
|
|
|
.map(|s| s.parse().unwrap())
|
2018-04-30 08:55:51 -07:00
|
|
|
.collect(),
|
2018-03-27 13:59:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2018-05-08 07:20:32 -07:00
|
|
|
env_logger::init();
|
2018-03-27 13:59:38 -07:00
|
|
|
let args: Args = parse_args();
|
|
|
|
println!("{:?}", args);
|
|
|
|
let node = Node::new(args.bind_address, args.remote_addresses, args.value);
|
2018-04-04 04:18:57 -07:00
|
|
|
node.run().expect("Node failed");
|
2018-03-27 13:59:38 -07:00
|
|
|
}
|