Fix first Tailscale connection fallback in Windows 0.3.14

This commit is contained in:
2026-11-13 12:31:22 +08:00
parent 839434a313
commit cf02204e35
5 changed files with 17 additions and 15 deletions
+4 -4
View File
@@ -40,7 +40,7 @@ internal static class NodeTransportConnector
{ {
selected = fallback!; selected = fallback!;
tailnet = false; tailnet = false;
diagnostic?.Invoke(new("rebind_fallback", "ping_unreachable", "")); diagnostic?.Invoke(new("rebind_fallback", "endpoint_unreachable", ""));
} }
} }
await start(selected, deadline.Token); await start(selected, deadline.Token);
@@ -96,9 +96,9 @@ internal static class NodeTransportConnector
{ {
try try
{ {
status("正在 Ping 代理内网 IP(最多 1 秒)"); status("正在检测 Tailscale 代理端口(最多 5 秒)");
if (!await endpointProbe(TailnetTransport.Address(tailnet)!, TailnetTransport.Port(tailnet), token)) if (!await endpointProbe(TailnetTransport.Address(tailnet)!, TailnetTransport.Port(tailnet), token))
throw new IOException("代理内网 IP Ping 不通。"); throw new IOException("Tailscale 代理端口不可达。");
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
} }
catch (Exception e) when (e is not OperationCanceledException && e is not ClientRuntimeException) catch (Exception e) when (e is not OperationCanceledException && e is not ClientRuntimeException)
@@ -107,7 +107,7 @@ internal static class NodeTransportConnector
tailnet = null; tailnet = null;
reason = "endpoint_unreachable"; reason = "endpoint_unreachable";
Report("tailnet_skipped", reason); Report("tailnet_skipped", reason);
status("内网 IP Ping 不通,使用同一节点公网入口"); status("Tailscale 代理端口不可达,使用同一节点公网入口");
} }
} }
if (tailnet is not null) if (tailnet is not null)
+7 -5
View File
@@ -107,16 +107,18 @@ internal static class TailnetTransport
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
if (!IsTailnetAddress(address) || port is < 1 or > 65535) return false; if (!IsTailnetAddress(address) || port is < 1 or > 65535) return false;
using var deadline = CancellationTokenSource.CreateLinkedTokenSource(token); using var deadline = CancellationTokenSource.CreateLinkedTokenSource(token);
deadline.CancelAfter(TimeSpan.FromSeconds(1)); deadline.CancelAfter(TimeSpan.FromSeconds(5));
try try
{ {
RequireProbeRoute(address); RequireProbeRoute(address);
using var ping = new Ping(); // The first connection may need to establish a Tailscale path.
var reply = await ping.SendPingAsync(IPAddress.Parse(address), 1000).WaitAsync(deadline.Token).ConfigureAwait(false); // Test the actual proxy listener instead of gating on ICMP.
return reply.Status == IPStatus.Success; 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 (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; } or InvalidOperationException or IOException or System.ComponentModel.Win32Exception) { return false; }
} }
+1 -1
View File
@@ -25,7 +25,7 @@ internal static class TailnetTransportProbe
var prepared = TailnetTransport.TryPrepare(response, allowKnownEndpoints: true) ?? throw new InvalidOperationException("probe_not_eligible"); var prepared = TailnetTransport.TryPrepare(response, allowKnownEndpoints: true) ?? throw new InvalidOperationException("probe_not_eligible");
endpoint = TailnetTransport.Address(prepared)!; endpoint = TailnetTransport.Address(prepared)!;
checks["same_authorized_fallback"] = TailnetTransport.SameAuthorizedFallback(prepared, response.GetRuntimeConfigJson()); 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"); if (!checks.Values.All(v => v)) throw new IOException("probe_preflight_failed");
var interfaceName = TailnetTransport.RequireExistingRoute(endpoint); var interfaceName = TailnetTransport.RequireExistingRoute(endpoint);
var runtime = JsonNode.Parse(TunConfigBuilder.Build(prepared, interfaceName, false, var runtime = JsonNode.Parse(TunConfigBuilder.Build(prepared, interfaceName, false,
+1 -1
View File
@@ -270,7 +270,7 @@ internal static class TailnetTransportSelfTest
selected = await NodeTransportConnector.ConnectAsync(known,deniedPreference,Start,Stop,Healthy,Route,statuses.Add,()=>tick,CancellationToken.None, selected = await NodeTransportConnector.ConnectAsync(known,deniedPreference,Start,Stop,Healthy,Route,statuses.Add,()=>tick,CancellationToken.None,
allowKnownEndpoints:true, endpointProbe:(_,_,_)=>Task.FromResult(false)); 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["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); checks["closed_port_sets_node_cooldown"] = !deniedPreference.MayTry(known.Node.Slug,tick+1);
starts.Clear(); starts.Clear();
selected = await NodeTransportConnector.ConnectAsync(known,deniedPreference,Start,Stop,Healthy,Route,_=>{},()=>tick+1,CancellationToken.None, selected = await NodeTransportConnector.ConnectAsync(known,deniedPreference,Start,Stop,Healthy,Route,_=>{},()=>tick+1,CancellationToken.None,
+4 -4
View File
@@ -10,10 +10,10 @@
<ApplicationIcon>assets\zonghengjia-app-v1.ico</ApplicationIcon> <ApplicationIcon>assets\zonghengjia-app-v1.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode> <ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
<Version>0.3.13</Version> <Version>0.3.14</Version>
<AssemblyVersion>0.3.13.0</AssemblyVersion> <AssemblyVersion>0.3.14.0</AssemblyVersion>
<FileVersion>0.3.13.0</FileVersion> <FileVersion>0.3.14.0</FileVersion>
<InformationalVersion>0.3.13</InformationalVersion> <InformationalVersion>0.3.14</InformationalVersion>
<Product>纵横家</Product> <Product>纵横家</Product>
<Company>优创未来(UCVL)</Company> <Company>优创未来(UCVL)</Company>
<Description>纵横家 Windows 智能网络客户端</Description> <Description>纵横家 Windows 智能网络客户端</Description>