From ccacda9bf5d9df01b7973928b3041751afe8f3cd Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:01:36 +0800 Subject: [PATCH] Using mixed local listening ports --- v2rayN/ServiceLib/Enums/EInboundProtocol.cs | 3 +-- v2rayN/ServiceLib/Global.cs | 2 +- .../Handler/SysProxy/SysProxyHandler.cs | 9 ++++----- v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 4 ++-- v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 4 ++-- v2rayN/ServiceLib/Resx/ResUI.resx | 4 ++-- v2rayN/ServiceLib/Resx/ResUI.ru.resx | 4 ++-- v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 4 ++-- v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 4 ++-- .../CoreConfig/CoreConfigClashService.cs | 6 ++---- .../CoreConfig/CoreConfigSingboxService.cs | 16 +++------------- .../CoreConfig/CoreConfigV2rayService.cs | 18 +++--------------- v2rayN/ServiceLib/Services/DownloadService.cs | 2 +- .../ViewModels/StatusBarViewModel.cs | 8 ++------ 14 files changed, 29 insertions(+), 59 deletions(-) diff --git a/v2rayN/ServiceLib/Enums/EInboundProtocol.cs b/v2rayN/ServiceLib/Enums/EInboundProtocol.cs index c1ff81ea..2d7c3034 100644 --- a/v2rayN/ServiceLib/Enums/EInboundProtocol.cs +++ b/v2rayN/ServiceLib/Enums/EInboundProtocol.cs @@ -3,12 +3,11 @@ public enum EInboundProtocol { socks = 0, - http, socks2, - http2, pac, api, api2, + mixed, speedtest = 21 } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 1dbff452..70e85556 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -198,7 +198,7 @@ public static readonly List Languages = new() { "zh-Hans", "zh-Hant", "en", "fa-Ir", "ru" }; public static readonly List Alpns = new() { "h3", "h2", "http/1.1", "h3,h2", "h2,http/1.1", "h3,h2,http/1.1", "" }; public static readonly List LogLevels = new() { "debug", "info", "warning", "error", "none" }; - public static readonly List InboundTags = new() { "socks", "http", "socks2", "http2" }; + public static readonly List InboundTags = new() { "socks", "socks2" }; public static readonly List RuleProtocols = new() { "http", "tls", "bittorrent" }; public static readonly List RuleNetworks = new() { "", "tcp", "udp", "tcp,udp" }; public static readonly List destOverrideProtocols = ["http", "tls", "quic", "fakedns", "fakedns+others"]; diff --git a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs index 8f1a0446..0230b0a4 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -13,8 +13,7 @@ try { - var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); - var portSocks = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); + var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); if (port <= 0) { return false; @@ -23,7 +22,7 @@ { case ESysProxyType.ForcedChange when Utils.IsWindows(): { - GetWindowsProxyString(config, port, portSocks, out var strProxy, out var strExceptions); + GetWindowsProxyString(config, port, out var strProxy, out var strExceptions); ProxySettingWindows.SetProxy(strProxy, strExceptions, 2); break; } @@ -64,7 +63,7 @@ return true; } - private static void GetWindowsProxyString(Config config, int port, int portSocks, out string strProxy, out string strExceptions) + private static void GetWindowsProxyString(Config config, int port, out string strProxy, out string strExceptions) { strExceptions = $"{config.ConstItem.DefIEProxyExceptions};{config.SystemProxyItem.SystemProxyExceptions}"; if (config.SystemProxyItem.NotProxyLocalAddress) @@ -82,7 +81,7 @@ strProxy = config.SystemProxyItem.SystemProxyAdvancedProtocol .Replace("{ip}", Global.Loopback) .Replace("{http_port}", port.ToString()) - .Replace("{socks_port}", portSocks.ToString()); + .Replace("{socks_port}", port.ToString()); } } diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 87415bd1..49a08c2a 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3311,7 +3311,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 SOCKS Port 的本地化字符串。 + /// 查找类似 Mixed Port 的本地化字符串。 /// public static string TbSettingsSocksPort { get { @@ -3320,7 +3320,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6; 的本地化字符串。 + /// 查找类似 Pac port = +2; Xray API port = +3; mihomo API port = +4; 的本地化字符串。 /// public static string TbSettingsSocksPortTip { get { diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 830cefe5..37d4d93c 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -752,7 +752,7 @@ Turn on Sniffing - ساکس Port + Mixed Port درهنگام راه ائدازی شروع شود @@ -1244,7 +1244,7 @@ Copy the font TTF/TTC file to the directory guiFonts, restart the settings - http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6; + Pac port = +2; Xray API port = +3; mihomo API port = +4; Set this with admin privileges, get admin privileges after startup diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 3f006a0b..0b24b483 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -755,7 +755,7 @@ Turn on Sniffing - SOCKS Port + Mixed Port Start on boot @@ -992,7 +992,7 @@ Copy the font TTF/TTC file to the directory guiFonts, restart the settings - http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6; + Pac port = +2; Xray API port = +3; mihomo API port = +4; Set this with admin privileges, get admin privileges after startup diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 493fb702..9134409b 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -761,7 +761,7 @@ Включить сниффинг - Порт Socks + Mixed Port Автозапуск @@ -1310,7 +1310,7 @@ Move up and down - http port = +1; Pac port = +4; *ray API port = +5; mihomo API port = +6; + Pac port = +2; Xray API port = +3; mihomo API port = +4; Install the font to the system and restart the settings diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index d5fd572e..c1f3426c 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -755,7 +755,7 @@ 开启流量探测 - 本地socks监听端口 + 本地混合监听端口 开机启动(可能会不成功) @@ -992,7 +992,7 @@ 拷贝字体TTF/TTC文件到目录guiFonts,重启设置 - http端口= +1;Pac端口= +4;*ray API端口= +5;mihomo API端口= +6; + Pac端口= +2;Xray API端口= +3;mihomo API端口= +4; 以管理员权限设置此项,在启动后获得管理员权限 diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 87e5be51..30b605c6 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -755,7 +755,7 @@ 開啟流量探測 - 本機SOCKS偵聽埠 + 本機混合偵聽埠 開機啟動(可能會不成功) @@ -992,7 +992,7 @@ 複製字型TTF/TTC檔案到目錄guiFonts,重啟設定 - http連接埠= +1;Pac連接埠= +4;*ray API連接埠= +5;mihomo API連接埠= +6; + Pac連接埠= +2;Xray API連接埠= +3;mihomo API連接埠= +4; 以管理員權限設定此項,在啟動後獲得管理員權限 diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs index ca820d91..e48f3a5f 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs @@ -78,10 +78,8 @@ namespace ServiceLib.Services.CoreConfig return ret; } - //port - fileContent["port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); - //socks-port - fileContent["socks-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); + //mixed-port + fileContent["mixed-port"] = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); //log-level fileContent["log-level"] = GetLogLevel(_config.CoreBasicItem.Loglevel); diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 4ee4ff71..4170db6c 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -174,7 +174,7 @@ namespace ServiceLib.Services.CoreConfig { listen = Global.Loopback, listen_port = port, - type = EInboundProtocol.http.ToString(), + type = EInboundProtocol.mixed.ToString(), }; inbound.tag = inbound.type + inbound.listen_port.ToString(); singboxConfig.inbounds.Add(inbound); @@ -488,7 +488,7 @@ namespace ServiceLib.Services.CoreConfig { var inbound = new Inbound4Sbox() { - type = EInboundProtocol.socks.ToString(), + type = EInboundProtocol.mixed.ToString(), tag = EInboundProtocol.socks.ToString(), listen = Global.Loopback, }; @@ -505,10 +505,6 @@ namespace ServiceLib.Services.CoreConfig inbound.domain_strategy = routing.DomainStrategy4Singbox; } - //http - var inbound2 = GetInbound(inbound, EInboundProtocol.http, false); - singboxConfig.inbounds.Add(inbound2); - if (_config.Inbound.First().AllowLANConn) { if (_config.Inbound.First().NewPort4LAN) @@ -517,21 +513,15 @@ namespace ServiceLib.Services.CoreConfig inbound3.listen = listen; singboxConfig.inbounds.Add(inbound3); - var inbound4 = GetInbound(inbound, EInboundProtocol.http2, false); - inbound4.listen = listen; - singboxConfig.inbounds.Add(inbound4); - //auth if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass)) { inbound3.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } }; - inbound4.users = new() { new() { username = _config.Inbound.First().User, password = _config.Inbound.First().Pass } }; } } else { inbound.listen = listen; - inbound2.listen = listen; } } } @@ -574,7 +564,7 @@ namespace ServiceLib.Services.CoreConfig var inbound = JsonUtils.DeepCopy(inItem); inbound.tag = protocol.ToString(); inbound.listen_port = inItem.listen_port + (int)protocol; - inbound.type = bSocks ? EInboundProtocol.socks.ToString() : EInboundProtocol.http.ToString(); + inbound.type = EInboundProtocol.mixed.ToString(); return inbound; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index ca7e53b6..c55a5930 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -322,7 +322,7 @@ namespace ServiceLib.Services.CoreConfig { listen = Global.Loopback, port = port, - protocol = EInboundProtocol.http.ToString(), + protocol = EInboundProtocol.socks.ToString(), }; inbound.tag = inbound.protocol + inbound.port.ToString(); v2rayConfig.inbounds.Add(inbound); @@ -391,13 +391,9 @@ namespace ServiceLib.Services.CoreConfig var listen = "0.0.0.0"; v2rayConfig.inbounds = []; - Inbounds4Ray? inbound = GetInbound(_config.Inbound.First(), EInboundProtocol.socks, true); + var inbound = GetInbound(_config.Inbound.First(), EInboundProtocol.socks, true); v2rayConfig.inbounds.Add(inbound); - //http - Inbounds4Ray? inbound2 = GetInbound(_config.Inbound.First(), EInboundProtocol.http, false); - v2rayConfig.inbounds.Add(inbound2); - if (_config.Inbound.First().AllowLANConn) { if (_config.Inbound.First().NewPort4LAN) @@ -406,24 +402,16 @@ namespace ServiceLib.Services.CoreConfig inbound3.listen = listen; v2rayConfig.inbounds.Add(inbound3); - var inbound4 = GetInbound(_config.Inbound.First(), EInboundProtocol.http2, false); - inbound4.listen = listen; - v2rayConfig.inbounds.Add(inbound4); - //auth if (Utils.IsNotEmpty(_config.Inbound.First().User) && Utils.IsNotEmpty(_config.Inbound.First().Pass)) { inbound3.settings.auth = "password"; inbound3.settings.accounts = new List { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } }; - - inbound4.settings.auth = "password"; - inbound4.settings.accounts = new List { new AccountsItem4Ray() { user = _config.Inbound.First().User, pass = _config.Inbound.First().Pass } }; } } else { inbound.listen = listen; - inbound2.listen = listen; } } } @@ -449,7 +437,7 @@ namespace ServiceLib.Services.CoreConfig } inbound.tag = protocol.ToString(); inbound.port = inItem.LocalPort + (int)protocol; - inbound.protocol = bSocks ? EInboundProtocol.socks.ToString() : EInboundProtocol.http.ToString(); + inbound.protocol = EInboundProtocol.socks.ToString(); inbound.settings.udp = inItem.UdpEnabled; inbound.sniffing.enabled = inItem.SniffingEnabled; inbound.sniffing.destOverride = inItem.DestOverride; diff --git a/v2rayN/ServiceLib/Services/DownloadService.cs b/v2rayN/ServiceLib/Services/DownloadService.cs index d27732b5..2a076c41 100644 --- a/v2rayN/ServiceLib/Services/DownloadService.cs +++ b/v2rayN/ServiceLib/Services/DownloadService.cs @@ -280,7 +280,7 @@ namespace ServiceLib.Services { return null; } - var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.http); + var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); if (await SocketCheck(Global.Loopback, httpPort) == false) { return null; diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 656f74c0..e999576f 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -451,9 +451,7 @@ namespace ServiceLib.ViewModels public async Task InboundDisplayStatus() { StringBuilder sb = new(); - sb.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}]"); - sb.Append(" | "); - sb.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http)}]"); + sb.Append($"[{EInboundProtocol.mixed}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks)}]"); InboundDisplay = $"{ResUI.LabLocal}:{sb}"; if (_config.Inbound.First().AllowLANConn) @@ -461,9 +459,7 @@ namespace ServiceLib.ViewModels if (_config.Inbound.First().NewPort4LAN) { StringBuilder sb2 = new(); - sb2.Append($"[{EInboundProtocol.socks}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]"); - sb2.Append(" | "); - sb2.Append($"[{EInboundProtocol.http}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.http2)}]"); + sb2.Append($"[{EInboundProtocol.mixed}:{AppHandler.Instance.GetLocalPort(EInboundProtocol.socks2)}]"); InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}"; } else