Windows 0.3.4 connection resilience and fixed-grid source delta; no private history or other platform changes
This commit is contained in:
+34
-5
@@ -15,6 +15,7 @@ internal sealed partial class MainForm : Form
|
||||
private readonly System.Windows.Forms.Timer _trafficTimer = new() { Interval = 5_000 };
|
||||
private readonly System.Windows.Forms.Timer _healthTimer = new() { Interval = 5_000 };
|
||||
private readonly ConnectionHealthPolicy _connectionHealth = new();
|
||||
private readonly ConnectionAuthorizationLease _connectionAuthorization = new();
|
||||
private readonly Label _currentNodeLabel = new();
|
||||
private readonly TrafficChart _trafficChart = new();
|
||||
private readonly DailyTrafficChart _dailyChart = new();
|
||||
@@ -439,7 +440,7 @@ internal sealed partial class MainForm : Form
|
||||
try
|
||||
{
|
||||
var response = await _api.LoginAsync(login, password, _lifetime.Token);
|
||||
SetSessionToken(response.AccessToken);
|
||||
SetSessionToken(response.AccessToken, response.ExpiresAt);
|
||||
TokenStore.Save(_accessToken);
|
||||
_passwordText.Clear();
|
||||
ShowDashboard(response.Profile);
|
||||
@@ -515,6 +516,13 @@ internal sealed partial class MainForm : Form
|
||||
var replacementStarted = false;
|
||||
try
|
||||
{
|
||||
if (!_connectionAuthorization.AccountIsValid(DateTimeOffset.UtcNow, Environment.TickCount64))
|
||||
{
|
||||
var refreshed = await _api.GetProfileAsync(_accessToken, connectionToken);
|
||||
UpdateProfile(refreshed, preserveSelections: true);
|
||||
if (!_connectionAuthorization.AccountIsValid(DateTimeOffset.UtcNow, Environment.TickCount64))
|
||||
throw new ApiException(403, "账号或订阅授权已到期,请重新登录验证。");
|
||||
}
|
||||
var failures = new List<string>();
|
||||
ConfigResponse? response = null;
|
||||
var privateGrants = _privateAuxiliaryNodes.Where(n => n.ExpiresAt > DateTimeOffset.UtcNow).ToArray();
|
||||
@@ -597,7 +605,7 @@ internal sealed partial class MainForm : Form
|
||||
}
|
||||
catch (ApiException exception) when (exception.StatusCode is not (401 or 403))
|
||||
{
|
||||
if (ConnectionRecoveryPolicy.KeepExisting(reconnect, replacementStarted, _xray.IsRunning, exception)) throw;
|
||||
if (ConnectionRecoveryPolicy.KeepExisting(reconnect, replacementStarted, _xray.IsRunning, exception, CanRetainAuthorizedCore())) throw;
|
||||
failures.Add($"{candidate?.Name ?? "AI 调度"}: {exception.Message}");
|
||||
await _xray.StopAsync();
|
||||
if (candidate is null) break;
|
||||
@@ -606,7 +614,7 @@ internal sealed partial class MainForm : Form
|
||||
}
|
||||
catch (Exception exception) when (exception is not OperationCanceledException && exception is not ApiException { StatusCode: 401 or 403 })
|
||||
{
|
||||
if (ConnectionRecoveryPolicy.KeepExisting(reconnect, replacementStarted, _xray.IsRunning, exception)) throw;
|
||||
if (ConnectionRecoveryPolicy.KeepExisting(reconnect, replacementStarted, _xray.IsRunning, exception, CanRetainAuthorizedCore())) throw;
|
||||
failures.Add($"{candidate?.Name ?? "AI 调度"}: {exception.Message}");
|
||||
await _xray.StopAsync();
|
||||
if (candidate is not null) _failedNodes[candidate.Slug] = DateTimeOffset.UtcNow.AddMinutes(5);
|
||||
@@ -642,7 +650,7 @@ internal sealed partial class MainForm : Form
|
||||
{
|
||||
if (!_exiting) await DisconnectAsync();
|
||||
}
|
||||
catch (Exception exception) when (ConnectionRecoveryPolicy.KeepExisting(reconnect, replacementStarted, _xray.IsRunning, exception))
|
||||
catch (Exception exception) when (ConnectionRecoveryPolicy.KeepExisting(reconnect, replacementStarted, _xray.IsRunning, exception, CanRetainAuthorizedCore()))
|
||||
{
|
||||
AppPaths.WriteLog("调度请求失败,尚未启动替换线路,保留原内核与路由;两分钟后重试。" + exception.GetType().Name);
|
||||
_wantConnected = true;
|
||||
@@ -761,6 +769,13 @@ internal sealed partial class MainForm : Form
|
||||
|
||||
private async Task MaintainConnectionAsync()
|
||||
{
|
||||
if (_wantConnected && !_connectionAuthorization.AccountIsValid(DateTimeOffset.UtcNow, Environment.TickCount64)
|
||||
&& !_busy && !_healthChecking && !_handoverOperating && !_exiting)
|
||||
{
|
||||
await DisconnectAsync();
|
||||
_statusDetail.Text = "已知账号或订阅授权已到期,请联网重新验证。";
|
||||
return;
|
||||
}
|
||||
if (_currentNodeIsPrivateAuxiliary && _privateLeaseDeadlineTicks > 0
|
||||
&& Environment.TickCount64 >= _privateLeaseDeadlineTicks && !_busy && !_healthChecking && !_handoverOperating && !_exiting)
|
||||
{
|
||||
@@ -788,7 +803,8 @@ internal sealed partial class MainForm : Form
|
||||
var health = await _xray.CheckHealthWithRepairAsync(_lifetime.Token);
|
||||
var healthy = health.Healthy;
|
||||
var decision = _connectionHealth.Observe(revision, testedCore, _xray.CoreId,
|
||||
_wantConnected, _busy, _xray.IsTransitioning, _exiting, healthy, Environment.TickCount64, health.ProxyHealthy);
|
||||
_wantConnected, _busy, _xray.IsTransitioning, _exiting, healthy, Environment.TickCount64, health.ProxyHealthy,
|
||||
_xray.UsesTailnet, health.BusinessUnavailable);
|
||||
if (decision == ConnectionHealthPolicy.Decision.Ignore) return;
|
||||
if (healthy && _xray.IsRunning) {
|
||||
if (_localRoutingFault) {
|
||||
@@ -800,6 +816,15 @@ internal sealed partial class MainForm : Form
|
||||
ConnectionAcceptanceTrace.Record("health_ok", _currentNodeSlug, true, _xray.CoreId);
|
||||
return;
|
||||
}
|
||||
if (decision == ConnectionHealthPolicy.Decision.Degraded) {
|
||||
_localRoutingFault = true;
|
||||
SetConnectionState(true, "网站探测异常,连接保留", $"{_currentNodeName ?? _currentNodeSlug} · 目标网站可用性尚未确认,保留当前线路");
|
||||
_statusTitle.ForeColor = Color.FromArgb(155, 88, 12);
|
||||
_statusDot.ForeColor = _statusTitle.ForeColor;
|
||||
_notifyIcon.Text = "纵横家 · 网站探测异常";
|
||||
AppPaths.WriteLog("健康诊断:网站探测异常,保留当前内核和已授权线路;未将网站状态判为节点传输失败。");
|
||||
return;
|
||||
}
|
||||
if (decision == ConnectionHealthPolicy.Decision.Repair) {
|
||||
_localRoutingFault = true;
|
||||
SetConnectionState(true, "分流异常,正在修复", $"{_currentNodeName ?? _currentNodeSlug} · 代理出口可达,保留现有连接并重试规则验证");
|
||||
@@ -949,7 +974,9 @@ internal sealed partial class MainForm : Form
|
||||
var accepted = await _xray.RenewPrivateAuthorizationAsync(renewed.GetRuntimeConfigJson(), privateCore, _lifetime.Token);
|
||||
if (!IsCurrent() || _xray.CoreId != privateCore) return;
|
||||
if (accepted)
|
||||
{
|
||||
_privateLeaseDeadlineTicks = Environment.TickCount64 + Math.Max(0, (long)(renewed.ConfigExpiresAt!.Value - DateTimeOffset.UtcNow).TotalMilliseconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
await DisconnectAsync();
|
||||
@@ -1058,6 +1085,8 @@ internal sealed partial class MainForm : Form
|
||||
private void UpdateProfile(Profile profile, bool preserveSelections)
|
||||
{
|
||||
if (_exiting || IsDisposed || Disposing) return;
|
||||
_connectionAuthorization.AcceptProfile(profile.Subscription.Status, profile.Subscription.ExpiresAt,
|
||||
DateTimeOffset.UtcNow, Environment.TickCount64);
|
||||
_knownTailnetAllowed = true;
|
||||
SetNodeTrafficPermission(profile.CanViewNodeTraffic);
|
||||
var selectedRoute = preserveSelections ? (_routeCombo.SelectedItem as RouteModeInfo)?.Id : null;
|
||||
|
||||
Reference in New Issue
Block a user