#![doc(
html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg",
html_favicon_url = "https://commonware.xyz/favicon.ico"
)]
commonware_macros::stability_scope!(ALPHA {
use commonware_codec::Codec;
use commonware_cryptography::{Committable, Digestible, PublicKey};
use commonware_p2p::Recipients;
use commonware_utils::channel::oneshot;
use std::future::Future;
use thiserror::Error;
pub mod p2p;
#[derive(Error, Debug)]
pub enum Error {
#[error("send failed: {0}")]
SendFailed(anyhow::Error),
#[error("canceled")]
Canceled,
}
pub trait Originator: Clone + Send + 'static {
type PublicKey: PublicKey;
type Request: Committable + Digestible + Codec;
fn send(
&mut self,
recipients: Recipients<Self::PublicKey>,
request: Self::Request,
) -> impl Future<Output = Result<Vec<Self::PublicKey>, Error>> + Send;
fn cancel(
&mut self,
commitment: <Self::Request as Committable>::Commitment,
) -> impl Future<Output = ()> + Send;
}
pub trait Handler: Clone + Send + 'static {
type PublicKey: PublicKey;
type Request: Committable + Digestible + Codec;
type Response: Committable<Commitment = <Self::Request as Committable>::Commitment>
+ Digestible<Digest = <Self::Request as Digestible>::Digest>
+ Codec;
fn process(
&mut self,
origin: Self::PublicKey,
request: Self::Request,
response: oneshot::Sender<Self::Response>,
) -> impl Future<Output = ()> + Send;
}
pub trait Monitor: Clone + Send + 'static {
type PublicKey: PublicKey;
type Response: Committable + Digestible + Codec;
fn collected(
&mut self,
handler: Self::PublicKey,
response: Self::Response,
count: usize,
) -> impl Future<Output = ()> + Send;
}
});