Skip to content

Commit 40c2b6c

Browse files
feat(udp): SOCKS5 UDP ASSOCIATE relay through full tunnel
Adds end-to-end UDP support: SOCKS5 client UDP ASSOCIATE → tunnel-mux udp_open/udp_data ops → tunnel-node UDP sessions → real UDP to upstream. QUIC/HTTP3, DNS, and STUN now traverse full mode without falling back to TCP or leaking outside the tunnel. Apps Script proxies the new ops opaquely through the existing batch endpoint; CodeFull.gs only gets a doc-comment update. Highlights: - proxy_server.rs: SOCKS5 UDP ASSOCIATE handler with per-session task, bounded uplink mpsc channel, adaptive empty-poll backoff (500 ms → 30 s), source-IP validation against the control TCP peer, port-locking on first valid datagram, and self-removal from the dispatch map on eof. - tunnel_client.rs: UdpOpen / UdpData / close_session mux variants alongside the existing TCP plumbing; pkts decoder helper. - tunnel-node: UdpSessionInner with bounded VecDeque queue, drop-oldest on overflow with queue_drops counter and warn-then-throttled logs, last_active refreshed only on real activity (uplink send or upstream recv — empty polls do not refresh), independent TCP/UDP drain in handle_batch Phase 2, separate active-drain (150 ms) and retry (250 ms) windows for UDP, idle long-poll (5 s). - Tests: SOCKS5 UDP packet parser (IPv4/IPv6/DOMAIN round-trips, truncation rejects, fragmented rejects), UDP queue overflow drop + counter, regression test that batch with both UDP and TCP-data ops still runs the TCP retry pass. Docs: README + android.{md,fa.md} updated to reflect UDP availability in full mode; tunnel-node/README documents the new ops.
1 parent fb552c2 commit 40c2b6c

9 files changed

Lines changed: 1314 additions & 151 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ HTTP/HTTPS continues to route through the Apps Script relay (no change), and the
267267

268268
## Full tunnel mode
269269

270-
Full tunnel mode (`"mode": "full"`) routes **all** traffic end-to-end through Apps Script and a remote [tunnel-node](tunnel-node/) — no MITM certificate needed. The trade-off is higher latency per request (every byte goes Apps Script → tunnel-node → destination), but it works for every protocol and every app without CA installation.
270+
Full tunnel mode (`"mode": "full"`) routes **all** traffic end-to-end through Apps Script and a remote [tunnel-node](tunnel-node/) — no MITM certificate needed. TCP is carried as persistent tunnel sessions, and UDP from Android/TUN clients is carried via SOCKS5 `UDP ASSOCIATE` to the tunnel-node, which then emits real UDP from the server side. The trade-off is higher latency per request (every byte/datagram goes Apps Script → tunnel-node → destination), but it works for protocols and apps that cannot use the MITM relay path.
271271

272272
### How deployment IDs affect performance
273273

‎assets/apps_script/CodeFull.gs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* 2. Batch relay: POST { k, q: [{m,u,h,b,ct,r}, ...] } → { q: [{s,h,b}, ...] }
77
* 3. Tunnel: POST { k, t, h, p, sid, d } → { sid, d, eof }
88
* 4. Tunnel batch: POST { k, t:"batch", ops:[...] } → { r: [...] }
9+
* Batch ops include TCP (`connect`, `data`) and UDP (`udp_open`,
10+
* `udp_data`) tunnel-node operations.
911
*
1012
* CHANGE THESE TO YOUR OWN VALUES!
1113
*/

‎docs/android.fa.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ VpnService TUN ──► tun2proxy (داخل فرایند)
234234

235235
**سایت‌هایی که فقط بارگذاری اول را `gate` می‌کنند** (اکثر مشتریان `Bot Fight Mode` کلادفلر) بعد از یک حل بی‌مشکل کار می‌کنند. سایت‌هایی که هر درخواست `challenge` می‌زنند (صرافی‌های رمزارز، بزرگسال، بعضی فوروم‌ها) ذاتاً با این معماری نمی‌شوند — برایشان از تونل دیگری استفاده کنید.
236236

237-
### UDP / QUIC (HTTP/3) رد نمی‌شود
237+
### UDP / QUIC (HTTP/3)
238238

239-
`SOCKS5 listener` فقط `CONNECT` را می‌فهمد، نه `UDP ASSOCIATE`. `Chrome` اول `HTTP/3` را امتحان می‌کند و به `HTTP/2 over TCP` برمی‌گردد — که از پروکسی رد می‌شود. اثر: اولین اتصال کمی کندتر، بقیه چیزها عادی.
239+
در حالت `full`، `SOCKS5 listener` دستور `UDP ASSOCIATE` را هم می‌فهمد و دیتاگرام‌های UDP را داخل مسیر Apps Script تا `tunnel-node` می‌برد؛ بعد `tunnel-node` از سمت سرور UDP واقعی به مقصد می‌فرستد. ISP شما همچنان فقط HTTPS به Google می‌بیند. در حالت `apps_script`، UDP هنوز مسیر قدیمی را دارد: `Chrome` اول `HTTP/3` را امتحان می‌کند و بعد به `HTTP/2 over TCP` برمی‌گردد.
240240

241241
### نشت IPv6
242242

‎docs/android.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ Cloudflare's `cf_clearance` cookie is bound to the `(IP, UA, JA3)` tuple the cha
221221

222222
**Sites that only gate the first page load** (most of CF's Bot Fight Mode customers) work fine after one solve. Sites that challenge every request (crypto exchanges, adult, some forums) fundamentally can't hold a session through this architecture — use a different tunnel for those.
223223

224-
### UDP / QUIC (HTTP/3) doesn't go through
224+
### UDP / QUIC (HTTP/3)
225225

226-
The SOCKS5 listener only handles `CONNECT`, not `UDP ASSOCIATE`. Chrome tries HTTP/3 first and falls back to HTTP/2 over TCP, which works fine. Effect: slightly slower first connect, everything else normal.
226+
In `full` mode, the SOCKS5 listener handles `UDP ASSOCIATE` and tunnels UDP datagrams through Apps Script to `tunnel-node`, which then sends real UDP to the destination. Your ISP still only sees HTTPS to Google. In `apps_script` mode, UDP still falls back the old way: Chrome tries HTTP/3 first and then uses HTTP/2 over TCP.
227227

228228
### IPv6 leaks
229229

‎src/domain_fronter.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ pub struct TunnelResponse {
181181
pub sid: Option<String>,
182182
#[serde(default)]
183183
pub d: Option<String>,
184+
/// UDP datagrams returned by tunnel-node, base64-encoded individually.
185+
#[serde(default)]
186+
pub pkts: Option<Vec<String>>,
184187
#[serde(default)]
185188
pub eof: Option<bool>,
186189
#[serde(default)]

0 commit comments

Comments
 (0)