Publish Zonghengjia Windows 0.3.13 client source
This commit is contained in:
@@ -6,7 +6,7 @@ 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 Observation(bool BusinessHealthy, bool TransportReachable, string? Diagnostic = null);
|
||||
internal readonly record struct Report(bool BusinessHealthy, bool TransportReachable);
|
||||
internal static bool Accepts(int target, int status) => target == 0
|
||||
? status is 200 or 204
|
||||
@@ -112,21 +112,43 @@ internal static class NodeHealthProbe
|
||||
UseProxy = true, Proxy = new WebProxy(proxyPort > 0 ? $"socks5://127.0.0.1:{proxyPort}" : "http://127.0.0.1:10809"),
|
||||
ConnectTimeout = TimeSpan.FromSeconds(8), AllowAutoRedirect = false,
|
||||
}) { Timeout = Timeout.InfiniteTimeSpan };
|
||||
var urls = new[] { "https://www.google.com/generate_204", "https://api.openai.com/v1/models",
|
||||
"https://chatgpt.com/backend-api/codex/models" };
|
||||
var probes = urls.Select(async (url, index) => {
|
||||
var targets = new[] {
|
||||
(Name: "google", Url: "https://www.google.com/generate_204"),
|
||||
(Name: "openai", Url: "https://api.openai.com/v1/models"),
|
||||
(Name: "codex", Url: "https://chatgpt.com/backend-api/codex/models"),
|
||||
};
|
||||
var probes = targets.Select(async (target, index) => {
|
||||
try {
|
||||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, timeout.Token);
|
||||
return new Observation(Accepts(index, (int)response.StatusCode), AcceptsTransportStatus((int)response.StatusCode));
|
||||
using var response = await client.GetAsync(target.Url, HttpCompletionOption.ResponseHeadersRead, timeout.Token);
|
||||
var status = (int)response.StatusCode;
|
||||
return new Observation(Accepts(index, status), AcceptsTransportStatus(status), $"http_{status}");
|
||||
}
|
||||
catch (OperationCanceledException) when (token.IsCancellationRequested) { throw; }
|
||||
catch { return default(Observation); }
|
||||
catch (OperationCanceledException) { return new Observation(false, false, "timeout"); }
|
||||
catch (HttpRequestException ex) { return new Observation(false, false, ex.HttpRequestError.ToString()); }
|
||||
catch { return new Observation(false, false, "request_failed"); }
|
||||
}).ToArray();
|
||||
// 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);
|
||||
try
|
||||
{
|
||||
var report = await AggregateReportAsync(probes, token, () => { }).ConfigureAwait(false);
|
||||
if (!report.BusinessHealthy)
|
||||
{
|
||||
var path = proxyPort > 0 ? "forced_proxy" : "ordinary";
|
||||
var outcomes = targets.Select((target, index) =>
|
||||
{
|
||||
var probe = probes[index];
|
||||
var result = probe.IsCompletedSuccessfully ? probe.Result.Diagnostic : "pending";
|
||||
return $"{target.Name}={result}";
|
||||
});
|
||||
AppPaths.WriteLog($"site_probe path={path} transport={report.TransportReachable} {string.Join(" ", outcomes)}");
|
||||
}
|
||||
return report;
|
||||
}
|
||||
finally { timeout.Cancel(); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user