rwebtransport 0.1.0

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.
Files changed (122) hide show
  1. package/Cargo.lock +666 -0
  2. package/Cargo.toml +31 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +41 -0
  5. package/README.md +550 -0
  6. package/crates/echo-server/Cargo.toml +20 -0
  7. package/crates/echo-server/src/main.rs +666 -0
  8. package/crates/native/Cargo.toml +23 -0
  9. package/crates/native/src/config.rs +129 -0
  10. package/crates/native/src/driver.rs +463 -0
  11. package/crates/native/src/lib.rs +821 -0
  12. package/crates/native/src/server.rs +718 -0
  13. package/crates/native/src/session.rs +1191 -0
  14. package/crates/native/src/tls.rs +96 -0
  15. package/crates/wtcore/Cargo.toml +15 -0
  16. package/crates/wtcore/src/h3.rs +226 -0
  17. package/crates/wtcore/src/lib.rs +9 -0
  18. package/dist/datagrams.d.ts +16 -0
  19. package/dist/errors.d.ts +10 -0
  20. package/dist/index.d.ts +7 -0
  21. package/dist/index.js +1512 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/index.mjs +1473 -0
  24. package/dist/index.mjs.map +1 -0
  25. package/dist/loader.d.ts +2 -0
  26. package/dist/native.d.ts +226 -0
  27. package/dist/server.d.ts +44 -0
  28. package/dist/streams.d.ts +14 -0
  29. package/dist/types.d.ts +24 -0
  30. package/dist/webtransport.d.ts +20 -0
  31. package/package.json +79 -0
  32. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  33. package/scripts/bench.mjs +180 -0
  34. package/scripts/build.js +67 -0
  35. package/scripts/postinstall.js +67 -0
  36. package/scripts/setup-unix.sh +129 -0
  37. package/scripts/setup-windows.ps1 +229 -0
  38. package/vendor/quiche/AGENTS.md +75 -0
  39. package/vendor/quiche/COPYING +23 -0
  40. package/vendor/quiche/Cargo.lock +1212 -0
  41. package/vendor/quiche/Cargo.toml +215 -0
  42. package/vendor/quiche/README.md +466 -0
  43. package/vendor/quiche/examples/Makefile +46 -0
  44. package/vendor/quiche/examples/README.md +20 -0
  45. package/vendor/quiche/examples/cert-big.crt +90 -0
  46. package/vendor/quiche/examples/cert.crt +18 -0
  47. package/vendor/quiche/examples/cert.key +28 -0
  48. package/vendor/quiche/examples/client.c +343 -0
  49. package/vendor/quiche/examples/client.rs +281 -0
  50. package/vendor/quiche/examples/gen-certs.sh +15 -0
  51. package/vendor/quiche/examples/http3-client.c +473 -0
  52. package/vendor/quiche/examples/http3-client.rs +349 -0
  53. package/vendor/quiche/examples/http3-server.c +614 -0
  54. package/vendor/quiche/examples/http3-server.rs +680 -0
  55. package/vendor/quiche/examples/qpack-decode.rs +87 -0
  56. package/vendor/quiche/examples/qpack-encode.rs +88 -0
  57. package/vendor/quiche/examples/rootca.crt +21 -0
  58. package/vendor/quiche/examples/server.c +529 -0
  59. package/vendor/quiche/examples/server.rs +529 -0
  60. package/vendor/quiche/include/quiche.h +1282 -0
  61. package/vendor/quiche/quiche.svg +1 -0
  62. package/vendor/quiche/src/buffers.rs +105 -0
  63. package/vendor/quiche/src/build.rs +66 -0
  64. package/vendor/quiche/src/cid.rs +1079 -0
  65. package/vendor/quiche/src/crypto/boringssl.rs +373 -0
  66. package/vendor/quiche/src/crypto/mod.rs +671 -0
  67. package/vendor/quiche/src/dgram.rs +118 -0
  68. package/vendor/quiche/src/error.rs +263 -0
  69. package/vendor/quiche/src/ffi.rs +2290 -0
  70. package/vendor/quiche/src/flowcontrol.rs +246 -0
  71. package/vendor/quiche/src/frame.rs +2172 -0
  72. package/vendor/quiche/src/h3/AGENTS.md +54 -0
  73. package/vendor/quiche/src/h3/ffi.rs +442 -0
  74. package/vendor/quiche/src/h3/frame.rs +1404 -0
  75. package/vendor/quiche/src/h3/mod.rs +8223 -0
  76. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -0
  77. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -0
  78. package/vendor/quiche/src/h3/qpack/mod.rs +202 -0
  79. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -0
  80. package/vendor/quiche/src/h3/stream.rs +1595 -0
  81. package/vendor/quiche/src/lib.rs +9556 -0
  82. package/vendor/quiche/src/minmax.rs +446 -0
  83. package/vendor/quiche/src/packet.rs +2334 -0
  84. package/vendor/quiche/src/path.rs +1374 -0
  85. package/vendor/quiche/src/pmtud.rs +652 -0
  86. package/vendor/quiche/src/rand.rs +64 -0
  87. package/vendor/quiche/src/range_buf.rs +186 -0
  88. package/vendor/quiche/src/ranges.rs +755 -0
  89. package/vendor/quiche/src/recovery/AGENTS.md +80 -0
  90. package/vendor/quiche/src/recovery/bandwidth.rs +565 -0
  91. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -0
  92. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -0
  93. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -0
  94. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -0
  95. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -0
  96. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -0
  97. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -0
  98. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -0
  99. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -0
  100. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -0
  101. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -0
  102. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -0
  103. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -0
  104. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -0
  105. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -0
  106. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -0
  107. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -0
  108. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -0
  109. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -0
  110. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -0
  111. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -0
  112. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -0
  113. package/vendor/quiche/src/recovery/mod.rs +3086 -0
  114. package/vendor/quiche/src/recovery/rtt.rs +152 -0
  115. package/vendor/quiche/src/stream/mod.rs +2210 -0
  116. package/vendor/quiche/src/stream/recv_buf.rs +1236 -0
  117. package/vendor/quiche/src/stream/send_buf.rs +849 -0
  118. package/vendor/quiche/src/test_utils.rs +681 -0
  119. package/vendor/quiche/src/tests.rs +12922 -0
  120. package/vendor/quiche/src/tls/boringssl.rs +375 -0
  121. package/vendor/quiche/src/tls/mod.rs +1245 -0
  122. package/vendor/quiche/src/transport_params.rs +628 -0
@@ -0,0 +1,291 @@
1
+ // Copyright (C) 2019, 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
+ //! Reno Congestion Control
28
+ //!
29
+ //! Note that Slow Start can use HyStart++ when enabled.
30
+
31
+ use std::cmp;
32
+ use std::time::Instant;
33
+
34
+ use super::rtt::RttStats;
35
+ use super::Acked;
36
+ use super::Sent;
37
+
38
+ use super::Congestion;
39
+ use super::CongestionControlOps;
40
+ use crate::recovery::LOSS_REDUCTION_FACTOR;
41
+ use crate::recovery::MINIMUM_WINDOW_PACKETS;
42
+
43
+ pub(crate) static RENO: CongestionControlOps = CongestionControlOps {
44
+ on_init,
45
+ on_packet_sent,
46
+ on_packets_acked,
47
+ congestion_event,
48
+ checkpoint,
49
+ rollback,
50
+ #[cfg(feature = "qlog")]
51
+ state_str,
52
+ debug_fmt,
53
+ };
54
+
55
+ pub fn on_init(_r: &mut Congestion) {}
56
+
57
+ pub fn on_packet_sent(
58
+ _r: &mut Congestion, _sent_bytes: usize, _bytes_in_flight: usize,
59
+ _now: Instant,
60
+ ) {
61
+ }
62
+
63
+ fn on_packets_acked(
64
+ r: &mut Congestion, _bytes_in_flight: usize, packets: &mut Vec<Acked>,
65
+ now: Instant, rtt_stats: &RttStats,
66
+ ) {
67
+ for pkt in packets.drain(..) {
68
+ on_packet_acked(r, &pkt, now, rtt_stats);
69
+ }
70
+ }
71
+
72
+ fn on_packet_acked(
73
+ r: &mut Congestion, packet: &Acked, now: Instant, rtt_stats: &RttStats,
74
+ ) {
75
+ if r.in_congestion_recovery(packet.time_sent) {
76
+ return;
77
+ }
78
+
79
+ if r.app_limited {
80
+ return;
81
+ }
82
+
83
+ if r.congestion_window < r.ssthresh.get() {
84
+ // In Slow slart, bytes_acked_sl is used for counting
85
+ // acknowledged bytes.
86
+ r.bytes_acked_sl += packet.size;
87
+
88
+ if r.hystart.in_css() {
89
+ r.congestion_window += r.hystart.css_cwnd_inc(r.max_datagram_size);
90
+ } else {
91
+ r.congestion_window += r.max_datagram_size;
92
+ }
93
+
94
+ if r.hystart.on_packet_acked(packet, rtt_stats.latest_rtt, now) {
95
+ // Exit to congestion avoidance if CSS ends.
96
+ r.ssthresh.update(r.congestion_window, true);
97
+ }
98
+ } else {
99
+ // Congestion avoidance.
100
+ r.bytes_acked_ca += packet.size;
101
+
102
+ if r.bytes_acked_ca >= r.congestion_window {
103
+ r.bytes_acked_ca -= r.congestion_window;
104
+ r.congestion_window += r.max_datagram_size;
105
+ }
106
+ }
107
+ }
108
+
109
+ fn congestion_event(
110
+ r: &mut Congestion, _bytes_in_flight: usize, _lost_bytes: usize,
111
+ largest_lost_pkt: &Sent, now: Instant,
112
+ ) {
113
+ // Start a new congestion event if packet was sent after the
114
+ // start of the previous congestion recovery period.
115
+ let time_sent = largest_lost_pkt.time_sent;
116
+
117
+ if !r.in_congestion_recovery(time_sent) {
118
+ r.congestion_recovery_start_time = Some(now);
119
+
120
+ r.congestion_window =
121
+ (r.congestion_window as f64 * LOSS_REDUCTION_FACTOR) as usize;
122
+
123
+ r.congestion_window = cmp::max(
124
+ r.congestion_window,
125
+ r.max_datagram_size * MINIMUM_WINDOW_PACKETS,
126
+ );
127
+
128
+ r.bytes_acked_ca =
129
+ (r.congestion_window as f64 * LOSS_REDUCTION_FACTOR) as usize;
130
+
131
+ r.ssthresh.update(r.congestion_window, r.hystart.in_css());
132
+
133
+ if r.hystart.in_css() {
134
+ r.hystart.congestion_event();
135
+ }
136
+ }
137
+ }
138
+
139
+ fn checkpoint(_r: &mut Congestion) {}
140
+
141
+ fn rollback(_r: &mut Congestion) -> bool {
142
+ true
143
+ }
144
+
145
+ #[cfg(feature = "qlog")]
146
+ pub fn state_str(r: &Congestion, now: Instant) -> &'static str {
147
+ if r.hystart.in_css() {
148
+ "conservative_slow_start"
149
+ } else if r.congestion_window < r.ssthresh.get() {
150
+ "slow_start"
151
+ } else if r.in_congestion_recovery(now) {
152
+ "recovery"
153
+ } else {
154
+ "congestion_avoidance"
155
+ }
156
+ }
157
+
158
+ fn debug_fmt(_r: &Congestion, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
159
+ Ok(())
160
+ }
161
+
162
+ #[cfg(test)]
163
+ mod tests {
164
+ use crate::CongestionControlAlgorithm;
165
+
166
+ use super::*;
167
+
168
+ use crate::recovery::congestion::recovery::LegacyRecovery;
169
+ use crate::recovery::congestion::test_sender::TestSender;
170
+ use crate::recovery::RecoveryOps;
171
+
172
+ use std::time::Duration;
173
+
174
+ fn test_sender() -> TestSender {
175
+ TestSender::new(CongestionControlAlgorithm::Reno, false)
176
+ }
177
+
178
+ #[test]
179
+ fn reno_init() {
180
+ let mut cfg = crate::Config::new(crate::PROTOCOL_VERSION).unwrap();
181
+ cfg.set_cc_algorithm(CongestionControlAlgorithm::Reno);
182
+
183
+ let r = LegacyRecovery::new(&cfg);
184
+
185
+ assert!(r.cwnd() > 0);
186
+ assert_eq!(r.bytes_in_flight(), 0);
187
+ }
188
+
189
+ #[test]
190
+ fn reno_slow_start() {
191
+ let mut sender = test_sender();
192
+ let size = sender.max_datagram_size;
193
+
194
+ // Send initcwnd full MSS packets to become no longer app limited
195
+ for _ in 0..sender.initial_congestion_window_packets {
196
+ sender.send_packet(size);
197
+ }
198
+
199
+ let cwnd_prev = sender.congestion_window;
200
+
201
+ sender.ack_n_packets(1, size);
202
+
203
+ // Check if cwnd increased by packet size (slow start).
204
+ assert_eq!(sender.congestion_window, cwnd_prev + size);
205
+ }
206
+
207
+ #[test]
208
+ fn reno_slow_start_multi_acks() {
209
+ let mut sender = test_sender();
210
+ let size = sender.max_datagram_size;
211
+
212
+ // Send initcwnd full MSS packets to become no longer app limited
213
+ for _ in 0..sender.initial_congestion_window_packets {
214
+ sender.send_packet(size);
215
+ }
216
+
217
+ let cwnd_prev = sender.congestion_window;
218
+
219
+ sender.ack_n_packets(3, size);
220
+
221
+ // Acked 3 packets.
222
+ assert_eq!(sender.congestion_window, cwnd_prev + size * 3);
223
+ }
224
+
225
+ #[test]
226
+ fn reno_congestion_event() {
227
+ let mut sender = test_sender();
228
+ let size = sender.max_datagram_size;
229
+
230
+ let prev_cwnd = sender.congestion_window;
231
+
232
+ sender.send_packet(size);
233
+ sender.lose_n_packets(1, size, None);
234
+
235
+ // In Reno, after congestion event, cwnd will be cut in half.
236
+ assert_eq!(prev_cwnd / 2, sender.congestion_window);
237
+ }
238
+
239
+ #[test]
240
+ fn reno_congestion_avoidance() {
241
+ let mut sender = test_sender();
242
+ let size = sender.max_datagram_size;
243
+
244
+ // Send initcwnd full MSS packets to become no longer app limited
245
+ for _ in 0..14 {
246
+ sender.send_packet(size);
247
+ }
248
+
249
+ let rtt = Duration::from_millis(100);
250
+ let prev_cwnd = sender.congestion_window;
251
+
252
+ sender.advance_time(rtt);
253
+ sender.lose_n_packets(1, size, None);
254
+
255
+ // After congestion event, cwnd will be reduced.
256
+ let cur_cwnd = (prev_cwnd as f64 * LOSS_REDUCTION_FACTOR) as usize;
257
+ assert_eq!(sender.congestion_window, cur_cwnd);
258
+
259
+ sender.update_rtt(rtt);
260
+ sender.advance_time(2 * rtt);
261
+
262
+ sender.ack_n_packets(13, size);
263
+ // Acked packets were sent before the loss event, window does not
264
+ // increase.
265
+ assert_eq!(sender.congestion_window, cur_cwnd);
266
+
267
+ for _ in 0..7 {
268
+ sender.send_packet(size);
269
+ }
270
+ sender.advance_time(rtt);
271
+ sender.ack_n_packets(2, size);
272
+ // Not enough ACKed, window does not increase.
273
+ assert_eq!(sender.congestion_window, cur_cwnd);
274
+
275
+ sender.ack_n_packets(1, size);
276
+ // Expect cwnd increased by MSS
277
+ assert_eq!(sender.congestion_window, cur_cwnd + size);
278
+
279
+ for _ in 0..7 {
280
+ sender.send_packet(size);
281
+ }
282
+
283
+ // Expect a second window increase after a cwnd's worth of ACKs.
284
+ sender.ack_n_packets(5, size);
285
+ // Not yet, one more ACK needed.
286
+ assert_eq!(sender.congestion_window, cur_cwnd + size);
287
+ sender.ack_n_packets(1, size);
288
+ // Expect cwnd increased by MSS
289
+ assert_eq!(sender.congestion_window, cur_cwnd + 2 * size);
290
+ }
291
+ }
@@ -0,0 +1,201 @@
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
+ use std::collections::VecDeque;
28
+ use std::ops::Deref;
29
+ use std::ops::DerefMut;
30
+ use std::time::Duration;
31
+ use std::time::Instant;
32
+
33
+ use super::rtt::RttStats;
34
+ use super::Acked;
35
+ use super::Congestion;
36
+ use super::RecoveryConfig;
37
+ use super::Sent;
38
+ use crate::CongestionControlAlgorithm;
39
+ use crate::DEFAULT_INITIAL_RTT;
40
+
41
+ pub(crate) struct TestSender {
42
+ cc: Congestion,
43
+ pub(crate) next_pkt: u64,
44
+ pub(crate) next_ack: u64,
45
+ pub(crate) bytes_in_flight: usize,
46
+ pub(crate) time: Instant,
47
+ rtt_stats: RttStats,
48
+ sent_packets: VecDeque<Sent>,
49
+ }
50
+
51
+ impl TestSender {
52
+ pub(crate) fn new(algo: CongestionControlAlgorithm, hystart: bool) -> Self {
53
+ let mut cfg = crate::Config::new(crate::PROTOCOL_VERSION).unwrap();
54
+ cfg.set_cc_algorithm(algo);
55
+ cfg.enable_hystart(hystart);
56
+
57
+ TestSender {
58
+ next_pkt: 0,
59
+ next_ack: 0,
60
+ bytes_in_flight: 0,
61
+ time: Instant::now(),
62
+ rtt_stats: RttStats::new(
63
+ DEFAULT_INITIAL_RTT,
64
+ Duration::from_micros(0),
65
+ ),
66
+ cc: Congestion::from_config(&RecoveryConfig::from_config(&cfg)),
67
+ sent_packets: VecDeque::new(),
68
+ }
69
+ }
70
+
71
+ pub(crate) fn send_packet(&mut self, bytes: usize) {
72
+ let mut sent = Sent {
73
+ pkt_num: self.next_pkt,
74
+ frames: Default::default(),
75
+ time_sent: self.time,
76
+ time_acked: None,
77
+ time_lost: None,
78
+ size: bytes,
79
+ ack_eliciting: true,
80
+ in_flight: true,
81
+ delivered: 0,
82
+ delivered_time: self.time,
83
+ first_sent_time: self.time,
84
+ is_app_limited: false,
85
+ tx_in_flight: 0,
86
+ lost: 0,
87
+ has_data: false,
88
+ is_pmtud_probe: false,
89
+ };
90
+
91
+ self.cc.on_packet_sent(
92
+ self.bytes_in_flight,
93
+ bytes,
94
+ self.time,
95
+ &mut sent,
96
+ 0,
97
+ true,
98
+ );
99
+
100
+ self.sent_packets.push_back(sent);
101
+
102
+ self.bytes_in_flight += bytes;
103
+ self.next_pkt += 1;
104
+ }
105
+
106
+ pub(crate) fn inject_ack(&mut self, acked: Acked, now: Instant) {
107
+ let _ = self.sent_packets.pop_front().unwrap();
108
+
109
+ self.cc.on_packets_acked(
110
+ self.bytes_in_flight,
111
+ &mut vec![acked],
112
+ &self.rtt_stats,
113
+ now,
114
+ );
115
+ }
116
+
117
+ pub(crate) fn ack_n_packets(&mut self, n: usize, bytes: usize) {
118
+ let mut acked = Vec::new();
119
+
120
+ for _ in 0..n {
121
+ let unacked = self.sent_packets.pop_front().unwrap();
122
+
123
+ acked.push(Acked {
124
+ pkt_num: unacked.pkt_num,
125
+ time_sent: unacked.time_sent,
126
+ size: unacked.size,
127
+
128
+ rtt: self.time.saturating_duration_since(unacked.time_sent),
129
+ delivered: unacked.delivered,
130
+ delivered_time: unacked.delivered_time,
131
+ first_sent_time: unacked.first_sent_time,
132
+ is_app_limited: unacked.is_app_limited,
133
+ });
134
+
135
+ self.next_ack += 1;
136
+ }
137
+
138
+ self.cc.on_packets_acked(
139
+ self.bytes_in_flight,
140
+ &mut acked,
141
+ &self.rtt_stats,
142
+ self.time,
143
+ );
144
+
145
+ self.bytes_in_flight -= n * bytes;
146
+ }
147
+
148
+ pub(crate) fn lose_n_packets(
149
+ &mut self, n: usize, bytes: usize, time_sent: Option<Instant>,
150
+ ) {
151
+ let mut unacked = None;
152
+
153
+ for _ in 0..n {
154
+ self.next_ack += 1;
155
+ unacked = self.sent_packets.pop_front();
156
+ }
157
+
158
+ let mut unacked = unacked.unwrap();
159
+ if let Some(time) = time_sent {
160
+ unacked.time_sent = time;
161
+ }
162
+
163
+ if !self.cc.in_congestion_recovery(unacked.time_sent) {
164
+ (self.cc.cc_ops.checkpoint)(&mut self.cc);
165
+ }
166
+
167
+ (self.cc_ops.congestion_event)(
168
+ &mut self.cc,
169
+ self.bytes_in_flight,
170
+ n * bytes,
171
+ &unacked,
172
+ self.time,
173
+ );
174
+
175
+ self.cc.lost_count += n;
176
+ self.bytes_in_flight -= n * bytes;
177
+ }
178
+
179
+ pub(crate) fn update_rtt(&mut self, rtt: Duration) {
180
+ self.rtt_stats
181
+ .update_rtt(rtt, Duration::ZERO, self.time, true)
182
+ }
183
+
184
+ pub(crate) fn advance_time(&mut self, period: Duration) {
185
+ self.time += period;
186
+ }
187
+ }
188
+
189
+ impl Deref for TestSender {
190
+ type Target = Congestion;
191
+
192
+ fn deref(&self) -> &Self::Target {
193
+ &self.cc
194
+ }
195
+ }
196
+
197
+ impl DerefMut for TestSender {
198
+ fn deref_mut(&mut self) -> &mut Self::Target {
199
+ &mut self.cc
200
+ }
201
+ }