From cf02204e35b2de9b6c3c7f3aae42a42ecb2e41c6 Mon Sep 17 00:00:00 2001 From: UCVL Date: Fri, 13 Nov 2026 12:31:22 +0800 Subject: [PATCH] Fix first Tailscale connection fallback in Windows 0.3.14 --- windows/NodeTransportConnector.cs | 8 ++++---- windows/TailnetTransport.cs | 12 +++++++----- windows/TailnetTransportProbe.cs | 2 +- windows/TailnetTransportSelfTest.cs | 2 +- windows/VPNPlus.csproj | 8 ++++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/windows/NodeTransportConnector.cs b/windows/NodeTransportConnector.cs index 504281c..9ec526a 100644 --- a/windows/NodeTransportConnector.cs +++ b/windows/NodeTransportConnector.cs @@ -40,7 +40,7 @@ internal static class NodeTransportConnector { selected = fallback!; tailnet = false; - diagnostic?.Invoke(new("rebind_fallback", "ping_unreachable", "")); + diagnostic?.Invoke(new("rebind_fallback", "endpoint_unreachable", "")); } } await start(selected, deadline.Token); @@ -96,9 +96,9 @@ internal static class NodeTransportConnector { try { - status("正在 Ping 代理内网 IP(最多 1 秒)"); + status("正在检测 Tailscale 代理端口(最多 5 秒)"); if (!await endpointProbe(TailnetTransport.Address(tailnet)!, TailnetTransport.Port(tailnet), token)) - throw new IOException("代理内网 IP Ping 不通。"); + throw new IOException("Tailscale 代理端口不可达。"); token.ThrowIfCancellationRequested(); } catch (Exception e) when (e is not OperationCanceledException && e is not ClientRuntimeException) @@ -107,7 +107,7 @@ internal static class NodeTransportConnector tailnet = null; reason = "endpoint_unreachable"; Report("tailnet_skipped", reason); - status("内网 IP Ping 不通,使用同一节点公网入口"); + status("Tailscale 代理端口不可达,使用同一节点公网入口"); } } if (tailnet is not null) diff --git a/windows/TailnetTransport.cs b/windows/TailnetTransport.cs index 31318c7..b742f19 100644 --- a/windows/TailnetTransport.cs +++ b/windows/TailnetTransport.cs @@ -107,16 +107,18 @@ internal static class TailnetTransport token.ThrowIfCancellationRequested(); if (!IsTailnetAddress(address) || port is < 1 or > 65535) return false; using var deadline = CancellationTokenSource.CreateLinkedTokenSource(token); - deadline.CancelAfter(TimeSpan.FromSeconds(1)); + deadline.CancelAfter(TimeSpan.FromSeconds(5)); try { RequireProbeRoute(address); - using var ping = new Ping(); - var reply = await ping.SendPingAsync(IPAddress.Parse(address), 1000).WaitAsync(deadline.Token).ConfigureAwait(false); - return reply.Status == IPStatus.Success; + // The first connection may need to establish a Tailscale path. + // Test the actual proxy listener instead of gating on ICMP. + using var socket = new TcpClient(AddressFamily.InterNetwork); + await socket.ConnectAsync(IPAddress.Parse(address), port, deadline.Token).ConfigureAwait(false); + return true; } catch (OperationCanceledException) when (!token.IsCancellationRequested) { return false; } - catch (Exception e) when (e is PingException or SocketException or NetworkInformationException + catch (Exception e) when (e is SocketException or NetworkInformationException or InvalidOperationException or IOException or System.ComponentModel.Win32Exception) { return false; } } diff --git a/windows/TailnetTransportProbe.cs b/windows/TailnetTransportProbe.cs index 584180c..aae0a17 100644 --- a/windows/TailnetTransportProbe.cs +++ b/windows/TailnetTransportProbe.cs @@ -25,7 +25,7 @@ internal static class TailnetTransportProbe var prepared = TailnetTransport.TryPrepare(response, allowKnownEndpoints: true) ?? throw new InvalidOperationException("probe_not_eligible"); endpoint = TailnetTransport.Address(prepared)!; checks["same_authorized_fallback"] = TailnetTransport.SameAuthorizedFallback(prepared, response.GetRuntimeConfigJson()); - checks["three_second_preflight"] = await TailnetTransport.ProbeEndpointAsync(endpoint, TailnetTransport.Port(prepared), deadline.Token); + checks["tcp_endpoint_preflight"] = await TailnetTransport.ProbeEndpointAsync(endpoint, TailnetTransport.Port(prepared), deadline.Token); if (!checks.Values.All(v => v)) throw new IOException("probe_preflight_failed"); var interfaceName = TailnetTransport.RequireExistingRoute(endpoint); var runtime = JsonNode.Parse(TunConfigBuilder.Build(prepared, interfaceName, false, diff --git a/windows/TailnetTransportSelfTest.cs b/windows/TailnetTransportSelfTest.cs index 06f82ae..47605db 100644 --- a/windows/TailnetTransportSelfTest.cs +++ b/windows/TailnetTransportSelfTest.cs @@ -270,7 +270,7 @@ internal static class TailnetTransportSelfTest selected = await NodeTransportConnector.ConnectAsync(known,deniedPreference,Start,Stop,Healthy,Route,statuses.Add,()=>tick,CancellationToken.None, allowKnownEndpoints:true, endpointProbe:(_,_,_)=>Task.FromResult(false)); checks["closed_port_skips_tailnet_start_and_stop"] = !selected && starts.SequenceEqual(new[]{"002.vpn.toplc.cn"}) && stops == beforeStops && probes == 0; - checks["ping_unreachable_status_is_distinct_from_route_failure"] = statuses.Last() == "内网 IP Ping 不通,使用同一节点公网入口"; + checks["endpoint_unreachable_status_is_distinct_from_route_failure"] = statuses.Last() == "Tailscale 代理端口不可达,使用同一节点公网入口"; checks["closed_port_sets_node_cooldown"] = !deniedPreference.MayTry(known.Node.Slug,tick+1); starts.Clear(); selected = await NodeTransportConnector.ConnectAsync(known,deniedPreference,Start,Stop,Healthy,Route,_=>{},()=>tick+1,CancellationToken.None, diff --git a/windows/VPNPlus.csproj b/windows/VPNPlus.csproj index 0326fc5..345228b 100644 --- a/windows/VPNPlus.csproj +++ b/windows/VPNPlus.csproj @@ -10,10 +10,10 @@ assets\zonghengjia-app-v1.ico app.manifest PerMonitorV2 - 0.3.13 - 0.3.13.0 - 0.3.13.0 - 0.3.13 + 0.3.14 + 0.3.14.0 + 0.3.14.0 + 0.3.14 纵横家 优创未来(UCVL) 纵横家 Windows 智能网络客户端