Skip to content

Commit 9cbe2b9

Browse files
committed
Fixed the inbound issue caused by server configuration error during speed test
2dust#6110
1 parent e915726 commit 9cbe2b9

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
9090

9191
ret.Msg = ResUI.InitialConfiguration;
9292

93-
string result = Utils.GetEmbedText(Global.SingboxSampleClient);
94-
string txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound);
93+
var result = Utils.GetEmbedText(Global.SingboxSampleClient);
94+
var txtOutbound = Utils.GetEmbedText(Global.SingboxSampleOutbound);
9595
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
9696
{
9797
ret.Msg = ResUI.FailedGetDefaultConfiguration;
@@ -119,10 +119,10 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
119119

120120
await GenLog(singboxConfig);
121121
//GenDns(new(), singboxConfig);
122-
singboxConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts.
122+
singboxConfig.inbounds.Clear();
123123
singboxConfig.outbounds.RemoveAt(0);
124124

125-
int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
125+
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
126126

127127
foreach (var it in selecteds)
128128
{

v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
216216

217217
ret.Msg = ResUI.InitialConfiguration;
218218

219-
string result = Utils.GetEmbedText(Global.V2raySampleClient);
220-
string txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
219+
var result = Utils.GetEmbedText(Global.V2raySampleClient);
220+
var txtOutbound = Utils.GetEmbedText(Global.V2raySampleOutbound);
221221
if (Utils.IsNullOrEmpty(result) || txtOutbound.IsNullOrEmpty())
222222
{
223223
ret.Msg = ResUI.FailedGetDefaultConfiguration;
@@ -244,10 +244,11 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
244244
}
245245

246246
await GenLog(v2rayConfig);
247-
v2rayConfig.inbounds.Clear(); // Remove "proxy" service for speedtest, avoiding port conflicts.
248-
v2rayConfig.outbounds.RemoveAt(0);
247+
v2rayConfig.inbounds.Clear();
248+
v2rayConfig.outbounds.Clear();
249+
v2rayConfig.routing.rules.Clear();
249250

250-
int httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
251+
var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
251252

252253
foreach (var it in selecteds)
253254
{
@@ -270,7 +271,7 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
270271

271272
//find unused port
272273
var port = httpPort;
273-
for (int k = httpPort; k < Global.MaxPort; k++)
274+
for (var k = httpPort; k < Global.MaxPort; k++)
274275
{
275276
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
276277
{
@@ -294,16 +295,6 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
294295
it.Port = port;
295296
it.AllowTest = true;
296297

297-
//inbound
298-
Inbounds4Ray inbound = new()
299-
{
300-
listen = Global.Loopback,
301-
port = port,
302-
protocol = EInboundProtocol.http.ToString(),
303-
};
304-
inbound.tag = inbound.protocol + inbound.port.ToString();
305-
v2rayConfig.inbounds.Add(inbound);
306-
307298
//outbound
308299
if (item is null)
309300
{
@@ -325,6 +316,16 @@ public async Task<RetResult> GenerateClientSpeedtestConfig(List<ServerTestItem>
325316
{
326317
continue;
327318
}
319+
320+
//inbound
321+
Inbounds4Ray inbound = new()
322+
{
323+
listen = Global.Loopback,
324+
port = port,
325+
protocol = EInboundProtocol.http.ToString(),
326+
};
327+
inbound.tag = inbound.protocol + inbound.port.ToString();
328+
v2rayConfig.inbounds.Add(inbound);
328329

329330
var outbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound);
330331
await GenOutbound(item, outbound);

0 commit comments

Comments
 (0)