Windows 0.3.0 clean next-generation source delta; no private history or other platform changes
This commit is contained in:
+30
-4
@@ -26,8 +26,23 @@ internal sealed class XrayManager : IDisposable, IAsyncDisposable, IHandoverRunt
|
||||
private readonly string _xrayDirectory = Path.Combine(AppContext.BaseDirectory, "xray");
|
||||
private string? _baseConfigJson;
|
||||
private string? _tailnetFallbackConfigJson;
|
||||
// Retain only the authenticated in-memory alternative. A physical-network
|
||||
// recovery already has to restart the core, so it can recheck the overlay
|
||||
// instead of permanently retaining an earlier public fallback.
|
||||
private string? _preferredTailnetConfigJson;
|
||||
private string? _tailnetInterfaceName;
|
||||
internal bool UsesTailnet => _baseConfigJson is not null && TailnetTransport.Address(_baseConfigJson) is not null;
|
||||
internal (string Address, int Port)? PreferredTailnetEndpoint
|
||||
{
|
||||
get
|
||||
{
|
||||
var current = _baseConfigJson;
|
||||
var preferred = _preferredTailnetConfigJson;
|
||||
if (!IsRunning || current is null || preferred is null
|
||||
|| !TailnetTransport.SameAuthorizedFallback(preferred, current)) return null;
|
||||
return (TailnetTransport.Address(preferred)!, TailnetTransport.Port(preferred));
|
||||
}
|
||||
}
|
||||
private string _routeMode = "smart";
|
||||
private string _nodeSlug = "";
|
||||
private string XrayPath => Path.Combine(_xrayDirectory, "xray.exe");
|
||||
@@ -57,8 +72,11 @@ internal sealed class XrayManager : IDisposable, IAsyncDisposable, IHandoverRunt
|
||||
token.ThrowIfCancellationRequested();
|
||||
_baseConfigJson = await NodeTransportConnector.RebindAsync(_baseConfigJson!, _tailnetFallbackConfigJson,
|
||||
async (config, rebindToken) => { _baseConfigJson = config; await StartCoreAsync(rebindToken); },
|
||||
StopCoreAsync, CheckProxyHealthAsync, token);
|
||||
if (!UsesTailnet) _tailnetFallbackConfigJson = null;
|
||||
StopCoreAsync, CheckProxyHealthAsync, token,
|
||||
preferredTailnetConfig: _preferredTailnetConfigJson,
|
||||
requireRoute: address => { TailnetTransport.RequireExistingRoute(address); },
|
||||
endpointProbe: TailnetTransport.ProbeEndpointAsync,
|
||||
diagnostic: entry => AppPaths.WriteLog((entry with { Node = _nodeSlug }).SafeMessage));
|
||||
}
|
||||
catch { await StopCoreAsync(); throw; }
|
||||
finally { _lifecycle.Release(); }
|
||||
@@ -166,18 +184,25 @@ internal sealed class XrayManager : IDisposable, IAsyncDisposable, IHandoverRunt
|
||||
}
|
||||
|
||||
internal async Task StartAsync(string configJson, string routeMode, string nodeSlug, CancellationToken cancellationToken,
|
||||
string? tailnetFallbackConfigJson = null)
|
||||
string? tailnetFallbackConfigJson = null, string? preferredTailnetConfigJson = null)
|
||||
{
|
||||
if (TailnetTransport.Address(configJson) is not null
|
||||
&& !TailnetTransport.SameAuthorizedFallback(configJson, tailnetFallbackConfigJson))
|
||||
throw new InvalidOperationException("Tailscale 原入口与已授权线路不匹配。");
|
||||
var preferred = preferredTailnetConfigJson
|
||||
?? (TailnetTransport.Address(configJson) is not null ? configJson : null);
|
||||
var original = tailnetFallbackConfigJson
|
||||
?? (TailnetTransport.Address(configJson) is null ? configJson : null);
|
||||
if (preferred is not null && !TailnetTransport.SameAuthorizedFallback(preferred, original))
|
||||
throw new InvalidOperationException("Tailscale 恢复入口与已授权线路不匹配。");
|
||||
await InitializeAsync(cancellationToken);
|
||||
await _lifecycle.WaitAsync(cancellationToken);
|
||||
try
|
||||
{
|
||||
await StopCoreAsync();
|
||||
_baseConfigJson = configJson;
|
||||
_tailnetFallbackConfigJson = tailnetFallbackConfigJson;
|
||||
_tailnetFallbackConfigJson = preferred is not null ? original : tailnetFallbackConfigJson;
|
||||
_preferredTailnetConfigJson = preferred;
|
||||
_routeMode = routeMode;
|
||||
_nodeSlug = nodeSlug;
|
||||
await StartCoreAsync(cancellationToken);
|
||||
@@ -212,6 +237,7 @@ internal sealed class XrayManager : IDisposable, IAsyncDisposable, IHandoverRunt
|
||||
await StopCoreAsync().ConfigureAwait(false);
|
||||
_baseConfigJson = null;
|
||||
_tailnetFallbackConfigJson = null;
|
||||
_preferredTailnetConfigJson = null;
|
||||
_tailnetInterfaceName = null;
|
||||
_nodeSlug = "";
|
||||
_boundNetwork = null;
|
||||
|
||||
Reference in New Issue
Block a user