Publish Zonghengjia Windows 0.3.13 client source

This commit is contained in:
2026-11-13 10:35:04 +08:00
parent 1590443809
commit 839434a313
55 changed files with 2324 additions and 963 deletions
+30 -33
View File
@@ -2,47 +2,44 @@ using System.Runtime.CompilerServices;
namespace UCVL.VPNPlus;
internal sealed record PlannedTransport(ConnectionAttempt Attempt, ConfigResponse? Cached = null,
bool TailnetOnly = false, bool Dispatched = false, bool DispatchPass = false)
{
// Preserve a known dispatched node even if confirmation fails before it
// returns a new config; that is one candidate failure, not an empty AI pool.
internal NodeInfo? KnownCandidate => Attempt.Auxiliary ?? Cached?.Node;
}
internal static class TransportPlan
{
internal static IReadOnlyList<PlannedTransport> Create(ConnectionSelection selection,
IReadOnlyList<PrivateAuxiliaryNode> rankedPrivate, string routeMode, int publicNodeCount)
{
var legacy = ConnectionAttemptPlanner.CreateRanked(selection, rankedPrivate, publicNodeCount);
if (selection.Manual || routeMode == "direct")
return legacy.Select(a => new PlannedTransport(a)).ToArray();
// This marker does no API work. Its public pass is expanded only when
// iteration reaches it after the private inner attempts have failed.
return rankedPrivate.Where(n => n.ProbeIpv4 != PrivateAuxiliaryRouting.PublicPhoneAddress)
.Select(n => new PlannedTransport(new(n.Slug, n)))
.Concat([new PlannedTransport(new("auto", null), TailnetOnly: true, DispatchPass: true)])
.Concat(rankedPrivate.Where(n => n.ProbeIpv4 == PrivateAuxiliaryRouting.PublicPhoneAddress)
.Select(n => new PlannedTransport(new(n.Slug, n))))
.Concat(legacy.Where(a => !a.IsPrivate).Select(a => new PlannedTransport(a))).ToArray();
}
internal static async IAsyncEnumerable<PlannedTransport> ExpandAsync(IEnumerable<PlannedTransport> plans,
Func<CancellationToken, Task<IReadOnlyList<PlannedTransport>>> dispatch,
internal static async IAsyncEnumerable<ConnectionAttempt> AttemptsAsync(ConnectionSelection selection,
string routeMode, int publicNodeCount, string? retryPublicSlug,
Func<CancellationToken, Task<IReadOnlyList<PrivateAuxiliaryNode>>> rankPrivate,
[EnumeratorCancellation] CancellationToken token)
{
foreach (var plan in plans)
token.ThrowIfCancellationRequested();
if (selection.Manual)
{
token.ThrowIfCancellationRequested();
if (!plan.DispatchPass) { yield return plan; continue; }
var dispatched = await dispatch(token).WaitAsync(token).ConfigureAwait(false);
token.ThrowIfCancellationRequested();
foreach (var candidate in dispatched)
var ranked = routeMode == "direct" ? [] : await rankPrivate(token).WaitAsync(token).ConfigureAwait(false);
foreach (var attempt in ConnectionAttemptPlanner.CreateRanked(selection, ranked, publicNodeCount))
{
token.ThrowIfCancellationRequested();
yield return candidate;
yield return attempt;
}
yield break;
}
var publicAttempts = selection.Attempts(publicNodeCount);
// Returning the first attempt does no discovery. The caller requests
// and tries its one authorized config before it can advance here.
if (publicAttempts > 0) yield return new(retryPublicSlug ?? "auto", null);
token.ThrowIfCancellationRequested();
if (routeMode != "direct")
{
var ranked = await rankPrivate(token).WaitAsync(token).ConfigureAwait(false);
foreach (var auxiliary in ranked)
{
token.ThrowIfCancellationRequested();
yield return new(auxiliary.Slug, auxiliary);
}
}
for (var attempt = 1; attempt < publicAttempts; attempt++)
{
token.ThrowIfCancellationRequested();
yield return new("auto", null);
}
}
}