Windows 0.3.4 connection resilience and fixed-grid source delta; no private history or other platform changes

This commit is contained in:
2026-11-05 03:41:46 +00:00
parent aff1a50d35
commit 991b029b37
25 changed files with 629 additions and 96 deletions
+61 -6
View File
@@ -6,6 +6,8 @@ namespace UCVL.VPNPlus;
// It is NOT part of 0.2.5's connection transaction and never changes routes.
internal static class NodeHealthProbe
{
internal readonly record struct Observation(bool BusinessHealthy, bool TransportReachable);
internal readonly record struct Report(bool BusinessHealthy, bool TransportReachable);
internal static bool Accepts(int target, int status) => target == 0
? status is 200 or 204
: status is >= 200 and < 500;
@@ -13,6 +15,51 @@ internal static class NodeHealthProbe
internal static bool OverallHealthy(IReadOnlyList<bool> results) =>
results.Count >= 3 && results[2] && (results[0] || results[1]);
internal static bool AcceptsTransportStatus(int status) => status is >= 100 and <= 599;
private static async Task<Observation> Observed(Task<Observation> probe)
{
try { return await probe.ConfigureAwait(false); }
catch { return default; }
}
internal static async Task<bool> AggregateTransportAsync(IReadOnlyList<Task<Observation>> probes,
CancellationToken token, Action cancelRemaining)
{
var pending = probes.Select(Observed).ToList();
try
{
token.ThrowIfCancellationRequested();
while (pending.Count > 0)
{
var finished = await Task.WhenAny(pending).WaitAsync(token).ConfigureAwait(false);
pending.Remove(finished);
var observation = await finished.ConfigureAwait(false);
token.ThrowIfCancellationRequested();
if (observation.TransportReachable) return true;
}
return false;
}
finally { cancelRemaining(); }
}
internal static async Task<Report> AggregateReportAsync(IReadOnlyList<Task<Observation>> probes,
CancellationToken token, Action cancelRemaining)
{
var observations = probes.Select(Observed).ToArray();
async Task<bool> BusinessAsync(Task<Observation> probe) => (await probe.ConfigureAwait(false)).BusinessHealthy;
try
{
token.ThrowIfCancellationRequested();
var business = AggregateAsync(observations.Select(BusinessAsync).ToArray(), token, () => { });
var transport = AggregateTransportAsync(observations, token, () => { });
await Task.WhenAll(business, transport).ConfigureAwait(false);
token.ThrowIfCancellationRequested();
return new(await business.ConfigureAwait(false), await transport.ConfigureAwait(false));
}
finally { cancelRemaining(); }
}
internal static async Task<bool> AggregateAsync(IReadOnlyList<Task<bool>> probes,
CancellationToken token, Action cancelRemaining)
{
@@ -52,6 +99,12 @@ internal static class NodeHealthProbe
}
internal static async Task<bool> CheckAsync(CancellationToken token, int proxyPort = 0)
=> (await CheckReportAsync(token, proxyPort).ConfigureAwait(false)).BusinessHealthy;
internal static async Task<bool> CheckTransportAsync(CancellationToken token, int proxyPort)
=> (await CheckReportAsync(token, proxyPort, transportOnly: true).ConfigureAwait(false)).TransportReachable;
internal static async Task<Report> CheckReportAsync(CancellationToken token, int proxyPort = 0, bool transportOnly = false)
{
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(token);
timeout.CancelAfter(TimeSpan.FromSeconds(15));
@@ -64,14 +117,16 @@ internal static class NodeHealthProbe
var probes = urls.Select(async (url, index) => {
try {
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, timeout.Token);
return Accepts(index, (int)response.StatusCode);
return new Observation(Accepts(index, (int)response.StatusCode), AcceptsTransportStatus((int)response.StatusCode));
}
catch (OperationCanceledException) when (token.IsCancellationRequested) { throw; }
catch { return false; }
catch { return default(Observation); }
}).ToArray();
// This client exists primarily for ChatGPT/Codex. Google or the OpenAI
// REST API remaining reachable must not mask a broken Codex transport.
// Require the Codex endpoint plus one independent Internet target.
return await AggregateAsync(probes, token, timeout.Cancel);
// Retain the stricter business-site diagnostic separately. A valid
// TLS/HTTP response through the forced proxy, including 5xx, proves
// transport reachability without claiming the target service is healthy.
if (transportOnly)
return new(false, await AggregateTransportAsync(probes, token, timeout.Cancel).ConfigureAwait(false));
return await AggregateReportAsync(probes, token, timeout.Cancel);
}
}