点对点(P2P):设备直连
两台 wantasticd 设备如何直接通信、如何检查,以及一直停留在 relay 时如何获得直连路径。
你的设备可以通过 VPN IP 互相访问,wantasticd peers 显示 PATH direct。
开始之前
- 两台设备都已安装 wantasticd 且为 Online
- 两台设备在同一个 Wantastic 团队中
P2P 的工作方式
P2P 是自动的。无需开启任何开关,也无需开放端口。
- 每台 wantasticd 设备都可以通过 VPN IP 访问你团队中的任何其他设备。
- 最初的数据包经由 Wantastic 服务器(relay)转发,因此连接立即可用。
- 两台设备会在后台寻找直连路径。成功后,流量会切换过去(PATH direct)。
- 如果无法建立直连,流量会继续走 relay。连接仍然可用,只是延迟更高。
- P2P 适用于运行 wantasticd 的设备:Linux、Raspberry Pi、OpenWrt、macOS、Windows 和 Docker。MikroTik 路由器和使用 WireGuard 应用的手机始终经由服务器。
连接两台设备
- 1在两台设备上安装 wantasticd 并认领它们。
- 2在其中一台设备上运行 wantasticd peers,记下另一台设备的 VPN IP。
- 3用任意应用连接该 VPN IP,例如 SSH、浏览器或 ping。
- 4等待最多一分钟,再次运行 wantasticd peers。PATH 应从 relay 变为 direct。
wantasticd peerswantasticd ping -c 4 <vpn-ip>ssh user@<vpn-ip>提示: wantasticd ping 也接受设备名称,例如 wantasticd ping office-gw。
检查是 direct 还是 relay
| PATH | 含义 |
|---|---|
| direct | P2P。流量在两台设备之间直接传输。 |
| 中继 | 流量经由 Wantastic 服务器转发。连接可用,正在重试直连路径。 |
| 服务器 | Wantastic 服务器本身,或未运行 wantasticd 的设备(MikroTik、WireGuard 应用)。 |
$ wantasticd peersHOSTNAME VPN IP PATH ENDPOINT HANDSHAKE RX TX STATE(server) - server 172.239.44.171:51820 8s ago 14.1 KiB 7.9 KiB -office-gw 10.200.0.3 direct 203.0.113.24:41641 21s ago 3.2 KiB 1.1 KiB established1lab-pi 10.200.0.9 relay - never 0 B 0 B trying2
- 1P2P 直连路径
- 2仍在 relay,正在重试
注意: 在 macOS 和 Windows 上,托盘菜单显示相同信息:Peers: N (P2P: x, Relay: y)。
获得直连路径
大多数设备会自动切换到 direct。如果某台设备一直停留在 relay,请按顺序尝试以下操作。
- 1在每台设备的路由器上开启 UPnP 或 NAT-PMP。这是最有效的方法。
- 2在 macOS 上,如果出现 "Do you want the application wantasticd to accept incoming network connections?",点击 Allow。
- 3在 Windows 上,如果 Windows 防火墙询问 wantasticd.exe,点击 Allow。
- 4在两台设备上重启 wantasticd,然后再次发送流量。
警告: 移动网络和部分家庭宽带使用 CGNAT。在这些网络中直连常常失败,设备会停留在 relay。这是正常的,连接仍然可用。
P2P 与出口节点
出口节点需要直连路径。在 Topology 中,Assign Exit Node 只列出已支持 P2P 的设备。如果托盘显示 "Relayed right now: exit traffic starts once a direct path is up",请等待 PATH direct。
验证结果
常见问题
另一台设备没有列出。No peers.wantasticd peers
另一台设备离线、未认领,或在另一个团队中。
在控制台中确认两台设备在同一团队中且为 Online,然后再次运行 wantasticd peers。
某台设备一直停留在 relay。[P2P] Punch timeout for peer N after M targetswantasticd 日志
路由器或防火墙阻止了直连路径。
在路由器上开启 UPnP 或 NAT-PMP。wantasticd 会自动重试,期间 relay 继续工作。
直连路径建立后又回退到 relay。[P2P] Direct path validation failed for peer N; relay remains active: direct handshake timeoutwantasticd 日志
打洞包已通过,但加密握手未通过,通常是防火墙过于严格。
在两台设备的防火墙中允许 wantasticd,然后重启 wantasticd。
macOS 一直停留在 relay。[P2P] Could not add … to the application firewallwantasticd 日志(macOS)
macOS 防火墙阻止了到 wantasticd 的入站连接。
打开 System Settings > Network > Firewall > Options,将 wantasticd 设为 Allow incoming connections,然后重启 wantasticd。
sudo launchctl kickstart -k system/com.wantastic.wantasticdMikroTik 路由器始终显示 PATH server。
MikroTik 和 WireGuard 应用设备不运行 wantasticd,因此始终经由服务器。
无需修复。它们仍可通过 VPN IP 访问。
继续阅读
仍然无法解决?
请通过邮件发送设备名称、平台和完整的错误文本。切勿发送令牌、密钥或密码。