原生数据面协议层:桌面 engine 进度节流 / pion 日志 + iOS 数据面路由

- 桌面 engine(pion 数据面,承 ab57afd 之后的精修):
  - 新增 logging.go——把 pion 内部日志路由到宿主 OnLog(真机无 stderr,连接失败无从查);仅 ice/mdns 作用域放 Debug、余 Info+、Trace 丢弃,按 session 聚合
  - wire.go / session.go / engine.go:进度回调 ~10Hz 节流(progressEmitThrottleMs,高吞吐下每片一回调打满宿主主线程;终态由 emitProgressNow 强发最终值),与 web store push 同量级;engine_test.go 跟进
- web 数据面路由:p2p.ts 翻 IOS_NATIVE=true(iOS 走原生 libwebrtc 引擎)+ 新增 p2pIos.ts(iOS p2p 后端)+ p2pNative.ts / net/ios.ts 跟进
- 数据面设计文档 NATIVE-TRANSFER.md:U1(gomobile+pion)真机证伪 → 翻案 U2(libwebrtc)的依据与实测证据(§7/§8)
- 线协议三端一致(cdrop-file ordered / meta+chunk(64KB)+done+ack / 16MB-4MB 水位 / ack 追平完成),桌面 pion ↔ iOS libwebrtc ↔ web JS 互通
This commit is contained in:
2026-06-28 19:32:37 +08:00
parent ab57afdec2
commit f1a00d128e
11 changed files with 587 additions and 22 deletions
+9 -2
View File
@@ -52,6 +52,13 @@ func New(cfg Config, ev Events) *Engine {
return &Engine{cfg: cfg, ev: ev, byPeer: make(map[string]*session)}
}
// NewEngine 是 gomobile-friendly 构造器:以 downloadDir 字符串 + Events 接口构造,避开 New 的
// Config 值参数——gomobile 不绑定按值传递的结构体(故 New 在 iOS 头里被 skip)。桌面侧仍用 New;
// iOS Swift 经 xcframework 调本函数。二者构造同一 *Engine,无行为差异。
func NewEngine(downloadDir string, ev Events) *Engine {
return New(Config{DownloadDir: downloadDir}, ev)
}
// SetDownloadDir 更新落地目录(设置页改下载目录时调用)。
func (e *Engine) SetDownloadDir(dir string) {
e.mu.Lock()
@@ -75,7 +82,7 @@ func (e *Engine) StartOutgoing(sessionID, peerName, filePath, iceServersJSON str
if fi.IsDir() {
return fmt.Errorf("%s is a directory", filePath)
}
pc, err := newPeerConnection(iceServersJSON)
pc, err := newPeerConnection(sessionID, iceServersJSON, e.ev.OnLog)
if err != nil {
return err
}
@@ -109,7 +116,7 @@ func (e *Engine) StartOutgoing(sessionID, peerName, filePath, iceServersJSON str
// StartIncoming 作为接收端预备:建 PeerConnection 等对端 offer。收到 DataChannel 后按
// 线协议接收并直接落盘。须在对端 offer 到达前调用(宿主在 transfer:incoming 时预备)。
func (e *Engine) StartIncoming(sessionID, peerName, iceServersJSON string) error {
pc, err := newPeerConnection(iceServersJSON)
pc, err := newPeerConnection(sessionID, iceServersJSON, e.ev.OnLog)
if err != nil {
return err
}