Repository navigation
feat(android): add udpgw_server parameter to JNI run() - #247
yyoyoian-pixel wants to merge 1 commit into
Conversation
|
@ssrlive can we have a review on this one please? |
Add an optional `udpgw_server` JString parameter to the Android JNI `run()` function. When non-empty (e.g. "198.18.0.1:7300"), tun2proxy will forward UDP packets via the udpgw protocol through a TCP connection to the specified address. This enables Android VPN apps using tun2proxy to leverage the existing udpgw support for UDP forwarding (DNS, QUIC, VoIP) without needing to call `tun2proxy_run_with_cli_args` or fork the crate. The parameter is gated behind `#[cfg(feature = "udpgw")]` — when the feature is disabled, the extra JString argument is accepted but ignored, keeping the JNI signature stable.
f20af68 to
dfc24ed
Compare
Use the idiomatic Rust [patch.crates-io] mechanism instead of a git submodule. Points to yyoyoian-pixel/tun2proxy fork with the udpgw JNI parameter patch (upstream PR: tun2proxy/tun2proxy#247). Will be removed once upstream ships the change in tun2proxy >= 0.8. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
I examined the |
…table VoIP, faster browsing - needs new tunnel deployment for udpgw (#222) * feat: native udpgw protocol alongside existing UDP associate Why udpgw is needed even with UDP associate: UDP associate (udp_open/udp_data) creates one tunnel session per UDP destination and polls each independently. On high-latency or shaky networks this compounds — N simultaneous UDP flows need N separate polling loops, each paying its own batch round-trip overhead. Google Meet calls, which fire dozens of concurrent STUN + RTP flows, stall or fail entirely because the per-destination polling can't keep up. udpgw multiplexes ALL UDP over one persistent TCP-like session using conn_id framing. One batch op carries frames for many destinations. Persistent sockets per (conn_id, dest) with continuous reader tasks keep source ports stable — critical for protocols like Telegram VoIP and STUN that expect replies on the same port. Both paths coexist — they serve different traffic: - UDP associate (SOCKS5): apps that negotiate SOCKS5 UDP relay - udpgw (198.18.0.1:7300): TUN-captured UDP (DNS, QUIC, Meet, etc.) tun2proxy vendored as git submodule at v0.7.20 with one transparent commit adding udpgw_server to the Android JNI run() function. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: block QUIC (UDP 443) and DNS (UDP 53) from udpgw QUIC through udpgw is slower than TCP/HTTP2 through the batch pipeline — blocking it forces browsers to fall back to TCP, improving YouTube and general browsing speed. DNS is better handled by tun2proxy's virtual DNS / SOCKS5 UDP associate path which is more reliable for single request-response exchanges. VoIP (Telegram, Meet) still flows through udpgw normally. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: replace submodule with [patch.crates-io] for tun2proxy udpgw Use the idiomatic Rust [patch.crates-io] mechanism instead of a git submodule. Points to yyoyoian-pixel/tun2proxy fork with the udpgw JNI parameter patch (upstream PR: tun2proxy/tun2proxy#247). Will be removed once upstream ships the change in tun2proxy >= 0.8. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * chore: pin tun2proxy patch SHA in Cargo.lock Locks tun2proxy at dfc24ed1 so the patch resolution is recorded and any branch rewrite is visible in the lockfile diff. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: use AbortHandle for ConnSocket readers to prevent FD leaks JoinHandle::drop detaches the task without aborting it. When udpgw_server_task is cancelled (session close), the post-loop cleanup never runs and per-(conn_id, dest) reader tasks become zombies holding Arc<UdpSocket> file descriptors. AbortHandle::drop aborts the task automatically, so cleanup is correct by construction regardless of how the parent task exits. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: yyoyoian-pixel <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
|
@ssrlive right, i didn't know we already have support for that, i'm testing and if all works will close. thanks! |
|
thanks, cli args working. |
|
Hi @yyoyoian-pixel , |
Summary
Adds an optional
udpgw_serverJString parameter to the Android JNIrun()function, enabling Android apps to configure UDP forwarding via the existing udpgw support without resorting totun2proxy_run_with_cli_argsor forking the crate.Motivation
Android VPN apps using tun2proxy via JNI currently have no way to pass
--udpgw-serverto therun()entry point. The only options are:tun2proxy_run_with_cli_argsvia dlsym — fragile, and the force-exit timeout thread kills the Android processAdding the parameter to the JNI function is the clean solution — 13 lines, no new dependencies, gated behind
#[cfg(feature = "udpgw")].Changes
src/android.rs:udpgw_server: JString<'_>parameter toJava_com_github_shadowsocks_bg_Tun2proxy_runSocketAddrand callsargs.udpgw_server(addr)Use case
This enables UDP forwarding (DNS, QUIC, VoIP calls) through a tunnel-node's udpgw handler. The Android app passes something like
"198.18.0.1:7300"as the udpgw server address, and tun2proxy opens a TCP connection to it through the SOCKS5 proxy, multiplexing all UDP flows via the udpgw wire protocol.Compatibility
The JNI function signature changes (one additional parameter). Callers must update their Kotlin/Java
external fundeclarations to include the newudpgwServer: Stringparameter. Passing an empty string preserves the previous behavior.