FoxiGram/TMessagesProj/jni/tgnet/IptController.h
instant992 8e79f2ee9c FoxiGram: Telegram client with built-in Xray VLESS proxy
Based on Nekogram. Key additions:
- Rebrand to FoxiGram (app name, APK name, applicationId com.foxigram.app)
- Embedded Xray (VLESS+Reality) proxy client via JNI libxray.so
- Bundled hidden one-tap proxies (LTE + WiFi), read-only in UI
- Auto-restore proxy on restart, rebind to active network (LTE/WiFi)
- Server credentials externalized to git-ignored XrayServers.java (+ template)
- libxray Go source included; compiled .so, keystore, google-services.json ignored
2026-06-08 16:41:07 +04:00

70 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* IptController.h — Inter-Packet Timing obfuscation for tgnet
* Ported from telemt/tdlib-obf (MIT License, Copyright 2026 telemt community)
* Adapted for tgnet: C++17, no tdlib dependencies.
*
* IPT uses a two-state Markov model (Burst / Idle) to add randomised delays
* between TLS records, mimicking the inter-packet timing of interactive
* browser sessions and defeating timing-based DPI correlation attacks.
*
* Burst state: lognormal delays (µ=3.5ms, σ=0.8), capped at 200ms
* Idle state: heavy-tail Pareto gaps (α=1.5, scale=500ms, max=3s)
*
* Bypass (zero delay) for: BulkData, Keepalive, AuthHandshake
*/
#ifndef IPT_CONTROLLER_H
#define IPT_CONTROLLER_H
#include <cstdint>
#include "DrsEngine.h" // for TrafficHint
namespace stealth {
struct IptParams {
double burst_mu_ms{3.5};
double burst_sigma{0.8};
double burst_max_ms{200.0};
double idle_alpha{1.5};
double idle_scale_ms{500.0};
double idle_max_ms{3000.0};
// Markov transition probabilities
double p_burst_stay{0.95}; // P(stay Burst | was Burst)
double p_idle_to_burst{0.30}; // P(go Burst | was Idle)
};
class IptController {
public:
explicit IptController(const IptParams &params = IptParams{});
// Returns delay in microseconds before the next record should be sent.
// has_pending_data: true if outgoing buffer is non-empty after this send.
// hint: traffic type — BulkData/Keepalive/AuthHandshake bypass IPT (return 0).
uint64_t next_delay_us(bool has_pending_data,
TrafficHint hint = TrafficHint::Interactive);
// Sample an idle gap delay — used by ChaffScheduler.
uint64_t sample_idle_delay_us();
private:
enum class State : uint8_t { Idle = 0, Burst = 1 };
static bool is_bypass(TrafficHint hint);
State transition(bool has_pending_data);
double sample_uniform01();
double sample_normal();
double sample_lognormal(double mu, double sigma);
double sample_pareto(double u, double alpha, double scale, double max_val) const;
IptParams params_;
State state_{State::Idle};
bool has_spare_normal_{false};
double spare_normal_{0.0};
};
} // namespace stealth
#endif // IPT_CONTROLLER_H