Tun protect (#8779)

* Tun protect

* Remove EnableExInbound

* Fix

* Fix balancer tag

* Fix

---------

Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
This commit is contained in:
DHR60
2026-02-26 07:06:17 +00:00
committed by GitHub
parent 3a5293bf87
commit 3c1ecf085b
21 changed files with 234 additions and 110 deletions
+20 -21
View File
@@ -67,7 +67,14 @@ public class CoreManager
var fileName = Utils.GetBinConfigPath(Global.CoreConfigFileName);
var context = await CoreConfigHandler.BuildCoreConfigContext(_config, node);
context = context with { IsTunEnabled = _config.TunModeItem.EnableTun };
var preContext = ConfigHandler.GetPreSocksCoreConfigContext(context);
if (preContext is not null)
{
context = context with
{
TunProtectSsPort = preContext.TunProtectSsPort, ProxyRelaySsPort = preContext.ProxyRelaySsPort,
};
}
var result = await CoreConfigHandler.GenerateClientConfig(context, fileName);
if (result.Success != true)
{
@@ -88,7 +95,7 @@ public class CoreManager
}
await CoreStart(context);
await CoreStartPreService(context);
await CoreStartPreService(preContext);
if (_processService != null)
{
await UpdateFunc(true, $"{node.GetSummary()}");
@@ -183,30 +190,22 @@ public class CoreManager
_processService = proc;
}
private async Task CoreStartPreService(CoreConfigContext context)
private async Task CoreStartPreService(CoreConfigContext? preContext)
{
var node = context.Node;
if (_processService != null && !_processService.HasExited)
if (_processService is { HasExited: false } && preContext != null)
{
var coreType = AppManager.Instance.GetCoreType(node, node.ConfigType);
var itemSocks = ConfigHandler.GetPreSocksItem(_config, node, coreType);
if (itemSocks != null)
var preCoreType = preContext?.Node?.CoreType ?? ECoreType.sing_box;
var fileName = Utils.GetBinConfigPath(Global.CorePreConfigFileName);
var result = await CoreConfigHandler.GenerateClientConfig(preContext, fileName);
if (result.Success)
{
var preCoreType = itemSocks.CoreType ?? ECoreType.sing_box;
var fileName = Utils.GetBinConfigPath(Global.CorePreConfigFileName);
var itemSocksContext = await CoreConfigHandler.BuildCoreConfigContext(_config, itemSocks);
itemSocksContext.ProtectDomainList.AddRangeSafe(context.ProtectDomainList);
var result = await CoreConfigHandler.GenerateClientConfig(itemSocksContext, fileName);
if (result.Success)
var coreInfo = CoreInfoManager.Instance.GetCoreInfo(preCoreType);
var proc = await RunProcess(coreInfo, Global.CorePreConfigFileName, true, true);
if (proc is null)
{
var coreInfo = CoreInfoManager.Instance.GetCoreInfo(preCoreType);
var proc = await RunProcess(coreInfo, Global.CorePreConfigFileName, true, true);
if (proc is null)
{
return;
}
_processPreService = proc;
return;
}
_processPreService = proc;
}
}
}