commonware_collector/
lib.rs1#![doc(
9 html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg",
10 html_favicon_url = "https://commonware.xyz/favicon.ico"
11)]
12
13use commonware_codec::Codec;
14use commonware_cryptography::{Committable, Digestible, PublicKey};
15use commonware_p2p::Recipients;
16use futures::channel::oneshot;
17use std::future::Future;
18use thiserror::Error;
19
20pub mod p2p;
21
22#[derive(Error, Debug)]
24pub enum Error {
25 #[error("send failed: {0}")]
26 SendFailed(anyhow::Error),
27 #[error("canceled")]
28 Canceled,
29}
30
31pub trait Originator: Clone + Send + 'static {
33 type PublicKey: PublicKey;
35
36 type Request: Committable + Digestible + Codec;
38
39 fn send(
42 &mut self,
43 recipients: Recipients<Self::PublicKey>,
44 request: Self::Request,
45 ) -> impl Future<Output = Result<Vec<Self::PublicKey>, Error>> + Send;
46
47 fn cancel(
51 &mut self,
52 commitment: <Self::Request as Committable>::Commitment,
53 ) -> impl Future<Output = ()> + Send;
54}
55
56pub trait Handler: Clone + Send + 'static {
58 type PublicKey: PublicKey;
60
61 type Request: Committable + Digestible + Codec;
63
64 type Response: Committable<Commitment = <Self::Request as Committable>::Commitment>
66 + Digestible<Digest = <Self::Request as Digestible>::Digest>
67 + Codec;
68
69 fn process(
73 &mut self,
74 origin: Self::PublicKey,
75 request: Self::Request,
76 response: oneshot::Sender<Self::Response>,
77 ) -> impl Future<Output = ()> + Send;
78}
79
80pub trait Monitor: Clone + Send + 'static {
82 type PublicKey: PublicKey;
84
85 type Response: Committable + Digestible + Codec;
87
88 fn collected(
93 &mut self,
94 handler: Self::PublicKey,
95 response: Self::Response,
96 count: usize,
97 ) -> impl Future<Output = ()> + Send;
98}