Publish Zonghengjia Windows 0.3.13 client source
This commit is contained in:
@@ -110,12 +110,14 @@ internal static class TailnetTransport
|
||||
deadline.CancelAfter(TimeSpan.FromSeconds(1));
|
||||
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;
|
||||
}
|
||||
catch (OperationCanceledException) when (!token.IsCancellationRequested) { return false; }
|
||||
catch (Exception e) when (e is PingException or SocketException or NetworkInformationException or InvalidOperationException) { return false; }
|
||||
catch (Exception e) when (e is PingException or SocketException or NetworkInformationException
|
||||
or InvalidOperationException or IOException or System.ComponentModel.Win32Exception) { return false; }
|
||||
}
|
||||
|
||||
internal static bool SameAuthorizedFallback(string current, string? fallback)
|
||||
@@ -140,7 +142,13 @@ internal static class TailnetTransport
|
||||
// default route. No adapter-name, service or route-prefix prerequisite.
|
||||
// This UDP Connect sends no payload. Refuse our own TUN to avoid recursion;
|
||||
// no /32 or user route is manufactured or removed.
|
||||
internal static string RequireExistingRoute(string address)
|
||||
internal static string RequireExistingRoute(string address) => ResolveRoute(address, false);
|
||||
|
||||
// Candidate discovery requires a specific existing route to the authorized
|
||||
// Tailnet address. A generic internet default must not carry probe packets.
|
||||
internal static void RequireProbeRoute(string address) => ResolveRoute(address, true);
|
||||
|
||||
private static string ResolveRoute(string address, bool requireSpecificRoute)
|
||||
{
|
||||
if (!IsTailnetAddress(address)) throw new InvalidOperationException("Tailscale 地址无效。");
|
||||
using var route = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
@@ -150,7 +158,12 @@ internal static class TailnetTransport
|
||||
.Where(n => n.OperationalStatus == OperationalStatus.Up && n.NetworkInterfaceType != NetworkInterfaceType.Loopback
|
||||
&& !n.Name.StartsWith(TunRouting.AdapterName, StringComparison.OrdinalIgnoreCase))
|
||||
.FirstOrDefault(n => n.GetIPProperties().UnicastAddresses.Any(a => a.Address.Equals(local)));
|
||||
return owner?.Name ?? throw new InvalidOperationException("代理内网 IP 路径暂不可用,保留域名入口作为回退。");
|
||||
if (owner is null)
|
||||
throw new InvalidOperationException("代理内网 IP 路径暂不可用,保留公网入口作为回退。");
|
||||
if (requireSpecificRoute && (owner.GetIPProperties().GetIPv4Properties()?.Index is not { } index
|
||||
|| SelectRoute(address, new WindowsRouteTable().Snapshot(), new HashSet<int> { index }) != index))
|
||||
throw new InvalidOperationException("未找到可验证的 Tailscale 节点探测路由。");
|
||||
return owner.Name;
|
||||
}
|
||||
|
||||
internal static int? SelectRoute(string address, IEnumerable<Ipv4Route> routes, IReadOnlySet<int> usable)
|
||||
@@ -191,6 +204,7 @@ internal sealed class TailnetPreference
|
||||
// continues respecting the existing monotonic cooldown.
|
||||
internal void ResetForUserConnect() { _cooldowns.Clear(); DomainOnly = false; }
|
||||
internal void CommitDomainFallback() => DomainOnly = true;
|
||||
internal void ReleaseDomainFallbackAfterNodeFailure() => DomainOnly = false;
|
||||
internal bool MayTry(string slug, long now) => !DomainOnly && (!_cooldowns.TryGetValue(slug, out var expiry) || now >= expiry);
|
||||
internal void Failed(string slug, long now) => _cooldowns[slug] = now + 5 * 60_000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user