Optimize speed test

pull/3107/head
2dust 2023-01-06 19:23:36 +08:00
parent 5a5d686be1
commit c6ec4f38b0
3 changed files with 26 additions and 24 deletions

View File

@ -12,6 +12,7 @@ namespace v2rayN.Handler
private Config _config;
private CoreHandler _coreHandler;
private List<ServerTestItem> _selecteds;
private ESpeedActionType _actionType;
Action<string, string, string> _updateFunc;
public SpeedtestHandler(Config config)
@ -23,7 +24,7 @@ namespace v2rayN.Handler
{
_config = config;
_coreHandler = coreHandler;
//_selecteds = Utils.DeepCopy(selecteds);
_actionType = actionType;
_updateFunc = update;
_selecteds = new List<ServerTestItem>();
@ -106,7 +107,7 @@ namespace v2rayN.Handler
});
}
private async Task RunRealPing()
private Task RunRealPing()
{
int pid = -1;
try
@ -117,7 +118,7 @@ namespace v2rayN.Handler
if (pid < 0)
{
UpdateFunc("", ResUI.FailedToRunCore);
return;
return Task.CompletedTask;
}
DownloadHandle downloadHandle = new DownloadHandle();
@ -144,6 +145,8 @@ namespace v2rayN.Handler
LazyConfig.Instance.SetTestResult(it.indexId, output, "");
UpdateFunc(it.indexId, output);
int.TryParse(output, out int delay);
it.delay = delay;
}
catch (Exception ex)
{
@ -162,10 +165,17 @@ namespace v2rayN.Handler
{
if (pid > 0) _coreHandler.CoreStopPid(pid);
}
return Task.CompletedTask;
}
private async Task RunSpeedTestAsync()
{
int pid = -1;
if (_actionType == ESpeedActionType.Mixedtest)
{
_selecteds = _selecteds.OrderBy(t => t.delay).ToList();
}
pid = _coreHandler.LoadCoreConfigString(_config, _selecteds);
if (pid < 0)
@ -188,6 +198,10 @@ namespace v2rayN.Handler
{
continue;
}
if (it.delay < 0)
{
continue;
}
_ = LazyConfig.Instance.SetTestResult(it.indexId, "", "-1");
UpdateFunc(it.indexId, "", ResUI.Speedtesting);
@ -216,6 +230,8 @@ namespace v2rayN.Handler
{
await RunRealPing();
Thread.Sleep(1000);
await RunSpeedTestAsync();
}

View File

@ -3,25 +3,11 @@
[Serializable]
class ServerTestItem
{
public string indexId
{
get; set;
}
public string address
{
get; set;
}
public int port
{
get; set;
}
public EConfigType configType
{
get; set;
}
public bool allowTest
{
get; set;
}
public string indexId { get; set; }
public string address { get; set; }
public int port { get; set; }
public EConfigType configType { get; set; }
public bool allowTest { get; set; }
public int delay { get; set; }
}
}

View File

@ -1087,7 +1087,7 @@ namespace v2rayN.ViewModels
return;
}
//ClearTestResult();
SpeedtestHandler statistics = new SpeedtestHandler(_config, _coreHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
new SpeedtestHandler(_config, _coreHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
}
private void Export2ClientConfig()