use std::{
io,
num::NonZeroUsize,
sync::Arc,
task::{Context, Poll},
};
use iroh_base::CustomAddr;
use super::{Addr, Transmit};
pub trait CustomTransport: std::fmt::Debug + Send + Sync + 'static {
fn bind(&self) -> io::Result<Box<dyn CustomEndpoint>>;
}
pub trait CustomEndpoint: std::fmt::Debug + Send + Sync + 'static {
fn watch_local_addrs(&self) -> n0_watcher::Direct<Vec<CustomAddr>>;
fn create_sender(&self) -> Arc<dyn CustomSender>;
fn poll_recv(
&mut self,
cx: &mut Context,
bufs: &mut [io::IoSliceMut<'_>],
metas: &mut [noq_udp::RecvMeta],
source_addrs: &mut [Addr],
) -> Poll<io::Result<usize>>;
fn max_transmit_segments(&self) -> NonZeroUsize {
NonZeroUsize::MIN
}
}
pub trait CustomSender: std::fmt::Debug + Send + Sync + 'static {
fn is_valid_send_addr(&self, addr: &CustomAddr) -> bool;
fn poll_send(
&self,
cx: &mut std::task::Context,
dst: &CustomAddr,
transmit: &Transmit<'_>,
) -> Poll<io::Result<()>>;
}