Skip to content

Commit

Permalink
Fixed the inbound issue caused by server configuration error during s…
Browse files Browse the repository at this point in the history
…peed test

2dust#6110
  • Loading branch information
2dust committed Nov 20, 2024
1 parent e915726 commit 9cbe2b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>

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;
Expand Down Expand Up @@ -119,10 +119,10 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>

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)
{
Expand Down
33 changes: 17 additions & 16 deletions v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>

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;
Expand All @@ -244,10 +244,11 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
}

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)
{
Expand All @@ -270,7 +271,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>

//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)
{
Expand All @@ -294,16 +295,6 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
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)
{
Expand All @@ -325,6 +316,16 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
{
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<Outbounds4Ray>(txtOutbound);
await GenOutbound(item, outbound);
Expand Down

0 comments on commit 9cbe2b9

Please sign in to comment.