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,275 +1,275 @@
|
|
|
1
|
-
// Copyright (C) 2024, 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
|
-
mod bbr;
|
|
28
|
-
mod bbr2;
|
|
29
|
-
pub mod pacer;
|
|
30
|
-
mod recovery;
|
|
31
|
-
|
|
32
|
-
use std::fmt::Debug;
|
|
33
|
-
use std::str::FromStr;
|
|
34
|
-
use std::time::Instant;
|
|
35
|
-
|
|
36
|
-
pub use self::recovery::GRecovery;
|
|
37
|
-
use crate::recovery::bandwidth::Bandwidth;
|
|
38
|
-
|
|
39
|
-
use crate::recovery::rtt::RttStats;
|
|
40
|
-
use crate::recovery::RecoveryStats;
|
|
41
|
-
|
|
42
|
-
#[derive(Debug)]
|
|
43
|
-
pub struct Lost {
|
|
44
|
-
pub(super) packet_number: u64,
|
|
45
|
-
pub(super) bytes_lost: usize,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
#[derive(Debug)]
|
|
49
|
-
pub struct Acked {
|
|
50
|
-
pub(super) pkt_num: u64,
|
|
51
|
-
pub(super) time_sent: Instant,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
pub(super) trait CongestionControl: Debug {
|
|
55
|
-
/// Returns the name of the current state of the congestion control state
|
|
56
|
-
/// machine. Used to annotate qlogs after state transitions.
|
|
57
|
-
#[cfg(feature = "qlog")]
|
|
58
|
-
fn state_str(&self) -> &'static str;
|
|
59
|
-
|
|
60
|
-
/// Returns the size of the current congestion window in bytes. Note, this
|
|
61
|
-
/// is not the *available* window. Some send algorithms may not use a
|
|
62
|
-
/// congestion window and will return 0.
|
|
63
|
-
fn get_congestion_window(&self) -> usize;
|
|
64
|
-
|
|
65
|
-
/// Returns the size of the current congestion window in packets. Note, this
|
|
66
|
-
/// is not the *available* window. Some send algorithms may not use a
|
|
67
|
-
/// congestion window and will return 0.
|
|
68
|
-
fn get_congestion_window_in_packets(&self) -> usize;
|
|
69
|
-
|
|
70
|
-
/// Make decision on whether the sender can send right now. Note that even
|
|
71
|
-
/// when this method returns true, the sending can be delayed due to pacing.
|
|
72
|
-
fn can_send(&self, bytes_in_flight: usize) -> bool;
|
|
73
|
-
|
|
74
|
-
/// Inform that we sent `bytes` to the wire, and if the packet is
|
|
75
|
-
/// retransmittable. `bytes_in_flight` is the number of bytes in flight
|
|
76
|
-
/// before the packet was sent. Note: this function must be called for
|
|
77
|
-
/// every packet sent to the wire.
|
|
78
|
-
fn on_packet_sent(
|
|
79
|
-
&mut self, sent_time: Instant, bytes_in_flight: usize,
|
|
80
|
-
packet_number: u64, bytes: usize, is_retransmissible: bool,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
/// Inform that `packet_number` has been neutered.
|
|
84
|
-
fn on_packet_neutered(&mut self, _packet_number: u64) {}
|
|
85
|
-
|
|
86
|
-
/// Indicates an update to the congestion state, caused either by an
|
|
87
|
-
/// incoming ack or loss event timeout. `rtt_updated` indicates whether a
|
|
88
|
-
/// new `latest_rtt` sample has been taken, `prior_in_flight` the bytes in
|
|
89
|
-
/// flight prior to the congestion event. `acked_packets` and `lost_packets`
|
|
90
|
-
/// are any packets considered acked or lost as a result of the
|
|
91
|
-
/// congestion event.
|
|
92
|
-
#[allow(clippy::too_many_arguments)]
|
|
93
|
-
fn on_congestion_event(
|
|
94
|
-
&mut self, rtt_updated: bool, prior_in_flight: usize,
|
|
95
|
-
bytes_in_flight: usize, event_time: Instant, acked_packets: &[Acked],
|
|
96
|
-
lost_packets: &[Lost], least_unacked: u64, rtt_stats: &RttStats,
|
|
97
|
-
recovery_stats: &mut RecoveryStats,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
/// Called when an RTO fires. Resets the retransmission alarm if there are
|
|
101
|
-
/// remaining unacked packets.
|
|
102
|
-
fn on_retransmission_timeout(&mut self, packets_retransmitted: bool);
|
|
103
|
-
|
|
104
|
-
/// Called when connection migrates and cwnd needs to be reset.
|
|
105
|
-
#[allow(dead_code)]
|
|
106
|
-
fn on_connection_migration(&mut self);
|
|
107
|
-
|
|
108
|
-
/// Adjust the current cwnd to a new maximal size
|
|
109
|
-
fn limit_cwnd(&mut self, _max_cwnd: usize) {}
|
|
110
|
-
|
|
111
|
-
fn is_in_recovery(&self) -> bool;
|
|
112
|
-
|
|
113
|
-
#[allow(dead_code)]
|
|
114
|
-
fn is_cwnd_limited(&self, bytes_in_flight: usize) -> bool;
|
|
115
|
-
|
|
116
|
-
fn pacing_rate(
|
|
117
|
-
&self, bytes_in_flight: usize, rtt_stats: &RttStats,
|
|
118
|
-
) -> Bandwidth;
|
|
119
|
-
|
|
120
|
-
fn bandwidth_estimate(&self, rtt_stats: &RttStats) -> Bandwidth;
|
|
121
|
-
|
|
122
|
-
fn max_bandwidth(&self) -> Bandwidth;
|
|
123
|
-
|
|
124
|
-
fn update_mss(&mut self, new_mss: usize);
|
|
125
|
-
|
|
126
|
-
fn on_app_limited(&mut self, _bytes_in_flight: usize) {}
|
|
127
|
-
|
|
128
|
-
#[cfg(feature = "qlog")]
|
|
129
|
-
fn ssthresh(&self) -> Option<u64> {
|
|
130
|
-
None
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/// BBR settings used to customize the algorithm's behavior.
|
|
135
|
-
///
|
|
136
|
-
/// This functionality is experimental and will be removed in the future.
|
|
137
|
-
///
|
|
138
|
-
/// A congestion control algorithm has dual-responsibility of effective network
|
|
139
|
-
/// utilization and avoiding congestion. Custom values should be choosen
|
|
140
|
-
/// carefully since incorrect values can lead to network degradation for all
|
|
141
|
-
/// connections on the shared network.
|
|
142
|
-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
|
|
143
|
-
#[repr(C)]
|
|
144
|
-
#[doc(hidden)]
|
|
145
|
-
pub struct BbrParams {
|
|
146
|
-
/// Controls the BBR startup gain.
|
|
147
|
-
pub startup_cwnd_gain: Option<f32>,
|
|
148
|
-
|
|
149
|
-
/// Controls the BBR startup pacing gain.
|
|
150
|
-
pub startup_pacing_gain: Option<f32>,
|
|
151
|
-
|
|
152
|
-
/// Controls the BBR full bandwidth threshold.
|
|
153
|
-
pub full_bw_threshold: Option<f32>,
|
|
154
|
-
|
|
155
|
-
/// Controls the number of rounds to stay in STARTUP before
|
|
156
|
-
/// exiting due to bandwidth plateau.
|
|
157
|
-
pub startup_full_bw_rounds: Option<usize>,
|
|
158
|
-
|
|
159
|
-
/// Controls the BBR startup loss count necessary to exit startup.
|
|
160
|
-
pub startup_full_loss_count: Option<usize>,
|
|
161
|
-
|
|
162
|
-
/// Controls the BBR drain cwnd gain.
|
|
163
|
-
pub drain_cwnd_gain: Option<f32>,
|
|
164
|
-
|
|
165
|
-
/// Controls the BBR drain pacing gain.
|
|
166
|
-
pub drain_pacing_gain: Option<f32>,
|
|
167
|
-
|
|
168
|
-
/// Controls if BBR should respect Reno coexistence.
|
|
169
|
-
pub enable_reno_coexistence: Option<bool>,
|
|
170
|
-
|
|
171
|
-
/// Controls if BBR should enable code in Bandwidth Sampler that
|
|
172
|
-
/// attempts to avoid overestimating bandwidth on ack compression.
|
|
173
|
-
pub enable_overestimate_avoidance: Option<bool>,
|
|
174
|
-
|
|
175
|
-
/// Controls if BBR should enable a possible fix in Bandwidth
|
|
176
|
-
/// Sampler that attempts to bandwidth over estimation avoidance.
|
|
177
|
-
pub choose_a0_point_fix: Option<bool>,
|
|
178
|
-
|
|
179
|
-
/// Controls the BBR bandwidth probe up pacing gain.
|
|
180
|
-
pub probe_bw_probe_up_pacing_gain: Option<f32>,
|
|
181
|
-
|
|
182
|
-
/// Controls the BBR bandwidth probe down pacing gain.
|
|
183
|
-
pub probe_bw_probe_down_pacing_gain: Option<f32>,
|
|
184
|
-
|
|
185
|
-
/// Controls the BBR probe bandwidth DOWN/CRUISE/REFILL cwnd gain.
|
|
186
|
-
pub probe_bw_cwnd_gain: Option<f32>,
|
|
187
|
-
|
|
188
|
-
/// Controls the BBR probe bandwidth UP cwnd gain.
|
|
189
|
-
pub probe_bw_up_cwnd_gain: Option<f32>,
|
|
190
|
-
|
|
191
|
-
/// Controls the BBR probe RTT pacing gain.
|
|
192
|
-
pub probe_rtt_pacing_gain: Option<f32>,
|
|
193
|
-
|
|
194
|
-
/// Controls the BBR probe RTT cwnd gain.
|
|
195
|
-
pub probe_rtt_cwnd_gain: Option<f32>,
|
|
196
|
-
|
|
197
|
-
/// Controls the number of rounds BBR should stay in probe up if
|
|
198
|
-
/// bytes_in_flight doesn't drop below target.
|
|
199
|
-
pub max_probe_up_queue_rounds: Option<usize>,
|
|
200
|
-
|
|
201
|
-
/// Controls the BBR loss threshold.
|
|
202
|
-
pub loss_threshold: Option<f32>,
|
|
203
|
-
|
|
204
|
-
/// Controls if BBR should use bytes delievered as an estimate for
|
|
205
|
-
/// inflight_hi.
|
|
206
|
-
pub use_bytes_delivered_for_inflight_hi: Option<bool>,
|
|
207
|
-
|
|
208
|
-
/// Controls if BBR should adjust startup pacing at round end.
|
|
209
|
-
pub decrease_startup_pacing_at_end_of_round: Option<bool>,
|
|
210
|
-
|
|
211
|
-
/// Controls the BBR bandwidth lo reduction strategy.
|
|
212
|
-
pub bw_lo_reduction_strategy: Option<BbrBwLoReductionStrategy>,
|
|
213
|
-
|
|
214
|
-
/// Determines whether app limited rounds with no bandwidth growth count
|
|
215
|
-
/// towards the rounds threshold to exit startup.
|
|
216
|
-
pub ignore_app_limited_for_no_bandwidth_growth: Option<bool>,
|
|
217
|
-
|
|
218
|
-
/// Initial pacing rate for a new connection before an RTT
|
|
219
|
-
/// estimate is available. This rate serves as an upper bound on
|
|
220
|
-
/// the initial pacing rate, which is calculated by dividing the
|
|
221
|
-
/// initial cwnd by the first RTT estimate.
|
|
222
|
-
pub initial_pacing_rate_bytes_per_second: Option<u64>,
|
|
223
|
-
|
|
224
|
-
/// If true, scale the pacing rate when updating mss when doing pmtud.
|
|
225
|
-
pub scale_pacing_rate_by_mss: Option<bool>,
|
|
226
|
-
|
|
227
|
-
/// Disable `has_stayed_long_enough_in_probe_down` which can cause ProbeDown
|
|
228
|
-
/// to exit early.
|
|
229
|
-
pub disable_probe_down_early_exit: Option<bool>,
|
|
230
|
-
|
|
231
|
-
/// Set the expected send time for packets when using BBR to `now`
|
|
232
|
-
/// instead of `get_next_release_time()`. Setting the time based
|
|
233
|
-
/// on `get_next_release_time()` can result in artificially low
|
|
234
|
-
/// minRTT measurements which will make BBR misbehave.
|
|
235
|
-
pub time_sent_set_to_now: Option<bool>,
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/// Controls BBR's bandwidth reduction strategy on congestion event.
|
|
239
|
-
///
|
|
240
|
-
/// This functionality is experimental and will be removed in the future.
|
|
241
|
-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
242
|
-
#[repr(C)]
|
|
243
|
-
#[doc(hidden)]
|
|
244
|
-
pub enum BbrBwLoReductionStrategy {
|
|
245
|
-
/// Uses the default strategy based on `BBRBeta`.
|
|
246
|
-
Default = 0,
|
|
247
|
-
|
|
248
|
-
/// Considers min-rtt to estimate bandwidth reduction.
|
|
249
|
-
MinRttReduction = 1,
|
|
250
|
-
|
|
251
|
-
/// Considers inflight data to estimate bandwidth reduction.
|
|
252
|
-
InflightReduction = 2,
|
|
253
|
-
|
|
254
|
-
/// Considers cwnd to estimate bandwidth reduction.
|
|
255
|
-
CwndReduction = 3,
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
#[doc(hidden)]
|
|
259
|
-
impl FromStr for BbrBwLoReductionStrategy {
|
|
260
|
-
type Err = crate::Error;
|
|
261
|
-
|
|
262
|
-
/// Converts a string to `BbrBwLoReductionStrategy`.
|
|
263
|
-
///
|
|
264
|
-
/// If `name` is not valid, `Error::CongestionControl` is returned.
|
|
265
|
-
fn from_str(name: &str) -> Result<Self, Self::Err> {
|
|
266
|
-
match name {
|
|
267
|
-
"default" => Ok(BbrBwLoReductionStrategy::Default),
|
|
268
|
-
"minrtt" => Ok(BbrBwLoReductionStrategy::MinRttReduction),
|
|
269
|
-
"inflight" => Ok(BbrBwLoReductionStrategy::InflightReduction),
|
|
270
|
-
"cwnd" => Ok(BbrBwLoReductionStrategy::CwndReduction),
|
|
271
|
-
|
|
272
|
-
_ => Err(crate::Error::CongestionControl),
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
1
|
+
// Copyright (C) 2024, 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
|
+
mod bbr;
|
|
28
|
+
mod bbr2;
|
|
29
|
+
pub mod pacer;
|
|
30
|
+
mod recovery;
|
|
31
|
+
|
|
32
|
+
use std::fmt::Debug;
|
|
33
|
+
use std::str::FromStr;
|
|
34
|
+
use std::time::Instant;
|
|
35
|
+
|
|
36
|
+
pub use self::recovery::GRecovery;
|
|
37
|
+
use crate::recovery::bandwidth::Bandwidth;
|
|
38
|
+
|
|
39
|
+
use crate::recovery::rtt::RttStats;
|
|
40
|
+
use crate::recovery::RecoveryStats;
|
|
41
|
+
|
|
42
|
+
#[derive(Debug)]
|
|
43
|
+
pub struct Lost {
|
|
44
|
+
pub(super) packet_number: u64,
|
|
45
|
+
pub(super) bytes_lost: usize,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[derive(Debug)]
|
|
49
|
+
pub struct Acked {
|
|
50
|
+
pub(super) pkt_num: u64,
|
|
51
|
+
pub(super) time_sent: Instant,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub(super) trait CongestionControl: Debug {
|
|
55
|
+
/// Returns the name of the current state of the congestion control state
|
|
56
|
+
/// machine. Used to annotate qlogs after state transitions.
|
|
57
|
+
#[cfg(feature = "qlog")]
|
|
58
|
+
fn state_str(&self) -> &'static str;
|
|
59
|
+
|
|
60
|
+
/// Returns the size of the current congestion window in bytes. Note, this
|
|
61
|
+
/// is not the *available* window. Some send algorithms may not use a
|
|
62
|
+
/// congestion window and will return 0.
|
|
63
|
+
fn get_congestion_window(&self) -> usize;
|
|
64
|
+
|
|
65
|
+
/// Returns the size of the current congestion window in packets. Note, this
|
|
66
|
+
/// is not the *available* window. Some send algorithms may not use a
|
|
67
|
+
/// congestion window and will return 0.
|
|
68
|
+
fn get_congestion_window_in_packets(&self) -> usize;
|
|
69
|
+
|
|
70
|
+
/// Make decision on whether the sender can send right now. Note that even
|
|
71
|
+
/// when this method returns true, the sending can be delayed due to pacing.
|
|
72
|
+
fn can_send(&self, bytes_in_flight: usize) -> bool;
|
|
73
|
+
|
|
74
|
+
/// Inform that we sent `bytes` to the wire, and if the packet is
|
|
75
|
+
/// retransmittable. `bytes_in_flight` is the number of bytes in flight
|
|
76
|
+
/// before the packet was sent. Note: this function must be called for
|
|
77
|
+
/// every packet sent to the wire.
|
|
78
|
+
fn on_packet_sent(
|
|
79
|
+
&mut self, sent_time: Instant, bytes_in_flight: usize,
|
|
80
|
+
packet_number: u64, bytes: usize, is_retransmissible: bool,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
/// Inform that `packet_number` has been neutered.
|
|
84
|
+
fn on_packet_neutered(&mut self, _packet_number: u64) {}
|
|
85
|
+
|
|
86
|
+
/// Indicates an update to the congestion state, caused either by an
|
|
87
|
+
/// incoming ack or loss event timeout. `rtt_updated` indicates whether a
|
|
88
|
+
/// new `latest_rtt` sample has been taken, `prior_in_flight` the bytes in
|
|
89
|
+
/// flight prior to the congestion event. `acked_packets` and `lost_packets`
|
|
90
|
+
/// are any packets considered acked or lost as a result of the
|
|
91
|
+
/// congestion event.
|
|
92
|
+
#[allow(clippy::too_many_arguments)]
|
|
93
|
+
fn on_congestion_event(
|
|
94
|
+
&mut self, rtt_updated: bool, prior_in_flight: usize,
|
|
95
|
+
bytes_in_flight: usize, event_time: Instant, acked_packets: &[Acked],
|
|
96
|
+
lost_packets: &[Lost], least_unacked: u64, rtt_stats: &RttStats,
|
|
97
|
+
recovery_stats: &mut RecoveryStats,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
/// Called when an RTO fires. Resets the retransmission alarm if there are
|
|
101
|
+
/// remaining unacked packets.
|
|
102
|
+
fn on_retransmission_timeout(&mut self, packets_retransmitted: bool);
|
|
103
|
+
|
|
104
|
+
/// Called when connection migrates and cwnd needs to be reset.
|
|
105
|
+
#[allow(dead_code)]
|
|
106
|
+
fn on_connection_migration(&mut self);
|
|
107
|
+
|
|
108
|
+
/// Adjust the current cwnd to a new maximal size
|
|
109
|
+
fn limit_cwnd(&mut self, _max_cwnd: usize) {}
|
|
110
|
+
|
|
111
|
+
fn is_in_recovery(&self) -> bool;
|
|
112
|
+
|
|
113
|
+
#[allow(dead_code)]
|
|
114
|
+
fn is_cwnd_limited(&self, bytes_in_flight: usize) -> bool;
|
|
115
|
+
|
|
116
|
+
fn pacing_rate(
|
|
117
|
+
&self, bytes_in_flight: usize, rtt_stats: &RttStats,
|
|
118
|
+
) -> Bandwidth;
|
|
119
|
+
|
|
120
|
+
fn bandwidth_estimate(&self, rtt_stats: &RttStats) -> Bandwidth;
|
|
121
|
+
|
|
122
|
+
fn max_bandwidth(&self) -> Bandwidth;
|
|
123
|
+
|
|
124
|
+
fn update_mss(&mut self, new_mss: usize);
|
|
125
|
+
|
|
126
|
+
fn on_app_limited(&mut self, _bytes_in_flight: usize) {}
|
|
127
|
+
|
|
128
|
+
#[cfg(feature = "qlog")]
|
|
129
|
+
fn ssthresh(&self) -> Option<u64> {
|
|
130
|
+
None
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// BBR settings used to customize the algorithm's behavior.
|
|
135
|
+
///
|
|
136
|
+
/// This functionality is experimental and will be removed in the future.
|
|
137
|
+
///
|
|
138
|
+
/// A congestion control algorithm has dual-responsibility of effective network
|
|
139
|
+
/// utilization and avoiding congestion. Custom values should be choosen
|
|
140
|
+
/// carefully since incorrect values can lead to network degradation for all
|
|
141
|
+
/// connections on the shared network.
|
|
142
|
+
#[derive(Debug, Default, Copy, Clone, PartialEq)]
|
|
143
|
+
#[repr(C)]
|
|
144
|
+
#[doc(hidden)]
|
|
145
|
+
pub struct BbrParams {
|
|
146
|
+
/// Controls the BBR startup gain.
|
|
147
|
+
pub startup_cwnd_gain: Option<f32>,
|
|
148
|
+
|
|
149
|
+
/// Controls the BBR startup pacing gain.
|
|
150
|
+
pub startup_pacing_gain: Option<f32>,
|
|
151
|
+
|
|
152
|
+
/// Controls the BBR full bandwidth threshold.
|
|
153
|
+
pub full_bw_threshold: Option<f32>,
|
|
154
|
+
|
|
155
|
+
/// Controls the number of rounds to stay in STARTUP before
|
|
156
|
+
/// exiting due to bandwidth plateau.
|
|
157
|
+
pub startup_full_bw_rounds: Option<usize>,
|
|
158
|
+
|
|
159
|
+
/// Controls the BBR startup loss count necessary to exit startup.
|
|
160
|
+
pub startup_full_loss_count: Option<usize>,
|
|
161
|
+
|
|
162
|
+
/// Controls the BBR drain cwnd gain.
|
|
163
|
+
pub drain_cwnd_gain: Option<f32>,
|
|
164
|
+
|
|
165
|
+
/// Controls the BBR drain pacing gain.
|
|
166
|
+
pub drain_pacing_gain: Option<f32>,
|
|
167
|
+
|
|
168
|
+
/// Controls if BBR should respect Reno coexistence.
|
|
169
|
+
pub enable_reno_coexistence: Option<bool>,
|
|
170
|
+
|
|
171
|
+
/// Controls if BBR should enable code in Bandwidth Sampler that
|
|
172
|
+
/// attempts to avoid overestimating bandwidth on ack compression.
|
|
173
|
+
pub enable_overestimate_avoidance: Option<bool>,
|
|
174
|
+
|
|
175
|
+
/// Controls if BBR should enable a possible fix in Bandwidth
|
|
176
|
+
/// Sampler that attempts to bandwidth over estimation avoidance.
|
|
177
|
+
pub choose_a0_point_fix: Option<bool>,
|
|
178
|
+
|
|
179
|
+
/// Controls the BBR bandwidth probe up pacing gain.
|
|
180
|
+
pub probe_bw_probe_up_pacing_gain: Option<f32>,
|
|
181
|
+
|
|
182
|
+
/// Controls the BBR bandwidth probe down pacing gain.
|
|
183
|
+
pub probe_bw_probe_down_pacing_gain: Option<f32>,
|
|
184
|
+
|
|
185
|
+
/// Controls the BBR probe bandwidth DOWN/CRUISE/REFILL cwnd gain.
|
|
186
|
+
pub probe_bw_cwnd_gain: Option<f32>,
|
|
187
|
+
|
|
188
|
+
/// Controls the BBR probe bandwidth UP cwnd gain.
|
|
189
|
+
pub probe_bw_up_cwnd_gain: Option<f32>,
|
|
190
|
+
|
|
191
|
+
/// Controls the BBR probe RTT pacing gain.
|
|
192
|
+
pub probe_rtt_pacing_gain: Option<f32>,
|
|
193
|
+
|
|
194
|
+
/// Controls the BBR probe RTT cwnd gain.
|
|
195
|
+
pub probe_rtt_cwnd_gain: Option<f32>,
|
|
196
|
+
|
|
197
|
+
/// Controls the number of rounds BBR should stay in probe up if
|
|
198
|
+
/// bytes_in_flight doesn't drop below target.
|
|
199
|
+
pub max_probe_up_queue_rounds: Option<usize>,
|
|
200
|
+
|
|
201
|
+
/// Controls the BBR loss threshold.
|
|
202
|
+
pub loss_threshold: Option<f32>,
|
|
203
|
+
|
|
204
|
+
/// Controls if BBR should use bytes delievered as an estimate for
|
|
205
|
+
/// inflight_hi.
|
|
206
|
+
pub use_bytes_delivered_for_inflight_hi: Option<bool>,
|
|
207
|
+
|
|
208
|
+
/// Controls if BBR should adjust startup pacing at round end.
|
|
209
|
+
pub decrease_startup_pacing_at_end_of_round: Option<bool>,
|
|
210
|
+
|
|
211
|
+
/// Controls the BBR bandwidth lo reduction strategy.
|
|
212
|
+
pub bw_lo_reduction_strategy: Option<BbrBwLoReductionStrategy>,
|
|
213
|
+
|
|
214
|
+
/// Determines whether app limited rounds with no bandwidth growth count
|
|
215
|
+
/// towards the rounds threshold to exit startup.
|
|
216
|
+
pub ignore_app_limited_for_no_bandwidth_growth: Option<bool>,
|
|
217
|
+
|
|
218
|
+
/// Initial pacing rate for a new connection before an RTT
|
|
219
|
+
/// estimate is available. This rate serves as an upper bound on
|
|
220
|
+
/// the initial pacing rate, which is calculated by dividing the
|
|
221
|
+
/// initial cwnd by the first RTT estimate.
|
|
222
|
+
pub initial_pacing_rate_bytes_per_second: Option<u64>,
|
|
223
|
+
|
|
224
|
+
/// If true, scale the pacing rate when updating mss when doing pmtud.
|
|
225
|
+
pub scale_pacing_rate_by_mss: Option<bool>,
|
|
226
|
+
|
|
227
|
+
/// Disable `has_stayed_long_enough_in_probe_down` which can cause ProbeDown
|
|
228
|
+
/// to exit early.
|
|
229
|
+
pub disable_probe_down_early_exit: Option<bool>,
|
|
230
|
+
|
|
231
|
+
/// Set the expected send time for packets when using BBR to `now`
|
|
232
|
+
/// instead of `get_next_release_time()`. Setting the time based
|
|
233
|
+
/// on `get_next_release_time()` can result in artificially low
|
|
234
|
+
/// minRTT measurements which will make BBR misbehave.
|
|
235
|
+
pub time_sent_set_to_now: Option<bool>,
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/// Controls BBR's bandwidth reduction strategy on congestion event.
|
|
239
|
+
///
|
|
240
|
+
/// This functionality is experimental and will be removed in the future.
|
|
241
|
+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
242
|
+
#[repr(C)]
|
|
243
|
+
#[doc(hidden)]
|
|
244
|
+
pub enum BbrBwLoReductionStrategy {
|
|
245
|
+
/// Uses the default strategy based on `BBRBeta`.
|
|
246
|
+
Default = 0,
|
|
247
|
+
|
|
248
|
+
/// Considers min-rtt to estimate bandwidth reduction.
|
|
249
|
+
MinRttReduction = 1,
|
|
250
|
+
|
|
251
|
+
/// Considers inflight data to estimate bandwidth reduction.
|
|
252
|
+
InflightReduction = 2,
|
|
253
|
+
|
|
254
|
+
/// Considers cwnd to estimate bandwidth reduction.
|
|
255
|
+
CwndReduction = 3,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#[doc(hidden)]
|
|
259
|
+
impl FromStr for BbrBwLoReductionStrategy {
|
|
260
|
+
type Err = crate::Error;
|
|
261
|
+
|
|
262
|
+
/// Converts a string to `BbrBwLoReductionStrategy`.
|
|
263
|
+
///
|
|
264
|
+
/// If `name` is not valid, `Error::CongestionControl` is returned.
|
|
265
|
+
fn from_str(name: &str) -> Result<Self, Self::Err> {
|
|
266
|
+
match name {
|
|
267
|
+
"default" => Ok(BbrBwLoReductionStrategy::Default),
|
|
268
|
+
"minrtt" => Ok(BbrBwLoReductionStrategy::MinRttReduction),
|
|
269
|
+
"inflight" => Ok(BbrBwLoReductionStrategy::InflightReduction),
|
|
270
|
+
"cwnd" => Ok(BbrBwLoReductionStrategy::CwndReduction),
|
|
271
|
+
|
|
272
|
+
_ => Err(crate::Error::CongestionControl),
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|