v5.40.0 — Mosh through the WireGuard / Tailscale tunnel
Targeted release for #164 (Senkoi): with Haven's built-in tunnel enabled, SSH worked but Mosh's UDP packets bypassed the tunnel and never reached the server. Now Mosh rides the same tunnel as SSH.
What changed under the hood
Haven's gomobile bridges (wgbridge, tsbridge) only exposed TCP to Kotlin. gVisor netstack (wireguard-go) and tsnet both support UDP natively — that surface just wasn't bound. v5.40 adds it.
| Layer | Before | After |
|---|---|---|
| Go (wgbridge / tsbridge) | TunnelHandle.Dial (TCP only)
| + ListenUDP, UDPConn.{ReadFrom, WriteTo, Close}
|
Kotlin Tunnel interface
| dial, socksAddress
| + listenUdp() (default null)
|
TunnelResolver
| dial, socketFactory, socksEndpoint, socketDialer
| + dialUdp, + udpSocketSupplier
|
mosh-kotlin
| hardcoded DatagramSocket()
| UdpSocketProvider → AndroidUdpAdapter (default) or tunneled adapter
|
| Wiring | — | ConnectionsViewModel.finishMoshConnect resolves a provider per profile; non-tunneled profiles fall through to the same raw socket as before
|
| MCP | — | list_ssh_keys / import_ssh_key / delete_ssh_key; create_connection accepts useMosh + keyId
|
Backends that can't carry UDP — Cloudflare Access (WebSocket), legacy SOCKS / HTTP proxies — opt out via the default listenUdp() = null. Mosh falls through to a plain DatagramSocket for those, matching pre-#164 behaviour.
Two gotchas worth flagging
For anyone bringing up other userspace UDP transports against wireguard-go's bundled gVisor netstack:
netip.AddrPort{}(zero value) as the bind → SIGABRT inside libgojni.so. The netstack leaves itsNetworkProtocolNumberunset; gVisor abort()s on endpoint creation.netip.IPv4Unspecified()(0.0.0.0:0) as the bind → firstWriteToreturnsnetwork is unreachable. The stack can't pick a primary IP from the NIC for the unspecified source.
Fix: bind to the tunnel's [Interface] Address from the wg-quick config (e.g. 10.0.0.2:0). Both fixes are in this release; the wgbridge.go comment block has the full story.
Verified
- WireGuard end-to-end on a Pixel 8 Pro against a real
mosh-server: handshake, throughput, persistent session. - Tailscale end-to-end against a
tsnetnode in the same tailnet: tcpdump ontailscale0confirms steady bidirectional UDP between the Pixel and the server on the tailnet IPs, never on the default route. The whole flow was driven through the new MCP endpoints (import_ssh_key→create_tunnel→create_connection(useMosh=true, keyId=…, tunnelConfigId=…)→connect_profile) without touching the on-device UI. - Non-tunneled Mosh: unchanged code path, regression spot-check green.
- Existing
MoshConnectivityTest/MoshTransportTestsuites green after the refactor.
What hasn't changed
The v5.39 UX work (auto-hide tabs, autoscroll velocity scaling, per-phase install retry, step-ca OIDC normalisation), the v5.38 multi-distro proot Linux installer, MCP foreground-service binding, and the rest of the MCP toolkit all carry forward unchanged.