Browse Source

Remove ping test

pull/4711/head
2dust 10 months ago
parent
commit
ff215bc9aa
  1. 102
      v2rayN/v2rayN/Handler/SpeedtestHandler.cs
  2. 1
      v2rayN/v2rayN/Mode/ESpeedActionType.cs
  3. 9
      v2rayN/v2rayN/Resx/ResUI.Designer.cs
  4. 3
      v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx
  5. 3
      v2rayN/v2rayN/Resx/ResUI.resx
  6. 5
      v2rayN/v2rayN/Resx/ResUI.ru.resx
  7. 3
      v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
  8. 3
      v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
  9. 5
      v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
  10. 4
      v2rayN/v2rayN/Views/MainWindow.xaml
  11. 5
      v2rayN/v2rayN/Views/MainWindow.xaml.cs

102
v2rayN/v2rayN/Handler/SpeedtestHandler.cs

@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using v2rayN.Mode;
using v2rayN.Resx;
@ -9,7 +8,7 @@ namespace v2rayN.Handler
{
internal class SpeedtestHandler
{
private Config _config;
private Config? _config;
private CoreHandler _coreHandler;
private List<ServerTestItem> _selecteds;
private ESpeedActionType _actionType;
@ -51,7 +50,6 @@ namespace v2rayN.Handler
{
switch (actionType)
{
case ESpeedActionType.Ping:
case ESpeedActionType.Tcping:
case ESpeedActionType.Realping:
UpdateFunc(it.indexId, ResUI.Speedtesting, "");
@ -73,10 +71,6 @@ namespace v2rayN.Handler
switch (actionType)
{
case ESpeedActionType.Ping:
Task.Run(RunPing);
break;
case ESpeedActionType.Tcping:
Task.Run(RunTcping);
break;
@ -95,52 +89,45 @@ namespace v2rayN.Handler
}
}
private async Task RunPingSubAsync(Action<ServerTestItem> updateFun)
private Task RunTcping()
{
try
{
foreach (var it in _selecteds.Where(it => it.configType != EConfigType.Custom))
List<Task> tasks = [];
foreach (var it in _selecteds)
{
try
if (it.configType == EConfigType.Custom)
{
_ = Task.Run(() => updateFun(it));
continue;
}
catch (Exception ex)
tasks.Add(Task.Run(() =>
{
Logging.SaveLog(ex.Message, ex);
}
}
try
{
int time = GetTcpingTime(it.address, it.port);
var output = FormatOut(time, Global.DelayUnit);
await Task.Delay(10);
ProfileExHandler.Instance.SetTestDelay(it.indexId, output);
UpdateFunc(it.indexId, output);
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
}
}));
}
Task.WaitAll([.. tasks]);
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
}
}
private async void RunPing()
{
await RunPingSubAsync((ServerTestItem it) =>
{
long time = Ping(it.address);
var output = FormatOut(time, Global.DelayUnit);
ProfileExHandler.Instance.SetTestDelay(it.indexId, output);
UpdateFunc(it.indexId, output);
});
}
private async void RunTcping()
{
await RunPingSubAsync((ServerTestItem it) =>
finally
{
int time = GetTcpingTime(it.address, it.port);
var output = FormatOut(time, Global.DelayUnit);
ProfileExHandler.Instance.SaveTo();
}
ProfileExHandler.Instance.SetTestDelay(it.indexId, output);
UpdateFunc(it.indexId, output);
});
return Task.CompletedTask;
}
private Task RunRealPing()
@ -336,7 +323,7 @@ namespace v2rayN.Handler
await RunSpeedTestMulti();
}
public async Task<string> GetRealPingTime(DownloadHandle downloadHandle, IWebProxy webProxy)
private async Task<string> GetRealPingTime(DownloadHandle downloadHandle, IWebProxy webProxy)
{
int responseTime = await downloadHandle.GetRealPingTime(_config.speedTestItem.speedPingTestUrl, webProxy, 10);
//string output = Utils.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;
@ -376,43 +363,6 @@ namespace v2rayN.Handler
return responseTime;
}
/// <summary>
/// Ping
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public long Ping(string host)
{
long roundtripTime = -1;
try
{
int timeout = 30;
int echoNum = 2;
using Ping pingSender = new();
for (int i = 0; i < echoNum; i++)
{
PingReply reply = pingSender.Send(host, timeout);
if (reply.Status == IPStatus.Success)
{
if (reply.RoundtripTime < 0)
{
continue;
}
if (roundtripTime < 0 || reply.RoundtripTime < roundtripTime)
{
roundtripTime = reply.RoundtripTime;
}
}
}
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
return -1;
}
return roundtripTime;
}
private string FormatOut(object time, string unit)
{
//if (time.ToString().Equals("-1"))

1
v2rayN/v2rayN/Mode/ESpeedActionType.cs

@ -2,7 +2,6 @@
{
public enum ESpeedActionType
{
Ping,
Tcping,
Realping,
Speedtest,

9
v2rayN/v2rayN/Resx/ResUI.Designer.cs generated

@ -969,15 +969,6 @@ namespace v2rayN.Resx {
}
}
/// <summary>
/// 查找类似 Test servers ping (Ctrl+P) 的本地化字符串。
/// </summary>
public static string menuPingServer {
get {
return ResourceManager.GetString("menuPingServer", resourceCulture);
}
}
/// <summary>
/// 查找类似 Promotion 的本地化字符串。
/// </summary>

3
v2rayN/v2rayN/Resx/ResUI.fa-Ir.resx

@ -529,9 +529,6 @@
<data name="menuClearServerStatistics" xml:space="preserve">
<value>تمام آمار خدمات را پاک کنید</value>
</data>
<data name="menuPingServer" xml:space="preserve">
<value>تست پینگ سرورها (Ctrl+P)</value>
</data>
<data name="menuRealPingServer" xml:space="preserve">
<value>آزمایش سرورها با تاخیر واقعی (Ctrl+R)</value>
</data>

3
v2rayN/v2rayN/Resx/ResUI.resx

@ -532,9 +532,6 @@
<data name="menuClearServerStatistics" xml:space="preserve">
<value>Clear all service statistics</value>
</data>
<data name="menuPingServer" xml:space="preserve">
<value>Test servers ping (Ctrl+P)</value>
</data>
<data name="menuRealPingServer" xml:space="preserve">
<value>Test servers real delay (Ctrl+R)</value>
</data>

5
v2rayN/v2rayN/Resx/ResUI.ru.resx

@ -532,9 +532,6 @@
<data name="menuClearServerStatistics" xml:space="preserve">
<value>Очистить всю статистику</value>
</data>
<data name="menuPingServer" xml:space="preserve">
<value>Тест на задержку сервера (Ctrl+P)</value>
</data>
<data name="menuRealPingServer" xml:space="preserve">
<value>Тест на реальную задержку сервера (Ctrl+R)</value>
</data>
@ -1072,4 +1069,4 @@
<data name="TbSettingsSpeedTestUrl" xml:space="preserve">
<value>URL спидтеста</value>
</data>
</root>
</root>

3
v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx

@ -532,9 +532,6 @@
<data name="menuClearServerStatistics" xml:space="preserve">
<value>清除所有服务统计数据</value>
</data>
<data name="menuPingServer" xml:space="preserve">
<value>测试服务器延迟Ping(多选) (Ctrl+P)</value>
</data>
<data name="menuRealPingServer" xml:space="preserve">
<value>测试服务器真连接延迟(多选) (Ctrl+R)</value>
</data>

3
v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx

@ -531,9 +531,6 @@
<data name="menuClearServerStatistics" xml:space="preserve">
<value>清除所有服務統計資料</value>
</data>
<data name="menuPingServer" xml:space="preserve">
<value>測試伺服器延遲Ping(多選) (Ctrl+P)</value>
</data>
<data name="menuRealPingServer" xml:space="preserve">
<value>測試伺服器真連接延遲(多選) (Ctrl+R)</value>
</data>

5
v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs

@ -112,7 +112,6 @@ namespace v2rayN.ViewModels
//servers ping
public ReactiveCommand<Unit, Unit> MixedTestServerCmd { get; }
public ReactiveCommand<Unit, Unit> PingServerCmd { get; }
public ReactiveCommand<Unit, Unit> TcpingServerCmd { get; }
public ReactiveCommand<Unit, Unit> RealPingServerCmd { get; }
public ReactiveCommand<Unit, Unit> SpeedServerCmd { get; }
@ -409,10 +408,6 @@ namespace v2rayN.ViewModels
{
ServerSpeedtest(ESpeedActionType.Mixedtest);
});
PingServerCmd = ReactiveCommand.Create(() =>
{
ServerSpeedtest(ESpeedActionType.Ping);
}, canEditRemove);
TcpingServerCmd = ReactiveCommand.Create(() =>
{
ServerSpeedtest(ESpeedActionType.Tcping);

4
v2rayN/v2rayN/Views/MainWindow.xaml

@ -581,10 +581,6 @@
x:Name="menuMixedTestServer"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuMixedTestServer}" />
<MenuItem
x:Name="menuPingServer"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuPingServer}" />
<MenuItem
x:Name="menuTcpingServer"
Height="{StaticResource MenuItemHeight}"

5
v2rayN/v2rayN/Views/MainWindow.xaml.cs

@ -113,7 +113,6 @@ namespace v2rayN.Views
//servers ping
this.BindCommand(ViewModel, vm => vm.MixedTestServerCmd, v => v.menuMixedTestServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.PingServerCmd, v => v.menuPingServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.TcpingServerCmd, v => v.menuTcpingServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RealPingServerCmd, v => v.menuRealPingServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SpeedServerCmd, v => v.menuSpeedServer).DisposeWith(disposables);
@ -330,10 +329,6 @@ namespace v2rayN.Views
ViewModel?.AddServerViaClipboard();
break;
case Key.P:
ViewModel?.ServerSpeedtest(ESpeedActionType.Ping);
break;
case Key.O:
ViewModel?.ServerSpeedtest(ESpeedActionType.Tcping);
break;

Loading…
Cancel
Save