2018-03-14 17:03:21 -07:00
|
|
|
//! Binary Byzantine agreement protocol from a common coin protocol.
|
2018-05-01 10:12:05 -07:00
|
|
|
|
2018-05-02 03:57:28 -07:00
|
|
|
use proto::AgreementMessage;
|
2018-05-03 02:10:31 -07:00
|
|
|
use std::collections::{BTreeSet, VecDeque};
|
2018-05-02 03:57:28 -07:00
|
|
|
|
2018-05-04 02:19:36 -07:00
|
|
|
#[derive(Default)]
|
2018-05-01 10:12:05 -07:00
|
|
|
pub struct Agreement {
|
2018-05-03 01:05:26 -07:00
|
|
|
input: Option<bool>,
|
2018-05-04 02:19:36 -07:00
|
|
|
_bin_values: BTreeSet<bool>,
|
2018-05-01 10:12:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Agreement {
|
2018-05-02 06:10:26 -07:00
|
|
|
pub fn new() -> Self {
|
2018-05-03 01:05:26 -07:00
|
|
|
Agreement {
|
|
|
|
input: None,
|
2018-05-04 02:19:36 -07:00
|
|
|
_bin_values: BTreeSet::new(),
|
2018-05-03 01:05:26 -07:00
|
|
|
}
|
2018-05-02 06:10:26 -07:00
|
|
|
}
|
|
|
|
|
2018-05-03 02:10:31 -07:00
|
|
|
pub fn set_input(&mut self, input: bool) -> AgreementMessage {
|
2018-05-01 10:12:05 -07:00
|
|
|
self.input = Some(input);
|
2018-05-03 01:05:26 -07:00
|
|
|
// Multicast BVAL
|
2018-05-03 02:10:31 -07:00
|
|
|
AgreementMessage::BVal(input)
|
2018-05-01 10:12:05 -07:00
|
|
|
}
|
2018-05-02 03:57:28 -07:00
|
|
|
|
|
|
|
pub fn has_input(&self) -> bool {
|
|
|
|
self.input.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Receive input from a remote node.
|
2018-05-03 02:10:31 -07:00
|
|
|
pub fn on_input(
|
|
|
|
&self,
|
2018-05-04 02:19:36 -07:00
|
|
|
_message: &AgreementMessage,
|
2018-05-03 02:10:31 -07:00
|
|
|
) -> Result<VecDeque<AgreementMessage>, Error> {
|
2018-05-02 03:57:28 -07:00
|
|
|
Err(Error::NotImplemented)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum Error {
|
2018-05-03 02:10:31 -07:00
|
|
|
NotImplemented,
|
2018-05-01 10:12:05 -07:00
|
|
|
}
|