use iroh::EndpointId;
use tokio::sync::mpsc;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionDirection {
Incoming,
Outgoing,
}
#[derive(Debug)]
pub enum NetworkEvent<M> {
PeerConnected {
peer_id: EndpointId,
direction: ConnectionDirection,
},
PeerDisconnected {
peer_id: EndpointId,
reason: Option<String>,
},
MessageReceived {
peer_id: EndpointId,
message: M,
},
ProtocolError {
peer_id: Option<EndpointId>,
error: String,
},
}
#[derive(Debug)]
pub struct NetworkEventReceiver<M> {
rx: mpsc::Receiver<NetworkEvent<M>>,
}
impl<M> NetworkEventReceiver<M> {
pub(crate) fn new(rx: mpsc::Receiver<NetworkEvent<M>>) -> Self {
Self { rx }
}
pub async fn recv(&mut self) -> Option<NetworkEvent<M>> {
self.rx.recv().await
}
}