Windows 0.3.3 dashboard layout and speed presentation source delta; no private history or other platform changes
This commit is contained in:
@@ -12,6 +12,72 @@ internal static class PublicTailnetSelection
|
||||
internal sealed record Candidate(ConfigResponse Response, long LatencyMilliseconds);
|
||||
private static readonly Regex ValidSlug = new("^[a-z0-9][a-z0-9-]{0,79}$", RegexOptions.CultureInvariant);
|
||||
|
||||
// Use the existing authenticated backend dispatcher for new client-session
|
||||
// allocations. Its real throughput/reservation score is not a bandwidth
|
||||
// capacity measurement and does not split an individual TCP stream.
|
||||
internal static async Task<IReadOnlyList<Candidate>> RankDispatchedAsync(
|
||||
IEnumerable<NodeInfo> authorizedNodes, string routeMode, Func<string, bool> coolingDown,
|
||||
Func<IReadOnlyCollection<string>, CancellationToken, Task<ConfigResponse>> dispatch,
|
||||
Func<string, int, CancellationToken, Task<bool>> endpointProbe,
|
||||
CancellationToken token, bool allowKnownEndpoints = false,
|
||||
Action<string, string>? diagnostic = null, TimeSpan? budget = null)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
if (routeMode is not ("smart" or "global")) return [];
|
||||
var nodes = authorizedNodes.Where(n => n is not null && n is not PrivateAuxiliaryNode
|
||||
&& n.Slug is not null && n.Slug != "auto" && ValidSlug.IsMatch(n.Slug))
|
||||
.DistinctBy(n => n.Slug, StringComparer.Ordinal).Take(32).ToArray();
|
||||
var excluded = nodes.Where(n => coolingDown(n.Slug)).Select(n => n.Slug).ToHashSet(StringComparer.Ordinal);
|
||||
var remaining = nodes.Where(n => !excluded.Contains(n.Slug)).ToDictionary(n => n.Slug, StringComparer.Ordinal);
|
||||
if (remaining.Count == 0) return [];
|
||||
using var deadline = CancellationTokenSource.CreateLinkedTokenSource(token);
|
||||
deadline.CancelAfter(TimeSpan.FromMilliseconds(Math.Clamp((budget ?? TimeSpan.FromSeconds(15)).TotalMilliseconds, 1, 15_000)));
|
||||
var candidates = new List<Candidate>();
|
||||
for (var attempt = 0; attempt < 8 && remaining.Count > 0; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await dispatch(excluded.ToArray(), deadline.Token).WaitAsync(deadline.Token).ConfigureAwait(false);
|
||||
deadline.Token.ThrowIfCancellationRequested();
|
||||
var slug = response?.Node?.Slug;
|
||||
// The backend's auto result must still be in this authenticated
|
||||
// public profile. Never promote private, removed, or repeated nodes.
|
||||
if (slug is null || !remaining.Remove(slug, out var node)) break;
|
||||
excluded.Add(slug);
|
||||
var reachable = await RankAsync([node], routeMode, _ => false,
|
||||
(_, _) => Task.FromResult(response!), endpointProbe, deadline.Token,
|
||||
allowKnownEndpoints, diagnostic).ConfigureAwait(false);
|
||||
candidates.AddRange(reachable);
|
||||
}
|
||||
catch (ApiException error) when (error.StatusCode is 401 or 403) { throw; }
|
||||
catch (OperationCanceledException) when (!token.IsCancellationRequested) { break; }
|
||||
catch (OperationCanceledException) { throw; }
|
||||
catch (Exception) { break; } // Existing domain passes remain available.
|
||||
}
|
||||
token.ThrowIfCancellationRequested();
|
||||
return candidates;
|
||||
}
|
||||
|
||||
internal static async Task<ConfigResponse> ConfirmDispatchAsync(Candidate candidate,
|
||||
IEnumerable<NodeInfo> authorizedNodes, string routeMode,
|
||||
Func<IReadOnlyCollection<string>, CancellationToken, Task<ConfigResponse>> dispatch,
|
||||
CancellationToken token)
|
||||
{
|
||||
var slugs = authorizedNodes.Where(n => n is not null && n is not PrivateAuxiliaryNode
|
||||
&& n.Slug is not null && n.Slug != "auto" && ValidSlug.IsMatch(n.Slug))
|
||||
.Select(n => n.Slug).Distinct(StringComparer.Ordinal).ToArray();
|
||||
var expected = candidate.Response.Node.Slug;
|
||||
if (!slugs.Contains(expected, StringComparer.Ordinal) || slugs.Length > 32)
|
||||
throw new InvalidOperationException("自动调度候选已不属于当前授权节点范围。请刷新账号信息。");
|
||||
// Planning may have inspected other nodes. Before starting this proxy,
|
||||
// restore the shared backend reservation to the node actually attempted.
|
||||
var response = await dispatch(slugs.Where(slug => slug != expected).ToArray(), token).ConfigureAwait(false);
|
||||
if (response.Node.Slug != expected || response.RouteMode != routeMode
|
||||
|| response.ConnectionScope == PrivateAuxiliaryRouting.Scope)
|
||||
throw new InvalidOperationException("后台调度确认与当前候选不一致,已拒绝连接。");
|
||||
return response;
|
||||
}
|
||||
|
||||
internal static async Task<IReadOnlyList<Candidate>> RankAsync(
|
||||
IEnumerable<NodeInfo> authorizedNodes, string routeMode,
|
||||
Func<string, bool> coolingDown,
|
||||
|
||||
Reference in New Issue
Block a user