commonware_broadcast/
lib.rs

1//! Disseminate data over a wide-area network.
2
3use commonware_codec::Codec;
4use futures::channel::oneshot;
5use std::future::Future;
6
7pub mod buffered;
8
9/// Broadcaster is the interface responsible for attempting replication of messages across a network.
10pub trait Broadcaster: Clone + Send + 'static {
11    /// The type of recipients that can receive messages.
12    type Recipients;
13
14    /// Message is the type of data that can be broadcasted.
15    ///
16    /// It must implement the Codec trait so that it can be:
17    /// - serialized upon broadcast
18    /// - deserialized upon reception
19    type Message: Codec + Clone + Send + 'static;
20
21    /// The type of data that is returned once the message is broadcasted.
22    ///
23    /// It may also indicate the success or failure of the broadcast attempt.
24    type Response: Clone + Send + 'static;
25
26    /// Attempt to broadcast a message to the associated recipients.
27    fn broadcast(
28        &mut self,
29        recipients: Self::Recipients,
30        message: Self::Message,
31    ) -> impl Future<Output = oneshot::Receiver<Self::Response>> + Send;
32}