memberlist_quic/
stream_layer.rs1use std::{future::Future, io, net::SocketAddr};
2
3use agnostic_lite::RuntimeLite;
4use bytes::Bytes;
5
6#[cfg(feature = "quinn")]
8#[cfg_attr(docsrs, doc(cfg(feature = "quinn")))]
9pub mod quinn;
10
11pub trait QuicStream:
13 memberlist_core::transport::Connection + Unpin + Send + Sync + 'static
14{
15 type SendStream: memberlist_core::proto::ProtoWriter;
17
18 fn read_packet(&mut self) -> impl Future<Output = std::io::Result<Bytes>> + Send;
20}
21
22pub trait StreamLayer: Sized + Send + Sync + 'static {
24 type Runtime: RuntimeLite;
26
27 type Acceptor: QuicAcceptor<Connection = Self::Connection>;
29
30 type Connector: QuicConnector<Connection = Self::Connection>;
32
33 type Stream: QuicStream;
35
36 type Connection: QuicConnection<Stream = Self::Stream>;
38
39 type Options: Send + Sync + 'static;
41
42 fn max_stream_data(&self) -> usize;
44
45 fn new(options: Self::Options) -> impl Future<Output = std::io::Result<Self>> + Send;
47
48 fn bind(
51 &self,
52 addr: SocketAddr,
53 ) -> impl Future<Output = std::io::Result<(SocketAddr, Self::Acceptor, Self::Connector)>> + Send;
54}
55
56#[auto_impl::auto_impl(Box)]
59pub trait QuicAcceptor: Send + Sync + 'static {
60 type Connection: QuicConnection;
62
63 fn accept(&mut self) -> impl Future<Output = io::Result<(Self::Connection, SocketAddr)>> + Send;
65
66 fn close(&mut self) -> impl Future<Output = io::Result<()>> + Send;
68
69 fn local_addr(&self) -> SocketAddr;
71}
72
73#[auto_impl::auto_impl(Box, Arc)]
76pub trait QuicConnector: Send + Sync + 'static {
77 type Connection: QuicConnection;
79
80 fn connect(&self, addr: SocketAddr) -> impl Future<Output = io::Result<Self::Connection>> + Send;
82
83 fn close(&self) -> impl Future<Output = io::Result<()>> + Send;
85
86 fn wait_idle(&self) -> impl Future<Output = io::Result<()>> + Send;
95
96 fn local_addr(&self) -> SocketAddr;
98}
99
100#[auto_impl::auto_impl(Box, Arc)]
102pub trait QuicConnection: Send + Sync + 'static {
103 type Stream: QuicStream;
105
106 fn accept_bi(&self) -> impl Future<Output = io::Result<(Self::Stream, SocketAddr)>> + Send;
108
109 fn open_bi(&self) -> impl Future<Output = io::Result<(Self::Stream, SocketAddr)>> + Send;
111
112 fn close(&self) -> impl Future<Output = io::Result<()>> + Send;
114
115 fn is_closed(&self) -> impl Future<Output = bool> + Send;
117
118 fn local_addr(&self) -> SocketAddr;
120}