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