forked from nbro/multi-paxos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_acceptor.rs
executable file
·50 lines (41 loc) · 1.44 KB
/
start_acceptor.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! A script used to start one acceptor, which will infinitely listen to incoming messages (from
//! proposers).
//!
//! You can run this example as follows
//! RUST_LOG=multi_paxos=info cargo run --example start_acceptor -- <acceptor_uid> Config
//! where <acceptor_uid> is a non-negative number which should be unique (among all nodes).
extern crate env_logger;
#[macro_use]
extern crate log;
extern crate multi_paxos;
extern crate serde;
use std::env;
use multi_paxos::configurations::get_config;
use multi_paxos::multi_paxos::Acceptor;
use multi_paxos::multi_paxos::Runnable;
fn main() {
env_logger::init();
let args: Vec<String> = env::args().collect();
info!("{:?}", args);
match args.len() {
3 => {
let uid = &args[1];
let uid: usize = match uid.parse() {
Ok(n) => n,
Err(_) => {
eprintln!("Error: second argument not an usize");
return;
}
};
let config_file_name = &args[2];
let config = get_config(config_file_name);
let (_, proposers_address) = config["proposers"];
let (_, acceptors_address) = config["acceptors"];
let mut acceptor = Acceptor::<usize>::new(uid, acceptors_address, proposers_address);
acceptor.run();
}
_ => {
panic!("Expected 2 arguments (excluding file name)");
}
}
}