Skip to main content

fedimint_core/net/
mod.rs

1pub mod api_announcement;
2pub mod auth;
3pub mod guardian_metadata;
4pub mod iroh;
5
6#[cfg(not(target_family = "wasm"))]
7pub mod fake;
8
9pub const STANDARD_FEDIMINT_P2P_PORT: u16 = 8173;
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14use fedimint_core::PeerId;
15
16pub type DynP2PConnections<M> = Arc<dyn IP2PConnections<M>>;
17
18/// Connection manager that tries to keep connections open to all peers
19#[async_trait]
20pub trait IP2PConnections<M>: Send + Sync + 'static {
21    /// Send message to recipient; drop message if channel is full.
22    fn send(&self, recipient: Recipient, msg: M);
23
24    /// Await the next message; return None if we are shutting down.
25    async fn receive(&self) -> Option<(PeerId, M)>;
26
27    /// Await the next message from peer; return None if we are shutting down.
28    async fn receive_from_peer(&self, peer: PeerId) -> Option<M>;
29
30    /// Convert the struct to trait object.
31    fn into_dyn(self) -> DynP2PConnections<M>
32    where
33        Self: Sized,
34    {
35        Arc::new(self)
36    }
37}
38
39/// This enum defines the intended recipient of a p2p message.
40#[derive(Clone, Copy, Debug, PartialEq, Eq)]
41pub enum Recipient {
42    Everyone,
43    Peer(PeerId),
44}