fedimint_core/net/
peers.rs1use std::sync::Arc;
2
3use async_trait::async_trait;
4use fedimint_core::PeerId;
5
6#[cfg(not(target_family = "wasm"))]
7pub mod fake;
8
9pub type DynP2PConnections<M> = Arc<dyn IP2PConnections<M>>;
10
11#[async_trait]
13pub trait IP2PConnections<M>: Send + Sync + 'static {
14 async fn send(&self, recipient: Recipient, msg: M);
16
17 fn try_send(&self, recipient: Recipient, msg: M);
19
20 async fn receive(&self) -> Option<(PeerId, M)>;
22
23 async fn receive_from_peer(&self, peer: PeerId) -> Option<M>;
25
26 fn into_dyn(self) -> DynP2PConnections<M>
28 where
29 Self: Sized,
30 {
31 Arc::new(self)
32 }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
37pub enum Recipient {
38 Everyone,
39 Peer(PeerId),
40}