Files
MeshPort/docs/architecture.md
shenleiandClaude Opus 5.5 dc1bfc99d2 Move mesh networking logic into the SDK and fix lifecycle bugs
SDK:
- Add build_config/migrate_config, mesh_cidrs, route_generation, health
  and start_bridged; expose abi_info (capability revision 2).
- Add wait_routes long-poll; stop wakes waiters, and context_free now
  stops the network immediately instead of waiting for waiters to time out.

Hosts:
- Dart: waitRoutes(), MeshProxySession route watcher, ABI capability check.
- Android: fix a deadlock where every VPN request waited on its own
  single-thread worker; requests are now async, status is served from a
  snapshot, and combined mode reports Partial when the mesh stops.
- macOS helper: mesh-only unified mode stops when the mesh is lost;
  installed_subnet_routes excludes the overlay.
- Lab: restore Partial sessions, write migrated profiles back, remove the
  unreachable TOML import dialog; native test now connects via the form.

Docs updated accordingly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 18:17:42 +09:00

24 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 架构
本文描述当前实现。下一阶段 sing-box 组合客户端方案见 [组网与代理组合架构](next-stage-architecture.md),配套页面见 [移动端 UI V4](ui-design.md)。
已新增可选的应用内 [SOCKS 桥接](socks-bridge.md):通过 Rust 数据面并发转发本机 SOCKS5 TCP/UDP,C ABI/Dart 只负责启动、停止和状态。[sing-box Go 封装与本机联调](singbox-integration.md)已通过;客户端统一 TUN 尚未接入,现有普通 JSON I/O 的串行限制仍保留。
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)。
组网规则归 SDK:配置生成与模式约束(`build_config`)、旧配置迁移(`migrate_config`)、虚拟网段与本机接口冲突检查、应用模式网络加桥接的原子启动(`start_bridged`)、路由目标投影(`mesh_cidrs` 与 `route_generation`)、组网可用性(`health`)以及节点直连/中继与延迟来源判定(`nodes`)都在 Rust 中实现。Dart 客户端核心、Android VpnService 与 macOS helper 只安装和展示这些结果,负责平台授权、socket protect、物理网络选择、OS 路由/DNS 守护与 sing-box 配置。质量测量循环仍由 Dart 驱动:ABI v1 每 context 串行,在原生侧运行约 30 秒的采样循环会阻塞同一 context 的状态轮询。