ali_rajabpour 721b75c687 perf/deploy: optimize hot-path allocs (cut per-session ad_tag allocations), split metrics module, and add ENV config support
Three independent changes bundled here — performance, maintainability, and
deployment DX.

1. Hot-path Allocations (ad_tag caching):
Every middle-relay session was doing a hex::decode of the user's ad_tag (plus a fallback to the global one) on every single connection. That's two string allocations and two hex decodes per session for data that only changes on config reload. Moved the decoding into ProxyConfig load/hot-reload into a precomputed runtime_ad_tags cache (same #[serde(skip)] pattern as runtime_user_auth). The session path now does a single O(1) lookup via config.effective_ad_tag(&user). Falls back to on-demand decode if the cache isn't built (e.g. in tests), so existing behavior is preserved. This eliminates two useless allocations and hex decodes per connection.

2. Metrics Monolith Split(structural refactor):
Broke up the massive 4,200-line `metrics.rs` into a proper `metrics/` directory module (`mod.rs`, `tls_front.rs`, `tests.rs`). I isolated the giant `render_metrics` function into its own `render.rs` file. This was a purely structural move—no locks or function bodies were changed, keeping things build-safe while making the crate significantly easier to navigate. The /metrics endpoint output is byte-identical.

3. GitOps / Dokploy Auto-Deployment Support (deployment DX):
Added `figment` to `Cargo.toml` to seamlessly merge TOML config files with Environment Variables. You can now configure the proxy entirely using `TELEMT_` prefixed ENV variables (e.g., `TELEMT_GENERAL__PORT=443`) without needing to manually mount a physical `config.toml` via Docker volumes. The Dockerfile and compose setups now gracefully handle missing config files by generating an empty placeholder, making stateless auto-deployments on platforms like Dokploy frictionless.
2026-08-03 18:41:24 +04:00
2026-06-29 11:01:36 +03:00
2026-05-10 13:29:02 +03:00
2026-07-19 18:36:04 +03:00
2026-04-10 13:17:51 +03:00
2026-07-03 23:39:46 +03:00
2026-05-28 12:26:46 +03:00
2026-04-06 13:21:16 +03:00
2026-03-14 15:59:21 +03:00
2026-06-14 12:03:55 +03:00
2026-02-18 19:04:39 +03:00

Telemt - MTProxy on Rust + Tokio

Latest Release Stars Forks

🇷🇺 README на русском

Note

From June 5th, 2026: we are already analyzing the causes of a new wave of "malfunctions"

Telegram Clients TLS ClientHello has been banned by JA4/JA4+ Fingerprint: we are already looking for ways to solve this problem

You can try build your client with our Telegram Devlibrary - tdlib-obf

Telemt is a fast, secure, and feature-rich server written in Rust: it fully implements the official Telegram proxy algo and adds many production-ready improvements

One-command Install and Update

curl -fsSL https://raw.githubusercontent.com/telemt/telemt/main/install.sh | sh

Features

Our implementation of TLS-fronting is one of the most deeply debugged, focused, advanced and almost "behaviorally consistent to real": we are confident we have it right - see evidence on our validation and traces

Our Middle-End Pool is fastest by design in standard scenarios, compared to other implementations of connecting to the Middle-End Proxy: non dramatically, but usual

  • Full support for all official MTProto proxy modes:
    • Classic;
    • Secure - with dd prefix;
    • Fake TLS - with ee prefix + SNI fronting;
  • Replay attack protection;
  • Optional traffic masking: forward unrecognized connections to a real web server, e.g. GitHub 🤪;
  • Configurable keepalives + timeouts + IPv6 and "Fast Mode";
  • Graceful shutdown on Ctrl+C;
  • Extensive logging via trace and debug with RUST_LOG method.

FAQ

Learn more about Telemt

Build

# Cloning repo
git clone https://github.com/telemt/telemt 
# Changing Directory to telemt
cd telemt
# Starting Release Build
cargo build --release

# Current release profile uses lto = "fat" for maximum optimization (see Cargo.toml).
# On low-RAM systems (~1 GB) you can override it to "thin".

# Move to /bin
mv ./target/release/telemt /bin
# Make executable
chmod +x /bin/telemt
# Lets go!
telemt config.toml

Why Rust?

  • Long-running reliability and idempotent behavior
  • Rust's deterministic resource management - RAII
  • No garbage collector
  • Memory safety and reduced attack surface
  • Tokio's asynchronous architecture

Support Telemt

Telemt is free, open-source, and built in personal time. If it helps you — consider supporting continued development.

Any cryptocurrency (BTC, ETH, USDT, 350+ coins):

Cryptocurrency & Bitcoin donation button by NOWPayments

Monero (XMR) directly:

8Bk4tZEYPQWSypeD2hrUXG2rKbAKF16GqEN942ZdAP5cFdSqW6h4DwkP5cJMAdszzuPeHeHZPTyjWWFwzeFdjuci3ktfMoB

All donations go toward infrastructure, development and research

telemt_scheme

Languages
Rust 97.2%
JavaScript 1.2%
Python 0.9%
Shell 0.6%