s2n_quic_core/endpoint/
mod.rs1use crate::{
5 io::{rx, tx},
6 path::{self, mtu},
7 time::{Clock, Timestamp},
8};
9use core::{
10 fmt,
11 future::Future,
12 task::{Context, Poll},
13};
14
15pub mod limits;
16pub use limits::Limiter;
17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
20pub enum Type {
21 Client,
23 Server,
25}
26
27impl Type {
28 pub fn is_client(self) -> bool {
30 self == Self::Client
31 }
32
33 pub fn is_server(self) -> bool {
35 self == Self::Server
36 }
37
38 #[must_use]
42 pub fn peer_type(self) -> Self {
43 match self {
44 Self::Client => Self::Server,
45 Self::Server => Self::Client,
46 }
47 }
48}
49
50#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
52pub enum Location {
53 Local,
55 Remote,
57}
58
59impl fmt::Display for Location {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 match self {
62 Self::Local => write!(f, "the local endpoint"),
63 Self::Remote => write!(f, "the remote endpoint"),
64 }
65 }
66}
67
68impl Location {
69 pub fn is_local(self) -> bool {
71 self == Self::Local
72 }
73
74 pub fn is_remote(self) -> bool {
76 self == Self::Remote
77 }
78
79 #[must_use]
83 pub fn peer_type(self) -> Self {
84 match self {
85 Self::Local => Self::Remote,
86 Self::Remote => Self::Local,
87 }
88 }
89}
90
91pub trait Endpoint: 'static + Send + Sized {
93 type PathHandle: path::Handle;
94 type Subscriber: crate::event::Subscriber;
95
96 const ENDPOINT_TYPE: Type;
97
98 fn receive<Rx, C>(&mut self, rx: &mut Rx, clock: &C)
100 where
101 Rx: rx::Queue<Handle = Self::PathHandle>,
102 C: Clock;
103
104 fn transmit<Tx, C>(&mut self, tx: &mut Tx, clock: &C)
106 where
107 Tx: tx::Queue<Handle = Self::PathHandle>,
108 C: Clock;
109
110 fn wakeups<'a, C: Clock>(&'a mut self, clock: &'a C) -> Wakeups<'a, Self, C> {
114 Wakeups {
115 endpoint: self,
116 clock,
117 }
118 }
119
120 fn poll_wakeups<C: Clock>(
124 &mut self,
125 cx: &mut Context<'_>,
126 clock: &C,
127 ) -> Poll<Result<usize, CloseError>>;
128
129 fn timeout(&self) -> Option<Timestamp>;
131
132 fn set_mtu_config(&mut self, mtu_config: mtu::Config);
134
135 fn subscriber(&mut self) -> &mut Self::Subscriber;
137}
138
139pub struct Wakeups<'a, E: Endpoint, C: Clock> {
141 endpoint: &'a mut E,
142 clock: &'a C,
143}
144
145impl<E: Endpoint, C: Clock> Future for Wakeups<'_, E, C> {
146 type Output = Result<usize, CloseError>;
147
148 fn poll(mut self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
149 let clock = self.clock;
150 self.endpoint.poll_wakeups(cx, clock)
151 }
152}
153
154#[derive(Clone, Copy, Debug)]
156pub struct CloseError;