valnesfjord/tg-ws-proxy-rs
소개
Telegram MTProto WebSocket Bridge Proxy — a Rust vibecoded port of Flowseal/tg-ws-proxy
시스템 및 인프라측정된 스타 증가
- in 24h
- +6
- in 7 days
- +15
- in 15 days
- +36
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
tg-ws-proxy-rs
Telegram MTProto WebSocket Bridge Proxy — a Rust vibecoded port of Flowseal/tg-ws-proxy.
Listens for Telegram Desktop's MTProto connections on a local port and tunnels them through WebSocket (TLS) connections to Telegram's DC servers.
Telegram channel: @tg_ws_proxy_rs.
Telegram Desktop → MTProto (TCP 1443) → tg-ws-proxy-rs → WS (TLS 443) → Telegram DC
↘ CF proxy (kws{N}.{cf-domain}) → Telegram DC (WS via Cloudflare)
↘ CF Worker (*.workers.dev) → Telegram DC (TCP tunnel via Cloudflare)
↘ upstream MTProto proxy → Telegram DC (WS fallback)
↘ direct TCP :443 → Telegram DC (last resort)
Why Rust?
| Python original | This port | |
|---|---|---|
| Runtime | CPython required | Single static binary |
| Memory | ~30–50 MB | ~3–5 MB |
| CPU | Higher | Lower (compiled) |
| OpenWrt | Needs Python install | Just copy the binary |
| Static build | No | Yes (musl) |
Quick Start
Pre-built binaries
Download from the Releases page. Linux musl targets also ship
a -upx variant that is ~70% smaller on disk, for routers where flash is
tight — see docs/Building.md
for the RAM trade-off that comes with it.
On Windows 7 and 8, take tg-ws-proxy-x86_64-win7-windows-msvc.zip (or the
i686 one for 32-bit Windows). The regular x86_64-pc-windows-gnu build needs
Windows 10 or newer.
The Android app ships on the same page. Take
tg-ws-proxy-rs-android-<version>-universal.apk unless you know your phone's
ABI — the per-ABI arm64-v8a, armeabi-v7a and x86_64 builds are about a
third of the size. Android 8.0 is the minimum.
Docker
Published to Docker Hub as
valnesfjord/tg-ws-proxy-rs
(linux/amd64 + linux/arm64):
docker run -d --name tg-ws-proxy -p 1443:1443 valnesfjord/tg-ws-proxy-rs
Set TG_SECRET so the secret survives restarts, and --link-ip so the printed
tg:// link points at a reachable address — see
docs/Deployment.md.
Build from source
cargo build --release
The binary lands in target/release/tg-ws-proxy. Cross-compiling for OpenWrt
(MIPS/ARM/ARM64) is covered in docs/Building.md.
Android
A Jetpack Compose app in android/ runs the same core as a library: paste the
CLI flags, start/stop, open the tg://proxy link. Install the APK from the
Releases page or F-Droid, or build it from source — see
docs/Android.md.
OpenWrt
Raw release binaries, LuCI packages and a one-line installer are available. See OpenWrt installation below.
Entware
Keenetic and other routers running Entware at /opt take the same release
binary, without the LuCI package. See
Entware installation below.
Telegram Desktop setup
- Settings → Advanced → Connection type → Use custom proxy
- Add MTProto proxy:
- Server:
127.0.0.1 - Port:
1443(or your--port) - Secret: shown in the proxy startup log
- Server:
Or use the tg://proxy?... link that is printed on startup.
Optional SOCKS5 input / Forkop
Enable --socks-enabled (or Enable SOCKS5 input in LuCI) to expose a separate
Telegram-only SOCKS5 listener on 127.0.0.1:1080. A local routing service can send
supported Telegram TCP transports through it while existing MTProto clients keep
using the original listener. WSS, Cloudflare and fallback settings are shared.
See SOCKS5 and Forkop setup / Настройка Forkop на русском for installation, device-scoped routing, loop prevention, DC mappings, testing and rollback. This is not a general-purpose SOCKS proxy or a virtual VPN interface; UDP calls and arbitrary HTTPS traffic are not supported.
OpenWrt installation
Requirements
- OpenWrt 25.12+ (APK) or ImmortalWrt 25.12+ (APK).
- OpenWrt 24.10 (opkg) or ImmortalWrt 24.10 (opkg).
- Root SSH access and a supported musl target: AArch64, ARMv7, MIPS, MIPSel or x86_64. Python is not required.
The proxy itself is the existing static musl release binary, not an OpenWrt
package. Only the architecture-independent LuCI/service integration is packaged:
luci-app-tg-ws-proxy-rs is published as APK (noarch) and IPK (all). Every
installed path carries the -rs suffix, so a router can keep an upstream
tg-ws-proxy package installed alongside this port.
Quick install (one-liner)
Run over SSH on the router:
wget -qO- https://raw.githubusercontent.com/valnesfjord/tg-ws-proxy-rs/main/install.sh | sh
The installer detects APK/opkg and DISTRIB_ARCH, downloads the matching raw
musl archive and LuCI package, verifies both against immutable SHA-256 digests
from the GitHub release API, migrates a known manual configuration and starts
the procd service. Re-run it to upgrade.
To trade higher runtime memory use for a smaller file on flash, explicitly select the existing UPX release asset:
wget -qO- https://raw.githubusercontent.com/valnesfjord/tg-ws-proxy-rs/main/install.sh | \
sh -s -- --upx
If GitHub release downloads require a mirror, put the variable on sh (not on
wget):
wget -qO- https://raw.githubusercontent.com/valnesfjord/tg-ws-proxy-rs/main/install.sh | \
GH_MIRROR=https://your.mirror sh
The mirror may provide the payload, but the expected digest always comes from
api.github.com; the mirror is not part of the trust boundary.
Beta releases
Beta tags (vX.Y.Z-beta.N) are normal GitHub prereleases. Stable is the default;
beta installation is explicit and can be combined with --upx:
wget -qO- https://raw.githubusercontent.com/valnesfjord/tg-ws-proxy-rs/main/install.sh | \
sh -s -- --channel beta
Publishing a beta does not change the stable releases/latest channel.
Local install
If the router cannot download from GitHub, use a computer to save
install.sh and three files from the same release: the router's musl
.tar.gz, the separate LuCI package (.apk for OpenWrt 25.12+ or .ipk
for 24.10), and SHA256SUMS. Copy all four to the router and run
sh /tmp/install.sh with the archive and LuCI package paths.
Download, transfer and install commands.
Configure and operate
After installation, open Services → Telegram WS Proxy (Rust) in LuCI. Configure the
listener, advertised link address, secret and any outbound/Cloudflare fallback,
then use Save & Apply. The page includes service controls and a filtered live
view of the bounded OpenWrt logd ring buffer. The package does not open a WAN
firewall port automatically.

For UCI examples, firewall guidance and rollback details, see the full OpenWrt guide.
Entware installation
Keenetic and other routers that run Entware at /opt
take the same static musl release binary as OpenWrt, without the LuCI package:
there is no LuCI, no UCI and no procd on Entware, so the integration is one
Entware init script and one config file. The installer tells the platforms apart
by their own markers — /etc/openwrt_release on OpenWrt, /opt/etc/opkg.conf
elsewhere — so the one-liner below is the same one to run on either.
Requirements
- Entware installed at
/optand started at boot, which is the standard Keenetic setup:rc.unslungunder/opt/etc/init.dis what starts it. - Root SSH access and a supported musl target, i.e.
opkg print-architectureanswering one of the Entware namesaarch64-3.10,armv7-3.2,mips-3.4,mipsel-3.4orx64-3.2(the Keenetic feeds suffix theirs with_kn). Entware's ARMv7 feeds are soft-float builds reported asarmv7-3.2, and the release binary is hard-float: a core without VFP is refused by the run check rather than by its name. ARMv5 (armv5-3.2) and the 32-bit x86 feed have no matching release binary and are refused rather than installed and crashed.
Quick install (one-liner)
Run over SSH on the router:
curl -fsSL https://raw.githubusercontent.com/valnesfjord/tg-ws-proxy-rs/main/install.sh | sh
wget -qO- … | sh is the one to use where BusyBox wget has TLS compiled in —
without it the fetch answers not an http or ftp url. The installer itself
tries either downloader for what it fetches.
Re-run it to upgrade. On a box that already runs the Go port (tg-ws-proxy) on
the same port, the installer stops it and clears its init script's executable
bit, leaving that build's files and configuration where they are; a failed
install puts the bit back.
Configure and operate
Check the running service and print its Telegram link:
/opt/etc/init.d/S99tg-ws-proxy-rs status
Use the same script with start, stop, or restart to control it.
Settings live in /opt/etc/tg-ws-proxy-rs/config.conf and the MTProto secret in
secret.conf beside it, both 0600; an existing secret and port survive an
upgrade. LINK_IP is written from the bridge address the installer finds, so
the tg:// link it prints is one the LAN can dial — the binary's own detection
reports a tunnel address on a router that has one. status prints that link,
and the log is /opt/var/log/tg-ws-proxy-rs.log, with the previous run kept as
.log.1 (a run over 1 MiB is kept as its last 64 KiB). The executable bit on
the init script is what enables the proxy at boot: chmod -x disables it
without deleting anything.
The listener is not exposed to the WAN. That is a firewall decision here exactly as it is on OpenWrt.
Usage
tg-ws-proxy [OPTIONS]
| Flag | Default | Description |
|---|---|---|
--port <PORT> |
1443 |
Listen port |
--host <HOST> |
auto-detected | Listen address. Binds 0.0.0.0 if a LAN IP is detected (so it matches the auto-detected link IP below), otherwise 127.0.0.1 |
--link-ip <IP> |
auto-detected | IP shown in the tg:// link (see Router deployment) |
--secret <HEX> |
random | 32 hex-char MTProto secret (repeatable / comma-separated for per-user secrets) |
--listen-faketls-domain <DOMAIN> |
— | Accept inbound clients with ee FakeTLS and advertise this SNI domain in the link |
--socks-enabled |
off | Also listen for Telegram over SOCKS5, no authentication (see docs/Forkop.md) |
--socks-host <IP> / --socks-port <PORT> |
127.0.0.1 / 1080 |
SOCKS5 listen address |
--socks-dc <DC:IP> |
built-in map | Extra SOCKS destination mappings, signed (-2 = DC2 media), comma-separated/repeatable |
--dc-ip <DC:IP> |
DC2 + DC4 | Target IP per DC (repeatable); omit when using --cf-domain to let CF proxy handle all DCs |
--buf-kb <KB> |
256 |
Socket buffer size (accepted but currently unused) |
--pool-size <N> |
4 |
Pre-warmed WS connections per DC |
--cf-domain <DOMAIN> |
— | Cloudflare-proxied domain(s) for alternative WS routing, comma-separated |
--cf-worker-domain <DOMAIN> |
— | Cloudflare Worker domain(s) for TCP-tunnel fallback, comma-separated/repeatable |
--default-domains |
off | Fetch the community CF proxy domain list from GitHub and refresh it hourly (no Cloudflare setup needed) |
--pinned-upstream <TIERS> / --pinned-media-upstream <TIERS> |
default ladder | Pin the upstream tier order (ws,cfworker,cfproxy,mtproto,tcp, try-order); the media flag overrides the base one for media connections, which otherwise inherit it (see docs/Fallbacks.md) |
--cf-balance |
off | Round-robin load balance across multiple --cf-domain and --cf-worker-domain values |
--cf-disable-tls |
off | Use plaintext ws:// on port 80 for CF proxy and Worker connections; direct Telegram WS remains TLS |
--cf-http-fallback |
off | Retry a timed-out CF proxy WebSocket on port 80. Plain HTTP exposes the hostname and connection metadata. |
--cf-ip <IP> |
DNS | Preferred Cloudflare edge IPv4/IPv6 addresses for CF proxy and Worker connections (comma-separated/repeatable); tries every address, never DNS-falls back |
--ip-fail-cooldown <SECS> |
3600 |
How long to skip the direct WS path for a --dc-ip address whose TCP connect timed out, when a Cloudflare/upstream fallback is configured |
--fronting-domain <DOMAIN> |
off | Always present this domain as the TLS SNI for direct WS connections (fronting), e.g. sprinthost.ru; needs --dc-ip |
--max-connections <N> |
auto | Max concurrent client connections (auto-computed from ulimit -n) |
--client-idle-timeout <SECS> |
900 |
Close a client session after this long without traffic in either direction. 0 disables the timeout. |
--mtproto-proxy <HOST:PORT:SECRET> |
— | Upstream MTProto proxy fallback (repeatable) |
--outbound-proxy <URL> |
— | Proxy for all outgoing connections: http://, socks5://, or socks5h://; https:// proxy URLs are not supported |
--no-outbound-proxy |
off | Ignore standard outbound proxy environment variables |
--no-proxy <LIST> |
— | Comma-separated host bypass list for --outbound-proxy |
--outbound-mark <MARK> |
— | Linux firewall mark for outbound TCP sockets, in decimal or 0x-prefixed hex |
--check |
off | Test every configured CF domain and MTProto proxy, print OK/FAIL with latency, then exit 0 if all pass and 1 otherwise |
--check-listener |
off | Implies --check: binds and serves, probes its own listener end-to-end (obfuscation handshake, a real req_pq_multi, the DC's resPQ back), then exits with the check's code |
--print-links |
off | Print every enabled listener's connection links (inbound<TAB>label<TAB>url per line) and exit without binding; LuCI uses it for its copy buttons |
--log-file <PATH> |
— | Write logs to a file instead of stderr (no ANSI color codes) |
-q / --quiet |
off | Suppress all log output |
-v / --verbose |
off | Debug logging |
--danger-accept-invalid-certs |
off | Skip TLS verification |
-V / --version |
— | Print the version and exit |
Every flag has a matching TG_* environment variable (TG_PORT, TG_HOST,
TG_SECRET, …) — the full list is in
docs/Deployment.md.
On startup the proxy prints a tg://proxy?... link you can paste into
Telegram Desktop to configure it automatically. With --listen-faketls-domain,
the printed link uses secret=ee<key><domain_hex>; otherwise it uses the
classic dd<key> padded MTProto secret.
To issue separate credentials per user, pass multiple --secret values — the
proxy accepts all of them and prints an individual tg:// link for each:
tg-ws-proxy --host 0.0.0.0 --port 443 \
--secret 11111111111111111111111111111111 \
--secret 22222222222222222222222222222222
Examples
# Standard run (random secret, DC 2 + 4)
tg-ws-proxy
# Custom port and extra DCs
tg-ws-proxy --port 9050 --dc-ip 1:149.154.175.205 --dc-ip 2:149.154.167.220
# Use default CF domains from GitHub — no Cloudflare setup required
tg-ws-proxy --default-domains
# Default domains + CF-first pin (try CF first, fall back to direct WS)
tg-ws-proxy --default-domains --dc-ip 2:149.154.167.220 --dc-ip 4:149.154.167.220 \
--pinned-upstream cfproxy,ws,tcp
# Your own Cloudflare-proxied domain
tg-ws-proxy --cf-domain yourdomain.com
# Multiple CF domains with round-robin load balancing
tg-ws-proxy --cf-domain proxy.net,example.com --cf-balance
# Free workers.dev TCP tunnel fallback
tg-ws-proxy --cf-worker-domain random-symbols-1234.username.workers.dev
# Use plaintext WebSocket to Cloudflare when TLS interception breaks WSS
tg-ws-proxy --cf-domain yourdomain.com --cf-disable-tls
# Upstream MTProto proxy fallback
tg-ws-proxy --mtproto-proxy proxy.example.com:443:ddabcdef1234567890abcdef1234567890
# Route all outbound connections through a SOCKS5 proxy with remote DNS
tg-ws-proxy --outbound-proxy socks5h://user:[email protected]:1080
# Router deployment: listen on all interfaces, let all LAN devices use the proxy
tg-ws-proxy --host 0.0.0.0
# Public home server: inbound ee FakeTLS, backend still WSS to Telegram Web
tg-ws-proxy --host 0.0.0.0 --port 443 --listen-faketls-domain www.yandex.ru
# Log to a file instead of stderr (no garbled ANSI codes — useful on Windows)
tg-ws-proxy --log-file proxy.log
# All options via environment variables (useful for Docker / systemd)
TG_PORT=1443 TG_SECRET=deadbeef... tg-ws-proxy
How it works
- Telegram Desktop connects to the proxy on
127.0.0.1:1443. - The proxy reads the 64-byte MTProto obfuscation handshake, validates the secret, and extracts the target DC id and transport protocol.
- A WebSocket connection is opened to
wss://kwsN.web.telegram.org/apiws(using the DC-specific domain as TLS SNI but routing TCP to the configured IP). - The relay init packet is sent to Telegram, and bidirectional bridging begins with AES-256-CTR re-encryption (client keys ↔ relay keys).
- If that path fails, each configured fallback tier is tried in turn — Cloudflare Worker, Cloudflare proxy, upstream MTProto proxy, then direct TCP on port 443.
- A small pool of pre-connected WebSocket connections is maintained per DC to reduce connection latency for subsequent clients.
The tier order, how to configure each one, and when a failing tier goes into cooldown are all documented in docs/Fallbacks.md.
Documentation
| Guide | Covers |
|---|---|
| docs/Fallbacks.md | Routing tiers: Cloudflare proxy/Worker, default domains, domain fronting, upstream MTProto proxies, inbound FakeTLS, outbound proxy |
| docs/Building.md | Building, cross-compiling for OpenWrt, and shrinking the binary with UPX |
| docs/Deployment.md | Docker, router deployment, OpenWrt init script, environment variables |
| docs/OpenWrtPackage.md | Standalone APK/IPK builds, UCI/procd configuration, installer, upgrades and rollback |
| docs/Android.md | The Android app: Gradle/NDK build, ABI splits, signing, installing and CI |
| docs/CfProxy.md | Cloudflare DNS proxy setup, step by step |
| docs/CfWorker.md | Cloudflare Worker TCP tunnel setup |
| AGENTS.md | Repository layout and conventions for contributors |
Releases and changes are announced on the Telegram channel @tg_ws_proxy_rs.
License
MIT
관련 프로젝트 살펴보기
불러오는 중…