mirror of
https://github.com/2dust/v2rayN.git
synced 2025-07-01 12:32:10 +00:00
Optimize speed test
This commit is contained in:
parent
5a5d686be1
commit
c6ec4f38b0
3 changed files with 26 additions and 24 deletions
|
@ -12,6 +12,7 @@ namespace v2rayN.Handler
|
||||||
private Config _config;
|
private Config _config;
|
||||||
private CoreHandler _coreHandler;
|
private CoreHandler _coreHandler;
|
||||||
private List<ServerTestItem> _selecteds;
|
private List<ServerTestItem> _selecteds;
|
||||||
|
private ESpeedActionType _actionType;
|
||||||
Action<string, string, string> _updateFunc;
|
Action<string, string, string> _updateFunc;
|
||||||
|
|
||||||
public SpeedtestHandler(Config config)
|
public SpeedtestHandler(Config config)
|
||||||
|
@ -23,7 +24,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_coreHandler = coreHandler;
|
_coreHandler = coreHandler;
|
||||||
//_selecteds = Utils.DeepCopy(selecteds);
|
_actionType = actionType;
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
|
|
||||||
_selecteds = new List<ServerTestItem>();
|
_selecteds = new List<ServerTestItem>();
|
||||||
|
@ -106,7 +107,7 @@ namespace v2rayN.Handler
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunRealPing()
|
private Task RunRealPing()
|
||||||
{
|
{
|
||||||
int pid = -1;
|
int pid = -1;
|
||||||
try
|
try
|
||||||
|
@ -117,7 +118,7 @@ namespace v2rayN.Handler
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
UpdateFunc("", ResUI.FailedToRunCore);
|
UpdateFunc("", ResUI.FailedToRunCore);
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new DownloadHandle();
|
||||||
|
@ -144,6 +145,8 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
LazyConfig.Instance.SetTestResult(it.indexId, output, "");
|
LazyConfig.Instance.SetTestResult(it.indexId, output, "");
|
||||||
UpdateFunc(it.indexId, output);
|
UpdateFunc(it.indexId, output);
|
||||||
|
int.TryParse(output, out int delay);
|
||||||
|
it.delay = delay;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -162,10 +165,17 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
if (pid > 0) _coreHandler.CoreStopPid(pid);
|
if (pid > 0) _coreHandler.CoreStopPid(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunSpeedTestAsync()
|
private async Task RunSpeedTestAsync()
|
||||||
{
|
{
|
||||||
int pid = -1;
|
int pid = -1;
|
||||||
|
if (_actionType == ESpeedActionType.Mixedtest)
|
||||||
|
{
|
||||||
|
_selecteds = _selecteds.OrderBy(t => t.delay).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
pid = _coreHandler.LoadCoreConfigString(_config, _selecteds);
|
pid = _coreHandler.LoadCoreConfigString(_config, _selecteds);
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
|
@ -188,6 +198,10 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (it.delay < 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ = LazyConfig.Instance.SetTestResult(it.indexId, "", "-1");
|
_ = LazyConfig.Instance.SetTestResult(it.indexId, "", "-1");
|
||||||
UpdateFunc(it.indexId, "", ResUI.Speedtesting);
|
UpdateFunc(it.indexId, "", ResUI.Speedtesting);
|
||||||
|
|
||||||
|
@ -216,6 +230,8 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
await RunRealPing();
|
await RunRealPing();
|
||||||
|
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
await RunSpeedTestAsync();
|
await RunSpeedTestAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,25 +3,11 @@
|
||||||
[Serializable]
|
[Serializable]
|
||||||
class ServerTestItem
|
class ServerTestItem
|
||||||
{
|
{
|
||||||
public string indexId
|
public string indexId { get; set; }
|
||||||
{
|
public string address { get; set; }
|
||||||
get; set;
|
public int port { get; set; }
|
||||||
}
|
public EConfigType configType { get; set; }
|
||||||
public string address
|
public bool allowTest { get; set; }
|
||||||
{
|
public int delay { get; set; }
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
public int port
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
public EConfigType configType
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
public bool allowTest
|
|
||||||
{
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1087,7 +1087,7 @@ namespace v2rayN.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//ClearTestResult();
|
//ClearTestResult();
|
||||||
SpeedtestHandler statistics = new SpeedtestHandler(_config, _coreHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
|
new SpeedtestHandler(_config, _coreHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Export2ClientConfig()
|
private void Export2ClientConfig()
|
||||||
|
|
Loading…
Reference in a new issue