commonware_broadcast/lib.rs
1//! Disseminate data over a wide-area network.
2
3use commonware_codec::{Codec, Config};
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<Cfg: Config>: Clone + Send + 'static {
11 /// Message is the type of data that can be broadcasted.
12 ///
13 /// It must implement the Codec trait so that it can be:
14 /// - serialized upon broadcast
15 /// - deserialized upon reception
16 type Message: Codec<Cfg> + Clone + Send + 'static;
17
18 /// Response is the type of data that is returned once the message is broadcasted.
19 ///
20 /// It may also indicate the success or failure of the broadcast attempt.
21 type Response: Clone + Send + 'static;
22
23 /// Attempt to broadcast a message to the network.
24 fn broadcast(
25 &mut self,
26 message: Self::Message,
27 ) -> impl Future<Output = oneshot::Receiver<Self::Response>> + Send;
28}