Fixes (Prioritize Node.CoreType over SplitCore configuration)

This commit is contained in:
DHR60 2025-07-24 21:26:52 +08:00
parent ac4692c7d0
commit e156aaae34
2 changed files with 66 additions and 57 deletions

View file

@ -1,3 +1,7 @@
using DynamicData;
using ServiceLib.Enums;
using ServiceLib.Models;
namespace ServiceLib.Handler;
public sealed class AppHandler
@ -246,5 +250,64 @@ public sealed class AppHandler
return item?.CoreType ?? ECoreType.Xray;
}
public (bool, ECoreType, ECoreType?) GetCoreAndPreType(ProfileItem profileItem)
{
var splitCore = _config.SplitCoreItem.EnableSplitCore;
var coreType = GetCoreType(profileItem, profileItem.ConfigType);
ECoreType? preCoreType = null;
var pureEndpointCore = GetSplitCoreType(profileItem, profileItem.ConfigType);
var splitRouteCore = _config.SplitCoreItem.RouteCoreType;
var enableTun = _config.TunModeItem.EnableTun;
if (profileItem.ConfigType == EConfigType.Custom)
{
splitCore = false;
coreType = profileItem.CoreType ?? ECoreType.Xray;
if (profileItem.PreSocksPort > 0)
{
preCoreType = enableTun ? ECoreType.sing_box : GetCoreType(profileItem, profileItem.ConfigType);
}
else
{
preCoreType = null;
}
}
else if (!splitCore && profileItem.CoreType is not (ECoreType.Xray or ECoreType.sing_box))
{
// Force SplitCore for cores that don't support direct routing (like Hysteria2, TUIC, etc.)
splitCore = true;
preCoreType = enableTun ? ECoreType.sing_box : splitRouteCore;
}
else if (splitCore)
{
// User explicitly enabled SplitCore
preCoreType = enableTun ? ECoreType.sing_box : splitRouteCore;
coreType = pureEndpointCore;
if (preCoreType == coreType)
{
preCoreType = null;
splitCore = false;
}
}
else if (enableTun) // EnableTun is true but SplitCore is false
{
// TUN mode handling for Xray/sing_box cores
preCoreType = ECoreType.sing_box;
if (preCoreType == coreType) // CoreType is sing_box
{
preCoreType = null;
}
else // CoreType is xray, etc.
{
// Force SplitCore for non-split cores
splitCore = true;
}
}
return (splitCore, coreType, preCoreType);
}
#endregion Core Type
}

View file

@ -76,7 +76,6 @@ public class CoreHandler
// Create launch context and configure parameters
var context = new CoreLaunchContext(node, _config);
context.AdjustForConfigType();
context.AdjustForSplitCore();
// Start main core
if (!await CoreStart(context))
@ -210,74 +209,21 @@ public class CoreHandler
/// </summary>
public void AdjustForConfigType()
{
(SplitCore, CoreType, PreCoreType) = AppHandler.Instance.GetCoreAndPreType(Node);
if (Node.ConfigType == EConfigType.Custom)
{
SplitCore = false;
CoreType = Node.CoreType ?? ECoreType.Xray;
if (Node.PreSocksPort > 0)
{
PreCoreType = EnableTun ? ECoreType.sing_box : AppHandler.Instance.GetCoreType(Node, Node.ConfigType);
PreSocksPort = Node.PreSocksPort.Value;
}
else
{
EnableTun = false;
PreCoreType = null;
}
}
else if (!SplitCore && !EnableTun)
else if (PreCoreType != null)
{
switch (Node.CoreType)
{
case ECoreType.hysteria2:
case ECoreType.tuic:
Node.CoreType = ECoreType.sing_box;
CoreType = ECoreType.sing_box;
break;
case ECoreType.v2fly:
case ECoreType.v2fly_v5:
Node.CoreType = ECoreType.Xray;
CoreType = ECoreType.Xray;
break;
default:
break;
}
}
}
/// <summary>
/// Adjust split core configuration
/// </summary>
public void AdjustForSplitCore()
{
if (SplitCore)
{
PreCoreType = EnableTun ? ECoreType.sing_box : SplitRouteCore;
CoreType = PureEndpointCore;
if (PreCoreType == CoreType)
{
PreCoreType = null;
SplitCore = false;
}
else
{
PreSocksPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.split);
}
}
else if (EnableTun)
{
PreCoreType = ECoreType.sing_box;
if (PreCoreType == CoreType) // CoreType is sing_box
{
PreCoreType = null;
}
else // CoreType is xray, hysteria2, tuic, etc.
{
SplitCore = true;
PreSocksPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.split);
}
PreSocksPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.split);
}
}
}