Fix Android VPN startup and verify automatic subnet routing
This commit is contained in:
Generated
+125
-1
@@ -715,6 +715,12 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "critical-section"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam"
|
name = "crossbeam"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
@@ -883,6 +889,12 @@ dependencies = [
|
|||||||
"parking_lot_core",
|
"parking_lot_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "data-encoding"
|
||||||
|
version = "2.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deflate64"
|
name = "deflate64"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
@@ -1062,6 +1074,8 @@ dependencies = [
|
|||||||
"git-version",
|
"git-version",
|
||||||
"globwalk 0.9.1",
|
"globwalk 0.9.1",
|
||||||
"guarden",
|
"guarden",
|
||||||
|
"hickory-proto",
|
||||||
|
"hickory-resolver",
|
||||||
"indoc",
|
"indoc",
|
||||||
"log",
|
"log",
|
||||||
"machine-uid",
|
"machine-uid",
|
||||||
@@ -1296,6 +1310,18 @@ dependencies = [
|
|||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enum-as-inner"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.119",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -1727,6 +1753,52 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hickory-proto"
|
||||||
|
version = "0.25.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8a6fe56c0038198998a6f217ca4e7ef3a5e51f46163bd6dd60b5c71ca6c6502"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"cfg-if",
|
||||||
|
"data-encoding",
|
||||||
|
"enum-as-inner",
|
||||||
|
"futures-channel",
|
||||||
|
"futures-io",
|
||||||
|
"futures-util",
|
||||||
|
"idna",
|
||||||
|
"ipnet",
|
||||||
|
"once_cell",
|
||||||
|
"rand 0.9.5",
|
||||||
|
"ring",
|
||||||
|
"thiserror 2.0.21",
|
||||||
|
"tinyvec",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hickory-resolver"
|
||||||
|
version = "0.25.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc62a9a99b0bfb44d2ab95a7208ac952d31060efc16241c87eaf36406fecf87a"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"futures-util",
|
||||||
|
"hickory-proto",
|
||||||
|
"ipconfig",
|
||||||
|
"moka",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot",
|
||||||
|
"rand 0.9.5",
|
||||||
|
"resolv-conf",
|
||||||
|
"smallvec",
|
||||||
|
"thiserror 2.0.21",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hmac"
|
name = "hmac"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@@ -2051,6 +2123,19 @@ dependencies = [
|
|||||||
"hybrid-array",
|
"hybrid-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ipconfig"
|
||||||
|
version = "0.3.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4d40460c0ce33d6ce4b0630ad68ff63d6661961c48b6dba35e5a4d81cfb48222"
|
||||||
|
dependencies = [
|
||||||
|
"socket2",
|
||||||
|
"widestring",
|
||||||
|
"windows-registry",
|
||||||
|
"windows-result",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.12.2"
|
version = "2.12.2"
|
||||||
@@ -2485,6 +2570,10 @@ name = "once_cell"
|
|||||||
version = "1.21.4"
|
version = "1.21.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
dependencies = [
|
||||||
|
"critical-section",
|
||||||
|
"portable-atomic",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell_polyfill"
|
name = "once_cell_polyfill"
|
||||||
@@ -2909,10 +2998,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
|
checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"rand_chacha",
|
"rand_chacha 0.3.1",
|
||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha 0.9.0",
|
||||||
|
"rand_core 0.9.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.10.3"
|
version = "0.10.3"
|
||||||
@@ -2934,6 +3033,16 @@ dependencies = [
|
|||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core 0.9.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.6.4"
|
version = "0.6.4"
|
||||||
@@ -2943,6 +3052,15 @@ dependencies = [
|
|||||||
"getrandom 0.2.17",
|
"getrandom 0.2.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.3.4",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_core"
|
name = "rand_core"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
@@ -3066,6 +3184,12 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "resolv-conf"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ring"
|
name = "ring"
|
||||||
version = "0.17.14"
|
version = "0.17.14"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
虚拟组网 SDK,默认应用内模式,复用 Rust EasyTier 核心,通过用户态 TCP/IP 栈提供 TCP/UDP 通信。Flutter **MeshPort Lab** 是使用同一公开 SDK 的验证客户端。
|
虚拟组网 SDK,默认应用内模式,复用 Rust EasyTier 核心,通过用户态 TCP/IP 栈提供 TCP/UDP 通信。Flutter **MeshPort Lab** 是使用同一公开 SDK 的验证客户端。
|
||||||
|
|
||||||
目前为 **0.1.0 开发原型**。已实现真实网络通信,不是 UI 模拟。macOS Apple Silicon 已验证;Android ARM64 已构建并通过真机应用内 TCP/UDP,系统 VPN 真机验证仍待完成。其他平台原生库打包与运行尚未完成。
|
目前为 **0.1.0 开发原型**。已实现真实网络通信,不是 UI 模拟。macOS Apple Silicon 已验证;Android ARM64 已通过真机应用内与系统 VPN TCP/UDP,以及公告子网自动接入和撤销。其他平台原生库打包与运行尚未完成。
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
<application
|
<application
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project(meshport_android)
|
project(meshport_android)
|
||||||
add_library(meshport_ffi SHARED IMPORTED)
|
add_library(meshport_ffi SHARED IMPORTED)
|
||||||
set_target_properties(meshport_ffi PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libmeshport_ffi.so")
|
set_target_properties(meshport_ffi PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libmeshport_ffi.so"
|
||||||
|
IMPORTED_NO_SONAME TRUE)
|
||||||
add_library(meshport_android SHARED bridge.cpp)
|
add_library(meshport_android SHARED bridge.cpp)
|
||||||
target_link_libraries(meshport_android meshport_ffi)
|
target_link_libraries(meshport_android meshport_ffi)
|
||||||
target_link_options(meshport_android PRIVATE "-Wl,-z,max-page-size=16384")
|
target_link_options(meshport_android PRIVATE "-Wl,-z,max-page-size=16384")
|
||||||
|
|||||||
+26
-1
@@ -8,6 +8,7 @@ import android.content.Intent
|
|||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.util.Log
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
if (call.method == "prepare_android_vpn") {
|
if (call.method == "prepare_android_vpn") {
|
||||||
if (permissionResult != null) { result.error("VPN_BUSY", "VPN authorization pending", null); return@setMethodCallHandler }
|
if (permissionResult != null) { result.error("VPN_BUSY", "VPN authorization pending", null); return@setMethodCallHandler }
|
||||||
val intent = VpnService.prepare(this)
|
val intent = VpnService.prepare(this)
|
||||||
|
Log.i("MeshPortVPN", "VPN permission request: ${if (intent == null) "already granted" else "dialog required"}")
|
||||||
if (intent == null) result.success(null)
|
if (intent == null) result.success(null)
|
||||||
else { permissionResult = result; startActivityForResult(intent, 1001) }
|
else { permissionResult = result; startActivityForResult(intent, 1001) }
|
||||||
return@setMethodCallHandler
|
return@setMethodCallHandler
|
||||||
@@ -29,6 +31,27 @@ class MainActivity : FlutterActivity() {
|
|||||||
try {
|
try {
|
||||||
val profiles = ProfileStore(this)
|
val profiles = ProfileStore(this)
|
||||||
when (call.method) {
|
when (call.method) {
|
||||||
|
"debug_os_echo" -> {
|
||||||
|
check(BuildConfig.DEBUG)
|
||||||
|
val host = "10.253.79.1"
|
||||||
|
val payload = "Android system socket".toByteArray()
|
||||||
|
java.net.Socket().use { socket ->
|
||||||
|
socket.soTimeout = 5000
|
||||||
|
socket.connect(java.net.InetSocketAddress(host, 17007), 5000)
|
||||||
|
socket.getOutputStream().write(payload)
|
||||||
|
val reply = ByteArray(payload.size)
|
||||||
|
java.io.DataInputStream(socket.getInputStream()).readFully(reply)
|
||||||
|
check(reply.contentEquals(payload))
|
||||||
|
}
|
||||||
|
java.net.DatagramSocket().use { socket ->
|
||||||
|
socket.soTimeout = 5000
|
||||||
|
socket.send(java.net.DatagramPacket(payload, payload.size, java.net.InetAddress.getByName(host), 17007))
|
||||||
|
val reply = java.net.DatagramPacket(ByteArray(256), 256)
|
||||||
|
socket.receive(reply)
|
||||||
|
check(reply.data.copyOf(reply.length).contentEquals(payload))
|
||||||
|
}
|
||||||
|
main.post { result.success(true) }
|
||||||
|
}
|
||||||
"load_profile" -> { val value = profiles.load(); main.post { result.success(value) } }
|
"load_profile" -> { val value = profiles.load(); main.post { result.success(value) } }
|
||||||
"save_profile" -> { profiles.save(call.arguments as String); main.post { result.success(null) } }
|
"save_profile" -> { profiles.save(call.arguments as String); main.post { result.success(null) } }
|
||||||
"delete_profile" -> { profiles.delete(); main.post { result.success(null) } }
|
"delete_profile" -> { profiles.delete(); main.post { result.success(null) } }
|
||||||
@@ -44,6 +67,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
"android_vpn_request" -> {
|
"android_vpn_request" -> {
|
||||||
val request = JSONObject(call.arguments as String)
|
val request = JSONObject(call.arguments as String)
|
||||||
|
if (request.optString("op") != "status") Log.i("MeshPortVPN", "Control operation: ${request.optString("op")}")
|
||||||
require(request.toString().toByteArray(Charsets.UTF_8).size <= 131072)
|
require(request.toString().toByteArray(Charsets.UTF_8).size <= 131072)
|
||||||
if (request.getString("op") == "start" && MeshVpnService.current == null) {
|
if (request.getString("op") == "start" && MeshVpnService.current == null) {
|
||||||
check(VpnService.prepare(this) == null) { "Android VPN authorization required" }
|
check(VpnService.prepare(this) == null) { "Android VPN authorization required" }
|
||||||
@@ -64,7 +88,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
try {
|
try {
|
||||||
val reply = service.request(request).toString()
|
val reply = service.request(request).toString()
|
||||||
main.post { result.success(reply) }
|
main.post { result.success(reply) }
|
||||||
} catch (error: Exception) { main.post { result.error("VPN_REQUEST", error.message, null) } }
|
} catch (error: Throwable) { main.post { result.error("VPN_REQUEST", error.message, null) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,6 +102,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
if (requestCode == 1001) {
|
if (requestCode == 1001) {
|
||||||
|
Log.i("MeshPortVPN", "VPN permission result: $resultCode")
|
||||||
val pending = permissionResult; permissionResult = null
|
val pending = permissionResult; permissionResult = null
|
||||||
if (resultCode == Activity.RESULT_OK) pending?.success(null)
|
if (resultCode == Activity.RESULT_OK) pending?.success(null)
|
||||||
else pending?.error("VPN_DENIED", "Android VPN authorization cancelled", null)
|
else pending?.error("VPN_DENIED", "Android VPN authorization cancelled", null)
|
||||||
|
|||||||
+29
-2
@@ -6,6 +6,9 @@ import android.app.NotificationManager
|
|||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.IpPrefix
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import android.system.OsConstants
|
import android.system.OsConstants
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@@ -53,8 +56,8 @@ class MeshVpnService : VpnService() {
|
|||||||
check(!running) { "VPN already started" }
|
check(!running) { "VPN already started" }
|
||||||
failure = null
|
failure = null
|
||||||
Log.i("MeshPortVPN", "Creating native VPN context")
|
Log.i("MeshPortVPN", "Creating native VPN context")
|
||||||
handle = NativeBridge.newContext()
|
|
||||||
try {
|
try {
|
||||||
|
handle = NativeBridge.newContext()
|
||||||
val config = request.getString("toml")
|
val config = request.getString("toml")
|
||||||
val validation = native(JSONObject().put("op", "validate").put("toml", config).put("include_profile", true)).getJSONObject("data")
|
val validation = native(JSONObject().put("op", "validate").put("toml", config).put("include_profile", true)).getJSONObject("data")
|
||||||
check(validation.getString("runtime_mode") == "system_vpn")
|
check(validation.getString("runtime_mode") == "system_vpn")
|
||||||
@@ -65,7 +68,7 @@ class MeshVpnService : VpnService() {
|
|||||||
running = true
|
running = true
|
||||||
rebuild(emptyList())
|
rebuild(emptyList())
|
||||||
result
|
result
|
||||||
} catch (error: Exception) { shutdown(); stopSelf(); throw error }
|
} catch (error: Throwable) { shutdown(); stopSelf(); throw error }
|
||||||
}
|
}
|
||||||
"stop" -> { shutdown(); stopSelf(); JSONObject().put("ok", true).put("data", JSONObject()) }
|
"stop" -> { shutdown(); stopSelf(); JSONObject().put("ok", true).put("data", JSONObject()) }
|
||||||
"status" -> {
|
"status" -> {
|
||||||
@@ -109,6 +112,30 @@ class MeshVpnService : VpnService() {
|
|||||||
Thread.sleep(100)
|
Thread.sleep(100)
|
||||||
}
|
}
|
||||||
check(ready) { "Native TUN attachment timed out" }
|
check(ready) { "Native TUN attachment timed out" }
|
||||||
|
// establish() returns before ConnectivityService publishes the
|
||||||
|
// network. Wait for the exact address and route set on this TUN,
|
||||||
|
// including removals, before exposing it as usable to callers.
|
||||||
|
val connectivity = getSystemService(ConnectivityManager::class.java)
|
||||||
|
val expected = (routes + "$network/$prefix").map {
|
||||||
|
val cidr = it.split('/')
|
||||||
|
IpPrefix(InetAddress.getByName(cidr[0]), cidr[1].toInt())
|
||||||
|
}.toSet()
|
||||||
|
var registered = false
|
||||||
|
for (attempt in 0 until 50) {
|
||||||
|
registered = connectivity.allNetworks.any { candidate ->
|
||||||
|
val capabilities = connectivity.getNetworkCapabilities(candidate)
|
||||||
|
val properties = connectivity.getLinkProperties(candidate)
|
||||||
|
capabilities?.hasTransport(NetworkCapabilities.TRANSPORT_VPN) == true &&
|
||||||
|
properties?.linkAddresses?.any { it.address.hostAddress == address } == true &&
|
||||||
|
properties.routes.filter { it.destination.address is java.net.Inet4Address && it.type == android.net.RouteInfo.RTN_UNICAST }
|
||||||
|
.map { it.destination }.toSet() == expected
|
||||||
|
}
|
||||||
|
if (registered) break
|
||||||
|
Thread.sleep(100)
|
||||||
|
}
|
||||||
|
check(registered) { "Android VPN network registration timed out" }
|
||||||
|
// Let newly published network state reach socket clients as well.
|
||||||
|
Thread.sleep(300)
|
||||||
Log.i("MeshPortVPN", "TUN ready")
|
Log.i("MeshPortVPN", "TUN ready")
|
||||||
tun = next
|
tun = next
|
||||||
installed = routes
|
installed = routes
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -11,7 +12,7 @@ const target = '10.253.79.1:17007';
|
|||||||
String config(String mode) =>
|
String config(String mode) =>
|
||||||
'''
|
'''
|
||||||
hostname = "Android-validation"
|
hostname = "Android-validation"
|
||||||
ipv4 = "10.253.83.11/24"
|
ipv4 = "10.253.83.${mode == 'application' ? '11' : '12'}/24"
|
||||||
listeners = []
|
listeners = []
|
||||||
stun_servers = []
|
stun_servers = []
|
||||||
stun_servers_v6 = []
|
stun_servers_v6 = []
|
||||||
@@ -30,8 +31,10 @@ Future<void> waitForRoutes(
|
|||||||
bool installed = false,
|
bool installed = false,
|
||||||
}) async {
|
}) async {
|
||||||
final deadline = DateTime.now().add(const Duration(seconds: 40));
|
final deadline = DateTime.now().add(const Duration(seconds: 40));
|
||||||
|
Map<String, dynamic>? lastState;
|
||||||
while (DateTime.now().isBefore(deadline)) {
|
while (DateTime.now().isBefore(deadline)) {
|
||||||
final state = await client.status();
|
final state = await client.status();
|
||||||
|
lastState = state;
|
||||||
final platform = state['platform_network'] as Map? ?? {};
|
final platform = state['platform_network'] as Map? ?? {};
|
||||||
final routes =
|
final routes =
|
||||||
platform[installed ? 'installed_subnet_routes' : 'subnet_routes']
|
platform[installed ? 'installed_subnet_routes' : 'subnet_routes']
|
||||||
@@ -40,6 +43,7 @@ Future<void> waitForRoutes(
|
|||||||
if (withdrawn ? routes.isEmpty : routes.contains('10.253.79.0/24')) return;
|
if (withdrawn ? routes.isEmpty : routes.contains('10.253.79.0/24')) return;
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||||
}
|
}
|
||||||
|
debugPrint('ANDROID_ROUTE_TIMEOUT_STATE ${jsonEncode(lastState)}');
|
||||||
throw StateError('Automatic subnet route transition timed out');
|
throw StateError('Automatic subnet route transition timed out');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,13 +95,24 @@ void main() {
|
|||||||
try {
|
try {
|
||||||
await vpn.start(config('system_vpn'));
|
await vpn.start(config('system_vpn'));
|
||||||
await waitForRoutes(vpn, installed: true);
|
await waitForRoutes(vpn, installed: true);
|
||||||
|
expect(await channel.invokeMethod<bool>('debug_os_echo'), true);
|
||||||
|
debugPrint('ANDROID_JAVA_OS_TCP_UDP_PASS');
|
||||||
// Plain OS sockets prove that traffic from other applications can use
|
// Plain OS sockets prove that traffic from other applications can use
|
||||||
// the VPN. No SDK stream is used for these transfers.
|
// the VPN. No SDK stream is used for these transfers.
|
||||||
final socket = await Socket.connect(
|
late Socket socket;
|
||||||
'10.253.79.1',
|
debugPrint('ANDROID_SYSTEM_SOCKET_START');
|
||||||
17007,
|
try {
|
||||||
timeout: const Duration(seconds: 10),
|
socket = await Socket.connect(
|
||||||
);
|
'10.253.79.1',
|
||||||
|
17007,
|
||||||
|
timeout: const Duration(seconds: 30),
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
debugPrint(
|
||||||
|
'ANDROID_OS_TCP_FAILURE_STATE ${jsonEncode(await vpn.status())}',
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
socket.add(utf8.encode('OS TCP Android'));
|
socket.add(utf8.encode('OS TCP Android'));
|
||||||
await socket.flush();
|
await socket.flush();
|
||||||
@@ -111,16 +126,27 @@ void main() {
|
|||||||
socket.destroy();
|
socket.destroy();
|
||||||
}
|
}
|
||||||
final udp = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
final udp = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
||||||
|
final received = Completer<Datagram>();
|
||||||
|
final subscription = udp.listen((event) {
|
||||||
|
if (event == RawSocketEvent.read) {
|
||||||
|
final packet = udp.receive();
|
||||||
|
if (packet != null && !received.isCompleted) {
|
||||||
|
received.complete(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, onError: received.completeError);
|
||||||
try {
|
try {
|
||||||
final reply = udp.firstWhere((event) => event == RawSocketEvent.read);
|
|
||||||
udp.send(
|
udp.send(
|
||||||
utf8.encode('OS UDP Android'),
|
utf8.encode('OS UDP Android'),
|
||||||
InternetAddress('10.253.79.1'),
|
InternetAddress('10.253.79.1'),
|
||||||
17007,
|
17007,
|
||||||
);
|
);
|
||||||
await reply.timeout(const Duration(seconds: 10));
|
final reply = await received.future.timeout(
|
||||||
expect(utf8.decode(udp.receive()!.data), 'OS UDP Android');
|
const Duration(seconds: 10),
|
||||||
|
);
|
||||||
|
expect(utf8.decode(reply.data), 'OS UDP Android');
|
||||||
} finally {
|
} finally {
|
||||||
|
await subscription.cancel();
|
||||||
udp.close();
|
udp.close();
|
||||||
}
|
}
|
||||||
debugPrint('ANDROID_SYSTEM_VPN_TCP_UDP_PASS');
|
debugPrint('ANDROID_SYSTEM_VPN_TCP_UDP_PASS');
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ async-trait = "0.1"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
system-vpn = ["easytier/tun", "easytier/proxy-cidr-monitor"]
|
system-vpn = ["easytier/tun", "easytier/proxy-cidr-monitor", "easytier/dns-resolver"]
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
+3
-1
@@ -19,6 +19,8 @@ scripts/build-lab-android.sh --release
|
|||||||
|
|
||||||
外层连接通过 VpnService.protect 排除在自己的 VPN 之外。系统模式不配置默认路由或 DNS;IPv6 保留系统通路,当前虚拟网络数据面为 IPv4。其他 Android VPN 与此系统 VPN 不能同时作为当前 VPN 运行。
|
外层连接通过 VpnService.protect 排除在自己的 VPN 之外。系统模式不配置默认路由或 DNS;IPv6 保留系统通路,当前虚拟网络数据面为 IPv4。其他 Android VPN 与此系统 VPN 不能同时作为当前 VPN 运行。
|
||||||
|
|
||||||
|
VPN 建立和路由更新会等待 Android ConnectivityService 发布匹配的虚拟地址及路由,再报告就绪,避免新连接提前使用物理源地址。JNI 使用库名链接 Rust 动态库,不携带构建机绝对路径;系统模式启用受保护的 DNS resolver,数字 IP 不经过 DNS 查询。
|
||||||
|
|
||||||
配置使用 Android Keystore 的 AES-GCM 密钥加密,私有存储仅保存密文与 IV,关闭 Android 备份。启动恢复表单,不自动连接;后台服务仍运行时重新打开界面会恢复该会话。
|
配置使用 Android Keystore 的 AES-GCM 密钥加密,私有存储仅保存密文与 IV,关闭 Android 备份。启动恢复表单,不自动连接;后台服务仍运行时重新打开界面会恢复该会话。
|
||||||
|
|
||||||
## 真机验证
|
## 真机验证
|
||||||
@@ -36,4 +38,4 @@ flutter test integration_test/android_network_test.dart -d DEVICE_SERIAL
|
|||||||
|
|
||||||
测试中的系统 VPN 授权必须由用户在手机上完成。测试结束应删除两条 adb reverse 并关闭夹具。测试使用固定地址,不覆盖公网打洞、移动网络切换、长期后台存活或实际游戏负载。
|
测试中的系统 VPN 授权必须由用户在手机上完成。测试结束应删除两条 adb reverse 并关闭夹具。测试使用固定地址,不覆盖公网打洞、移动网络切换、长期后台存活或实际游戏负载。
|
||||||
|
|
||||||
2026-10-10 已通过真机加密存储及应用内 TCP/UDP。系统 VPN 验证在设备断开时中止,仍待完成。
|
2026-10-10 在 OPPO PJZ110(API 37、4 KB 页面)完整通过:加密配置保存/重新读取/删除、SDK 应用内 TCP/UDP、Java 与 Dart 普通系统 TCP/UDP 经 VPN 通信、公告子网自动安装及撤销。隔离测试不修改用户配置。公网打洞、长期后台运行及移动网络切换尚未验证。
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ vendor/easytier 是固定提交的本地定制快照,来源和修改清单见
|
|||||||
|
|
||||||
当前本机验证:macOS aarch64、Rust1.99、Flutter3.41.4/Dart3.11.1。
|
当前本机验证:macOS aarch64、Rust1.99、Flutter3.41.4/Dart3.11.1。
|
||||||
|
|
||||||
目标平台:macOS/Linux/Windows/iOS/Android。macOS 原生库和客户端已验证。Android ARM64 原生库、JNI 和 APK 已构建,真机配置加密存储和应用内 TCP/UDP 已通过;系统 VPN 已实现但真机验证在设备断开时中止,仍待完成。其他 runner 是脚手架,仍需要目标编译、链接、库加载和真机测试。iOS 使用静态链接,并需要保留导出符号。Android 说明见 android.md。
|
目标平台:macOS/Linux/Windows/iOS/Android。macOS 原生库和客户端已验证。Android ARM64 原生库、JNI 和 APK 已构建,真机配置加密存储、应用内与系统 VPN TCP/UDP,以及公告子网自动接入和撤销已通过。其他 runner 是脚手架,仍需要目标编译、链接、库加载和真机测试。iOS 使用静态链接,并需要保留导出符号。Android 说明见 android.md。
|
||||||
|
|
||||||
本地集成测试两端使用同一固定 EasyTier 核心,因此证明的是该版本应用内数据面的组网与数据校验。与服务器既有发布版、跨版本混合网络、公网中继、NAT打洞、跨国链路和移动端后台恢复尚未实测。
|
本地集成测试两端使用同一固定 EasyTier 核心,因此证明的是该版本应用内数据面的组网与数据校验。与服务器既有发布版、跨版本混合网络、公网中继、NAT打洞、跨国链路和移动端后台恢复尚未实测。
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ Rust 的 `system-vpn` feature 是显式编译开关;默认 SDK 构建保持应
|
|||||||
|
|
||||||
## 发布边界
|
## 发布边界
|
||||||
|
|
||||||
这是开发版 helper 方案,使用临时管理员授权与 ad-hoc 签名,尚未完成正式签名、公证或 Network Extension 发布流程;macOS App Sandbox 已为此开发方案关闭。Android VpnService、iOS Packet Tunnel、移动端后台恢复尚未接入,不能把这次 macOS 实现视作移动端已可用。
|
这是开发版 helper 方案,使用临时管理员授权与 ad-hoc 签名,尚未完成正式签名、公证或 Network Extension 发布流程;macOS App Sandbox 已为此开发方案关闭。Android VpnService 已接入,并通过隔离真机 TCP/UDP 和自动公告路由验证,详见 [Android](android.md)。iOS Packet Tunnel、移动端长期后台恢复仍待验证。
|
||||||
|
|
||||||
显式特权自检:`sudo target/debug/meshport-vpn-helper --self-test`。自检通过 loopback 建立两个隔离的 EasyTier 节点,使用 10.253.77.0/24 作为客户端虚拟网段,自动学习另一节点发布的 10.253.78.0/24,验证额外子网路由以及普通系统 TCP/UDP 经 utun 回显、默认路由保持不变、公告撤回后的路由删除和停止后的接口删除。最多运行 45 秒;阶段日志写入 `/tmp/meshport-vpn-self-test-<pid>.log`,不写网络密钥。
|
显式特权自检:`sudo target/debug/meshport-vpn-helper --self-test`。自检通过 loopback 建立两个隔离的 EasyTier 节点,使用 10.253.77.0/24 作为客户端虚拟网段,自动学习另一节点发布的 10.253.78.0/24,验证额外子网路由以及普通系统 TCP/UDP 经 utun 回显、默认路由保持不变、公告撤回后的路由删除和停止后的接口删除。最多运行 45 秒;阶段日志写入 `/tmp/meshport-vpn-self-test-<pid>.log`,不写网络密钥。
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Android 阶段(2026-10-10)
|
## Android 阶段(2026-10-10)
|
||||||
|
|
||||||
ARM64 Rust 原生库、JNI 桥接、Android debug/release APK 构建通过。OPPO PJZ110(API 37,4 KB 页面)已完成 Android Keystore 独立测试存储的保存/重新读取/删除,以及 SDK 经隔离公告子网的 TCP/UDP 回显。系统 VPN 授权后前台服务已启动,测试在设备从 ADB 断开时中止,尚未确认系统 Socket 经 VPN 通信及公告撤销。未把该测试记为通过。
|
ARM64 Rust 原生库、JNI 桥接、Android debug/release APK 构建通过。OPPO PJZ110(API 37,4 KB 页面)已完成 Android Keystore 独立测试存储的保存/重新读取/删除,以及 SDK 经隔离公告子网的 TCP/UDP 回显。系统 VPN 授权后,Java 和 Dart 普通系统 Socket 的 TCP/UDP 回显、公告子网自动安装与撤销全部通过。修复了 JNI 绝对路径依赖、受保护 DNS resolver 功能缺失和 Android 网络注册时序。隔离 USB 夹具不覆盖公网打洞、长期后台运行或移动网络切换。
|
||||||
|
|
||||||
最新源代码 Flutter analyze 无问题、7 项 widget 测试通过(3 项依赖原生 macOS 库的测试跳过),Rust workspace 测试及 doc-tests 通过。正式客户端界面的新版 APK 已打包,设备离线时尚未安装;测试夹具已关闭。需要设备重新连接完成剩余测试。详见 android.md。
|
最新源代码 Flutter analyze 无问题、7 项 widget 测试通过(3 项依赖原生 macOS 库的测试跳过),Rust workspace 测试及 doc-tests 通过。正式客户端界面的新版 APK 已打包,设备离线时尚未安装;测试夹具已关闭。需要设备重新连接完成剩余测试。详见 android.md。
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ Clippy 使用 --no-deps 检查 MeshPort 工作区且 -D warnings 通过。保留
|
|||||||
|
|
||||||
系统模式自检曾完成真实 OS TCP/UDP → utun → EasyTier 的回显,并检查停止删除接口、默认路由不变。重复自检发现网卡初始化系统命令存在间歇性等待;macOS 命令已改为后台线程等待,避免依赖 Tokio 的进程信号通知;helper 增加原生操作 60 秒退出保护。最终代码连续两轮特权自检均通过:普通 OS TCP/UDP 经 utun 回显正确,停止后接口删除,启动期间及停止后默认路由保持不变。结果记录在 /tmp/meshport-system-vpn-final.log,阶段日志 PID 23903、23924。Clippy --no-deps -D warnings 通过。
|
系统模式自检曾完成真实 OS TCP/UDP → utun → EasyTier 的回显,并检查停止删除接口、默认路由不变。重复自检发现网卡初始化系统命令存在间歇性等待;macOS 命令已改为后台线程等待,避免依赖 Tokio 的进程信号通知;helper 增加原生操作 60 秒退出保护。最终代码连续两轮特权自检均通过:普通 OS TCP/UDP 经 utun 回显正确,停止后接口删除,启动期间及停止后默认路由保持不变。结果记录在 /tmp/meshport-system-vpn-final.log,阶段日志 PID 23903、23924。Clippy --no-deps -D warnings 通过。
|
||||||
|
|
||||||
Keychain 调用已编译,尚未执行保存/恢复的 GUI 端到端测试。Android/iOS 系统模式尚未实现;真实游戏、跨国长期压测和故障切换仍需后续验证。
|
Keychain 调用已编译,尚未执行保存/恢复的 GUI 端到端测试。此阶段的 Android/iOS 系统模式尚未实现(Android 最新验证见本文开头);真实游戏、跨国长期压测和故障切换仍需后续验证。
|
||||||
|
|
||||||
## 指定远端子网修复(2026-10-10)
|
## 指定远端子网修复(2026-10-10)
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
@@ -7,6 +7,7 @@ Imported using git archive. Retained LGPL-3.0 LICENSE and upstream crate sources
|
|||||||
This is a local source customization, not a published GitHub fork. Root workspace members were limited to easytier, easytier-core and easytier-proto for the SDK build. MeshPort root uses path dependencies and its own Cargo.lock.
|
This is a local source customization, not a published GitHub fork. Root workspace members were limited to easytier, easytier-core and easytier-proto for the SDK build. MeshPort root uses path dependencies and its own Cargo.lock.
|
||||||
|
|
||||||
Local modifications:
|
Local modifications:
|
||||||
|
- easytier/src/common/dns.rs: resolve numeric bootstrap addresses without DNS, including when a platform socket protector is installed.
|
||||||
- easytier/src/common/network.rs: macOS hardware enumeration uses blocking subprocess waits; physical connection candidates exclude route-probe addresses and nonphysical IPv6 interfaces so another VPN's TUN is not reintroduced. Hardware device names match exactly.
|
- easytier/src/common/network.rs: macOS hardware enumeration uses blocking subprocess waits; physical connection candidates exclude route-probe addresses and nonphysical IPv6 interfaces so another VPN's TUN is not reintroduced. Hardware device names match exactly.
|
||||||
- easytier-core/src/peers/meshport_optimization.rs: direct preference, improvement thresholds, hold/cooldown and candidate first-hop filter.
|
- easytier-core/src/peers/meshport_optimization.rs: direct preference, improvement thresholds, hold/cooldown and candidate first-hop filter.
|
||||||
- easytier-core/src/peers/mod.rs: exposes policy module.
|
- easytier-core/src/peers/mod.rs: exposes policy module.
|
||||||
|
|||||||
+4
@@ -350,6 +350,10 @@ impl RuntimeDnsResolver {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl DnsResolver for RuntimeDnsResolver {
|
impl DnsResolver for RuntimeDnsResolver {
|
||||||
async fn resolve(&self, query: DnsQuery) -> anyhow::Result<Vec<IpAddr>> {
|
async fn resolve(&self, query: DnsQuery) -> anyhow::Result<Vec<IpAddr>> {
|
||||||
|
// Numeric bootstrap endpoints do not require any DNS socket.
|
||||||
|
if let Ok(address) = query.host.parse::<IpAddr>() {
|
||||||
|
return Ok(vec![address]);
|
||||||
|
}
|
||||||
let context = RuntimeDnsIoContext::from_socket_context(&query.context);
|
let context = RuntimeDnsIoContext::from_socket_context(&query.context);
|
||||||
#[cfg(feature = "dns-resolver")]
|
#[cfg(feature = "dns-resolver")]
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user