From e70658f311afa47ab6d6c1a36dbd576167ee1fde Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 1 Mar 2025 21:13:37 +0800 Subject: [PATCH] Add Hy2 Port hopping for sing-box 1.11+ https://github.com/2dust/v2rayN/issues/6772 --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 1 + v2rayN/ServiceLib/Models/ConfigItems.cs | 1 + v2rayN/ServiceLib/Models/ProfileItem.cs | 6 ++-- v2rayN/ServiceLib/Models/SingboxConfig.cs | 22 ++++++++------- v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 18 ++++++++++++ v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 6 ++++ v2rayN/ServiceLib/Resx/ResUI.hu.resx | 6 ++++ v2rayN/ServiceLib/Resx/ResUI.resx | 6 ++++ v2rayN/ServiceLib/Resx/ResUI.ru.resx | 6 ++++ v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 6 ++++ v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 6 ++++ .../CoreConfig/CoreConfigSingboxService.cs | 7 +++++ .../Views/AddServerWindow.axaml | 21 +++++++++++++- .../Views/AddServerWindow.axaml.cs | 1 + v2rayN/v2rayN/Views/AddServerWindow.xaml | 28 +++++++++++++++++-- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 1 + 16 files changed, 126 insertions(+), 16 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 4232496e..0016de60 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -217,6 +217,7 @@ namespace ServiceLib.Handler item.Remarks = profileItem.Remarks; item.Address = profileItem.Address; item.Port = profileItem.Port; + item.Ports = profileItem.Ports; item.Id = profileItem.Id; item.AlterId = profileItem.AlterId; diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index b7fd31fe..8daf09c6 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -197,6 +197,7 @@ namespace ServiceLib.Models { public int UpMbps { get; set; } public int DownMbps { get; set; } + public int HopInterval { get; set; } = 30; } [Serializable] diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/ProfileItem.cs index 8bf5405e..5f708103 100644 --- a/v2rayN/ServiceLib/Models/ProfileItem.cs +++ b/v2rayN/ServiceLib/Models/ProfileItem.cs @@ -1,4 +1,4 @@ -using SQLite; +using SQLite; namespace ServiceLib.Models { @@ -64,11 +64,11 @@ namespace ServiceLib.Models [PrimaryKey] public string IndexId { get; set; } - public EConfigType ConfigType { get; set; } public int ConfigVersion { get; set; } public string Address { get; set; } public int Port { get; set; } + public string Ports { get; set; } public string Id { get; set; } public int AlterId { get; set; } public string Security { get; set; } @@ -93,4 +93,4 @@ namespace ServiceLib.Models public string SpiderX { get; set; } public string Extra { get; set; } } -} \ No newline at end of file +} diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/SingboxConfig.cs index 41eee042..bcd4b59b 100644 --- a/v2rayN/ServiceLib/Models/SingboxConfig.cs +++ b/v2rayN/ServiceLib/Models/SingboxConfig.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models +namespace ServiceLib.Models { public class SingboxConfig { @@ -101,21 +101,23 @@ public string tag { get; set; } public string? server { get; set; } public int? server_port { get; set; } - public string uuid { get; set; } - public string security { get; set; } + public List? server_ports { get; set; } + public string? uuid { get; set; } + public string? security { get; set; } public int? alter_id { get; set; } - public string flow { get; set; } + public string? flow { get; set; } + public string? hop_interval { get; set; } public int? up_mbps { get; set; } public int? down_mbps { get; set; } - public string auth_str { get; set; } + public string? auth_str { get; set; } public int? recv_window_conn { get; set; } public int? recv_window { get; set; } public bool? disable_mtu_discovery { get; set; } public string? detour { get; set; } - public string method { get; set; } - public string username { get; set; } - public string password { get; set; } - public string congestion_control { get; set; } + public string? method { get; set; } + public string? username { get; set; } + public string? password { get; set; } + public string? congestion_control { get; set; } public string? version { get; set; } public string? network { get; set; } public string? packet_encoding { get; set; } @@ -252,4 +254,4 @@ public string? download_detour { get; set; } public string? update_interval { get; set; } } -} \ No newline at end of file +} diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 66581eb1..1af33d3c 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -2536,6 +2536,24 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Server port range 的本地化字符串。 + /// + public static string TbPorts7 { + get { + return ResourceManager.GetString("TbPorts7", resourceCulture); + } + } + + /// + /// 查找类似 Will cover the port, separate with commas (,) 的本地化字符串。 + /// + public static string TbPorts7Tips { + get { + return ResourceManager.GetString("TbPorts7Tips", resourceCulture); + } + } + /// /// 查找类似 Socks port 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index feb1b6a2..090ebd83 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1396,4 +1396,10 @@ Removed {0} invalid test results. + + Server port range + + + Will cover the port, separate with commas (,) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index c796e157..e1741f12 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1396,4 +1396,10 @@ Removed {0} invalid test results. + + Server port range + + + Will cover the port, separate with commas (,) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 31f5d586..dc599d69 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1396,4 +1396,10 @@ Removed {0} invalid test results. + + Server port range + + + Will cover the port, separate with commas (,) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 4a276ac7..3e61dc81 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1396,4 +1396,10 @@ Removed {0} invalid test results. + + Server port range + + + Will cover the port, separate with commas (,) + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index c9a76989..2511fc95 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1393,4 +1393,10 @@ 移除无效测试结果 {0} 个。 + + 跳跃端口范围 + + + 会覆盖端口,多组时用逗号(,)隔开 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 17a76a6b..e7b76800 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1394,4 +1394,10 @@ 移除無效測試結果 {0} 個。 + + 跳躍端口範圍 + + + 會覆蓋端口,多組時用逗號(,)隔開 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 5afae7d9..39c6f0fd 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -730,6 +730,13 @@ namespace ServiceLib.Services.CoreConfig outbound.up_mbps = _config.HysteriaItem.UpMbps > 0 ? _config.HysteriaItem.UpMbps : null; outbound.down_mbps = _config.HysteriaItem.DownMbps > 0 ? _config.HysteriaItem.DownMbps : null; + if (node.Ports.IsNotEmpty()) + { + outbound.server_port = null; + outbound.server_ports = node.Ports.Split(",").ToList(); + outbound.hop_interval = _config.HysteriaItem.HopInterval > 0 ? $"{_config.HysteriaItem.HopInterval}s" : null; + } + break; } case EConfigType.TUIC: diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml index 6bedd86f..187a1289 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml @@ -308,7 +308,7 @@ @@ -337,6 +337,25 @@ Grid.Column="1" Width="400" Margin="{StaticResource Margin4}" /> + + + + vm.SelectedSource.Id, v => v.txtId7.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath7.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.Ports, v => v.txtPorts7.Text).DisposeWith(disposables); break; case EConfigType.TUIC: diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml b/v2rayN/v2rayN/Views/AddServerWindow.xaml index ce908673..3013cd43 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml @@ -1,4 +1,4 @@ - + + + + + - \ No newline at end of file + diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index 3afe8a9f..c29b3416 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -172,6 +172,7 @@ namespace v2rayN.Views case EConfigType.Hysteria2: this.Bind(ViewModel, vm => vm.SelectedSource.Id, v => v.txtId7.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath7.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedSource.Ports, v => v.txtPorts7.Text).DisposeWith(disposables); break; case EConfigType.TUIC: