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 fn send(&self, recipient: Recipient, msg: M);
16
17 async fn receive(&self) -> Option<(PeerId, M)>;
19
20 async fn receive_from_peer(&self, peer: PeerId) -> Option<M>;
22
23 fn into_dyn(self) -> DynP2PConnections<M>
25 where
26 Self: Sized,
27 {
28 Arc::new(self)
29 }
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub enum Recipient {
35 Everyone,
36 Peer(PeerId),
37}