using System.Runtime.CompilerServices; namespace UCVL.VPNPlus; internal static class TransportPlan { internal static async IAsyncEnumerable AttemptsAsync(ConnectionSelection selection, string routeMode, int publicNodeCount, string? retryPublicSlug, Func>> rankPrivate, [EnumeratorCancellation] CancellationToken token) { token.ThrowIfCancellationRequested(); if (selection.Manual) { var ranked = routeMode == "direct" ? [] : await rankPrivate(token).WaitAsync(token).ConfigureAwait(false); foreach (var attempt in ConnectionAttemptPlanner.CreateRanked(selection, ranked, publicNodeCount)) { token.ThrowIfCancellationRequested(); 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); } } }