rwebtransport 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +666 -666
- package/Cargo.toml +31 -31
- package/LICENSE +202 -202
- package/NOTICE +41 -41
- package/README.md +550 -550
- package/crates/echo-server/Cargo.toml +20 -20
- package/crates/echo-server/src/main.rs +666 -666
- package/crates/native/Cargo.toml +23 -23
- package/crates/native/src/config.rs +129 -129
- package/crates/native/src/driver.rs +463 -463
- package/crates/native/src/lib.rs +821 -821
- package/crates/native/src/server.rs +718 -718
- package/crates/native/src/session.rs +1191 -1191
- package/crates/native/src/tls.rs +96 -96
- package/crates/wtcore/Cargo.toml +15 -15
- package/crates/wtcore/src/h3.rs +226 -226
- package/crates/wtcore/src/lib.rs +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +80 -79
- package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-x64/rwebtransport.node +0 -0
- package/prebuilds/win32-x64/rwebtransport.node +0 -0
- package/scripts/bench.mjs +180 -180
- package/scripts/build.js +67 -67
- package/scripts/postinstall.js +67 -67
- package/scripts/setup-unix.sh +129 -129
- package/scripts/setup-windows.ps1 +229 -229
- package/vendor/quiche/AGENTS.md +75 -75
- package/vendor/quiche/COPYING +23 -23
- package/vendor/quiche/Cargo.lock +1212 -1212
- package/vendor/quiche/Cargo.toml +215 -215
- package/vendor/quiche/README.md +466 -466
- package/vendor/quiche/examples/Makefile +46 -46
- package/vendor/quiche/examples/README.md +20 -20
- package/vendor/quiche/examples/cert-big.crt +90 -90
- package/vendor/quiche/examples/cert.crt +18 -18
- package/vendor/quiche/examples/cert.key +28 -28
- package/vendor/quiche/examples/client.c +343 -343
- package/vendor/quiche/examples/client.rs +281 -281
- package/vendor/quiche/examples/gen-certs.sh +15 -15
- package/vendor/quiche/examples/http3-client.c +473 -473
- package/vendor/quiche/examples/http3-client.rs +349 -349
- package/vendor/quiche/examples/http3-server.c +614 -614
- package/vendor/quiche/examples/http3-server.rs +680 -680
- package/vendor/quiche/examples/qpack-decode.rs +87 -87
- package/vendor/quiche/examples/qpack-encode.rs +88 -88
- package/vendor/quiche/examples/rootca.crt +21 -21
- package/vendor/quiche/examples/server.c +529 -529
- package/vendor/quiche/examples/server.rs +529 -529
- package/vendor/quiche/include/quiche.h +1282 -1282
- package/vendor/quiche/src/buffers.rs +105 -105
- package/vendor/quiche/src/build.rs +66 -66
- package/vendor/quiche/src/cid.rs +1079 -1079
- package/vendor/quiche/src/crypto/boringssl.rs +373 -373
- package/vendor/quiche/src/crypto/mod.rs +671 -671
- package/vendor/quiche/src/dgram.rs +118 -118
- package/vendor/quiche/src/error.rs +263 -263
- package/vendor/quiche/src/ffi.rs +2290 -2290
- package/vendor/quiche/src/flowcontrol.rs +246 -246
- package/vendor/quiche/src/frame.rs +2172 -2172
- package/vendor/quiche/src/h3/AGENTS.md +54 -54
- package/vendor/quiche/src/h3/ffi.rs +442 -442
- package/vendor/quiche/src/h3/frame.rs +1404 -1404
- package/vendor/quiche/src/h3/mod.rs +8223 -8223
- package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
- package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
- package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
- package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
- package/vendor/quiche/src/h3/stream.rs +1595 -1595
- package/vendor/quiche/src/lib.rs +9556 -9556
- package/vendor/quiche/src/minmax.rs +446 -446
- package/vendor/quiche/src/packet.rs +2334 -2334
- package/vendor/quiche/src/path.rs +1374 -1374
- package/vendor/quiche/src/pmtud.rs +652 -652
- package/vendor/quiche/src/rand.rs +64 -64
- package/vendor/quiche/src/range_buf.rs +186 -186
- package/vendor/quiche/src/ranges.rs +755 -755
- package/vendor/quiche/src/recovery/AGENTS.md +80 -80
- package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
- package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
- package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
- package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
- package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
- package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
- package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
- package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
- package/vendor/quiche/src/recovery/mod.rs +3086 -3086
- package/vendor/quiche/src/recovery/rtt.rs +152 -152
- package/vendor/quiche/src/stream/mod.rs +2210 -2210
- package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
- package/vendor/quiche/src/stream/send_buf.rs +849 -849
- package/vendor/quiche/src/test_utils.rs +681 -681
- package/vendor/quiche/src/tests.rs +12922 -12922
- package/vendor/quiche/src/tls/boringssl.rs +375 -375
- package/vendor/quiche/src/tls/mod.rs +1245 -1245
- package/vendor/quiche/src/transport_params.rs +628 -628
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
// Copyright (C) 2020, Cloudflare, Inc.
|
|
2
|
-
// All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
// Redistribution and use in source and binary forms, with or without
|
|
5
|
-
// modification, are permitted provided that the following conditions are
|
|
6
|
-
// met:
|
|
7
|
-
//
|
|
8
|
-
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
-
// this list of conditions and the following disclaimer.
|
|
10
|
-
//
|
|
11
|
-
// * Redistributions in binary form must reproduce the above copyright
|
|
12
|
-
// notice, this list of conditions and the following disclaimer in the
|
|
13
|
-
// documentation and/or other materials provided with the distribution.
|
|
14
|
-
//
|
|
15
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
16
|
-
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
17
|
-
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
18
|
-
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
19
|
-
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
-
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
-
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
-
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
-
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
-
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
-
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
-
|
|
27
|
-
//! HyStart++
|
|
28
|
-
//!
|
|
29
|
-
//! This implementation is based on the following I-D:
|
|
30
|
-
//!
|
|
31
|
-
//! <https://datatracker.ietf.org/doc/html/draft-ietf-tcpm-hystartplusplus-04>
|
|
32
|
-
|
|
33
|
-
use std::cmp;
|
|
34
|
-
use std::time::Duration;
|
|
35
|
-
use std::time::Instant;
|
|
36
|
-
|
|
37
|
-
use super::Acked;
|
|
38
|
-
|
|
39
|
-
/// Constants from I-D.
|
|
40
|
-
const MIN_RTT_THRESH: Duration = Duration::from_millis(4);
|
|
41
|
-
|
|
42
|
-
const MAX_RTT_THRESH: Duration = Duration::from_millis(16);
|
|
43
|
-
|
|
44
|
-
pub const N_RTT_SAMPLE: usize = 8;
|
|
45
|
-
|
|
46
|
-
pub const CSS_GROWTH_DIVISOR: usize = 4;
|
|
47
|
-
|
|
48
|
-
pub const CSS_ROUNDS: usize = 5;
|
|
49
|
-
|
|
50
|
-
#[derive(Default)]
|
|
51
|
-
pub struct Hystart {
|
|
52
|
-
enabled: bool,
|
|
53
|
-
|
|
54
|
-
window_end: Option<u64>,
|
|
55
|
-
|
|
56
|
-
last_round_min_rtt: Duration,
|
|
57
|
-
|
|
58
|
-
current_round_min_rtt: Duration,
|
|
59
|
-
|
|
60
|
-
css_baseline_min_rtt: Duration,
|
|
61
|
-
|
|
62
|
-
rtt_sample_count: usize,
|
|
63
|
-
|
|
64
|
-
css_start_time: Option<Instant>,
|
|
65
|
-
|
|
66
|
-
css_round_count: usize,
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
impl std::fmt::Debug for Hystart {
|
|
70
|
-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
71
|
-
write!(f, "window_end={:?} ", self.window_end)?;
|
|
72
|
-
write!(f, "last_round_min_rtt={:?} ", self.last_round_min_rtt)?;
|
|
73
|
-
write!(f, "current_round_min_rtt={:?} ", self.current_round_min_rtt)?;
|
|
74
|
-
write!(f, "css_baseline_min_rtt={:?} ", self.css_baseline_min_rtt)?;
|
|
75
|
-
write!(f, "rtt_sample_count={:?} ", self.rtt_sample_count)?;
|
|
76
|
-
write!(f, "css_start_time={:?} ", self.css_start_time)?;
|
|
77
|
-
write!(f, "css_round_count={:?}", self.css_round_count)?;
|
|
78
|
-
|
|
79
|
-
Ok(())
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
impl Hystart {
|
|
84
|
-
pub fn new(enabled: bool) -> Self {
|
|
85
|
-
Self {
|
|
86
|
-
enabled,
|
|
87
|
-
|
|
88
|
-
last_round_min_rtt: Duration::MAX,
|
|
89
|
-
|
|
90
|
-
current_round_min_rtt: Duration::MAX,
|
|
91
|
-
|
|
92
|
-
css_baseline_min_rtt: Duration::MAX,
|
|
93
|
-
|
|
94
|
-
..Default::default()
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
pub fn enabled(&self) -> bool {
|
|
99
|
-
self.enabled
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
pub fn css_start_time(&self) -> Option<Instant> {
|
|
103
|
-
self.css_start_time
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
pub fn in_css(&self) -> bool {
|
|
107
|
-
self.enabled && self.css_start_time().is_some()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
pub fn start_round(&mut self, pkt_num: u64) {
|
|
111
|
-
if self.window_end.is_none() {
|
|
112
|
-
self.window_end = Some(pkt_num);
|
|
113
|
-
|
|
114
|
-
self.last_round_min_rtt = self.current_round_min_rtt;
|
|
115
|
-
|
|
116
|
-
self.current_round_min_rtt = Duration::MAX;
|
|
117
|
-
|
|
118
|
-
self.rtt_sample_count = 0;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// On receiving ACK. Returns true if need to enter Congestion Avoidance.
|
|
123
|
-
pub fn on_packet_acked(
|
|
124
|
-
&mut self, packet: &Acked, rtt: Duration, now: Instant,
|
|
125
|
-
) -> bool {
|
|
126
|
-
if !self.enabled {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
self.current_round_min_rtt = cmp::min(self.current_round_min_rtt, rtt);
|
|
131
|
-
|
|
132
|
-
self.rtt_sample_count += 1;
|
|
133
|
-
|
|
134
|
-
// Slow Start.
|
|
135
|
-
if self.css_start_time().is_none() {
|
|
136
|
-
if self.rtt_sample_count >= N_RTT_SAMPLE &&
|
|
137
|
-
self.current_round_min_rtt != Duration::MAX &&
|
|
138
|
-
self.last_round_min_rtt != Duration::MAX
|
|
139
|
-
{
|
|
140
|
-
// clamp(min_rtt_thresh, last_round_min_rtt/8,
|
|
141
|
-
// max_rtt_thresh)
|
|
142
|
-
let rtt_thresh =
|
|
143
|
-
cmp::max(self.last_round_min_rtt / 8, MIN_RTT_THRESH);
|
|
144
|
-
let rtt_thresh = cmp::min(rtt_thresh, MAX_RTT_THRESH);
|
|
145
|
-
|
|
146
|
-
// Check if we can exit to CSS.
|
|
147
|
-
if self.current_round_min_rtt >=
|
|
148
|
-
self.last_round_min_rtt.saturating_add(rtt_thresh)
|
|
149
|
-
{
|
|
150
|
-
self.css_baseline_min_rtt = self.current_round_min_rtt;
|
|
151
|
-
self.css_start_time = Some(now);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
// Conservative Slow Start.
|
|
156
|
-
if self.rtt_sample_count >= N_RTT_SAMPLE {
|
|
157
|
-
self.rtt_sample_count = 0;
|
|
158
|
-
|
|
159
|
-
if self.current_round_min_rtt < self.css_baseline_min_rtt {
|
|
160
|
-
self.css_baseline_min_rtt = Duration::MAX;
|
|
161
|
-
|
|
162
|
-
// Back to Slow Start.
|
|
163
|
-
self.css_start_time = None;
|
|
164
|
-
self.css_round_count = 0;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Check if we reached the end of the round.
|
|
170
|
-
if let Some(end_pkt_num) = self.window_end {
|
|
171
|
-
if packet.pkt_num >= end_pkt_num {
|
|
172
|
-
// Start of a new round.
|
|
173
|
-
self.window_end = None;
|
|
174
|
-
|
|
175
|
-
if self.css_start_time().is_some() {
|
|
176
|
-
self.css_round_count += 1;
|
|
177
|
-
|
|
178
|
-
// End of CSS - exit to congestion avoidance.
|
|
179
|
-
if self.css_round_count >= CSS_ROUNDS {
|
|
180
|
-
self.css_round_count = 0;
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
false
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Return a cwnd increment during CSS (Conservative Slow Start).
|
|
191
|
-
pub fn css_cwnd_inc(&self, pkt_size: usize) -> usize {
|
|
192
|
-
pkt_size / CSS_GROWTH_DIVISOR
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Exit HyStart++ when entering congestion avoidance.
|
|
196
|
-
pub fn congestion_event(&mut self) {
|
|
197
|
-
self.window_end = None;
|
|
198
|
-
self.css_start_time = None;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
#[cfg(test)]
|
|
203
|
-
mod tests {
|
|
204
|
-
use super::*;
|
|
205
|
-
|
|
206
|
-
#[test]
|
|
207
|
-
fn start_round() {
|
|
208
|
-
let mut hspp = Hystart::default();
|
|
209
|
-
let pkt_num = 100;
|
|
210
|
-
|
|
211
|
-
hspp.start_round(pkt_num);
|
|
212
|
-
|
|
213
|
-
assert_eq!(hspp.window_end, Some(pkt_num));
|
|
214
|
-
assert_eq!(hspp.current_round_min_rtt, Duration::MAX);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
#[test]
|
|
218
|
-
fn css_cwnd_inc() {
|
|
219
|
-
let hspp = Hystart::default();
|
|
220
|
-
let datagram_size = 1200;
|
|
221
|
-
|
|
222
|
-
let css_cwnd_inc = hspp.css_cwnd_inc(datagram_size);
|
|
223
|
-
|
|
224
|
-
assert_eq!(datagram_size / CSS_GROWTH_DIVISOR, css_cwnd_inc);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
#[test]
|
|
228
|
-
fn congestion_event() {
|
|
229
|
-
let mut hspp = Hystart::default();
|
|
230
|
-
let pkt_num = 100;
|
|
231
|
-
|
|
232
|
-
hspp.start_round(pkt_num);
|
|
233
|
-
|
|
234
|
-
assert_eq!(hspp.window_end, Some(pkt_num));
|
|
235
|
-
|
|
236
|
-
// When moving into CA mode, window_end should be cleared.
|
|
237
|
-
hspp.congestion_event();
|
|
238
|
-
|
|
239
|
-
assert_eq!(hspp.window_end, None);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
1
|
+
// Copyright (C) 2020, Cloudflare, Inc.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
|
5
|
+
// modification, are permitted provided that the following conditions are
|
|
6
|
+
// met:
|
|
7
|
+
//
|
|
8
|
+
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
// this list of conditions and the following disclaimer.
|
|
10
|
+
//
|
|
11
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
// documentation and/or other materials provided with the distribution.
|
|
14
|
+
//
|
|
15
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
16
|
+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
17
|
+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
18
|
+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
19
|
+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
|
|
27
|
+
//! HyStart++
|
|
28
|
+
//!
|
|
29
|
+
//! This implementation is based on the following I-D:
|
|
30
|
+
//!
|
|
31
|
+
//! <https://datatracker.ietf.org/doc/html/draft-ietf-tcpm-hystartplusplus-04>
|
|
32
|
+
|
|
33
|
+
use std::cmp;
|
|
34
|
+
use std::time::Duration;
|
|
35
|
+
use std::time::Instant;
|
|
36
|
+
|
|
37
|
+
use super::Acked;
|
|
38
|
+
|
|
39
|
+
/// Constants from I-D.
|
|
40
|
+
const MIN_RTT_THRESH: Duration = Duration::from_millis(4);
|
|
41
|
+
|
|
42
|
+
const MAX_RTT_THRESH: Duration = Duration::from_millis(16);
|
|
43
|
+
|
|
44
|
+
pub const N_RTT_SAMPLE: usize = 8;
|
|
45
|
+
|
|
46
|
+
pub const CSS_GROWTH_DIVISOR: usize = 4;
|
|
47
|
+
|
|
48
|
+
pub const CSS_ROUNDS: usize = 5;
|
|
49
|
+
|
|
50
|
+
#[derive(Default)]
|
|
51
|
+
pub struct Hystart {
|
|
52
|
+
enabled: bool,
|
|
53
|
+
|
|
54
|
+
window_end: Option<u64>,
|
|
55
|
+
|
|
56
|
+
last_round_min_rtt: Duration,
|
|
57
|
+
|
|
58
|
+
current_round_min_rtt: Duration,
|
|
59
|
+
|
|
60
|
+
css_baseline_min_rtt: Duration,
|
|
61
|
+
|
|
62
|
+
rtt_sample_count: usize,
|
|
63
|
+
|
|
64
|
+
css_start_time: Option<Instant>,
|
|
65
|
+
|
|
66
|
+
css_round_count: usize,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
impl std::fmt::Debug for Hystart {
|
|
70
|
+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
71
|
+
write!(f, "window_end={:?} ", self.window_end)?;
|
|
72
|
+
write!(f, "last_round_min_rtt={:?} ", self.last_round_min_rtt)?;
|
|
73
|
+
write!(f, "current_round_min_rtt={:?} ", self.current_round_min_rtt)?;
|
|
74
|
+
write!(f, "css_baseline_min_rtt={:?} ", self.css_baseline_min_rtt)?;
|
|
75
|
+
write!(f, "rtt_sample_count={:?} ", self.rtt_sample_count)?;
|
|
76
|
+
write!(f, "css_start_time={:?} ", self.css_start_time)?;
|
|
77
|
+
write!(f, "css_round_count={:?}", self.css_round_count)?;
|
|
78
|
+
|
|
79
|
+
Ok(())
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
impl Hystart {
|
|
84
|
+
pub fn new(enabled: bool) -> Self {
|
|
85
|
+
Self {
|
|
86
|
+
enabled,
|
|
87
|
+
|
|
88
|
+
last_round_min_rtt: Duration::MAX,
|
|
89
|
+
|
|
90
|
+
current_round_min_rtt: Duration::MAX,
|
|
91
|
+
|
|
92
|
+
css_baseline_min_rtt: Duration::MAX,
|
|
93
|
+
|
|
94
|
+
..Default::default()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
pub fn enabled(&self) -> bool {
|
|
99
|
+
self.enabled
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
pub fn css_start_time(&self) -> Option<Instant> {
|
|
103
|
+
self.css_start_time
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
pub fn in_css(&self) -> bool {
|
|
107
|
+
self.enabled && self.css_start_time().is_some()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
pub fn start_round(&mut self, pkt_num: u64) {
|
|
111
|
+
if self.window_end.is_none() {
|
|
112
|
+
self.window_end = Some(pkt_num);
|
|
113
|
+
|
|
114
|
+
self.last_round_min_rtt = self.current_round_min_rtt;
|
|
115
|
+
|
|
116
|
+
self.current_round_min_rtt = Duration::MAX;
|
|
117
|
+
|
|
118
|
+
self.rtt_sample_count = 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// On receiving ACK. Returns true if need to enter Congestion Avoidance.
|
|
123
|
+
pub fn on_packet_acked(
|
|
124
|
+
&mut self, packet: &Acked, rtt: Duration, now: Instant,
|
|
125
|
+
) -> bool {
|
|
126
|
+
if !self.enabled {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
self.current_round_min_rtt = cmp::min(self.current_round_min_rtt, rtt);
|
|
131
|
+
|
|
132
|
+
self.rtt_sample_count += 1;
|
|
133
|
+
|
|
134
|
+
// Slow Start.
|
|
135
|
+
if self.css_start_time().is_none() {
|
|
136
|
+
if self.rtt_sample_count >= N_RTT_SAMPLE &&
|
|
137
|
+
self.current_round_min_rtt != Duration::MAX &&
|
|
138
|
+
self.last_round_min_rtt != Duration::MAX
|
|
139
|
+
{
|
|
140
|
+
// clamp(min_rtt_thresh, last_round_min_rtt/8,
|
|
141
|
+
// max_rtt_thresh)
|
|
142
|
+
let rtt_thresh =
|
|
143
|
+
cmp::max(self.last_round_min_rtt / 8, MIN_RTT_THRESH);
|
|
144
|
+
let rtt_thresh = cmp::min(rtt_thresh, MAX_RTT_THRESH);
|
|
145
|
+
|
|
146
|
+
// Check if we can exit to CSS.
|
|
147
|
+
if self.current_round_min_rtt >=
|
|
148
|
+
self.last_round_min_rtt.saturating_add(rtt_thresh)
|
|
149
|
+
{
|
|
150
|
+
self.css_baseline_min_rtt = self.current_round_min_rtt;
|
|
151
|
+
self.css_start_time = Some(now);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
// Conservative Slow Start.
|
|
156
|
+
if self.rtt_sample_count >= N_RTT_SAMPLE {
|
|
157
|
+
self.rtt_sample_count = 0;
|
|
158
|
+
|
|
159
|
+
if self.current_round_min_rtt < self.css_baseline_min_rtt {
|
|
160
|
+
self.css_baseline_min_rtt = Duration::MAX;
|
|
161
|
+
|
|
162
|
+
// Back to Slow Start.
|
|
163
|
+
self.css_start_time = None;
|
|
164
|
+
self.css_round_count = 0;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check if we reached the end of the round.
|
|
170
|
+
if let Some(end_pkt_num) = self.window_end {
|
|
171
|
+
if packet.pkt_num >= end_pkt_num {
|
|
172
|
+
// Start of a new round.
|
|
173
|
+
self.window_end = None;
|
|
174
|
+
|
|
175
|
+
if self.css_start_time().is_some() {
|
|
176
|
+
self.css_round_count += 1;
|
|
177
|
+
|
|
178
|
+
// End of CSS - exit to congestion avoidance.
|
|
179
|
+
if self.css_round_count >= CSS_ROUNDS {
|
|
180
|
+
self.css_round_count = 0;
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
false
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Return a cwnd increment during CSS (Conservative Slow Start).
|
|
191
|
+
pub fn css_cwnd_inc(&self, pkt_size: usize) -> usize {
|
|
192
|
+
pkt_size / CSS_GROWTH_DIVISOR
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Exit HyStart++ when entering congestion avoidance.
|
|
196
|
+
pub fn congestion_event(&mut self) {
|
|
197
|
+
self.window_end = None;
|
|
198
|
+
self.css_start_time = None;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#[cfg(test)]
|
|
203
|
+
mod tests {
|
|
204
|
+
use super::*;
|
|
205
|
+
|
|
206
|
+
#[test]
|
|
207
|
+
fn start_round() {
|
|
208
|
+
let mut hspp = Hystart::default();
|
|
209
|
+
let pkt_num = 100;
|
|
210
|
+
|
|
211
|
+
hspp.start_round(pkt_num);
|
|
212
|
+
|
|
213
|
+
assert_eq!(hspp.window_end, Some(pkt_num));
|
|
214
|
+
assert_eq!(hspp.current_round_min_rtt, Duration::MAX);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
#[test]
|
|
218
|
+
fn css_cwnd_inc() {
|
|
219
|
+
let hspp = Hystart::default();
|
|
220
|
+
let datagram_size = 1200;
|
|
221
|
+
|
|
222
|
+
let css_cwnd_inc = hspp.css_cwnd_inc(datagram_size);
|
|
223
|
+
|
|
224
|
+
assert_eq!(datagram_size / CSS_GROWTH_DIVISOR, css_cwnd_inc);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#[test]
|
|
228
|
+
fn congestion_event() {
|
|
229
|
+
let mut hspp = Hystart::default();
|
|
230
|
+
let pkt_num = 100;
|
|
231
|
+
|
|
232
|
+
hspp.start_round(pkt_num);
|
|
233
|
+
|
|
234
|
+
assert_eq!(hspp.window_end, Some(pkt_num));
|
|
235
|
+
|
|
236
|
+
// When moving into CA mode, window_end should be cleared.
|
|
237
|
+
hspp.congestion_event();
|
|
238
|
+
|
|
239
|
+
assert_eq!(hspp.window_end, None);
|
|
240
|
+
}
|
|
241
|
+
}
|