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