mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Fixes (Prioritize Node.CoreType over SplitCore configuration)
This commit is contained in:
parent
ac4692c7d0
commit
e156aaae34
2 changed files with 66 additions and 57 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
using DynamicData;
|
||||||
|
using ServiceLib.Enums;
|
||||||
|
using ServiceLib.Models;
|
||||||
|
|
||||||
namespace ServiceLib.Handler;
|
namespace ServiceLib.Handler;
|
||||||
|
|
||||||
public sealed class AppHandler
|
public sealed class AppHandler
|
||||||
|
@ -246,5 +250,64 @@ public sealed class AppHandler
|
||||||
return item?.CoreType ?? ECoreType.Xray;
|
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
|
#endregion Core Type
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,6 @@ public class CoreHandler
|
||||||
// Create launch context and configure parameters
|
// Create launch context and configure parameters
|
||||||
var context = new CoreLaunchContext(node, _config);
|
var context = new CoreLaunchContext(node, _config);
|
||||||
context.AdjustForConfigType();
|
context.AdjustForConfigType();
|
||||||
context.AdjustForSplitCore();
|
|
||||||
|
|
||||||
// Start main core
|
// Start main core
|
||||||
if (!await CoreStart(context))
|
if (!await CoreStart(context))
|
||||||
|
@ -210,74 +209,21 @@ public class CoreHandler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AdjustForConfigType()
|
public void AdjustForConfigType()
|
||||||
{
|
{
|
||||||
|
(SplitCore, CoreType, PreCoreType) = AppHandler.Instance.GetCoreAndPreType(Node);
|
||||||
if (Node.ConfigType == EConfigType.Custom)
|
if (Node.ConfigType == EConfigType.Custom)
|
||||||
{
|
{
|
||||||
SplitCore = false;
|
|
||||||
CoreType = Node.CoreType ?? ECoreType.Xray;
|
|
||||||
if (Node.PreSocksPort > 0)
|
if (Node.PreSocksPort > 0)
|
||||||
{
|
{
|
||||||
PreCoreType = EnableTun ? ECoreType.sing_box : AppHandler.Instance.GetCoreType(Node, Node.ConfigType);
|
|
||||||
PreSocksPort = Node.PreSocksPort.Value;
|
PreSocksPort = Node.PreSocksPort.Value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EnableTun = false;
|
EnableTun = false;
|
||||||
PreCoreType = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!SplitCore && !EnableTun)
|
else if (PreCoreType != null)
|
||||||
{
|
{
|
||||||
switch (Node.CoreType)
|
PreSocksPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.split);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue