From 9cbe2b938cf0c7d86677ca01a9f2c8f500a7c2c7 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:34:51 +0800 Subject: [PATCH] Fixed the inbound issue caused by server configuration error during speed test https://github.com/2dust/v2rayN/issues/6110 --- .../CoreConfig/CoreConfigSingboxService.cs | 8 ++--- .../CoreConfig/CoreConfigV2rayService.cs | 33 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index adfffa91..cbdefc86 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -90,8 +90,8 @@ namespace ServiceLib.Services.CoreConfig ret.Msg = ResUI.InitialConfiguration; - string result = Utils.GetEmbedText(Global.SingboxSampleClient); - string txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound); + var result = Utils.GetEmbedText(Global.SingboxSampleClient); + var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound); if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; @@ -119,10 +119,10 @@ namespace ServiceLib.Services.CoreConfig await GenLog(singboxConfig); //GenDns(new(), singboxConfig); - singboxConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts. + singboxConfig.inbounds.Clear(); singboxConfig.outbounds.RemoveAt(0); - int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); + var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); foreach (var it in selecteds) { diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index 885986da..35ed0a5d 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -216,8 +216,8 @@ namespace ServiceLib.Services.CoreConfig ret.Msg = ResUI.InitialConfiguration; - string result = Utils.GetEmbedText(Global.V2raySampleClient); - string txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); + var result = Utils.GetEmbedText(Global.V2raySampleClient); + var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound); if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty()) { ret.Msg = ResUI.FailedGetDefaultConfiguration; @@ -244,10 +244,11 @@ namespace ServiceLib.Services.CoreConfig } await GenLog(v2rayConfig); - v2rayConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts. - v2rayConfig.outbounds.RemoveAt(0); + v2rayConfig.inbounds.Clear(); + v2rayConfig.outbounds.Clear(); + v2rayConfig.routing.rules.Clear(); - int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); + var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); foreach (var it in selecteds) { @@ -270,7 +271,7 @@ namespace ServiceLib.Services.CoreConfig //find unused port var port = httpPort; - for (int k = httpPort; k < Global.MaxPort; k++) + for (var k = httpPort; k < Global.MaxPort; k++) { if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0) { @@ -294,16 +295,6 @@ namespace ServiceLib.Services.CoreConfig it.Port = port; it.AllowTest = true; - //inbound - Inbounds4Ray inbound = new() - { - listen = Global.Loopback, - port = port, - protocol = EInboundProtocol.http.ToString(), - }; - inbound.tag = inbound.protocol + inbound.port.ToString(); - v2rayConfig.inbounds.Add(inbound); - //outbound if (item is null) { @@ -325,6 +316,16 @@ namespace ServiceLib.Services.CoreConfig { continue; } + + //inbound + Inbounds4Ray inbound = new() + { + listen = Global.Loopback, + port = port, + protocol = EInboundProtocol.http.ToString(), + }; + inbound.tag = inbound.protocol + inbound.port.ToString(); + v2rayConfig.inbounds.Add(inbound); var outbound = JsonUtils.Deserialize(txtOutbound); await GenOutbound(item, outbound);