35 lines
2.2 KiB
C#
35 lines
2.2 KiB
C#
|
|
namespace UCVL.VPNPlus;
|
||
|
|
|
||
|
|
internal sealed partial class MainForm
|
||
|
|
{
|
||
|
|
private sealed record PlannedTransport(ConnectionAttempt Attempt, ConfigResponse? Cached = null,
|
||
|
|
bool TailnetOnly = false);
|
||
|
|
|
||
|
|
private async Task<IReadOnlyList<PlannedTransport>> PlanTransportsAsync(ConnectionSelection selection,
|
||
|
|
IReadOnlyList<PrivateAuxiliaryNode> rankedPrivate, string routeMode, CancellationToken token)
|
||
|
|
{
|
||
|
|
var legacy = ConnectionAttemptPlanner.CreateRanked(selection, rankedPrivate, _publicNodeCount);
|
||
|
|
if (selection.Manual || routeMode == "direct")
|
||
|
|
return legacy.Select(a => new PlannedTransport(a)).ToArray();
|
||
|
|
|
||
|
|
_statusDetail.Text = "先并行检测授权内网入口,按响应时间选择;全部不可用后再使用公网。";
|
||
|
|
var publicTailnet = await PublicTailnetSelection.RankAsync(
|
||
|
|
_manualNodeCombo.Items.Cast<NodeInfo>().Where(n => n is not PrivateAuxiliaryNode), routeMode,
|
||
|
|
slug => _failedNodes.ContainsKey(slug) || !_tailnetPreference.MayTry(slug, Environment.TickCount64),
|
||
|
|
(slug, probeToken) => _api.GetConfigAsync(_accessToken!, slug, routeMode, probeToken),
|
||
|
|
TailnetTransport.ProbeEndpointAsync, token, allowKnownEndpoints: _knownTailnetAllowed,
|
||
|
|
diagnostic: (slug, reason) => AppPaths.WriteLog(new TransportDiagnostic("selection_probe", reason, slug).SafeMessage));
|
||
|
|
|
||
|
|
// All reachable authenticated-grant overlay candidates precede domain
|
||
|
|
// fallback. Failure of the fastest candidate does not consume the other
|
||
|
|
// candidates or incorrectly mark its still-usable public ingress down.
|
||
|
|
return rankedPrivate.Where(n => n.ProbeIpv4 != PrivateAuxiliaryRouting.PublicPhoneAddress)
|
||
|
|
.Select(n => new PlannedTransport(new(n.Slug, n)))
|
||
|
|
.Concat(publicTailnet.Select(c => new PlannedTransport(new(c.Response.Node.Slug, null), c.Response, 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();
|
||
|
|
}
|
||
|
|
}
|