fix(pairing): Direct AP 网关地址被挤出二维码,修复我上一版引入的回退

手机端诊断给出了决定性证据。二维码广播的三个地址是:
  192.168.8.68、192.168.30.1、192.168.31.1
而手机连上 Direct AP 后拿到的是 192.168.137.200/24、网关 192.168.137.1
——**码里根本没有它能到达的那个地址**。

回退是我造成的。上一版为了让真实网卡优先,把 192.168.137.1 / 192.168.49.1
这两个猜测性兜底地址挪到了列表末尾;而二维码只取前 3 个。二维码是在
点「启动接收」的瞬间生成的,此时 ICS 虚拟网卡往往还没拿到 IP,因此
不会出现在 get_if_addrs 里,只能靠那两个兜底地址补位——一挪到末尾就被
截断掉了。表现是"Wi-Fi 已连接但找不到电脑",从现象几乎无法反推到这里。

改动
- 新增 pairing::qr_endpoints(port, direct_ap_active):Direct AP 启用时
  把 ICS 网关地址强制放到最前,未启用时维持真实网卡优先
- 二维码端点上限 3 → 4,以便同时容纳 AP 网关与常规局域网地址
- Windows 接收页新增可展开的「二维码广播的地址」列表。手机报"找不到
  电脑"时,第一件要确认的就是码里有没有它能到达的地址——现在一眼可见,
  不必等手机端诊断

测试:新增三项,分别锁住「AP 网关必须排第一」「即使网卡很多也不能被
长度上限截断」「未开 AP 时不该让猜测地址占位」。cargo test 43/43。

注意:本次修复的是"地址没进二维码"。手机此前也直接探测过网关
192.168.137.1:39393 并且失败,说明 Windows 在 ICS 虚拟网卡上仍未接受
连接——那是防火墙配置文件的问题,需要在接收页点「放行防火墙」
(规则会以 profile=any 重建,覆盖该网卡的网络类型)。
This commit is contained in:
zhy200308
2026-08-11 22:03:19 +08:00
parent ae2c36fa54
commit f62fe8d23b
2 changed files with 102 additions and 3 deletions
+11 -2
View File
@@ -604,6 +604,15 @@ impl QftApp {
ui.vertical_centered(|ui| { let side = snap_to_physical(side, ui.ctx().pixels_per_point());
ui.image((texture.id(), egui::vec2(side, side))); });
}
// 把二维码实际广播的地址摊开显示。手机报"找不到电脑"时,
// 第一件要确认的就是码里到底有没有它能到达的那个地址——
// 在这里一眼可见,不必等手机端的诊断。
ui.collapsing("二维码广播的地址", |ui| {
for endpoint in pairing::qr_endpoints(listen_port, self.receive.direct_ap.is_some()).iter().take(4) {
ui.monospace(endpoint);
}
ui.small("手机连上后会依次尝试这些地址;其中必须有一个与手机同网段。");
});
if let Some(ap) = &self.receive.direct_ap {
ui.label(format!("临时网络:{}", ap.ssid));
ui.small("网络身份会在这台电脑上复用以减少重复确认;每次接收仍会生成新的会话 Token。");
@@ -1014,7 +1023,7 @@ impl QftApp {
pc_name: self.local_device.clone(),
transport: "http-parallel-v2".into(),
port: server.port,
endpoints: pairing::local_ipv4_endpoints(server.port),
endpoints: pairing::qr_endpoints(server.port, self.receive.direct_ap.is_some()),
wifi,
direction: PairingDirection::Upload,
file_name: None,
@@ -1094,7 +1103,7 @@ impl QftApp {
pc_name: self.local_device.clone(),
transport: "http-download-v2".into(),
port: server.port,
endpoints: pairing::local_ipv4_endpoints(server.port),
endpoints: pairing::qr_endpoints(server.port, self.send.direct_ap.is_some()),
wifi,
direction: PairingDirection::Download,
file_name: Some(file_name),