rwebtransport 0.2.2 → 0.2.5

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 (99) hide show
  1. package/Cargo.lock +523 -140
  2. package/Cargo.toml +5 -5
  3. package/README.md +8 -4
  4. package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
  5. package/crates/native/Cargo.toml +2 -0
  6. package/crates/native/src/config.rs +69 -8
  7. package/crates/native/src/driver.rs +253 -90
  8. package/crates/native/src/lib.rs +80 -57
  9. package/crates/native/src/parser_memory.rs +203 -0
  10. package/crates/native/src/server.rs +215 -183
  11. package/crates/native/src/session.rs +1341 -243
  12. package/crates/native/src/test_support.rs +119 -0
  13. package/crates/wtcore/Cargo.toml +1 -0
  14. package/crates/wtcore/src/h3.rs +250 -46
  15. package/dist/index.js +218 -75
  16. package/dist/index.js.map +7 -1
  17. package/dist/index.mjs +214 -69
  18. package/dist/index.mjs.map +7 -1
  19. package/dist/native.d.ts +10 -4
  20. package/dist/server.d.ts +1 -0
  21. package/package.json +84 -78
  22. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  24. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  25. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  26. package/scripts/build-linux-prebuilt.sh +46 -0
  27. package/scripts/build-ts.js +41 -0
  28. package/scripts/build.js +10 -3
  29. package/vendor/quiche/AGENTS.md +10 -0
  30. package/vendor/quiche/Cargo.lock +239 -248
  31. package/vendor/quiche/Cargo.toml +23 -10
  32. package/vendor/quiche/examples/Makefile +4 -4
  33. package/vendor/quiche/examples/client.rs +10 -28
  34. package/vendor/quiche/examples/http3-client.rs +20 -34
  35. package/vendor/quiche/examples/http3-server.rs +47 -78
  36. package/vendor/quiche/examples/server.rs +19 -49
  37. package/vendor/quiche/include/quiche.h +35 -4
  38. package/vendor/quiche/src/build.rs +17 -0
  39. package/vendor/quiche/src/cid.rs +129 -61
  40. package/vendor/quiche/src/crypto/boringssl.rs +98 -86
  41. package/vendor/quiche/src/crypto/mod.rs +64 -77
  42. package/vendor/quiche/src/dgram.rs +2 -3
  43. package/vendor/quiche/src/error.rs +22 -20
  44. package/vendor/quiche/src/ffi.rs +558 -280
  45. package/vendor/quiche/src/flowcontrol.rs +0 -7
  46. package/vendor/quiche/src/frame.rs +134 -135
  47. package/vendor/quiche/src/h3/ffi.rs +73 -60
  48. package/vendor/quiche/src/h3/frame.rs +70 -90
  49. package/vendor/quiche/src/h3/mod.rs +1024 -593
  50. package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
  51. package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
  52. package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
  53. package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
  54. package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
  55. package/vendor/quiche/src/h3/stream.rs +1009 -194
  56. package/vendor/quiche/src/lib.rs +1361 -1195
  57. package/vendor/quiche/src/minmax.rs +2 -6
  58. package/vendor/quiche/src/packet.rs +420 -552
  59. package/vendor/quiche/src/path.rs +202 -72
  60. package/vendor/quiche/src/pmtud.rs +18 -16
  61. package/vendor/quiche/src/ranges.rs +184 -82
  62. package/vendor/quiche/src/recovery/AGENTS.md +5 -2
  63. package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
  64. package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
  65. package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
  66. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
  67. package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
  68. package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
  69. package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
  70. package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
  71. package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
  72. package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
  73. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
  74. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
  75. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
  76. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
  77. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
  78. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
  79. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
  80. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
  81. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
  82. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
  83. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
  84. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
  85. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
  86. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
  87. package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
  88. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
  89. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
  90. package/vendor/quiche/src/recovery/mod.rs +414 -173
  91. package/vendor/quiche/src/recovery/rtt.rs +8 -5
  92. package/vendor/quiche/src/stream/mod.rs +864 -133
  93. package/vendor/quiche/src/stream/recv_buf.rs +476 -172
  94. package/vendor/quiche/src/stream/send_buf.rs +343 -81
  95. package/vendor/quiche/src/test_utils.rs +78 -64
  96. package/vendor/quiche/src/tests.rs +2559 -1335
  97. package/vendor/quiche/src/tls/boringssl.rs +60 -63
  98. package/vendor/quiche/src/tls/mod.rs +146 -193
  99. package/vendor/quiche/src/transport_params.rs +87 -103
@@ -0,0 +1,395 @@
1
+ // Copyright (C) 2026, 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
+ use super::RttJumpUpdate;
31
+
32
+ // 3-state discrete-emission Hidden Markov Model (HMM) RTT jump detector
33
+ // (forward filtering only).
34
+ //
35
+ // The detector is threshold agnostic: rather than binning the raw RTT ratio
36
+ // against fixed multiplicative cutoffs, it tracks the elevation the connection
37
+ // *operates* at above the running-min baseline (an EWMA of the relative
38
+ // deviation observed during calm samples, floored at `HMM_ELEVATION_FLOOR`) and
39
+ // standardizes each sample as its jump *above* that operating elevation, in
40
+ // multiples of it. A "jump" is therefore measured against the connection's own
41
+ // operating point, so ordinary slow self-queueing is less likely to commit as a
42
+ // persistent jump while genuine step changes remain detectable across links
43
+ // with very different absolute RTT and jitter.
44
+
45
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
46
+ enum HmmState {
47
+ Normal,
48
+ Transient,
49
+ Persistent,
50
+ }
51
+
52
+ impl HmmState {
53
+ fn as_index(self) -> usize {
54
+ match self {
55
+ HmmState::Normal => 0,
56
+ HmmState::Transient => 1,
57
+ HmmState::Persistent => 2,
58
+ }
59
+ }
60
+
61
+ fn from_index(index: usize) -> Self {
62
+ match index {
63
+ 0 => HmmState::Normal,
64
+ 1 => HmmState::Transient,
65
+ 2 => HmmState::Persistent,
66
+ _ => unreachable!("invalid HMM state index"),
67
+ }
68
+ }
69
+
70
+ fn from_episode(episode: HmmEpisode) -> Self {
71
+ match episode {
72
+ HmmEpisode::Idle => HmmState::Normal,
73
+ HmmEpisode::Active => HmmState::Transient,
74
+ HmmEpisode::Persistent => HmmState::Persistent,
75
+ }
76
+ }
77
+
78
+ fn to_episode(self) -> HmmEpisode {
79
+ match self {
80
+ HmmState::Normal => HmmEpisode::Idle,
81
+ HmmState::Transient => HmmEpisode::Active,
82
+ HmmState::Persistent => HmmEpisode::Persistent,
83
+ }
84
+ }
85
+
86
+ fn is_more_elevated_than(self, other: Self) -> bool {
87
+ self.as_index() > other.as_index()
88
+ }
89
+ }
90
+
91
+ #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
92
+ enum HmmEpisode {
93
+ #[default]
94
+ Idle,
95
+ Active,
96
+ Persistent,
97
+ }
98
+
99
+ const HMM_STATE_COUNT: usize = 3;
100
+ const HMM_BINS: usize = 5;
101
+
102
+ /// Valid RTT samples observed before the HMM may leave `Idle`.
103
+ const HMM_WARMUP_SAMPLES: u32 = 8;
104
+
105
+ /// Minimum wall-clock dwell for any committed-state transition.
106
+ const HMM_MIN_DWELL: Duration = Duration::from_millis(80);
107
+
108
+ /// RTTs the raw HMM argmax must continuously hold `Transient` before a
109
+ /// transient episode is committed.
110
+ const HMM_TRANSIENT_DWELL_RTTS: u32 = 1;
111
+
112
+ /// RTTs the raw HMM argmax must continuously hold `Persistent` before a
113
+ /// persistent jump is committed.
114
+ const HMM_PERSIST_DWELL_RTTS: u32 = 5;
115
+
116
+ /// RTTs the raw HMM argmax must continuously hold a calmer state before a
117
+ /// committed episode exits.
118
+ const HMM_CLEAR_DWELL_RTTS: u32 = 1;
119
+
120
+ /// HMM persistent-state samples required before committing a persistent jump.
121
+ const HMM_PERSIST_CONFIRM_SAMPLES: u32 = 3;
122
+
123
+ // These matrices are fixed model parameters for RTT-jump detection, calibrated
124
+ // offline from constructed RTT-jump scenarios. They intentionally remain fixed
125
+ // at runtime: the online adaptive parts of this detector are the per-connection
126
+ // operating-elevation estimate and RTT-scaled dwell gates. Adapting the
127
+ // probabilities online would make detections non-deterministic and risks
128
+ // learning persistent RTT jumps as normal behavior.
129
+
130
+ /// HMM transition matrix `A[i][j]` = P(state_t = j | state_{t-1} = i).
131
+ const HMM_TRANSITION: [[f32; HMM_STATE_COUNT]; HMM_STATE_COUNT] = [
132
+ // from Normal: strongly self-sticky; the small leak prefers Transient over
133
+ // Persistent so onset is routed through the middle state.
134
+ [0.9939, 0.0055, 0.0006],
135
+ // from Transient: decays back to Normal unless elevation is reinforced.
136
+ [0.4500, 0.3500, 0.2000],
137
+ // from Persistent: very sticky once a sustained shift is established.
138
+ [0.0243, 0.1603, 0.8154],
139
+ ];
140
+
141
+ /// HMM emission matrix `B[state][bin]` = P(bin | state) over the K = 5
142
+ /// standardized-elevation bins defined by `HMM_STD_BIN_EDGES`.
143
+ const HMM_EMISSION: [[f32; HMM_BINS]; HMM_STATE_COUNT] = [
144
+ // Normal: almost always within a dispersion of the baseline.
145
+ [0.9996, 0.0001, 0.0001, 0.0001, 0.0001],
146
+ // Transient: moderate-to-large elevation.
147
+ [0.1000, 0.3500, 0.3000, 0.1500, 0.1000],
148
+ // Persistent: sustained elevation above the operating level.
149
+ [0.0001, 0.5000, 0.2200, 0.1600, 0.1199],
150
+ ];
151
+
152
+ /// Upper-exclusive bin edges for the standardized elevation
153
+ /// `max(rel - dispersion, 0) / dispersion`.
154
+ const HMM_STD_BIN_EDGES: [f32; HMM_BINS - 1] = [1.0, 2.0, 4.0, 8.0];
155
+
156
+ /// EWMA weight for the online dispersion estimate.
157
+ const HMM_DISP_EWMA_ALPHA: f32 = 0.0625;
158
+
159
+ /// Lower bound on the operating-elevation estimate used to standardize a
160
+ /// sample.
161
+ const HMM_ELEVATION_FLOOR: f32 = 0.20;
162
+
163
+ /// Map a standardized elevation onto its discrete emission bin.
164
+ fn hmm_std_bin(elevation: f32, edges: &[f32; HMM_BINS - 1]) -> usize {
165
+ let mut bin = 0;
166
+ while bin < edges.len() && elevation >= edges[bin] {
167
+ bin += 1;
168
+ }
169
+ bin
170
+ }
171
+
172
+ /// One scaled forward-filter step.
173
+ fn hmm_forward_step(
174
+ alpha: &mut [f32; HMM_STATE_COUNT],
175
+ bin: usize,
176
+ transition: &[[f32; HMM_STATE_COUNT]; HMM_STATE_COUNT],
177
+ emission: &[[f32; HMM_BINS]; HMM_STATE_COUNT],
178
+ ) {
179
+ let mut next = [0.0f32; HMM_STATE_COUNT];
180
+ for (j, next_j) in next.iter_mut().enumerate() {
181
+ let mut predicted = 0.0f32;
182
+ for (i, &alpha_i) in alpha.iter().enumerate() {
183
+ predicted += alpha_i * transition[i][j];
184
+ }
185
+ *next_j = predicted * emission[j][bin];
186
+ }
187
+
188
+ let sum: f32 = next.iter().sum();
189
+ if sum > 0.0 {
190
+ let scale = 1.0 / sum;
191
+ for (dst, src) in alpha.iter_mut().zip(next.iter()) {
192
+ *dst = src * scale;
193
+ }
194
+ } else {
195
+ *alpha = [1.0, 0.0, 0.0];
196
+ }
197
+ }
198
+
199
+ /// `argmax_j alpha[j]`, ties broken toward the lower (calmer) state.
200
+ fn hmm_argmax(alpha: &[f32; HMM_STATE_COUNT]) -> HmmState {
201
+ let mut best = 0;
202
+ for state in 1..HMM_STATE_COUNT {
203
+ if alpha[state] > alpha[best] {
204
+ best = state;
205
+ }
206
+ }
207
+ HmmState::from_index(best)
208
+ }
209
+
210
+ fn relative_elevation(rtt_sample: Duration, baseline: Option<Duration>) -> f32 {
211
+ match baseline {
212
+ Some(baseline) if !baseline.is_zero() => {
213
+ (rtt_sample.as_secs_f32() / baseline.as_secs_f32() - 1.0).max(0.0)
214
+ }
215
+ _ => 0.0,
216
+ }
217
+ }
218
+
219
+ fn dwell_for_transition(current: HmmState, pending: HmmState, rtt_sample: Duration) -> Duration {
220
+ let rtts = if pending.is_more_elevated_than(current) {
221
+ match pending {
222
+ HmmState::Persistent => HMM_PERSIST_DWELL_RTTS,
223
+ HmmState::Transient => HMM_TRANSIENT_DWELL_RTTS,
224
+ HmmState::Normal => unreachable!("normal is not elevated"),
225
+ }
226
+ } else {
227
+ HMM_CLEAR_DWELL_RTTS
228
+ };
229
+
230
+ HMM_MIN_DWELL.max(rtt_sample * rtts)
231
+ }
232
+
233
+ #[derive(Debug)]
234
+ pub(super) struct HmmDetector {
235
+ episode: HmmEpisode,
236
+ /// Scaled forward-filter posterior over `[Normal, Transient, Persistent]`.
237
+ alpha: [f32; HMM_STATE_COUNT],
238
+ /// Count of valid RTT samples fed to the HMM detector.
239
+ valid_samples: u32,
240
+ /// Count of warmup samples that carried usable dispersion information.
241
+ warmup_contrib: u32,
242
+ /// Online per-connection estimate of the elevation the connection operates
243
+ /// at above the running-min baseline.
244
+ dispersion: f32,
245
+ /// Detector-private running-min RTT baseline.
246
+ baseline: Option<Duration>,
247
+ /// Raw per-sample argmax state currently being accumulated toward a commit.
248
+ pending_state: HmmState,
249
+ /// Event time of the first sample of the current pending run.
250
+ pending_start_time: Option<Instant>,
251
+ /// Samples observed while the same pending target remains stable.
252
+ pending_samples: u32,
253
+ /// Whether the current non-idle episode has already been counted.
254
+ episode_counted: bool,
255
+ }
256
+
257
+ impl Default for HmmDetector {
258
+ fn default() -> Self {
259
+ Self {
260
+ episode: HmmEpisode::Idle,
261
+ alpha: [1.0, 0.0, 0.0],
262
+ valid_samples: 0,
263
+ warmup_contrib: 0,
264
+ dispersion: 0.0,
265
+ baseline: None,
266
+ pending_state: HmmState::Normal,
267
+ pending_start_time: None,
268
+ pending_samples: 0,
269
+ episode_counted: false,
270
+ }
271
+ }
272
+ }
273
+
274
+ impl HmmDetector {
275
+ /// HMM RTT jump detector step: one scaled forward-filter update mapped onto
276
+ /// the committed episode state.
277
+ pub(super) fn on_rtt_sample(
278
+ &mut self,
279
+ rtt_sample: Duration,
280
+ event_time: Instant,
281
+ full_bandwidth_reached: bool,
282
+ ) -> RttJumpUpdate {
283
+ self.valid_samples = self.valid_samples.saturating_add(1);
284
+
285
+ let rel = relative_elevation(rtt_sample, self.baseline);
286
+
287
+ if self.valid_samples <= HMM_WARMUP_SAMPLES {
288
+ if rel > 0.0 {
289
+ self.warmup_contrib = self.warmup_contrib.saturating_add(1);
290
+ self.dispersion += (rel - self.dispersion) / self.warmup_contrib as f32;
291
+ }
292
+ self.update_baseline(rtt_sample);
293
+ return RttJumpUpdate::None;
294
+ }
295
+
296
+ let scale = self.dispersion.max(HMM_ELEVATION_FLOOR);
297
+ let elevation = (rel - self.dispersion).max(0.0) / scale;
298
+ let bin = hmm_std_bin(elevation, &HMM_STD_BIN_EDGES);
299
+ hmm_forward_step(&mut self.alpha, bin, &HMM_TRANSITION, &HMM_EMISSION);
300
+
301
+ let raw = hmm_argmax(&self.alpha);
302
+
303
+ if !full_bandwidth_reached {
304
+ self.reset_pending(HmmState::Normal);
305
+ self.update_adaptive_state(rtt_sample, false);
306
+ return RttJumpUpdate::None;
307
+ }
308
+
309
+ let committed_state = HmmState::from_episode(self.episode);
310
+ let mut committed_to_normal = false;
311
+ let mut update = RttJumpUpdate::None;
312
+
313
+ if raw == committed_state {
314
+ self.reset_pending(committed_state);
315
+ } else {
316
+ if raw != self.pending_state || self.pending_start_time.is_none() {
317
+ self.pending_state = raw;
318
+ self.pending_start_time = Some(event_time);
319
+ self.pending_samples = 1;
320
+ } else {
321
+ self.pending_samples = self.pending_samples.saturating_add(1);
322
+ }
323
+
324
+ let episode_start = self.pending_start_time.unwrap_or(event_time);
325
+ let dwell = dwell_for_transition(committed_state, raw, rtt_sample);
326
+ let samples_ok =
327
+ raw != HmmState::Persistent || self.pending_samples >= HMM_PERSIST_CONFIRM_SAMPLES;
328
+ let time_ok = event_time.saturating_duration_since(episode_start) >= dwell;
329
+
330
+ if samples_ok && time_ok {
331
+ match raw {
332
+ HmmState::Persistent => {
333
+ if !self.episode_counted {
334
+ self.episode_counted = true;
335
+ update = RttJumpUpdate::PersistentConfirmed {
336
+ episode_start_time: episode_start,
337
+ };
338
+ }
339
+ self.episode = raw.to_episode();
340
+ }
341
+ HmmState::Transient => {
342
+ self.episode = raw.to_episode();
343
+ }
344
+ HmmState::Normal => {
345
+ committed_to_normal = true;
346
+ self.episode_counted = false;
347
+ self.episode = raw.to_episode();
348
+ }
349
+ }
350
+ self.reset_pending(raw);
351
+ }
352
+ }
353
+
354
+ self.update_adaptive_state(rtt_sample, committed_to_normal);
355
+ update
356
+ }
357
+
358
+ fn reset_pending(&mut self, state: HmmState) {
359
+ self.pending_state = state;
360
+ self.pending_start_time = None;
361
+ self.pending_samples = 0;
362
+ }
363
+
364
+ fn update_adaptive_state(&mut self, rtt_sample: Duration, committed_to_normal: bool) {
365
+ if committed_to_normal {
366
+ self.baseline = Some(rtt_sample);
367
+ } else {
368
+ self.update_baseline(rtt_sample);
369
+ }
370
+
371
+ let rel = relative_elevation(rtt_sample, self.baseline);
372
+
373
+ if matches!(self.episode, HmmEpisode::Idle) && self.pending_start_time.is_none() {
374
+ self.dispersion += HMM_DISP_EWMA_ALPHA * (rel - self.dispersion);
375
+ }
376
+ }
377
+
378
+ fn update_baseline(&mut self, rtt_sample: Duration) {
379
+ self.baseline = Some(self.baseline.map_or(rtt_sample, |min| min.min(rtt_sample)));
380
+ }
381
+
382
+ #[cfg(test)]
383
+ pub(super) fn is_rtt_jump_active(&self) -> bool {
384
+ !matches!(self.episode, HmmEpisode::Idle)
385
+ }
386
+
387
+ #[cfg(test)]
388
+ pub(super) fn is_rtt_jump_persistent(&self) -> bool {
389
+ matches!(self.episode, HmmEpisode::Persistent)
390
+ }
391
+ }
392
+
393
+ #[cfg(test)]
394
+ #[path = "hmm_tests.rs"]
395
+ mod tests;