hbbft/src/honey_badger/message.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

2018-07-31 13:27:22 -07:00
use rand::Rand;
2018-10-29 07:36:56 -07:00
use rand_derive::Rand;
use serde_derive::{Deserialize, Serialize};
2018-07-31 13:27:22 -07:00
2018-08-14 06:06:51 -07:00
use subset;
use threshold_decrypt;
2018-07-31 13:27:22 -07:00
/// The content of a `HoneyBadger` message. It should be further annotated with an epoch.
#[derive(Clone, Debug, Deserialize, Rand, Serialize)]
// `threshold_sign::Message` triggers this Clippy lint, but `Box<T>` doesn't implement `Rand`.
#[cfg_attr(feature = "cargo-clippy", allow(large_enum_variant))]
pub enum MessageContent<N: Rand> {
2018-08-14 06:06:51 -07:00
/// A message belonging to the subset algorithm in the given epoch.
Subset(subset::Message<N>),
2018-07-31 13:27:22 -07:00
/// A decrypted share of the output of `proposer_id`.
DecryptionShare {
proposer_id: N,
share: threshold_decrypt::Message,
2018-07-31 13:27:22 -07:00
},
}
impl<N: Rand> MessageContent<N> {
pub fn with_epoch(self, epoch: u64) -> Message<N> {
Message {
2018-07-31 13:27:22 -07:00
epoch,
content: self,
}
}
}
/// A message sent to or received from another node's Honey Badger instance.
#[derive(Clone, Debug, Deserialize, Rand, Serialize)]
pub struct Message<N: Rand> {
pub(super) epoch: u64,
pub(super) content: MessageContent<N>,
2018-07-31 13:27:22 -07:00
}
impl<N: Rand> Message<N> {
/// Returns this message's Honey Badger epoch.
pub fn epoch(&self) -> u64 {
self.epoch
2018-07-31 13:27:22 -07:00
}
}