1#![warn(rust_2018_idioms)]
16#![allow(dead_code)]
17#![allow(clippy::bool_to_int_with_if)]
18
19use bytes::Bytes;
20use std::time::Instant;
21use std::{
22 fmt,
23 net::{IpAddr, SocketAddr},
24 ops,
25};
26
27mod association;
28pub use crate::association::{
29 stats::AssociationStats,
30 stream::{ReliabilityType, Stream, StreamEvent, StreamId, StreamState},
31 Association, AssociationError, Event,
32};
33
34pub(crate) mod chunk;
35pub use crate::chunk::{
36 chunk_payload_data::{ChunkPayloadData, PayloadProtocolIdentifier},
37 ErrorCauseCode,
38};
39
40mod config;
41pub use crate::config::{ClientConfig, EndpointConfig, ServerConfig, TransportConfig};
42
43mod endpoint;
44pub use crate::endpoint::{AssociationHandle, ConnectError, DatagramEvent, Endpoint};
45
46mod error;
47pub use crate::error::Error;
48
49mod packet;
50
51mod shared;
52pub use crate::shared::{AssociationEvent, AssociationId, EcnCodepoint, EndpointEvent};
53
54pub(crate) mod param;
55
56pub(crate) mod queue;
57pub use crate::queue::reassembly_queue::{Chunk, Chunks};
58
59pub(crate) mod util;
60
61#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
63pub enum Side {
64 #[default]
66 Client = 0,
67 Server = 1,
69}
70
71impl fmt::Display for Side {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 let s = match *self {
74 Side::Client => "Client",
75 Side::Server => "Server",
76 };
77 write!(f, "{}", s)
78 }
79}
80
81impl Side {
82 #[inline]
83 pub fn is_client(self) -> bool {
85 self == Side::Client
86 }
87
88 #[inline]
89 pub fn is_server(self) -> bool {
91 self == Side::Server
92 }
93}
94
95impl ops::Not for Side {
96 type Output = Side;
97 fn not(self) -> Side {
98 match self {
99 Side::Client => Side::Server,
100 Side::Server => Side::Client,
101 }
102 }
103}
104
105use crate::packet::PartialDecode;
106
107#[derive(Debug)]
109pub enum Payload {
110 PartialDecode(PartialDecode),
111 RawEncode(Vec<Bytes>),
112}
113
114#[derive(Debug)]
116pub struct Transmit {
117 pub now: Instant,
119 pub remote: SocketAddr,
121 pub ecn: Option<EcnCodepoint>,
123 pub local_ip: Option<IpAddr>,
125 pub payload: Payload,
127}
128
129#[cfg(test)]
130mod test {
131 use std::sync::Arc;
132
133 use super::*;
134
135 #[test]
136 fn ensure_send_sync() {
137 fn is_send_sync(_a: impl Send + Sync) {}
138
139 let c = EndpointConfig::new();
140 let e = Endpoint::new(Arc::new(c), None);
141 is_send_sync(e);
142
143 let a = Association::default();
144 is_send_sync(a);
145 }
146}