Skip to main content

ferogram_connect/
race.rs

1/*
2 * Copyright (c) 2026 Ankit Chaubey <ankitchaubey.dev@gmail.com>
3 * https://github.com/ankit-chaubey
4 *
5 * Project: ferogram
6 * Website: https://ferogram.dev
7 *
8 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
11 * This file may not be copied, modified, or distributed except according
12 * to those terms.
13 */
14
15use std::time::Duration;
16
17use crate::transport_kind::TransportKind;
18
19/// One leg of a transport race: transport plus its start delay.
20#[derive(Clone, Debug)]
21pub struct RaceLeg {
22    pub transport: TransportKind,
23    pub stagger: Duration,
24}
25
26impl RaceLeg {
27    pub fn new(transport: TransportKind, stagger_ms: u64) -> Self {
28        Self {
29            transport,
30            stagger: Duration::from_millis(stagger_ms),
31        }
32    }
33}
34
35/// Full vs Obfuscated. Abridged/Intermediate aren't included since they
36/// share Full's TCP path and framing fingerprint, so they live or die with
37/// it against DPI - racing them adds load with no extra chance of success.
38pub fn default_transport_race() -> Vec<RaceLeg> {
39    vec![
40        RaceLeg::new(TransportKind::Full, 0),
41        RaceLeg::new(TransportKind::Obfuscated { secret: None }, 200),
42    ]
43}