use std::{future::Future, io, net::SocketAddr};
use agnostic_lite::RuntimeLite;
use bytes::Bytes;
#[cfg(feature = "quinn")]
#[cfg_attr(docsrs, doc(cfg(feature = "quinn")))]
pub mod quinn;
pub trait QuicStream:
memberlist_core::transport::Connection + Unpin + Send + Sync + 'static
{
type SendStream: memberlist_core::proto::ProtoWriter;
fn read_packet(&mut self) -> impl Future<Output = std::io::Result<Bytes>> + Send;
}
pub trait StreamLayer: Sized + Send + Sync + 'static {
type Runtime: RuntimeLite;
type Acceptor: QuicAcceptor<Connection = Self::Connection>;
type Connector: QuicConnector<Connection = Self::Connection>;
type Stream: QuicStream;
type Connection: QuicConnection<Stream = Self::Stream>;
type Options: Send + Sync + 'static;
fn max_stream_data(&self) -> usize;
fn new(options: Self::Options) -> impl Future<Output = std::io::Result<Self>> + Send;
fn bind(
&self,
addr: SocketAddr,
) -> impl Future<Output = std::io::Result<(SocketAddr, Self::Acceptor, Self::Connector)>> + Send;
}
#[auto_impl::auto_impl(Box)]
pub trait QuicAcceptor: Send + Sync + 'static {
type Connection: QuicConnection;
fn accept(&mut self) -> impl Future<Output = io::Result<(Self::Connection, SocketAddr)>> + Send;
fn close(&mut self) -> impl Future<Output = io::Result<()>> + Send;
fn local_addr(&self) -> SocketAddr;
}
#[auto_impl::auto_impl(Box, Arc)]
pub trait QuicConnector: Send + Sync + 'static {
type Connection: QuicConnection;
fn connect(&self, addr: SocketAddr) -> impl Future<Output = io::Result<Self::Connection>> + Send;
fn close(&self) -> impl Future<Output = io::Result<()>> + Send;
fn wait_idle(&self) -> impl Future<Output = io::Result<()>> + Send;
fn local_addr(&self) -> SocketAddr;
}
#[auto_impl::auto_impl(Box, Arc)]
pub trait QuicConnection: Send + Sync + 'static {
type Stream: QuicStream;
fn accept_bi(&self) -> impl Future<Output = io::Result<(Self::Stream, SocketAddr)>> + Send;
fn open_bi(&self) -> impl Future<Output = io::Result<(Self::Stream, SocketAddr)>> + Send;
fn close(&self) -> impl Future<Output = io::Result<()>> + Send;
fn is_closed(&self) -> impl Future<Output = bool> + Send;
fn local_addr(&self) -> SocketAddr;
}