Measure live peer throughput on the encrypted mesh path

Advertise an optional versioned diagnostic to authenticated peers. A small
control exchange negotiates limits and carries receiver feedback. Paced
IPv4 probes enter the ordinary WireGuard tunnel and follow its current
carrier or relay. Accept them only for an active session and the peer's
actual signed address pair. Agents without the capability still exchange
normal mesh traffic.

Raise the offered rate using receiver-clock windows and unique payload
bytes. Require sustained delivery before reporting a rate, distinguish a
lower bound from a measured ceiling, and discard interrupted live values.
An agent runs one exchange at a time, with a five-second deadline and a
cap at both ends. Queued exit tests share a separate batch budget. Keep
bounded per-network results in memory and cancel on session replacement,
network removal or a change to a metered underlay.

Add a fixed speed cell to desktop and Android device views. Show direction
and live rate, let a click on the result rerun the test, and offer a
stoppable sequential test of compatible exit nodes. Expose local actions
and progress over IPC v27. Mesh identity and stored state are unchanged.

On macOS arm64 the real WireGuard test covered both directions, a
control-only peer, the responder's metered limit and stopping a repeat.
The three-peer exit batch test passed. The diagnostic crate passed 17
tests including shaped throughput, loss, delay, duplication and bursts.
All 33 shared UI tests passed. Strict Clippy passed for the diagnostic
and core libraries and an ARM64 Android debug APK was built.
This commit is contained in:
Aleksandr Bogomiakov committed 2026-11-25 19:25:58 +02:00
1 parent fb7a959d23
commit 200e716c28
34 files changed
+3658 -88

No files matched your search

@@ -40,6 +40,9 @@ class MeshVpn : VpnService() {
@Volatile private var upstream: Network? = null
private val changes = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) = useUnderlay(network)
override fun onCapabilitiesChanged(network: Network, capabilities: NetworkCapabilities) {
if (network == upstream && !closed) Native.setMetered(instance, isMetered(capabilities))
}
override fun onLinkPropertiesChanged(network: Network, properties: LinkProperties) {
if (network == upstream && !closed) updateAddresses(properties)
}
@@ -50,11 +53,15 @@ class MeshVpn : VpnService() {
// Falling back to the default network here could send iroh into its own TUN.
setUnderlyingNetworks(emptyArray())
physicalAddresses = ""
Native.setMetered(instance, true)
Native.networkChanged(instance, "")
}
}
private var physicalAddresses = ""
// Query the network the agent actually uses, even while its VPN is the app default.
private fun isMetered(capabilities: NetworkCapabilities?) =
capabilities?.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) != true
private fun addresses(properties: LinkProperties?) = properties?.linkAddresses.orEmpty()
.mapNotNull { it.address.hostAddress?.substringBefore('%') }.distinct().take(32).joinToString(",")
private fun updateAddresses(properties: LinkProperties) {
@@ -69,10 +76,14 @@ class MeshVpn : VpnService() {
upstream = network
setUnderlyingNetworks(arrayOf(network))
physicalAddresses = addresses(connectivity.getLinkProperties(network))
val metered = isMetered(connectivity.getNetworkCapabilities(network))
if (instance == 0L) {
Native.trust(applicationContext)
instance = Native.start(this, applicationContext, noBackupFilesDir.absolutePath, cacheDir.absolutePath, physicalAddresses)
} else Native.networkChanged(instance, physicalAddresses)
instance = Native.start(this, applicationContext, noBackupFilesDir.absolutePath, cacheDir.absolutePath, physicalAddresses, metered)
} else {
Native.setMetered(instance, metered)
Native.networkChanged(instance, physicalAddresses)
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@@ -6,12 +6,13 @@ import android.content.Context
internal object Native {
init { System.loadLibrary("tsunagi_android") }
external fun trust(context: Context)
external fun start(service: MeshVpn, context: Context, state: String, cache: String, addresses: String): Long
external fun start(service: MeshVpn, context: Context, state: String, cache: String, addresses: String, metered: Boolean): Long
external fun failed(instance: Long): Boolean
external fun stop(instance: Long)
external fun disconnectExit(instance: Long, network: String, peer: String): Boolean
external fun tileExit(instance: Long, network: String, peer: String, connect: Boolean, waitForDiscovery: Boolean): String?
external fun networkChanged(instance: Long, addresses: String)
external fun setMetered(instance: Long, metered: Boolean)
external fun surface()
external fun draw(host: MeshSurface, width: Int, height: Int, density: Float, serviceStarted: Boolean, landscape: Boolean): Long