use rand::distributions::{Distribution, Standard}; use rand::Rng; use rand_derive::Rand; use serde::{Deserialize, Serialize}; use crate::binary_agreement; use crate::broadcast; /// Message from Subset to remote nodes. #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Message { /// The proposer whose contribution this message is about. pub proposer_id: N, /// The wrapped broadcast or agreement message. pub content: MessageContent, } impl Distribution> for Standard where Standard: Distribution, { fn sample(&self, rng: &mut R) -> Message { Message { proposer_id: rng.gen::(), content: rng.gen::(), } } } /// A message about a particular proposer's contribution. #[derive(Serialize, Deserialize, Clone, Debug, Rand)] pub enum MessageContent { /// A wrapped message for the broadcast instance, to deliver the proposed value. Broadcast(broadcast::Message), /// A wrapped message for the agreement instance, to decide on whether to accept the value. Agreement(binary_agreement::Message), } impl MessageContent { /// Returns a `Message` with this content and the specified proposer ID. pub(super) fn with(self, proposer_id: N) -> Message { Message { proposer_id, content: self, } } }