Initial MeshPort SDK and cross-platform client

This commit is contained in:
shenlei
2026-10-10 15:16:32 +09:00
commit e73e599165
664 changed files with 209894 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
# Android 客户端与 SDK
当前实现面向 Android 8.0(API 26)及以上的 ARM64 设备。
## 构建
构建环境需要 Flutter、JDK 17、Android SDK、NDK 28.2.13676358、CMake 3.22.1,以及 Rust 的 aarch64-linux-android target。
```sh
scripts/build-lab-android.sh --release
```
脚本先编译含 system-vpn 功能的 Rust 库,再打包 Flutter APK,输出到 outputs/android。当前使用开发签名,适合本机安装验证。正式发行需配置自己的签名和应用 ID。原生库与 JNI 桥接使用 16 KB ELF 页面对齐;当前真机为 4 KB 页面,16 KB 设备运行尚未验证。
## 两种模式
- 应用内:通过 meshport_flutter SDK 的 TCP/UDP 接口通信,不创建系统 VPN。
- 系统 VPN:宿主请求用户授权,由前台 VpnService 创建虚拟网卡,将文件描述符交给 Rust 引擎。虚拟网段及符合规则的公告子网自动安装、更新和撤销,不需要填写远端子网。
外层连接通过 VpnService.protect 排除在自己的 VPN 之外。系统模式不配置默认路由或 DNS;IPv6 保留系统通路,当前虚拟网络数据面为 IPv4。其他 Android VPN 与此系统 VPN 不能同时作为当前 VPN 运行。
配置使用 Android Keystore 的 AES-GCM 密钥加密,私有存储仅保存密文与 IV,关闭 Android 备份。启动恢复表单,不自动连接;后台服务仍运行时重新打开界面会恢复该会话。
## 真机验证
integration_test/android_network_test.dart 使用隔离网络身份和 USB 转发的本机测试网关,覆盖加密存储、应用内 TCP/UDP、普通系统 Socket 经 VPN 访问自动公告子网,以及公告撤销。
```sh
# 先在项目根目录启动本机夹具
scripts/cargo-local.sh run -p meshport-easytier --example android_test_server
adb reverse tcp:18080 tcp:18080
adb reverse tcp:18081 tcp:18081
cd apps/meshport_lab
flutter test integration_test/android_network_test.dart -d DEVICE_SERIAL
```
测试中的系统 VPN 授权必须由用户在手机上完成。测试结束应删除两条 adb reverse 并关闭夹具。测试使用固定地址,不覆盖公网打洞、移动网络切换、长期后台存活或实际游戏负载。
2026-10-10 已通过真机加密存储及应用内 TCP/UDP。系统 VPN 验证在设备断开时中止,仍待完成。
+17
View File
@@ -0,0 +1,17 @@
# 架构
Flutter Lab → Dart SDK → C ABI → MeshPort → EasyTier 原生实例与其 smoltcp 数据面。
当前上游已经提供 `data_plane_tcp_connect`、`data_plane_tcp_bind`、`data_plane_udp_bind`。因此第一版不维护第二套 TCP/IP 栈;netstack crate 是适配边界,可在以后替换实现。
核心上游依赖禁用默认 features,仅开启 aes-gcm、ffi-dataplane、dhcp-ipv4、tcp-hole-punch、proxy-cidr-monitor。默认未启用 tun、magic-dns、linux-netlink、UPnP、出口节点和配置服务器集成。应用内模式强制 no_tun/use_smoltcp/加密。显式 system-vpn feature 可启用 macOS TUN,系统模式拒绝 DNS 和出口。两种模式共享公告子网过滤策略:应用内模式限制数据面发送,系统模式同步安装及删除 OS 路由。
每个 FFI context 有独立的两线程 Tokio runtime,实例与资源属于该 context。context free 从全局注册表移除句柄;正在执行的调用通过 Arc 保持资源活着,完成后再析构。句柄不复用。停止节点前清理 TCP/UDP 资源;关闭实例使上游会话失效。
第一版 JSON ABI 的用途是正确性与生命周期验证,数据以 byte array 传递,非零拷贝。单 context 串行,read 等待期间其他操作也会等待;停止不会抢占在途读操作。需在后续改为异步提交/取消/完成队列,并支持连接级并发。不同 context 可独立运行。
UI 仅显示实测状态与结果。连接耗时与 echo 往返耗时分开标识,不当成持续 RTT。默认配置不保存密钥;macOS 可 opt-in 保存完整配置到 Keychain,日志不记录配置原文。
选路优化在 vendor/easytier/easytier-core 的连接及下一跳选择层执行,适配层负责严格配置和实际路由快照。质量测量通过公开 Rust/C ABI/Dart API 发起真实 UDP echo,不改系统网络,详见 [优化说明](optimization.md)。
系统模式:Flutter → Dart Unix 控制通道 → macOS 特权 helper → 同一 C ABI → EasyTier TUN;其他应用通过普通系统 socket 使用虚拟网段。详见 [系统组网](system-vpn.md)。
+13
View File
@@ -0,0 +1,13 @@
# 兼容范围与依赖
EasyTier 仓库:https://github.com/EasyTier/EasyTier
vendor/easytier 是固定提交的本地定制快照,来源和修改清单见该目录 MESHPORT.md。基础提交:7af7bdc16a41d64d58743d15023a63b3eed2102c。Cargo.lock 固定传递依赖;build 使用 --locked。
当前本机验证: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。
本地集成测试两端使用同一固定 EasyTier 核心,因此证明的是该版本应用内数据面的组网与数据校验。与服务器既有发布版、跨版本混合网络、公网中继、NAT打洞、跨国链路和移动端后台恢复尚未实测。
上游 EasyTier 使用 LGPL-3.0,文本见 upstream/EasyTier-LICENSE;未复制 GPL-3.0 iOS 客户端代码。MeshPort 自身许可证尚未选定。发行原生库/客户端时需核对上游、smoltcp及传递依赖许可证和对应源码/构建材料。
+17
View File
@@ -0,0 +1,17 @@
# 配置
使用 EasyTier TOML,示例见 `examples/client.toml`。必须填写虚拟 IPv4 或 `dhcp = true`,二者互斥。自动分配实际地址由上游动态生成;状态从运行实例快照读取。
第一版允许顶层字段:hostname、instance_name、ipv4、dhcp、network_identity、peer、listeners、mapped_listeners、flags、stun_servers、stun_servers_v6、optimization、runtime。
network_identity 允许 network_name、network_secret。peer 数组的每项仅允许 uri。节点、监听与映射地址仅支持 tcp/udp。默认不开放监听端口;用户可显式设置 listeners。
flags 允许:default_protocol、latency_first、enable_ipv6、disable_p2p、p2p_only、lazy_p2p、need_p2p、disable_tcp_hole_punching、disable_udp_hole_punching、disable_sym_hole_punching、private_mode、foreign_relay_bps_limit,以及 no_tun、use_smoltcp、enable_encryption。enable_encryption 必须为 true;前两项在默认 application 模式必须为 true,在 system_vpn 模式必须为 false,可省略由模式确定。
未知、不支持的字段拒绝,不静默吞掉。解析器错误不返回配置原文,避免泄漏密钥。当前校验支持 TOML 解析与基本类型/策略,完整 runtime 能力校验仍在 start 阶段完成;validate 成功不保证远端可达。
UI 表单提供常用字段,其他已支持字段通过粘贴 TOML 输入。导出表单配置默认去掉密钥。高级安全模式、KCP/QUIC、Magic DNS、子网导出、系统出口、虚拟 IPv6 暂未支持。
`[runtime] mode = "system_vpn"` 显式选择 macOS 系统组网开发模式,默认 `application`。两种模式自动接入符合规则的已发布私有子网,无需 `subnet_routes`(该字段已移除)。只接入 /16~/32 的私有 IPv4,最多 32 项,过滤本机接口和虚拟网段冲突;公告撤回时取消接入。系统模式限制及权限要求见 [系统组网](system-vpn.md)。
MeshPort 扩展 `[optimization]` 配置在传入上游前解析并移除;模式、阈值、UDP优先和候选限制见 [优化说明](optimization.md)。
+41
View File
@@ -0,0 +1,41 @@
# C ABI v1
声明位于 `crates/meshport-ffi/include/meshport.h`。
- `meshport_context_new()` 返回非零 context;失败为 0。
- `meshport_call(context, request_json)` 返回库分配的 NUL 结尾 UTF-8 字符串。
- `meshport_string_free()` 必须且只能释放该返回值一次。
- `meshport_context_free()` 停止该实例并释放资源;重复释放 context 为 no-op。
- 传入字符串必须在调用期间有效,不能传悬空指针。异常不会跨 C ABI 展开。
返回格式:`{"ok":true,"data":{...}}` 或 `{"ok":false,"error":"..."}`。
控制操作:validate/start(toml)、stop、status。
Android 系统模式需宿主 VpnService 创建 TUN 后调用 attach_tun(fd)。fd 由宿主持有,原生库不负责关闭;必须在原生实例停止后再关闭,替换网卡时须等新接口 ready 后关闭旧 fd。启动前注册 meshport_set_android_socket_protector,将原生 worker 的外层 socket 交给 VpnService.protect,回调与 JVM 桥接需保持有效。参考客户端 MeshVpnService 和 JNI NativeBridge。
TCP:tcp_connect(target)返回 resource;tcp_write(resource、bytes);tcp_read(resource、max_bytes、timeout_ms)返回 bytes/eof。
UDP:udp_bind(port,0 表示动态端口)返回 resource;udp_send(resource、target、bytes);udp_receive(resource、timeout_ms)返回 bytes/source。仅接收已建立远端 flow 的报文。
resource_close 关闭指定资源。资源不能跨 context 使用;停止后资源全部失效。
probe:target、protocol(TCP/UDP)、echo、timeout_ms。TCP echo=false 只测建连;TCP echo=true/UDP 验证回显字节。UDP 必须 echo=true。耗时包括相应操作全过程,并非基础线路纯 RTT。
单次 JSON 请求 ≤128 KiB,配置 ≤64 KiB;写数据建议按16 KiB分块。UDP bytes ≤65507;TCP read 最大65535。普通 I/O 超时 1–30000 ms,默认5000 ms。连接/绑定超时当前固定5000 ms。
该 ABI 同步且每 context 串行,必须在后台线程执行。停止和释放会等待在途请求完成;当前不提供立即取消。TCP超时后可能已有部分字节发出,不应直接重发整个消息。后续生产版需异步资源接口和结构化错误码。
## 网络遥测
`status` 增加 `traffic`:`rx_bytes` / `tx_bytes` 为当前引擎运行期间采样到的累计隧道字节,`rx_bytes_per_second` / `tx_bytes_per_second` 是两次状态采样间的平均 B/s。首次采样速率为 null,重启引擎重新计数。包含组网控制、心跳和转发流量,不等于应用有效载荷。计数来自存活连接快照;若连接在两次采样之间消失,最后一次采样后的字节可能未计入。
`peers` 增加默认连接的 `latency_ms`(EasyTier ping RTT;未测出为 null),当前存活连接合计字节及采样速率。`routes` 增加所选路由的 `estimated_latency_ms` 与 `next_hop_peer_id`;估算为路由各链路延迟之和,不是端到端实测 RTT。多连接节点的 RTT 来自默认连接,流量为全部存活连接之和。中继目标未单独归集流量,其流量计入下一跳隧道。
`diagnostics_enable` 显式开启进程级穿透 tracing 采集,返回 enabled 与 scope。SDK 默认不安装全局 subscriber;已有宿主 subscriber 时 enabled=false,宿主应自行开启 EasyTier 穿透日志。启用后不可在本进程中卸载,采集仅匹配 easytier_core::connectivity::hole_punch,最多 200 条、每条 4 KiB;status 增加 diagnostic_traces,含递增 sequence,可跨采样去重。多实例共享采集范围;诊断中含节点地址,导出时当前网络密钥脱敏。
路由诊断增加 version、udp_nat_type、disable_p2p、need_p2p;cost 与 next_hop_peer_id 使用同一路由策略。peers.direct 表示存在物理直连,判断目标当前是否走直连还应核对对应 routes.next_hop_peer_id 是否等于目标 peer_id。
注意上游 directly_connected_conns 只统计非打洞连接,本 SDK 不再直接以其为空推断中继。peers.direct 包括 TCP/UDP 打洞后的物理连接,hole_punched 表示存在上游归类为打洞的存活连接。页面的直连/中继标签仍根据所选下一跳判断,而非仅根据 direct。
`quality_sample` 请求:`resource` 为已绑定 UDP 句柄,`target` 为 IPv4:port,`sequence` 为 u64,`timeout_ms` 为100–5000(默认1000)。返回 success、elapsed_ms、target_peer_id、next_hop_peer_id、next_hop_after、route_changed。超时/I/O错误返回 success=false、elapsed_ms=null;非法句柄或参数走 ABI 错误。复用 socket 并顺序调用,目标须支持原样 echo;状态前后采样不计入 RTT。
+43
View File
@@ -0,0 +1,43 @@
# 跨国线路优化:第一轮
MeshPort 使用本地定制的 EasyTier 核心,保持现有网络协议。修改位于 vendor/easytier,不要求现有服务端同步修改。混合版本、公网链路仍需实测。
## 线路策略
Flutter「设置 → 连接」默认选自适应。引擎只影响通过 MeshPort SDK 发起的通信,不创建 TUN 或改变系统路由。
```toml
[optimization]
mode = "adaptive"
min_improvement_ms = 15.0
min_improvement_ratio = 0.15
hold_seconds = 10
cooldown_seconds = 30
prefer_udp = true
relay_peer_ids = []
```
- adaptive:存在可用直连时,候选中继估算至少改善 15 ms 且 15%,持续 10 秒才切换;切换后冷却 30 秒。路径失效优先恢复可用路径。
- direct:有直连便使用,否则接受上游中继候选。
- latency:接受上游延迟优先候选,候选不可用时回退直连。
- hop:有直连便使用,否则按上游最少跳数候选选择。
没有 optimization 时,保留原 flags.latency_first 的含义:true 使用 adaptive,false/缺省使用 hop。显式 mode 优先决定该 flag。阈值范围:毫秒 0–1000、比例 0–0.9、持续时间 0–300 秒、冷却 0–600 秒。
UDP 优先作用于同一节点已经建立的连接,保留 TCP 作为备用。尚未首次 ping 确认的打洞连接不会抢占已确认连接。连接选择最多每 5 秒刷新;路由选择缓存 2 秒,通过流量或状态采样驱动阈值评估。策略不会凭空建立配置中没有的备用通道。
relay_peer_ids 最多 64 项,约束本机普通 peer-map 中上游候选的第一跳,空列表不限制。它不是完整的中继池调度器:上游最优候选不在列表时,不搜索第二优候选;没有直连可能暂时不可达。也不约束远端后续转发或所有 foreign-network 转发。建议第一轮留空。
## 实测质量
「测试 → 测量线路质量」复用 UDP socket,先预热,再发送 60 次带唯一序号的 echo,单次默认超时 1 秒,样本间隔 500 ms。需要目标虚拟 IP 上运行协作 UDP echo 服务,可以使用 meshport-test-server。任意游戏端口不能直接作为 echo 服务。
统计中位 RTT、P95(nearest-rank)、相邻有效 RTT 差值均值及未收到有效回包比例。超时也可能由 I/O 错误或 echo 服务不可用导致,不等同于纯链路丢包。迟到、其他来源及不匹配内容的回包不会被计为有效样本。按采样前下一跳分组;前后下一跳不同的样本单列。仅检测采样前后变化,不能证明途中没有短暂切换。
状态 routes.next_hop_peer_id 显示本机实际选择;candidate_next_hop_peer_id 保留上游候选,estimated_latency_ms 仍是上游候选路径估算;直连 RTT 从 peers.latency_ms 读取。optimization_basis 明确为 link_rtt_and_route_estimate。
当前自动选路比较直连的选中连接 RTT 与上游路径估算,并未将端到端 P95/抖动/丢包自动反馈到路由器,也未强制逐条候选路径探测。先分别使用 direct/adaptive 测量同一 echo 目标,检查结果再调阈值。配置修改需断开重连。
## 后续范围
独立候选路径探测与端到端反馈、完整专用中继池搜索、拥塞/排队感知、MTU 探测、游戏流优先和跨国长时故障测试尚未实现。此轮没有部署或购买中继服务器。
+49
View File
@@ -0,0 +1,49 @@
# P2P 差异调查(2026-10-09)
## 已观察到的证据
读取运行中的 MeshPort 界面:DIG-US 有直接链路,其余目标显示中继/路由估算。原版日志只有加载、启动、停止八条界面操作事件,没有原生连接事件,也没有 UDP 打洞失败细节。
用户提供的 EasyTier GUI 日志:两条初始 TCP 连接先超时、后成功;随后到节点 3157594741 建立 UDP 连接。它证明 GUI 建立了 UDP 隧道;是否由打洞建立,需要确认该地址不是手动配置的初始节点。新增连接时 latency_us 为零、包数为一,属于初始统计,不能当成打洞失败或零延迟。
## 代码对比
- UDP 穿透由上游 CoreUdpHolePunchService 创建并在原生实例启动时启动;不依赖 TUN,也不是因为本项目关掉默认 Cargo feature 就整体消失。TCP 穿透 feature 明确编译开启。
- MeshPort 普通 listeners 为空;上游 GUI 默认包含 TCP/UDP 11010。空监听影响普通主动直连/同局域网连接,不能直接推断 UDP 打洞被禁用;UDP 打洞服务会另建自己的监听。
- MeshPort 明确禁用 UPnP 且不编译其映射适配器;GUI 默认未禁用。这可能影响某些 NAT 的成功率,但目前没有证据证明 GUI 的成功链路使用了 UPnP。当前保留此限制,避免默认改变用户路由器端口映射。
- MeshPort 使用固定的 2.7.0 开发版上游提交;已从本机 /Applications/easytier-gui.app/Contents/Info.plist 确认 GUI 为 2.4.5;服务器实际版本未知。比较两版官方源码,UdpHolePunchRpc 的方法名和顺序仍一致,不能仅凭版本不同认定信令不兼容。
- MeshPort macOS Debug 包已有 network.client/server;Release 只有 client。本次补齐 Release 的 server entitlement。用户正在运行 Debug 包,所以此修复不能作为当前故障根因。
- 首版使用 latency_first=true,GUI 上游默认 false。选择路由和建立直连是不同问题;即使存在直连,延迟策略也可能选择另一条路径。
参考官方配置:https://easytier.rs/guide/network/configurations.html
参考官方 P2P 文档:https://easytier.rs/guide/network/p2p-optimize
## 本次改动
状态增加 UDP/TCP NAT 类型、STUN 更新时间、显式 STUN 配置、实际 TCP/UDP 普通监听地址、有效 P2P 开关和连接协议。STUN 配置 null 表示采用上游默认,空数组表示明确不给探测服务器;NAT Unknown 本身不区分尚未探测、探测失败或禁用。
在实例启动之前订阅原生事件,保留最多 100 条连接/监听事件,带 sequence;Flutter 刷新时去重写入日志。网络密钥从错误文本中脱敏。此事件流不是完整 tracing:UDP 打洞算法的内部重试/失败原因可能仍需额外 tracing 采集。复制网络诊断不含配置中的密钥,但包含节点名称、IP 等网络信息。
## 尚未确认
尚未取得故障发生时 MeshPort 的 NAT 结果及原生穿透内部错误,没有在用户真实网络复现并证明修复成功。本机双节点测试只证明网络模块与新增诊断工作,不证明跨 NAT 打洞。
下一轮按相同网络、初始节点和目标对比:先确认 NAT 是否完成检测、有效 P2P 禁用开关、到 3157594741 的 UDP 连接是否出现;再验证 GUI 使用的版本、STUN 和 UPnP。保持两个客户端分别运行,避免同时运行造成端口或路由干扰。
## 第二轮诊断
用户提供的状态:本地 UDP NAT 为 Symmetric,STUN 已更新,UDP/TCP/对称 NAT 打洞禁用开关均为 false。仅有到两个服务器的 TCP 连接;Redmi_AX6(3157594741)不存在直接连接。此前的约 2 秒 handshake timeout 是原生连接事件,未记录目的节点,不能据此认定是 UDP 打洞超时。
当前核心对 hard-symmetric → cone 有尝试路径,hard-symmetric → symmetric 不作为 UDP 客户端尝试。需要结合对端 NAT 分类判断是否触发;因此状态新增对端 NAT、版本和 P2P 通告开关。
还发现诊断把 latency_first 所选 next-hop 和普通模式 cost 混用了;已修正 cost 使用同一策略。UI 根据所选 next-hop 区分“当前直连”和“中继但有直连可用”,避免把已经存在的 TCP 直连误当成当前路由。
Lab 在创建网络前显式调用 diagnostics_enable,开启穿透模块 DEBUG 级详细 tracing,进程内保留最多 200 条、单条最多 4 KiB。用于观察 RPC 失败、端口预测、发包后等待超时。该操作不替换宿主已存在的 subscriber,默认 SDK 不自动启用;详细日志包含节点/网络地址信息。仍没有在真实故障网络确认根因或证明修复成功。
## 第三轮:确认 Redmi_AX6 已打洞成功,修正显示错误
最新诊断出现“连接建立 节点 3157594741 协议 udp”,RTT 7.497 ms,路由 cost=1,next_hop_peer_id 等于目标自身。因此 Redmi_AX6 当前有 UDP 物理直连;此前认为它始终打洞失败的判断不适用于本次状态。其他目标的失败日志不能代替它的当前状态。
根因是 MeshPort 错用了上游 directly_connected_conns:easytier-core/src/peers/conn/peer.rs 的 get_directly_connections 会明确 filter 掉 is_hole_punched() 的连接。空列表并非没有物理直连。
修正 peers.direct 判断为本地 peer-map 有默认连接且存在存活 TCP/UDP 隧道,排除只有 foreign logical 连接的节点。新增 hole_punched 字段,展示“直连 · 打洞建立”;是否当前走直连继续核对路由下一跳,显示 7.5 ms 实测 RTT。加入 Rust 回归测试覆盖打洞、关闭和 foreign 状态;Flutter 覆盖本次 Redmi_AX6 的路由与显示。
+45
View File
@@ -0,0 +1,45 @@
# macOS 系统组网开发版
MeshPort 保留两种独立模式:默认 `application` 只服务通过 SDK 发起的连接;`system_vpn` 创建 macOS utun,使其他应用的普通系统 TCP/UDP socket 可以访问虚拟网段。Flutter Lab 的设置页可选择模式。
## 配置与路由边界
```toml
ipv4 = "192.168.20.5/24"
listeners = []
[[peer]]
uri = "tcp://your-server:52015"
[network_identity]
network_name = "your-network"
network_secret = "your-secret"
[runtime]
mode = "system_vpn"
```
本阶段仅支持 macOS、静态私有 IPv4,前缀 /16 到 /30。虚拟地址必须唯一。helper 在启动前检查已有接口的 IPv4 网段,重叠时拒绝启动;同时使用 EasyTier GUI 时应先断开冲突网络。当前不支持系统模式 DHCP、本机子网发布、出口节点或默认路由。两种模式均自动学习符合规则的节点公告子网。系统模式安装相应 OS 路由;应用内模式仅供 SDK TCP/UDP 连接访问,不配置系统 DNS。
Rust 的 `system-vpn` feature 是显式编译开关;默认 SDK 构建保持应用内模式。系统模式使用操作系统 socket,不能调用应用内模式的 `connect_tcp/listen_tcp/bind_udp`;Lab 的单次 TCP/UDP 探测自动改用系统 socket。批量 UDP 线路采样仍属于应用内模式。
## 启动和生命周期
运行 `scripts/run-lab-macos.sh`,它构建并启动包含动态库与 helper 的开发应用。系统模式启动时 macOS 请求管理员授权;Flutter UI 不提权,独立 helper 创建网络接口。控制通道是当前用户私有临时目录中的 Unix socket,helper 校验对端 UID,限制请求大小与允许的操作。断开连接、控制通道关闭或空闲超时后停止引擎;临时目录由 Dart 清理。虚拟网段在启动前检查冲突。自动公告子网只允许私有 IPv4 /16 至 /32,最多 32 项(CIDR 排序后截取);过滤默认路由、公网、过宽网段、虚拟网段及本机接口重叠。接口缓存每 2 秒更新,系统路由定期重新同步;安装失败重试,公告撤回删除路由。
原生调用超过 60 秒时 helper 退出,以关闭 utun 文件描述符;Dart 控制请求超时为 30 秒。
设置页顶部有“配置保存”面板,可在未连接时点击“保存配置”。完整 TOML(包含网络密钥)保存在 macOS Keychain;启动时自动回填表单,不自动连接。已保存的配置可以重新载入或删除。“连接成功后自动保存配置”首次默认关闭,主动保存或加载已有配置后开启。未编辑的导入配置原样保留高级参数;修改表单后使用表单生成的配置。
## 发布边界
这是开发版 helper 方案,使用临时管理员授权与 ad-hoc 签名,尚未完成正式签名、公证或 Network Extension 发布流程;macOS App Sandbox 已为此开发方案关闭。Android VpnService、iOS Packet Tunnel、移动端后台恢复尚未接入,不能把这次 macOS 实现视作移动端已可用。
显式特权自检:`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`,不写网络密钥。
## 与其他 TUN 共存
macOS 的节点连接使用物理网卡候选,IPv4/IPv6 都排除其他 VPN 的 utun;不会将默认出口探测到的代理 TUN 地址重新加入候选。硬件检测在阻塞线程池等待子进程,避免嵌入宿主的异步信号处理影响冷启动。诊断中的 connectivity.bind_device 和 interface_ipv4s/interface_ipv6s 可确认实际候选。此调整由应用内和系统模式共用,不修改其他 VPN 的默认路由或配置。
例如 Redmi_AX6 已发布 192.168.21.0/24,Lab 虚拟 IP 为 192.168.20.4/24:无需填写远端子网。节点列表显示发布子网,两种模式的概览显示自动接入网段。该列表是通过规则的目标路由投影,不代表每一条 OS 路由安装均成功;实际系统路由可用 route 命令确认。
保留 v2rayN TUN,先用 `route -n get 192.168.21.201` 检查更具体的 /24 路由是否指向 MeshPort 的 utun。只设置 v2rayN “直连”规则不能建立 EasyTier 子网路由。如路由仍被代理接管,再检查 TUN 路由排除配置;不要依赖变化的 utun 编号设置永久路由。
旧版 runtime.subnet_routes 已移除;Lab 从钥匙串恢复旧版单行配置时会删除该字段并改用自动学习。直接使用 SDK 的旧配置应移除此字段。自动子网是 IPv4;移动端、Windows 的打包与实际互通尚待验证。
+94
View File
@@ -0,0 +1,94 @@
# 验证记录
## 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 通信及公告撤销。未把该测试记为通过。
最新源代码 Flutter analyze 无问题、7 项 widget 测试通过(3 项依赖原生 macOS 库的测试跳过),Rust workspace 测试及 doc-tests 通过。正式客户端界面的新版 APK 已打包,设备离线时尚未安装;测试夹具已关闭。需要设备重新连接完成剩余测试。详见 android.md。
2026-10-09,macOS Apple Silicon。
已经通过:
- Rust workspace 首次构建。
- 打洞 UDP 连接即使上游 directly_connected_conns 为空仍判为直连;关闭连接、外网逻辑连接不误判。
- 配置不允许 TUN、系统路由/DNS选项;未知字段拒绝;解析错误不泄漏密钥。
- 两个实际 EasyTier 原生实例通过本机 UDP tunnel 连接,虚拟 IP TCP echo 与 UDP数据校验。
- 实际通信后上传/下载计数增加、采样速率大于零、默认链路 RTT 测量成功。
- 停止实例及3次重新创建/停止。
- C ABI context 创建、停止态、非法/失效句柄、重复释放。
- 穿透详细日志 opt-in 采集、保留节点 ID、过滤其他应用模块日志。
- Dart后台isolate → C ABI → Rust → 两节点EasyTier UDP通信,校验字节与来源。
- Flutter widget 初始未连接状态、设置入口。
- Flutter TOML 导入 → 实际原生引擎启动 → 状态显示 → 断开连接。
- C 示例编译并读取原生实例状态。
- Flutter Redmi_AX6 打洞直连显示 7.5 ms 实测 RTT,排除错误中继标签。
- Flutter 节点 RTT、路由估算、流量速率和中继统计范围显示测试;已有直连但实际路由经中继时正确区分。
- Flutter macOS debug 构建。
注意:首次 UDP测试发现上游只接收已发送过的远端会话报文;测试按上游会话模型显式预热,不把它当成通用 UDP监听。游戏服务端的普通 socket 回包路径仍需实际服务器验证。
运行命令:
```sh
scripts/cargo-local.sh test --workspace --locked
scripts/cargo-local.sh clippy --workspace --all-targets --no-deps --locked -- -D warnings
cd apps/meshport_lab
flutter analyze
flutter test
# 包含真实原生引擎的界面测试(先构建 Rust 库)
flutter test --dart-define=MESHPORT_LIBRARY="$(cd ../.. && pwd)/target/debug/libmeshport_ffi.dylib"
dart run tool/native_smoke.dart ../../target/debug/libmeshport_ffi.dylib
```
最后一条从 apps/meshport_lab 执行,也可传入 Rust 库的绝对路径。
后续:真实游戏服务器发布版互通、网络切换/中继故障、长时内存与并发、用户态UDP首次入站支持、异步ABI、移动端打包与真机测试。
## 跨国优化第一轮回归
已通过:Rust workspace 12 个测试及 doc-tests;策略阈值、持续时间、冷却、候选限制与失效回退;两个实际 EasyTier 实例同时建立 TCP/UDP,确认 UDP 被选择,关闭 UDP 后选择 TCP。Dart → C ABI → 实际 overlay 质量采样验证成功回包、下一跳及超时结果。Flutter analyze 无问题,包含原生导入的 6 个测试全部通过;更新后的 macOS debug 包构建和签名通过。
Clippy 使用 --no-deps 检查 MeshPort 工作区且 -D warnings 通过。保留的上游源码在 Rust 1.99 下有 8 条既有弃用/未使用警告。
尚未完成真实跨国线路的长期对比、满负载游戏测试、UDP 黑洞恢复时延测试以及全部候选路径的端到端自动探测;本机功能测试不证明公网加速效果。
## macOS 系统组网阶段(2026-10-10)
已通过 Rust workspace 13 项测试及 doc-tests、Flutter analyze、Flutter 8 项测试(包含 Unix 控制通道并发请求顺序及关闭清理)、macOS debug 构建和 codesign 深度校验。
系统模式自检曾完成真实 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 系统模式尚未实现;真实游戏、跨国长期压测和故障切换仍需后续验证。
## 指定远端子网修复(2026-10-10)
Rust 13 项测试及 doc-tests、Flutter 8 项测试、analyze、Clippy --no-deps -D warnings、macOS 构建与签名通过。系统模式开启显式私有子网接入,拒绝默认路由、公网网段及本机接口网段重叠。
在 v2rayN TUN 开启时,特权自检为 10.253.78.0/24 添加 MeshPort 路由,经普通 OS TCP/UDP 完成额外子网的回显;确认目标路由指向测试 utun,停止后该接口及子网路由清理,默认路由不变。记录 /tmp/meshport-subnet-self-test.log。这验证的是本机额外子网路由和数据面;Redmi_AX6 发布的真实局域网及屏幕共享仍需用新版重连实测。当前显式接入,不自动接受全部节点发布的子网。
## 自动公告子网接入(2026-10-10)
此版本取代上一阶段的手动子网列表。应用内与系统模式使用相同的私有 IPv4 /16~/32、32 项上限、虚拟网段和本机接口冲突过滤规则。runtime.subnet_routes 配置与 UI 字段均已删除。
应用内集成测试使用真正的发布节点:将 loopback 服务映射发布为 10.253.79.0/24,SDK 客户端自动学习后通过该子网完成 TCP 和 UDP 双向回显;发布节点清空公告后确认接入列表消失。测试节点启用独立 packet proxy host capability,生产客户端无需启用子网发布或 KCP/QUIC。
系统特权自检通过自动公告学习安装额外子网路由,经普通 OS TCP/UDP 回显;发布节点清空公告后确认路由删除,停止后 utun 消失,默认路由不变。记录 /tmp/meshport-auto-system-final.log。该自检的服务位于另一节点的虚拟 IP,应用内映射子网测试另外覆盖了后端服务访问。
此前实际 Redmi_AX6 子网 192.168.21.0/24 的屏幕共享端口已验证返回 RFB 握手;用户确认访问问题已解决。新版在真实网络中的自动接入仍需用新客户端重连验证,已有真实验证使用的是手动路由版本。
最终检查:Rust 工作区 16 项测试及 doc-tests、Clippy --no-deps -D warnings、Flutter 8 项测试(含最终原生库导入)、analyze、macOS 构建和严格签名验证通过。独立应用 outputs/macos/MeshPortLab-20261010121113.app。
## 代理 TUN 先启动时的物理网卡连接(2026-10-10)
macOS 网络地址收集不再追加默认出口探测到的 TUN 地址;IPv6 使用同一物理网卡过滤。networksetup 硬件检测改用阻塞线程池等待。诊断增加 bind_device 和接口候选地址。
在 v2rayN utun58(172.18.0.1)保持开启时运行 `scripts/cargo-local.sh test -p meshport-easytier physical_bootstrap_with_existing_tun -- --ignored --nocapture`,通过物理地址启动独立测试网络并完成 EasyTier TCP 握手,同时断言候选不包含任何 utun 地址。测试不修改 OS 路由。这是本机真实套接字回归,不能替代用户远端节点在相同启动顺序下的互通验证。记录 /tmp/meshport-tun-bootstrap.log。
## 配置保存与 MeshPort 品牌(2026-10-10)
设置页增加独立保存、重新载入和删除;启动自动回填,不自动连接。保存的未编辑高级 TOML 原样保留。Flutter 测试覆盖未连接保存、重建界面后回填名称/密钥/节点/IP、保持断开、删除,以及高级参数保留。测试调用真实 FFI,钥匙串 MethodChannel 使用隔离内存替身,不覆盖用户已有钥匙串配置。原生 macOS Keychain 实现随应用编译,真实钥匙串跨重启访问授权仍以设备实测为准。
FFI 测试验证普通 validate 不返回密钥,只有显式 include_profile 才返回表单所需字段。应用正式名称为 MeshPort;macOS/iOS/Android/Windows 图标及 Flutter 页头配置为已设计图标。其他平台尚未打包验证。
最终验证:Flutter 10 项测试及 analyze、FFI 3 项测试、Clippy --no-deps -D warnings、macOS 构建和严格签名验证通过。已打开正式应用,窗口标题为 MeshPort,页头为新图标,设置页顶部“保存配置”按钮可见。独立应用 outputs/macos/MeshPort-20261010144609.app(0.1.0 预览版)。实机检查未保存测试配置,避免污染用户配置。
+165
View File
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.