Repository navigation
Conversation
preferredLanAddress() returned the first private IPv4 that os.networkInterfaces() enumerated. On Windows with WSL that is the vEthernet (WSL) switch, whose 192.168.x.1 address only the host can reach, so the QR code and pairing link pointed phones at a dead address (dataelement#601). The WSL address shares the 192.168 range with the real LAN, so only the adapter name separates the two. Prefer private IPv4 addresses on adapters that are not hypervisor switches, VM host-only networks, container bridges or VPN tunnels, and fall back to the first virtual adapter only when no physical adapter has a private address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Fixes #601。
preferredLanAddress()直接返回os.networkInterfaces()枚举到的第一个私网 IPv4。装了 WSL 的 Windows 上排第一的往往是vEthernet (WSL),它的192.168.x.1只有本机能访问,二维码和配对链接于是指向手机连不上的地址,WiFi 配对直接失败。关键细节:报告里 WSL 地址
192.168.208.1与真实网卡192.168.1.x同属 192.168 段,按网段排优先级修不了,只能靠适配器名区分。改动
src/main/mobile/lan-mobile-bridge.ts:VIRTUAL_INTERFACE_PATTERNS,按名称识别 Hyper‑V 虚拟交换机(vEthernet (…),含 WSL / Default Switch)、VMware、VirtualBox、容器与 libvirt 网桥(docker0、br-<id>、veth*、virbr*…)、macOSbridgeN、VPN 隧道(utun/tun/tap/wg、Tailscale、ZeroTier、WireGuard、OpenVPN、Wintun);preferredLanAddress()优先返回非虚拟适配器上的私网 IPv4,同级保持原枚举顺序;只剩虚拟适配器有私网地址时回退到原行为(取第一个),不让配对链接凭空消失;interfaces(默认networkInterfaces()),调用方不变,便于测试注入网卡表。br-<id>只匹配 Docker 自定义网桥;Linux 宿主承载局域网的br0不受影响(有测试覆盖)。为什么不按默认路由 / metric 选
preferredLanAddress()在snapshot()里同步调用,读路由表需要按平台起子进程(route print/Get-NetRoute/ip route),代价和改动面都偏大。issue 里的建议 3/4(对话框列出全部候选地址、标注网卡名)可以作为后续单独的 UI 改动。测试
test/lan-mobile-bridge.test.ts新增 5 个用例:issue 报告的真实枚举顺序(vEthernet (WSL)→Ethernet→Loopback)、Hyper‑V / VMware / VirtualBox 与中文系统网卡名(以太网 / WLAN)、Linux 容器网桥与隧道(且br0不误杀)、macOSbridge100/utun3、回退路径、IPv6 / internal / 非私网地址过滤。文件内 44 个用例全部通过。192.168.208.1,与报告现象一致。Meta198.18.x、WLAN、VMware VMnet1/VMnet8):真实网卡表选中 WLAN,无回归;在前面插入vEthernet (WSL)后仍选中 WLAN。vitest run:1562 通过;另有 12 个文件 28 个用例因本机缺 python3 / 未构建 PPT 与 Office 产物失败,已在干净基线上复跑同批文件,失败用例集合按全名逐条一致,与本 PR 无关。tsc --noEmit -p tsconfig.node.json无错误。