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,179 +1,179 @@
1
- // Copyright (C) 2025, 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::time::Duration;
28
- use std::time::Instant;
29
-
30
- /// Estimate the total duration a connection has bytes-in-flight.
31
- ///
32
- /// There can be multiple transitions from bytes-in-flight >0 to 0 and 0 to >0
33
- /// during a connection's lifetime. Total bytes-in-flight duration is the sum of
34
- /// all intervals that transition from idle to not-idle and back to idle. Close
35
- /// intervals are the ones that transitioned back to idle. The open one is the
36
- /// most recent interval for which we only have a start time, but no end time.
37
- #[derive(Default)]
38
- pub struct BytesInFlight {
39
- // Current bytes in flight.
40
- bytes_in_flight: usize,
41
-
42
- // Instant at which bytes_in_flight transitioned from 0 to >0.
43
- // Set if bytes_in_flight is currently >0 which indicates that
44
- // the bytes in flight interval is currently "open".
45
- bytes_in_flight_interval_start: Option<Instant>,
46
-
47
- // Duration of the current open interval.
48
- open_interval_duration: Duration,
49
-
50
- // Sum of closed interval durations seen so far.
51
- closed_interval_duration: Duration,
52
- }
53
-
54
- impl BytesInFlight {
55
- /// Add to bytes in flight. Record the start time when
56
- /// bytes_in_flight was 0 at the beginning of the function.
57
- pub(crate) fn add(&mut self, delta: usize, now: Instant) {
58
- if delta == 0 {
59
- return;
60
- }
61
-
62
- self.bytes_in_flight += delta;
63
-
64
- if self.bytes_in_flight_interval_start.is_some() {
65
- self.update_in_flight_duration(now);
66
- } else {
67
- self.bytes_in_flight_interval_start = Some(now);
68
- }
69
- }
70
-
71
- /// Substract from bytes in flight. If bytes_in_flight drops to 0,
72
- /// end the current bytes_in_flight >0 interval.
73
- pub(crate) fn saturating_subtract(&mut self, delta: usize, now: Instant) {
74
- self.bytes_in_flight = self.bytes_in_flight.saturating_sub(delta);
75
- self.update_in_flight_duration(now);
76
- }
77
-
78
- /// Current bytes in flight.
79
- pub(crate) fn get(&self) -> usize {
80
- self.bytes_in_flight
81
- }
82
-
83
- /// Returns true if there are 0 bytes in flight.
84
- pub(crate) fn is_zero(&self) -> bool {
85
- self.bytes_in_flight == 0
86
- }
87
-
88
- /// Total time during which bytes_in_flight was > 0.
89
- pub(crate) fn get_duration(&self) -> Duration {
90
- self.closed_interval_duration + self.open_interval_duration
91
- }
92
-
93
- fn update_in_flight_duration(&mut self, now: Instant) {
94
- if let Some(start) = self.bytes_in_flight_interval_start {
95
- if self.bytes_in_flight == 0 {
96
- self.open_interval_duration = Duration::ZERO;
97
- self.closed_interval_duration += now - start;
98
- self.bytes_in_flight_interval_start = None;
99
- } else {
100
- self.open_interval_duration = now - start;
101
- }
102
- }
103
- }
104
- }
105
-
106
- #[cfg(test)]
107
- mod tests {
108
- use super::*;
109
-
110
- #[test]
111
- fn bytes_in_flight_basic() {
112
- let start = Instant::now();
113
-
114
- let mut bytes_in_flight: BytesInFlight = Default::default();
115
- assert_eq!(bytes_in_flight.get(), 0);
116
- assert_eq!(bytes_in_flight.get_duration(), Duration::ZERO);
117
-
118
- // bytes_in_flight_interval_start is initialized when bytes > 0.
119
- bytes_in_flight.add(1, start);
120
- assert_eq!(bytes_in_flight.get(), 1);
121
- assert_eq!(bytes_in_flight.get_duration(), Duration::ZERO);
122
-
123
- // Advance time forward and verify that the inflight time for an open
124
- // interval.
125
- let mut now = start + Duration::from_secs(2);
126
- bytes_in_flight.add(2, now);
127
- bytes_in_flight.add(3, now);
128
- assert_eq!(bytes_in_flight.get(), 6);
129
- // Interval start does not change on adds
130
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(2));
131
-
132
- now += Duration::from_secs(5);
133
- bytes_in_flight.saturating_subtract(3, now);
134
- // Bytes > 0, interval remains open.
135
- assert_eq!(bytes_in_flight.get(), 3);
136
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(7));
137
-
138
- bytes_in_flight.saturating_subtract(3, now);
139
- // Bytes == 0, interval is closed.
140
- assert_eq!(bytes_in_flight.get(), 0);
141
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(7));
142
-
143
- // Open a second interval.
144
- now += Duration::from_secs(30);
145
- bytes_in_flight.add(10, now);
146
- assert_eq!(bytes_in_flight.get(), 10);
147
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(7));
148
-
149
- // Close the second interval.
150
- now += Duration::from_secs(5);
151
- bytes_in_flight.saturating_subtract(10, now);
152
- assert_eq!(bytes_in_flight.get(), 0);
153
- // Expect the time to be the 7sec + 5sec since those were the open time of
154
- // the two bytes in flight intervals.
155
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(12));
156
- }
157
-
158
- #[test]
159
- fn bytes_in_flight_saturating_sub() {
160
- let start = Instant::now();
161
-
162
- let mut bytes_in_flight: BytesInFlight = Default::default();
163
- bytes_in_flight.add(10, start);
164
- assert_eq!(bytes_in_flight.get(), 10);
165
-
166
- bytes_in_flight.saturating_subtract(7, start + Duration::from_secs(3));
167
- assert_eq!(bytes_in_flight.get(), 3);
168
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(3));
169
- // Interval is still open.
170
- bytes_in_flight.saturating_subtract(1, start + Duration::from_secs(20));
171
- assert_eq!(bytes_in_flight.get(), 2);
172
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(20));
173
-
174
- bytes_in_flight.saturating_subtract(7, start + Duration::from_secs(25));
175
- assert_eq!(bytes_in_flight.get(), 0);
176
- // Interval is closed.
177
- assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(25));
178
- }
179
- }
1
+ // Copyright (C) 2025, 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::time::Duration;
28
+ use std::time::Instant;
29
+
30
+ /// Estimate the total duration a connection has bytes-in-flight.
31
+ ///
32
+ /// There can be multiple transitions from bytes-in-flight >0 to 0 and 0 to >0
33
+ /// during a connection's lifetime. Total bytes-in-flight duration is the sum of
34
+ /// all intervals that transition from idle to not-idle and back to idle. Close
35
+ /// intervals are the ones that transitioned back to idle. The open one is the
36
+ /// most recent interval for which we only have a start time, but no end time.
37
+ #[derive(Default)]
38
+ pub struct BytesInFlight {
39
+ // Current bytes in flight.
40
+ bytes_in_flight: usize,
41
+
42
+ // Instant at which bytes_in_flight transitioned from 0 to >0.
43
+ // Set if bytes_in_flight is currently >0 which indicates that
44
+ // the bytes in flight interval is currently "open".
45
+ bytes_in_flight_interval_start: Option<Instant>,
46
+
47
+ // Duration of the current open interval.
48
+ open_interval_duration: Duration,
49
+
50
+ // Sum of closed interval durations seen so far.
51
+ closed_interval_duration: Duration,
52
+ }
53
+
54
+ impl BytesInFlight {
55
+ /// Add to bytes in flight. Record the start time when
56
+ /// bytes_in_flight was 0 at the beginning of the function.
57
+ pub(crate) fn add(&mut self, delta: usize, now: Instant) {
58
+ if delta == 0 {
59
+ return;
60
+ }
61
+
62
+ self.bytes_in_flight += delta;
63
+
64
+ if self.bytes_in_flight_interval_start.is_some() {
65
+ self.update_in_flight_duration(now);
66
+ } else {
67
+ self.bytes_in_flight_interval_start = Some(now);
68
+ }
69
+ }
70
+
71
+ /// Substract from bytes in flight. If bytes_in_flight drops to 0,
72
+ /// end the current bytes_in_flight >0 interval.
73
+ pub(crate) fn saturating_subtract(&mut self, delta: usize, now: Instant) {
74
+ self.bytes_in_flight = self.bytes_in_flight.saturating_sub(delta);
75
+ self.update_in_flight_duration(now);
76
+ }
77
+
78
+ /// Current bytes in flight.
79
+ pub(crate) fn get(&self) -> usize {
80
+ self.bytes_in_flight
81
+ }
82
+
83
+ /// Returns true if there are 0 bytes in flight.
84
+ pub(crate) fn is_zero(&self) -> bool {
85
+ self.bytes_in_flight == 0
86
+ }
87
+
88
+ /// Total time during which bytes_in_flight was > 0.
89
+ pub(crate) fn get_duration(&self) -> Duration {
90
+ self.closed_interval_duration + self.open_interval_duration
91
+ }
92
+
93
+ fn update_in_flight_duration(&mut self, now: Instant) {
94
+ if let Some(start) = self.bytes_in_flight_interval_start {
95
+ if self.bytes_in_flight == 0 {
96
+ self.open_interval_duration = Duration::ZERO;
97
+ self.closed_interval_duration += now - start;
98
+ self.bytes_in_flight_interval_start = None;
99
+ } else {
100
+ self.open_interval_duration = now - start;
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ #[cfg(test)]
107
+ mod tests {
108
+ use super::*;
109
+
110
+ #[test]
111
+ fn bytes_in_flight_basic() {
112
+ let start = Instant::now();
113
+
114
+ let mut bytes_in_flight: BytesInFlight = Default::default();
115
+ assert_eq!(bytes_in_flight.get(), 0);
116
+ assert_eq!(bytes_in_flight.get_duration(), Duration::ZERO);
117
+
118
+ // bytes_in_flight_interval_start is initialized when bytes > 0.
119
+ bytes_in_flight.add(1, start);
120
+ assert_eq!(bytes_in_flight.get(), 1);
121
+ assert_eq!(bytes_in_flight.get_duration(), Duration::ZERO);
122
+
123
+ // Advance time forward and verify that the inflight time for an open
124
+ // interval.
125
+ let mut now = start + Duration::from_secs(2);
126
+ bytes_in_flight.add(2, now);
127
+ bytes_in_flight.add(3, now);
128
+ assert_eq!(bytes_in_flight.get(), 6);
129
+ // Interval start does not change on adds
130
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(2));
131
+
132
+ now += Duration::from_secs(5);
133
+ bytes_in_flight.saturating_subtract(3, now);
134
+ // Bytes > 0, interval remains open.
135
+ assert_eq!(bytes_in_flight.get(), 3);
136
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(7));
137
+
138
+ bytes_in_flight.saturating_subtract(3, now);
139
+ // Bytes == 0, interval is closed.
140
+ assert_eq!(bytes_in_flight.get(), 0);
141
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(7));
142
+
143
+ // Open a second interval.
144
+ now += Duration::from_secs(30);
145
+ bytes_in_flight.add(10, now);
146
+ assert_eq!(bytes_in_flight.get(), 10);
147
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(7));
148
+
149
+ // Close the second interval.
150
+ now += Duration::from_secs(5);
151
+ bytes_in_flight.saturating_subtract(10, now);
152
+ assert_eq!(bytes_in_flight.get(), 0);
153
+ // Expect the time to be the 7sec + 5sec since those were the open time of
154
+ // the two bytes in flight intervals.
155
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(12));
156
+ }
157
+
158
+ #[test]
159
+ fn bytes_in_flight_saturating_sub() {
160
+ let start = Instant::now();
161
+
162
+ let mut bytes_in_flight: BytesInFlight = Default::default();
163
+ bytes_in_flight.add(10, start);
164
+ assert_eq!(bytes_in_flight.get(), 10);
165
+
166
+ bytes_in_flight.saturating_subtract(7, start + Duration::from_secs(3));
167
+ assert_eq!(bytes_in_flight.get(), 3);
168
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(3));
169
+ // Interval is still open.
170
+ bytes_in_flight.saturating_subtract(1, start + Duration::from_secs(20));
171
+ assert_eq!(bytes_in_flight.get(), 2);
172
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(20));
173
+
174
+ bytes_in_flight.saturating_subtract(7, start + Duration::from_secs(25));
175
+ assert_eq!(bytes_in_flight.get(), 0);
176
+ // Interval is closed.
177
+ assert_eq!(bytes_in_flight.get_duration(), Duration::from_secs(25));
178
+ }
179
+ }