From 33fa9865e69f6a597b286bb187b96487b935eecf Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:43:21 +0800 Subject: [PATCH] Move pre-SOCKS helper to config builder Encapsulate pre-SOCKS profile creation in CoreConfigContextBuilder instead of ConfigDbHandler, without changing its behavior. --- .../Builder/CoreConfigContextBuilder.cs | 43 ++++++++++++++++++- .../Handler/Data/ConfigDbHandler.cs | 40 ----------------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs index 3677f565..2fa6013b 100644 --- a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs +++ b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs @@ -204,7 +204,7 @@ public class CoreConfigContextBuilder var node = nodeContext.Node; var coreType = AppManager.Instance.GetCoreType(node, node.ConfigType); - var preSocksItem = ConfigDbHandler.GetPreSocksItem(config, node, coreType); + var preSocksItem = GetPreSocksItem(config, node, coreType); if (preSocksItem != null) { var preSocksResult = await Build(nodeContext.AppConfig, preSocksItem); @@ -518,4 +518,45 @@ public class CoreConfigContextBuilder context.AllProxiesMap[node.IndexId] = node; return childNodeValidatorResult; } + + /// + /// Get a SOCKS server profile for pre-SOCKS functionality + /// Used when TUN mode is enabled or when a custom config has a pre-SOCKS port + /// + /// Current configuration + /// Server node that might need pre-SOCKS + /// Core type being used + /// A SOCKS profile item or null if not needed + private static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType) + { + ProfileItem? itemSocks = null; + var enableLegacyProtect = config.TunModeItem.EnableLegacyProtect; + if (node.ConfigType != EConfigType.Custom + && coreType != ECoreType.sing_box + && config.TunModeItem.EnableTun + && enableLegacyProtect) + { + itemSocks = new ProfileItem() + { + CoreType = ECoreType.sing_box, + ConfigType = EConfigType.SOCKS, + Address = Global.Loopback, + Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks) + }; + } + else if (node.ConfigType == EConfigType.Custom + && node.PreSocksPort is > 0 and <= 65535) + { + var customPreCoreType = AppManager.Instance.GetCoreType(null, EConfigType.Custom); + var preCoreType = (enableLegacyProtect && config.TunModeItem.EnableTun) ? ECoreType.sing_box : customPreCoreType; + itemSocks = new ProfileItem() + { + CoreType = preCoreType, + ConfigType = EConfigType.SOCKS, + Address = Global.Loopback, + Port = node.PreSocksPort.Value, + }; + } + return itemSocks; + } } diff --git a/v2rayN/ServiceLib/Handler/Data/ConfigDbHandler.cs b/v2rayN/ServiceLib/Handler/Data/ConfigDbHandler.cs index 5f9f8297..d7510358 100644 --- a/v2rayN/ServiceLib/Handler/Data/ConfigDbHandler.cs +++ b/v2rayN/ServiceLib/Handler/Data/ConfigDbHandler.cs @@ -1415,46 +1415,6 @@ public static class ConfigDbHandler return result; } - /// - /// Get a SOCKS server profile for pre-SOCKS functionality - /// Used when TUN mode is enabled or when a custom config has a pre-SOCKS port - /// - /// Current configuration - /// Server node that might need pre-SOCKS - /// Core type being used - /// A SOCKS profile item or null if not needed - public static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType) - { - ProfileItem? itemSocks = null; - var enableLegacyProtect = config.TunModeItem.EnableLegacyProtect; - if (node.ConfigType != EConfigType.Custom - && coreType != ECoreType.sing_box - && config.TunModeItem.EnableTun - && enableLegacyProtect) - { - itemSocks = new ProfileItem() - { - CoreType = ECoreType.sing_box, - ConfigType = EConfigType.SOCKS, - Address = Global.Loopback, - Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks) - }; - } - else if (node.ConfigType == EConfigType.Custom - && node.PreSocksPort is > 0 and <= 65535) - { - var customPreCoreType = AppManager.Instance.GetCoreType(null, EConfigType.Custom); - var preCoreType = (enableLegacyProtect && config.TunModeItem.EnableTun) ? ECoreType.sing_box : customPreCoreType; - itemSocks = new ProfileItem() - { - CoreType = preCoreType, - ConfigType = EConfigType.SOCKS, - Address = Global.Loopback, - Port = node.PreSocksPort.Value, - }; - } - return itemSocks; - } /// /// Remove servers with invalid test results (timeout)