commonware_broadcast/
lib.rs

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