//! Communicate with authenticated peers over encrypted connections.
//!
//! # Status
//!
//! `commonware-p2p` is **ALPHA** software and is not yet recommended for production use. Developers should
//! expect breaking changes and occasional instability.
#![doc(
html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg",
html_favicon_url = "https://commonware.xyz/favicon.ico"
)]
use bytes::Bytes;
use commonware_cryptography::PublicKey;
use commonware_utils::ordered::Set;
use futures::channel::mpsc;
use std::{error::Error as StdError, fmt::Debug, future::Future, time::SystemTime};
pub mod authenticated;
pub mod simulated;
pub mod types;
pub mod utils;
pub use types::{Address, Ingress};
/// Tuple representing a message received from a given public key.
///
/// This message is guaranteed to adhere to the configuration of the channel and
/// will already be decrypted and authenticated.
pub type Message
= (P, Bytes);
/// Alias for identifying communication channels.
pub type Channel = u64;
/// Enum indicating the set of recipients to send a message to.
#[derive(Clone, Debug)]
pub enum Recipients {
All,
Some(Vec),
One(P),
}
/// Interface for sending messages to a set of recipients without rate-limiting restrictions.
pub trait UnlimitedSender: Clone + Send + Sync + 'static {
/// Public key type used to identify recipients.
type PublicKey: PublicKey;
/// Error that can occur when sending a message.
type Error: Debug + StdError + Send + Sync;
/// Sends a message to a set of recipients.
///
/// # Offline Recipients
///
/// If a recipient is offline at the time a message is sent, the message
/// will be dropped. It is up to the application to handle retries (if
/// necessary).
///
/// # Returns
///
/// A vector of recipients that the message was sent to, or an error if the
/// message could not be sent (e.g., too large).
///
/// Note: a successful send does not guarantee that the recipient will
/// receive the message.
fn send(
&mut self,
recipients: Recipients,
message: Bytes,
priority: bool,
) -> impl Future