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,446 @@
1
+ // Copyright (C) 2020, Cloudflare, Inc.
2
+ // Copyright (C) 2017, Google, Inc.
3
+ //
4
+ // Use of this source code is governed by the following BSD-style license:
5
+ //
6
+ // Redistribution and use in source and binary forms, with or without
7
+ // modification, are permitted provided that the following conditions are
8
+ // met:
9
+ //
10
+ // * Redistributions of source code must retain the above copyright
11
+ // notice, this list of conditions and the following disclaimer.
12
+ // * Redistributions in binary form must reproduce the above
13
+ // copyright notice, this list of conditions and the following disclaimer
14
+ // in the documentation and/or other materials provided with the
15
+ // distribution.
16
+ //
17
+ // * Neither the name of Google Inc. nor the names of its
18
+ // contributors may be used to endorse or promote products derived from
19
+ // this software without specific prior written permission.
20
+ //
21
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+
33
+ // lib/minmax.c: windowed min/max tracker
34
+ //
35
+ // Kathleen Nichols' algorithm for tracking the minimum (or maximum)
36
+ // value of a data stream over some fixed time interval. (E.g.,
37
+ // the minimum RTT over the past five minutes.) It uses constant
38
+ // space and constant time per update yet almost always delivers
39
+ // the same minimum as an implementation that has to keep all the
40
+ // data in the window.
41
+ //
42
+ // The algorithm keeps track of the best, 2nd best & 3rd best min
43
+ // values, maintaining an invariant that the measurement time of
44
+ // the n'th best >= n-1'th best. It also makes sure that the three
45
+ // values are widely separated in the time window since that bounds
46
+ // the worse case error when that data is monotonically increasing
47
+ // over the window.
48
+ //
49
+ // Upon getting a new min, we can forget everything earlier because
50
+ // it has no value - the new min is <= everything else in the window
51
+ // by definition and it's the most recent. So we restart fresh on
52
+ // every new min and overwrites 2nd & 3rd choices. The same property
53
+ // holds for 2nd & 3rd best.
54
+
55
+ use std::ops::Deref;
56
+
57
+ use std::time::Duration;
58
+ use std::time::Instant;
59
+
60
+ #[derive(Copy, Clone)]
61
+ struct MinmaxSample<T> {
62
+ time: Instant,
63
+ value: T,
64
+ }
65
+
66
+ pub struct Minmax<T> {
67
+ estimate: [MinmaxSample<T>; 3],
68
+ }
69
+
70
+ impl<T> Deref for Minmax<T> {
71
+ type Target = T;
72
+
73
+ fn deref(&self) -> &Self::Target {
74
+ &self.estimate[0].value
75
+ }
76
+ }
77
+
78
+ impl<T: PartialOrd + Copy> Minmax<T> {
79
+ pub fn new(val: T) -> Self {
80
+ Minmax {
81
+ estimate: [MinmaxSample {
82
+ time: Instant::now(),
83
+ value: val,
84
+ }; 3],
85
+ }
86
+ }
87
+
88
+ /// Resets the estimates to the given value.
89
+ pub fn reset(&mut self, time: Instant, meas: T) -> T {
90
+ let val = MinmaxSample { time, value: meas };
91
+
92
+ for i in self.estimate.iter_mut() {
93
+ *i = val;
94
+ }
95
+
96
+ self.estimate[0].value
97
+ }
98
+
99
+ /// Updates the min estimate based on the given measurement, and returns it.
100
+ pub fn running_min(&mut self, win: Duration, time: Instant, meas: T) -> T {
101
+ let val = MinmaxSample { time, value: meas };
102
+
103
+ let delta_time = time.duration_since(self.estimate[2].time);
104
+
105
+ // Reset if there's nothing in the window or a new min value is found.
106
+ if val.value <= self.estimate[0].value || delta_time > win {
107
+ return self.reset(time, meas);
108
+ }
109
+
110
+ if val.value <= self.estimate[1].value {
111
+ self.estimate[2] = val;
112
+ self.estimate[1] = val;
113
+ } else if val.value <= self.estimate[2].value {
114
+ self.estimate[2] = val;
115
+ }
116
+
117
+ self.subwin_update(win, time, meas)
118
+ }
119
+
120
+ /// Updates the max estimate based on the given measurement, and returns it.
121
+ #[cfg(test)]
122
+ pub fn running_max(&mut self, win: Duration, time: Instant, meas: T) -> T {
123
+ let val = MinmaxSample { time, value: meas };
124
+
125
+ let delta_time = time.duration_since(self.estimate[2].time);
126
+
127
+ // Reset if there's nothing in the window or a new max value is found.
128
+ if val.value >= self.estimate[0].value || delta_time > win {
129
+ return self.reset(time, meas);
130
+ }
131
+
132
+ if val.value >= self.estimate[1].value {
133
+ self.estimate[2] = val;
134
+ self.estimate[1] = val;
135
+ } else if val.value >= self.estimate[2].value {
136
+ self.estimate[2] = val
137
+ }
138
+
139
+ self.subwin_update(win, time, meas)
140
+ }
141
+
142
+ /// As time advances, update the 1st, 2nd and 3rd estimates.
143
+ fn subwin_update(&mut self, win: Duration, time: Instant, meas: T) -> T {
144
+ let val = MinmaxSample { time, value: meas };
145
+
146
+ let delta_time = time.duration_since(self.estimate[0].time);
147
+
148
+ if delta_time > win {
149
+ // Passed entire window without a new val so make 2nd estimate the
150
+ // new val & 3rd estimate the new 2nd choice. we may have to iterate
151
+ // this since our 2nd estimate may also be outside the window (we
152
+ // checked on entry that the third estimate was in the window).
153
+ self.estimate[0] = self.estimate[1];
154
+ self.estimate[1] = self.estimate[2];
155
+ self.estimate[2] = val;
156
+
157
+ if time.duration_since(self.estimate[0].time) > win {
158
+ self.estimate[0] = self.estimate[1];
159
+ self.estimate[1] = self.estimate[2];
160
+ self.estimate[2] = val;
161
+ }
162
+ } else if self.estimate[1].time == self.estimate[0].time &&
163
+ delta_time > win.div_f32(4.0)
164
+ {
165
+ // We've passed a quarter of the window without a new val so take a
166
+ // 2nd estimate from the 2nd quarter of the window.
167
+ self.estimate[2] = val;
168
+ self.estimate[1] = val;
169
+ } else if self.estimate[2].time == self.estimate[1].time &&
170
+ delta_time > win.div_f32(2.0)
171
+ {
172
+ // We've passed half the window without finding a new val so take a
173
+ // 3rd estimate from the last half of the window.
174
+ self.estimate[2] = val;
175
+ }
176
+
177
+ self.estimate[0].value
178
+ }
179
+ }
180
+
181
+ #[cfg(test)]
182
+ mod tests {
183
+ use super::*;
184
+
185
+ #[test]
186
+ fn reset_filter_rtt() {
187
+ let mut f = Minmax::new(Duration::ZERO);
188
+ let now = Instant::now();
189
+ let rtt = Duration::from_millis(50);
190
+
191
+ let rtt_min = f.reset(now, rtt);
192
+ assert_eq!(rtt_min, rtt);
193
+
194
+ assert_eq!(f.estimate[0].time, now);
195
+ assert_eq!(f.estimate[0].value, rtt);
196
+
197
+ assert_eq!(f.estimate[1].time, now);
198
+ assert_eq!(f.estimate[1].value, rtt);
199
+
200
+ assert_eq!(f.estimate[2].time, now);
201
+ assert_eq!(f.estimate[2].value, rtt);
202
+ }
203
+
204
+ #[test]
205
+ fn reset_filter_bandwidth() {
206
+ let mut f = Minmax::new(0);
207
+ let now = Instant::now();
208
+ let bw = 2000;
209
+
210
+ let bw_min = f.reset(now, bw);
211
+ assert_eq!(bw_min, bw);
212
+
213
+ assert_eq!(f.estimate[0].time, now);
214
+ assert_eq!(f.estimate[0].value, bw);
215
+
216
+ assert_eq!(f.estimate[1].time, now);
217
+ assert_eq!(f.estimate[1].value, bw);
218
+
219
+ assert_eq!(f.estimate[2].time, now);
220
+ assert_eq!(f.estimate[2].value, bw);
221
+ }
222
+
223
+ #[test]
224
+ fn get_windowed_min_rtt() {
225
+ let mut f = Minmax::new(Duration::ZERO);
226
+ let rtt_25 = Duration::from_millis(25);
227
+ let rtt_24 = Duration::from_millis(24);
228
+ let win = Duration::from_millis(500);
229
+ let mut time = Instant::now();
230
+
231
+ let mut rtt_min = f.reset(time, rtt_25);
232
+ assert_eq!(rtt_min, rtt_25);
233
+
234
+ time += Duration::from_millis(250);
235
+ rtt_min = f.running_min(win, time, rtt_24);
236
+ assert_eq!(rtt_min, rtt_24);
237
+ assert_eq!(f.estimate[1].value, rtt_24);
238
+ assert_eq!(f.estimate[2].value, rtt_24);
239
+
240
+ time += Duration::from_millis(600);
241
+ rtt_min = f.running_min(win, time, rtt_25);
242
+ assert_eq!(rtt_min, rtt_25);
243
+ assert_eq!(f.estimate[1].value, rtt_25);
244
+ assert_eq!(f.estimate[2].value, rtt_25);
245
+ }
246
+
247
+ #[test]
248
+ fn get_windowed_min_bandwidth() {
249
+ let mut f = Minmax::new(0);
250
+ let bw_200 = 200;
251
+ let bw_500 = 500;
252
+ let win = Duration::from_millis(500);
253
+ let mut time = Instant::now();
254
+
255
+ let mut bw_min = f.reset(time, bw_500);
256
+ assert_eq!(bw_min, bw_500);
257
+
258
+ time += Duration::from_millis(250);
259
+ bw_min = f.running_min(win, time, bw_200);
260
+ assert_eq!(bw_min, bw_200);
261
+ assert_eq!(f.estimate[1].value, bw_200);
262
+ assert_eq!(f.estimate[2].value, bw_200);
263
+
264
+ time += Duration::from_millis(600);
265
+ bw_min = f.running_min(win, time, bw_500);
266
+ assert_eq!(bw_min, bw_500);
267
+ assert_eq!(f.estimate[1].value, bw_500);
268
+ assert_eq!(f.estimate[2].value, bw_500);
269
+ }
270
+
271
+ #[test]
272
+ fn get_windowed_max_rtt() {
273
+ let mut f = Minmax::new(Duration::ZERO);
274
+ let rtt_25 = Duration::from_millis(25);
275
+ let rtt_24 = Duration::from_millis(24);
276
+ let win = Duration::from_millis(500);
277
+ let mut time = Instant::now();
278
+
279
+ let mut rtt_max = f.reset(time, rtt_24);
280
+ assert_eq!(rtt_max, rtt_24);
281
+
282
+ time += Duration::from_millis(250);
283
+ rtt_max = f.running_max(win, time, rtt_25);
284
+ assert_eq!(rtt_max, rtt_25);
285
+ assert_eq!(f.estimate[1].value, rtt_25);
286
+ assert_eq!(f.estimate[2].value, rtt_25);
287
+
288
+ time += Duration::from_millis(600);
289
+ rtt_max = f.running_max(win, time, rtt_24);
290
+ assert_eq!(rtt_max, rtt_24);
291
+ assert_eq!(f.estimate[1].value, rtt_24);
292
+ assert_eq!(f.estimate[2].value, rtt_24);
293
+ }
294
+
295
+ #[test]
296
+ fn get_windowed_max_bandwidth() {
297
+ let mut f = Minmax::new(0);
298
+ let bw_200 = 200;
299
+ let bw_500 = 500;
300
+ let win = Duration::from_millis(500);
301
+ let mut time = Instant::now();
302
+
303
+ let mut bw_max = f.reset(time, bw_200);
304
+ assert_eq!(bw_max, bw_200);
305
+
306
+ time += Duration::from_millis(5000);
307
+ bw_max = f.running_max(win, time, bw_500);
308
+ assert_eq!(bw_max, bw_500);
309
+ assert_eq!(f.estimate[1].value, bw_500);
310
+ assert_eq!(f.estimate[2].value, bw_500);
311
+
312
+ time += Duration::from_millis(600);
313
+ bw_max = f.running_max(win, time, bw_200);
314
+ assert_eq!(bw_max, bw_200);
315
+ assert_eq!(f.estimate[1].value, bw_200);
316
+ assert_eq!(f.estimate[2].value, bw_200);
317
+ }
318
+
319
+ #[test]
320
+ fn get_windowed_min_estimates_rtt() {
321
+ let mut f = Minmax::new(Duration::ZERO);
322
+ let rtt_25 = Duration::from_millis(25);
323
+ let rtt_24 = Duration::from_millis(24);
324
+ let rtt_23 = Duration::from_millis(23);
325
+ let rtt_22 = Duration::from_millis(22);
326
+ let win = Duration::from_secs(1);
327
+ let mut time = Instant::now();
328
+
329
+ let mut rtt_min = f.reset(time, rtt_23);
330
+ assert_eq!(rtt_min, rtt_23);
331
+
332
+ time += Duration::from_millis(300);
333
+ rtt_min = f.running_min(win, time, rtt_24);
334
+ assert_eq!(rtt_min, rtt_23);
335
+ assert_eq!(f.estimate[1].value, rtt_24);
336
+ assert_eq!(f.estimate[2].value, rtt_24);
337
+
338
+ time += Duration::from_millis(300);
339
+ rtt_min = f.running_min(win, time, rtt_25);
340
+ assert_eq!(rtt_min, rtt_23);
341
+ assert_eq!(f.estimate[1].value, rtt_24);
342
+ assert_eq!(f.estimate[2].value, rtt_25);
343
+
344
+ time += Duration::from_millis(300);
345
+ rtt_min = f.running_min(win, time, rtt_22);
346
+ assert_eq!(rtt_min, rtt_22);
347
+ assert_eq!(f.estimate[1].value, rtt_22);
348
+ assert_eq!(f.estimate[2].value, rtt_22);
349
+ }
350
+
351
+ #[test]
352
+ fn get_windowed_min_estimates_bandwidth() {
353
+ let mut f = Minmax::new(0);
354
+ let bw_500 = 500;
355
+ let bw_400 = 400;
356
+ let bw_300 = 300;
357
+ let bw_200 = 200;
358
+ let win = Duration::from_secs(1);
359
+ let mut time = Instant::now();
360
+
361
+ let mut bw_min = f.reset(time, bw_300);
362
+ assert_eq!(bw_min, bw_300);
363
+
364
+ time += Duration::from_millis(300);
365
+ bw_min = f.running_min(win, time, bw_400);
366
+ assert_eq!(bw_min, bw_300);
367
+ assert_eq!(f.estimate[1].value, bw_400);
368
+ assert_eq!(f.estimate[2].value, bw_400);
369
+
370
+ time += Duration::from_millis(300);
371
+ bw_min = f.running_min(win, time, bw_500);
372
+ assert_eq!(bw_min, bw_300);
373
+ assert_eq!(f.estimate[1].value, bw_400);
374
+ assert_eq!(f.estimate[2].value, bw_500);
375
+
376
+ time += Duration::from_millis(300);
377
+ bw_min = f.running_min(win, time, bw_200);
378
+ assert_eq!(bw_min, bw_200);
379
+ assert_eq!(f.estimate[1].value, bw_200);
380
+ assert_eq!(f.estimate[2].value, bw_200);
381
+ }
382
+
383
+ #[test]
384
+ fn get_windowed_max_estimates_rtt() {
385
+ let mut f = Minmax::new(Duration::ZERO);
386
+ let rtt_25 = Duration::from_millis(25);
387
+ let rtt_24 = Duration::from_millis(24);
388
+ let rtt_23 = Duration::from_millis(23);
389
+ let rtt_26 = Duration::from_millis(26);
390
+ let win = Duration::from_secs(1);
391
+ let mut time = Instant::now();
392
+
393
+ let mut rtt_max = f.reset(time, rtt_25);
394
+ assert_eq!(rtt_max, rtt_25);
395
+
396
+ time += Duration::from_millis(300);
397
+ rtt_max = f.running_max(win, time, rtt_24);
398
+ assert_eq!(rtt_max, rtt_25);
399
+ assert_eq!(f.estimate[1].value, rtt_24);
400
+ assert_eq!(f.estimate[2].value, rtt_24);
401
+
402
+ time += Duration::from_millis(300);
403
+ rtt_max = f.running_max(win, time, rtt_23);
404
+ assert_eq!(rtt_max, rtt_25);
405
+ assert_eq!(f.estimate[1].value, rtt_24);
406
+ assert_eq!(f.estimate[2].value, rtt_23);
407
+
408
+ time += Duration::from_millis(300);
409
+ rtt_max = f.running_max(win, time, rtt_26);
410
+ assert_eq!(rtt_max, rtt_26);
411
+ assert_eq!(f.estimate[1].value, rtt_26);
412
+ assert_eq!(f.estimate[2].value, rtt_26);
413
+ }
414
+
415
+ #[test]
416
+ fn get_windowed_max_estimates_bandwidth() {
417
+ let mut f = Minmax::new(0);
418
+ let bw_500 = 500;
419
+ let bw_400 = 400;
420
+ let bw_300 = 300;
421
+ let bw_600 = 600;
422
+ let win = Duration::from_secs(1);
423
+ let mut time = Instant::now();
424
+
425
+ let mut bw_max = f.reset(time, bw_500);
426
+ assert_eq!(bw_max, bw_500);
427
+
428
+ time += Duration::from_millis(300);
429
+ bw_max = f.running_max(win, time, bw_400);
430
+ assert_eq!(bw_max, bw_500);
431
+ assert_eq!(f.estimate[1].value, bw_400);
432
+ assert_eq!(f.estimate[2].value, bw_400);
433
+
434
+ time += Duration::from_millis(300);
435
+ bw_max = f.running_max(win, time, bw_300);
436
+ assert_eq!(bw_max, bw_500);
437
+ assert_eq!(f.estimate[1].value, bw_400);
438
+ assert_eq!(f.estimate[2].value, bw_300);
439
+
440
+ time += Duration::from_millis(300);
441
+ bw_max = f.running_max(win, time, bw_600);
442
+ assert_eq!(bw_max, bw_600);
443
+ assert_eq!(f.estimate[1].value, bw_600);
444
+ assert_eq!(f.estimate[2].value, bw_600);
445
+ }
446
+ }