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.
Files changed (113) hide show
  1. package/Cargo.lock +666 -666
  2. package/Cargo.toml +31 -31
  3. package/LICENSE +202 -202
  4. package/NOTICE +41 -41
  5. package/README.md +550 -550
  6. package/crates/echo-server/Cargo.toml +20 -20
  7. package/crates/echo-server/src/main.rs +666 -666
  8. package/crates/native/Cargo.toml +23 -23
  9. package/crates/native/src/config.rs +129 -129
  10. package/crates/native/src/driver.rs +463 -463
  11. package/crates/native/src/lib.rs +821 -821
  12. package/crates/native/src/server.rs +718 -718
  13. package/crates/native/src/session.rs +1191 -1191
  14. package/crates/native/src/tls.rs +96 -96
  15. package/crates/wtcore/Cargo.toml +15 -15
  16. package/crates/wtcore/src/h3.rs +226 -226
  17. package/crates/wtcore/src/lib.rs +9 -9
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +80 -79
  21. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  24. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  25. package/scripts/bench.mjs +180 -180
  26. package/scripts/build.js +67 -67
  27. package/scripts/postinstall.js +67 -67
  28. package/scripts/setup-unix.sh +129 -129
  29. package/scripts/setup-windows.ps1 +229 -229
  30. package/vendor/quiche/AGENTS.md +75 -75
  31. package/vendor/quiche/COPYING +23 -23
  32. package/vendor/quiche/Cargo.lock +1212 -1212
  33. package/vendor/quiche/Cargo.toml +215 -215
  34. package/vendor/quiche/README.md +466 -466
  35. package/vendor/quiche/examples/Makefile +46 -46
  36. package/vendor/quiche/examples/README.md +20 -20
  37. package/vendor/quiche/examples/cert-big.crt +90 -90
  38. package/vendor/quiche/examples/cert.crt +18 -18
  39. package/vendor/quiche/examples/cert.key +28 -28
  40. package/vendor/quiche/examples/client.c +343 -343
  41. package/vendor/quiche/examples/client.rs +281 -281
  42. package/vendor/quiche/examples/gen-certs.sh +15 -15
  43. package/vendor/quiche/examples/http3-client.c +473 -473
  44. package/vendor/quiche/examples/http3-client.rs +349 -349
  45. package/vendor/quiche/examples/http3-server.c +614 -614
  46. package/vendor/quiche/examples/http3-server.rs +680 -680
  47. package/vendor/quiche/examples/qpack-decode.rs +87 -87
  48. package/vendor/quiche/examples/qpack-encode.rs +88 -88
  49. package/vendor/quiche/examples/rootca.crt +21 -21
  50. package/vendor/quiche/examples/server.c +529 -529
  51. package/vendor/quiche/examples/server.rs +529 -529
  52. package/vendor/quiche/include/quiche.h +1282 -1282
  53. package/vendor/quiche/src/buffers.rs +105 -105
  54. package/vendor/quiche/src/build.rs +66 -66
  55. package/vendor/quiche/src/cid.rs +1079 -1079
  56. package/vendor/quiche/src/crypto/boringssl.rs +373 -373
  57. package/vendor/quiche/src/crypto/mod.rs +671 -671
  58. package/vendor/quiche/src/dgram.rs +118 -118
  59. package/vendor/quiche/src/error.rs +263 -263
  60. package/vendor/quiche/src/ffi.rs +2290 -2290
  61. package/vendor/quiche/src/flowcontrol.rs +246 -246
  62. package/vendor/quiche/src/frame.rs +2172 -2172
  63. package/vendor/quiche/src/h3/AGENTS.md +54 -54
  64. package/vendor/quiche/src/h3/ffi.rs +442 -442
  65. package/vendor/quiche/src/h3/frame.rs +1404 -1404
  66. package/vendor/quiche/src/h3/mod.rs +8223 -8223
  67. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
  68. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
  69. package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
  70. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
  71. package/vendor/quiche/src/h3/stream.rs +1595 -1595
  72. package/vendor/quiche/src/lib.rs +9556 -9556
  73. package/vendor/quiche/src/minmax.rs +446 -446
  74. package/vendor/quiche/src/packet.rs +2334 -2334
  75. package/vendor/quiche/src/path.rs +1374 -1374
  76. package/vendor/quiche/src/pmtud.rs +652 -652
  77. package/vendor/quiche/src/rand.rs +64 -64
  78. package/vendor/quiche/src/range_buf.rs +186 -186
  79. package/vendor/quiche/src/ranges.rs +755 -755
  80. package/vendor/quiche/src/recovery/AGENTS.md +80 -80
  81. package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
  82. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
  83. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
  84. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
  85. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
  86. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
  87. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
  88. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
  89. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
  90. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
  91. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
  92. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
  93. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
  94. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
  95. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
  96. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
  97. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
  98. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
  99. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
  100. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
  101. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
  102. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
  103. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
  104. package/vendor/quiche/src/recovery/mod.rs +3086 -3086
  105. package/vendor/quiche/src/recovery/rtt.rs +152 -152
  106. package/vendor/quiche/src/stream/mod.rs +2210 -2210
  107. package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
  108. package/vendor/quiche/src/stream/send_buf.rs +849 -849
  109. package/vendor/quiche/src/test_utils.rs +681 -681
  110. package/vendor/quiche/src/tests.rs +12922 -12922
  111. package/vendor/quiche/src/tls/boringssl.rs +375 -375
  112. package/vendor/quiche/src/tls/mod.rs +1245 -1245
  113. package/vendor/quiche/src/transport_params.rs +628 -628
@@ -1,158 +1,158 @@
1
- // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- // Implements Kathleen Nichols' algorithm for tracking the minimum (or maximum)
6
- // estimate of a stream of samples over some fixed time interval. (E.g.,
7
- // the minimum RTT over the past five minutes.) The algorithm keeps track of
8
- // the best, second best, and third best min (or max) estimates, maintaining an
9
- // invariant that the measurement time of the n'th best >= n-1'th best.
10
-
11
- // The algorithm works as follows. On a reset, all three estimates are set to
12
- // the same sample. The second best estimate is then recorded in the second
13
- // quarter of the window, and a third best estimate is recorded in the second
14
- // half of the window, bounding the worst case error when the true min is
15
- // monotonically increasing (or true max is monotonically decreasing) over the
16
- // window.
17
- //
18
- // A new best sample replaces all three estimates, since the new best is lower
19
- // (or higher) than everything else in the window and it is the most recent.
20
- // The window thus effectively gets reset on every new min. The same property
21
- // holds true for second best and third best estimates. Specifically, when a
22
- // sample arrives that is better than the second best but not better than the
23
- // best, it replaces the second and third best estimates but not the best
24
- // estimate. Similarly, a sample that is better than the third best estimate
25
- // but not the other estimates replaces only the third best estimate.
26
- //
27
- // Finally, when the best expires, it is replaced by the second best, which in
28
- // turn is replaced by the third best. The newest sample replaces the third
29
- // best.
30
-
31
- use std::ops::Div;
32
- use std::ops::Sub;
33
-
34
- #[derive(Debug, Clone, Copy)]
35
- struct Sample<T, I> {
36
- sample: T,
37
- time: I,
38
- }
39
-
40
- #[derive(Debug)]
41
- pub struct WindowedFilter<T, I, D> {
42
- window_length: D,
43
- estimates: [Option<Sample<T, I>>; 3],
44
- }
45
-
46
- impl<T, I, D> WindowedFilter<T, I, D>
47
- where
48
- T: Ord + Copy,
49
- I: Sub<I, Output = D> + Copy,
50
- D: Ord + Div<usize, Output = D> + Copy,
51
- {
52
- pub fn new(window_length: D) -> Self {
53
- WindowedFilter {
54
- window_length,
55
- estimates: [None, None, None],
56
- }
57
- }
58
-
59
- pub fn reset(&mut self, new_sample: T, new_time: I) {
60
- let sample = Some(Sample {
61
- sample: new_sample,
62
- time: new_time,
63
- });
64
-
65
- self.estimates = [sample, sample, sample];
66
- }
67
-
68
- pub fn get_best(&self) -> Option<T> {
69
- self.estimates[0].as_ref().map(|e| e.sample)
70
- }
71
-
72
- pub fn get_second_best(&self) -> Option<T> {
73
- self.estimates[1].as_ref().map(|e| e.sample)
74
- }
75
-
76
- pub fn get_third_best(&self) -> Option<T> {
77
- self.estimates[2].as_ref().map(|e| e.sample)
78
- }
79
-
80
- pub fn clear(&mut self) {
81
- self.estimates = [None, None, None];
82
- }
83
-
84
- pub fn update(&mut self, new_sample: T, new_time: I) {
85
- // Reset all estimates if they have not yet been initialized, if new
86
- // sample is a new best, or if the newest recorded estimate is too
87
- // old.
88
- if match &self.estimates[0] {
89
- None => true,
90
- Some(best) if new_sample > best.sample => true,
91
- _ =>
92
- new_time - self.estimates[2].as_ref().unwrap().time >
93
- self.window_length,
94
- } {
95
- return self.reset(new_sample, new_time);
96
- }
97
-
98
- if new_sample > self.estimates[1].unwrap().sample {
99
- self.estimates[1] = Some(Sample {
100
- sample: new_sample,
101
- time: new_time,
102
- });
103
- self.estimates[2] = self.estimates[1];
104
- } else if new_sample > self.estimates[2].unwrap().sample {
105
- self.estimates[2] = Some(Sample {
106
- sample: new_sample,
107
- time: new_time,
108
- });
109
- }
110
-
111
- // Expire and update estimates as necessary.
112
- if new_time - self.estimates[0].unwrap().time > self.window_length {
113
- // The best estimate hasn't been updated for an entire window, so
114
- // promote second and third best estimates.
115
- self.estimates[0] = self.estimates[1];
116
- self.estimates[1] = self.estimates[2];
117
- self.estimates[2] = Some(Sample {
118
- sample: new_sample,
119
- time: new_time,
120
- });
121
- // Need to iterate one more time. Check if the new best estimate is
122
- // outside the window as well, since it may also have been recorded a
123
- // long time ago. Don't need to iterate once more since we cover that
124
- // case at the beginning of the method.
125
- if new_time - self.estimates[0].unwrap().time > self.window_length {
126
- self.estimates[0] = self.estimates[1];
127
- self.estimates[1] = self.estimates[2];
128
- }
129
- return;
130
- }
131
-
132
- if self.estimates[1].unwrap().sample == self.estimates[0].unwrap().sample &&
133
- new_time - self.estimates[1].unwrap().time > self.window_length / 4
134
- {
135
- // A quarter of the window has passed without a better sample, so the
136
- // second-best estimate is taken from the second quarter of the
137
- // window.
138
- self.estimates[1] = Some(Sample {
139
- sample: new_sample,
140
- time: new_time,
141
- });
142
- self.estimates[2] = self.estimates[1];
143
- return;
144
- }
145
-
146
- if self.estimates[2].unwrap().sample == self.estimates[1].unwrap().sample &&
147
- new_time - self.estimates[2].unwrap().time > self.window_length / 2
148
- {
149
- // We've passed a half of the window without a better estimate, so
150
- // take a third-best estimate from the second half of the
151
- // window.
152
- self.estimates[2] = Some(Sample {
153
- sample: new_sample,
154
- time: new_time,
155
- });
156
- }
157
- }
158
- }
1
+ // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Implements Kathleen Nichols' algorithm for tracking the minimum (or maximum)
6
+ // estimate of a stream of samples over some fixed time interval. (E.g.,
7
+ // the minimum RTT over the past five minutes.) The algorithm keeps track of
8
+ // the best, second best, and third best min (or max) estimates, maintaining an
9
+ // invariant that the measurement time of the n'th best >= n-1'th best.
10
+
11
+ // The algorithm works as follows. On a reset, all three estimates are set to
12
+ // the same sample. The second best estimate is then recorded in the second
13
+ // quarter of the window, and a third best estimate is recorded in the second
14
+ // half of the window, bounding the worst case error when the true min is
15
+ // monotonically increasing (or true max is monotonically decreasing) over the
16
+ // window.
17
+ //
18
+ // A new best sample replaces all three estimates, since the new best is lower
19
+ // (or higher) than everything else in the window and it is the most recent.
20
+ // The window thus effectively gets reset on every new min. The same property
21
+ // holds true for second best and third best estimates. Specifically, when a
22
+ // sample arrives that is better than the second best but not better than the
23
+ // best, it replaces the second and third best estimates but not the best
24
+ // estimate. Similarly, a sample that is better than the third best estimate
25
+ // but not the other estimates replaces only the third best estimate.
26
+ //
27
+ // Finally, when the best expires, it is replaced by the second best, which in
28
+ // turn is replaced by the third best. The newest sample replaces the third
29
+ // best.
30
+
31
+ use std::ops::Div;
32
+ use std::ops::Sub;
33
+
34
+ #[derive(Debug, Clone, Copy)]
35
+ struct Sample<T, I> {
36
+ sample: T,
37
+ time: I,
38
+ }
39
+
40
+ #[derive(Debug)]
41
+ pub struct WindowedFilter<T, I, D> {
42
+ window_length: D,
43
+ estimates: [Option<Sample<T, I>>; 3],
44
+ }
45
+
46
+ impl<T, I, D> WindowedFilter<T, I, D>
47
+ where
48
+ T: Ord + Copy,
49
+ I: Sub<I, Output = D> + Copy,
50
+ D: Ord + Div<usize, Output = D> + Copy,
51
+ {
52
+ pub fn new(window_length: D) -> Self {
53
+ WindowedFilter {
54
+ window_length,
55
+ estimates: [None, None, None],
56
+ }
57
+ }
58
+
59
+ pub fn reset(&mut self, new_sample: T, new_time: I) {
60
+ let sample = Some(Sample {
61
+ sample: new_sample,
62
+ time: new_time,
63
+ });
64
+
65
+ self.estimates = [sample, sample, sample];
66
+ }
67
+
68
+ pub fn get_best(&self) -> Option<T> {
69
+ self.estimates[0].as_ref().map(|e| e.sample)
70
+ }
71
+
72
+ pub fn get_second_best(&self) -> Option<T> {
73
+ self.estimates[1].as_ref().map(|e| e.sample)
74
+ }
75
+
76
+ pub fn get_third_best(&self) -> Option<T> {
77
+ self.estimates[2].as_ref().map(|e| e.sample)
78
+ }
79
+
80
+ pub fn clear(&mut self) {
81
+ self.estimates = [None, None, None];
82
+ }
83
+
84
+ pub fn update(&mut self, new_sample: T, new_time: I) {
85
+ // Reset all estimates if they have not yet been initialized, if new
86
+ // sample is a new best, or if the newest recorded estimate is too
87
+ // old.
88
+ if match &self.estimates[0] {
89
+ None => true,
90
+ Some(best) if new_sample > best.sample => true,
91
+ _ =>
92
+ new_time - self.estimates[2].as_ref().unwrap().time >
93
+ self.window_length,
94
+ } {
95
+ return self.reset(new_sample, new_time);
96
+ }
97
+
98
+ if new_sample > self.estimates[1].unwrap().sample {
99
+ self.estimates[1] = Some(Sample {
100
+ sample: new_sample,
101
+ time: new_time,
102
+ });
103
+ self.estimates[2] = self.estimates[1];
104
+ } else if new_sample > self.estimates[2].unwrap().sample {
105
+ self.estimates[2] = Some(Sample {
106
+ sample: new_sample,
107
+ time: new_time,
108
+ });
109
+ }
110
+
111
+ // Expire and update estimates as necessary.
112
+ if new_time - self.estimates[0].unwrap().time > self.window_length {
113
+ // The best estimate hasn't been updated for an entire window, so
114
+ // promote second and third best estimates.
115
+ self.estimates[0] = self.estimates[1];
116
+ self.estimates[1] = self.estimates[2];
117
+ self.estimates[2] = Some(Sample {
118
+ sample: new_sample,
119
+ time: new_time,
120
+ });
121
+ // Need to iterate one more time. Check if the new best estimate is
122
+ // outside the window as well, since it may also have been recorded a
123
+ // long time ago. Don't need to iterate once more since we cover that
124
+ // case at the beginning of the method.
125
+ if new_time - self.estimates[0].unwrap().time > self.window_length {
126
+ self.estimates[0] = self.estimates[1];
127
+ self.estimates[1] = self.estimates[2];
128
+ }
129
+ return;
130
+ }
131
+
132
+ if self.estimates[1].unwrap().sample == self.estimates[0].unwrap().sample &&
133
+ new_time - self.estimates[1].unwrap().time > self.window_length / 4
134
+ {
135
+ // A quarter of the window has passed without a better sample, so the
136
+ // second-best estimate is taken from the second quarter of the
137
+ // window.
138
+ self.estimates[1] = Some(Sample {
139
+ sample: new_sample,
140
+ time: new_time,
141
+ });
142
+ self.estimates[2] = self.estimates[1];
143
+ return;
144
+ }
145
+
146
+ if self.estimates[2].unwrap().sample == self.estimates[1].unwrap().sample &&
147
+ new_time - self.estimates[2].unwrap().time > self.window_length / 2
148
+ {
149
+ // We've passed a half of the window without a better estimate, so
150
+ // take a third-best estimate from the second half of the
151
+ // window.
152
+ self.estimates[2] = Some(Sample {
153
+ sample: new_sample,
154
+ time: new_time,
155
+ });
156
+ }
157
+ }
158
+ }
@@ -1,37 +1,37 @@
1
- // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- // Copyright (C) 2023, Cloudflare, Inc.
6
- // All rights reserved.
7
- //
8
- // Redistribution and use in source and binary forms, with or without
9
- // modification, are permitted provided that the following conditions are
10
- // met:
11
- //
12
- // * Redistributions of source code must retain the above copyright notice,
13
- // this list of conditions and the following disclaimer.
14
- //
15
- // * Redistributions in binary form must reproduce the above copyright
16
- // notice, this list of conditions and the following disclaimer in the
17
- // documentation and/or other materials provided with the distribution.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
- // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
- // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
- // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23
- // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
- // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
- // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
- // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
- // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- mod bandwidth_sampler;
32
- mod windowed_filter;
33
-
34
- pub use bandwidth_sampler::BandwidthSampler;
35
- pub use bandwidth_sampler::SendTimeState;
36
-
37
- use super::Acked;
1
+ // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Copyright (C) 2023, Cloudflare, Inc.
6
+ // All rights reserved.
7
+ //
8
+ // Redistribution and use in source and binary forms, with or without
9
+ // modification, are permitted provided that the following conditions are
10
+ // met:
11
+ //
12
+ // * Redistributions of source code must retain the above copyright notice,
13
+ // this list of conditions and the following disclaimer.
14
+ //
15
+ // * Redistributions in binary form must reproduce the above copyright
16
+ // notice, this list of conditions and the following disclaimer in the
17
+ // documentation and/or other materials provided with the distribution.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
+ // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23
+ // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+ // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ mod bandwidth_sampler;
32
+ mod windowed_filter;
33
+
34
+ pub use bandwidth_sampler::BandwidthSampler;
35
+ pub use bandwidth_sampler::SendTimeState;
36
+
37
+ use super::Acked;
@@ -1,120 +1,120 @@
1
- // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- // Copyright (C) 2023, Cloudflare, Inc.
6
- // All rights reserved.
7
- //
8
- // Redistribution and use in source and binary forms, with or without
9
- // modification, are permitted provided that the following conditions are
10
- // met:
11
- //
12
- // * Redistributions of source code must retain the above copyright notice,
13
- // this list of conditions and the following disclaimer.
14
- //
15
- // * Redistributions in binary form must reproduce the above copyright
16
- // notice, this list of conditions and the following disclaimer in the
17
- // documentation and/or other materials provided with the distribution.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
- // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
- // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
- // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23
- // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
- // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
- // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
- // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
- // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- use std::time::Instant;
32
-
33
- use crate::recovery::gcongestion::bbr2::Params;
34
- use crate::recovery::gcongestion::Acked;
35
- use crate::recovery::gcongestion::Lost;
36
- use crate::recovery::RecoveryStats;
37
-
38
- use super::mode::Cycle;
39
- use super::mode::Mode;
40
- use super::mode::ModeImpl;
41
- use super::network_model::BBRv2NetworkModel;
42
- use super::BBRv2CongestionEvent;
43
- use super::Limits;
44
-
45
- #[derive(Debug)]
46
- pub(super) struct Drain {
47
- pub(super) model: BBRv2NetworkModel,
48
- pub(super) cycle: Cycle,
49
- }
50
-
51
- impl ModeImpl for Drain {
52
- #[cfg(feature = "qlog")]
53
- fn state_str(&self) -> &'static str {
54
- "bbr_drain"
55
- }
56
-
57
- fn is_probing_for_bandwidth(&self) -> bool {
58
- false
59
- }
60
-
61
- fn on_congestion_event(
62
- mut self, _prior_in_flight: usize, event_time: Instant,
63
- _acked_packets: &[Acked], _lost_packets: &[Lost],
64
- congestion_event: &mut BBRv2CongestionEvent,
65
- _target_bytes_inflight: usize, params: &Params,
66
- _recovery_stats: &mut RecoveryStats, _cwnd: usize,
67
- ) -> Mode {
68
- self.model.set_pacing_gain(params.drain_pacing_gain);
69
- // Only STARTUP can transition to DRAIN, both of them use the same cwnd
70
- // gain.
71
- self.model.set_cwnd_gain(params.drain_cwnd_gain);
72
-
73
- let drain_target = self.drain_target();
74
- if congestion_event.bytes_in_flight <= drain_target {
75
- return self.into_probe_bw(
76
- event_time,
77
- Some(congestion_event),
78
- params,
79
- );
80
- }
81
-
82
- Mode::Drain(self)
83
- }
84
-
85
- fn get_cwnd_limits(&self, _params: &Params) -> Limits<usize> {
86
- Limits {
87
- lo: 0,
88
- hi: self.model.inflight_lo(),
89
- }
90
- }
91
-
92
- fn on_exit_quiescence(
93
- self, _now: Instant, _quiescence_start_time: Instant, _params: &Params,
94
- ) -> Mode {
95
- Mode::Drain(self)
96
- }
97
-
98
- fn enter(
99
- &mut self, _: Instant, _: Option<&BBRv2CongestionEvent>, _params: &Params,
100
- ) {
101
- }
102
-
103
- fn leave(&mut self, _: Instant, _: Option<&BBRv2CongestionEvent>) {}
104
- }
105
-
106
- impl Drain {
107
- fn into_probe_bw(
108
- mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
109
- params: &Params,
110
- ) -> Mode {
111
- self.leave(now, congestion_event);
112
- let mut next_mode = Mode::probe_bw(self.model, self.cycle);
113
- next_mode.enter(now, congestion_event, params);
114
- next_mode
115
- }
116
-
117
- fn drain_target(&self) -> usize {
118
- self.model.bdp0()
119
- }
120
- }
1
+ // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Copyright (C) 2023, Cloudflare, Inc.
6
+ // All rights reserved.
7
+ //
8
+ // Redistribution and use in source and binary forms, with or without
9
+ // modification, are permitted provided that the following conditions are
10
+ // met:
11
+ //
12
+ // * Redistributions of source code must retain the above copyright notice,
13
+ // this list of conditions and the following disclaimer.
14
+ //
15
+ // * Redistributions in binary form must reproduce the above copyright
16
+ // notice, this list of conditions and the following disclaimer in the
17
+ // documentation and/or other materials provided with the distribution.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
+ // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23
+ // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+ // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ use std::time::Instant;
32
+
33
+ use crate::recovery::gcongestion::bbr2::Params;
34
+ use crate::recovery::gcongestion::Acked;
35
+ use crate::recovery::gcongestion::Lost;
36
+ use crate::recovery::RecoveryStats;
37
+
38
+ use super::mode::Cycle;
39
+ use super::mode::Mode;
40
+ use super::mode::ModeImpl;
41
+ use super::network_model::BBRv2NetworkModel;
42
+ use super::BBRv2CongestionEvent;
43
+ use super::Limits;
44
+
45
+ #[derive(Debug)]
46
+ pub(super) struct Drain {
47
+ pub(super) model: BBRv2NetworkModel,
48
+ pub(super) cycle: Cycle,
49
+ }
50
+
51
+ impl ModeImpl for Drain {
52
+ #[cfg(feature = "qlog")]
53
+ fn state_str(&self) -> &'static str {
54
+ "bbr_drain"
55
+ }
56
+
57
+ fn is_probing_for_bandwidth(&self) -> bool {
58
+ false
59
+ }
60
+
61
+ fn on_congestion_event(
62
+ mut self, _prior_in_flight: usize, event_time: Instant,
63
+ _acked_packets: &[Acked], _lost_packets: &[Lost],
64
+ congestion_event: &mut BBRv2CongestionEvent,
65
+ _target_bytes_inflight: usize, params: &Params,
66
+ _recovery_stats: &mut RecoveryStats, _cwnd: usize,
67
+ ) -> Mode {
68
+ self.model.set_pacing_gain(params.drain_pacing_gain);
69
+ // Only STARTUP can transition to DRAIN, both of them use the same cwnd
70
+ // gain.
71
+ self.model.set_cwnd_gain(params.drain_cwnd_gain);
72
+
73
+ let drain_target = self.drain_target();
74
+ if congestion_event.bytes_in_flight <= drain_target {
75
+ return self.into_probe_bw(
76
+ event_time,
77
+ Some(congestion_event),
78
+ params,
79
+ );
80
+ }
81
+
82
+ Mode::Drain(self)
83
+ }
84
+
85
+ fn get_cwnd_limits(&self, _params: &Params) -> Limits<usize> {
86
+ Limits {
87
+ lo: 0,
88
+ hi: self.model.inflight_lo(),
89
+ }
90
+ }
91
+
92
+ fn on_exit_quiescence(
93
+ self, _now: Instant, _quiescence_start_time: Instant, _params: &Params,
94
+ ) -> Mode {
95
+ Mode::Drain(self)
96
+ }
97
+
98
+ fn enter(
99
+ &mut self, _: Instant, _: Option<&BBRv2CongestionEvent>, _params: &Params,
100
+ ) {
101
+ }
102
+
103
+ fn leave(&mut self, _: Instant, _: Option<&BBRv2CongestionEvent>) {}
104
+ }
105
+
106
+ impl Drain {
107
+ fn into_probe_bw(
108
+ mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
109
+ params: &Params,
110
+ ) -> Mode {
111
+ self.leave(now, congestion_event);
112
+ let mut next_mode = Mode::probe_bw(self.model, self.cycle);
113
+ next_mode.enter(now, congestion_event, params);
114
+ next_mode
115
+ }
116
+
117
+ fn drain_target(&self) -> usize {
118
+ self.model.bdp0()
119
+ }
120
+ }