Skip to main content

ferogram_connect/
transport_kind.rs

1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2//
3// ferogram: async Telegram MTProto client in Rust
4// https://github.com/ankit-chaubey/ferogram
5//
6// Licensed under either the MIT License or the Apache License 2.0.
7// See the LICENSE-MIT or LICENSE-APACHE file in this repository:
8// https://github.com/ankit-chaubey/ferogram
9//
10// Feel free to use, modify, and share this code.
11// Please keep this notice when redistributing.
12
13/// Which MTProto wire framing to use for a connection.
14///
15/// | Variant | Init bytes | Notes |
16/// |---------|-----------|-------|
17/// | `Abridged` | `0xEF` | Lightest framing |
18/// | `Intermediate` | `0xEEEEEEEE` | 4-byte length prefix |
19/// | `Full` | none | length + seqno + CRC32 |
20/// | `Obfuscated` | random 64B | Bypasses DPI / MTProxy: **default** |
21/// | `PaddedIntermediate` | random 64B (`0xDDDDDDDD` tag) | Required for `0xDD` MTProxy secrets |
22/// | `FakeTls` | TLS 1.3 ClientHello | Most DPI-resistant; required for `0xEE` MTProxy secrets |
23#[derive(Clone, Debug)]
24pub enum TransportKind {
25    /// MTProto [Abridged] transport: length prefix is 1 or 4 bytes.
26    Abridged,
27    /// MTProto [Intermediate] transport: 4-byte LE length prefix.
28    Intermediate,
29    /// MTProto [Full] transport: 4-byte length + seqno + CRC32.
30    Full,
31    /// [Obfuscated2] transport: AES-256-CTR over Abridged framing.
32    /// Required for MTProxy and networks with deep-packet inspection.
33    /// **Default**: works on all networks, bypasses DPI, negligible CPU cost.
34    ///
35    /// `secret` is the 16-byte MTProxy secret, or `None` for keyless obfuscation.
36    Obfuscated { secret: Option<[u8; 16]> },
37    /// Obfuscated PaddedIntermediate transport (`0xDDDDDDDD` tag in nonce).
38    ///
39    /// Same AES-256-CTR obfuscation as `Obfuscated`, but uses Intermediate
40    /// framing and appends 0-15 random padding bytes to each frame.
41    /// Required for `0xDD` MTProxy secrets.
42    PaddedIntermediate { secret: Option<[u8; 16]> },
43    /// FakeTLS transport (`0xEE` prefix in MTProxy secret).
44    ///
45    /// Wraps all MTProto data in fake TLS 1.3 records.
46    FakeTls { secret: [u8; 16], domain: String },
47    /// HTTP transport fallback: sends raw MTProto frames as HTTP POST to port 80.
48    Http,
49}
50
51impl Default for TransportKind {
52    fn default() -> Self {
53        TransportKind::Obfuscated { secret: None }
54    }
55}