From 81efd25e0a59413e69b9565da1d295e21da3caa8 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:45:53 +0800 Subject: [PATCH] Added Hysteria2 support (using sing-box) --- v2rayN/v2rayN/Global.cs | 1 + v2rayN/v2rayN/Handler/ConfigHandler.cs | 14 ++++++- v2rayN/v2rayN/Handler/CoreConfigSingbox.cs | 3 ++ v2rayN/v2rayN/Handler/ShareHandler.cs | 2 +- v2rayN/v2rayN/Handler/SpeedtestHandler.cs | 2 +- v2rayN/v2rayN/Mode/Config.cs | 3 +- v2rayN/v2rayN/Mode/ConfigItems.cs | 9 ++++- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 9 +++++ v2rayN/v2rayN/Resx/ResUI.resx | 3 ++ v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 3 ++ .../ViewModels/OptionSettingViewModel.cs | 10 ++++- v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 40 +++++++++++++++++-- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 2 + 13 files changed, 89 insertions(+), 12 deletions(-) diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs index 78b2723a..b596371d 100644 --- a/v2rayN/v2rayN/Global.cs +++ b/v2rayN/v2rayN/Global.cs @@ -75,6 +75,7 @@ public const string trojanProtocol = "trojan://"; public const string trojanProtocolLite = "trojan"; public const string hysteria2Protocol = "hysteria2://"; + public const string hysteria2Protocol2 = "hy2://"; public const string hysteria2ProtocolLite = "hysteria2"; public const string userEMail = "t@t.tt"; diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 177ade0c..2d4f2105 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -184,9 +184,9 @@ namespace v2rayN.Handler config.speedTestItem.speedPingTestUrl = Global.SpeedPingTestUrl; } - if (config.mux4Sbox == null) + if (config.mux4SboxItem == null) { - config.mux4Sbox = new() + config.mux4SboxItem = new() { protocol = Global.SingboxMuxs[0], max_connections = 4, @@ -196,6 +196,16 @@ namespace v2rayN.Handler }; } + if (config.hysteriaItem == null) + { + config.hysteriaItem = new() + { + up_mbps = 100, + down_mbps = 100 + }; + } + + LazyConfig.Instance.SetConfig(config); return 0; } diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index 8d991471..328bdf74 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -289,6 +289,9 @@ namespace v2rayN.Handler outbound.password = node.id; + outbound.up_mbps = _config.hysteriaItem.up_mbps > 0 ? _config.hysteriaItem.up_mbps : null; + outbound.down_mbps = _config.hysteriaItem.down_mbps > 0 ? _config.hysteriaItem.down_mbps : null; + outboundMux(node, outbound); } diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs index 292e3ab0..14932a40 100644 --- a/v2rayN/v2rayN/Handler/ShareHandler.cs +++ b/v2rayN/v2rayN/Handler/ShareHandler.cs @@ -383,7 +383,7 @@ namespace v2rayN.Handler { profileItem = ResolveStdVLESS(result); } - else if (result.StartsWith(Global.hysteria2Protocol)) + else if (result.StartsWith(Global.hysteria2Protocol) || result.StartsWith(Global.hysteria2Protocol2)) { msg = ResUI.ConfigurationFormatIncorrect; diff --git a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs index bb1d3b66..2b9715e0 100644 --- a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs +++ b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs @@ -30,7 +30,7 @@ namespace v2rayN.Handler _selecteds = new List(); foreach (var it in selecteds) { - if (it.configType == EConfigType.Custom) + if (it.configType == EConfigType.Custom || it.configType == EConfigType.Hysteria2) { continue; } diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index f6639b93..a8c0ea27 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -27,7 +27,8 @@ public UIItem uiItem { get; set; } public ConstItem constItem { get; set; } public SpeedTestItem speedTestItem { get; set; } - public Mux4Sbox mux4Sbox { get; set; } + public Mux4SboxItem mux4SboxItem { get; set; } + public HysteriaItem hysteriaItem { get; set; } public List inbound { get; set; } public List globalHotkeys { get; set; } public List coreTypeItem { get; set; } diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index 799ed299..ef83051b 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -198,7 +198,7 @@ namespace v2rayN.Mode } [Serializable] - public class Mux4Sbox + public class Mux4SboxItem { public string protocol { get; set; } public int max_connections { get; set; } @@ -206,4 +206,11 @@ namespace v2rayN.Mode public int max_streams { get; set; } public bool padding { get; set; } } + + [Serializable] + public class HysteriaItem + { + public int up_mbps { get; set; } + public int down_mbps { get; set; } + } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index beaab19f..50408a1d 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -2563,6 +2563,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Hysteria Max bandwidth (Up/Dw) 的本地化字符串。 + /// + public static string TbSettingsHysteriaBandwidth { + get { + return ResourceManager.GetString("TbSettingsHysteriaBandwidth", resourceCulture); + } + } + /// /// 查找类似 Ignore Geo files when updating core 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index 77912383..eda26622 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1141,4 +1141,7 @@ Add [Trojan] server + + Hysteria Max bandwidth (Up/Dw) + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index 6ac5ee40..2aa6b98b 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1138,4 +1138,7 @@ 添加[Hysteria2]服务器 + + Hysteria 最大带宽(Up/Dw) + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index 7f621858..fe0547e2 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -32,6 +32,8 @@ namespace v2rayN.ViewModels [Reactive] public string defFingerprint { get; set; } [Reactive] public string defUserAgent { get; set; } [Reactive] public string mux4SboxProtocol { get; set; } + [Reactive] public int hyUpMbps { get; set; } + [Reactive] public int hyDownMbps { get; set; } #endregion Core @@ -120,7 +122,9 @@ namespace v2rayN.ViewModels defAllowInsecure = _config.coreBasicItem.defAllowInsecure; defFingerprint = _config.coreBasicItem.defFingerprint; defUserAgent = _config.coreBasicItem.defUserAgent; - mux4SboxProtocol = _config.mux4Sbox.protocol; + mux4SboxProtocol = _config.mux4SboxItem.protocol; + hyUpMbps = _config.hysteriaItem.up_mbps; + hyDownMbps = _config.hysteriaItem.down_mbps; #endregion Core @@ -274,7 +278,9 @@ namespace v2rayN.ViewModels _config.coreBasicItem.defAllowInsecure = defAllowInsecure; _config.coreBasicItem.defFingerprint = defFingerprint; _config.coreBasicItem.defUserAgent = defUserAgent; - _config.mux4Sbox.protocol = mux4SboxProtocol; + _config.mux4SboxItem.protocol = mux4SboxProtocol; + _config.hysteriaItem.up_mbps = hyUpMbps; + _config.hysteriaItem.down_mbps = hyDownMbps; //Kcp //_config.kcpItem.mtu = Kcpmtu; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index c2683b15..2569fb89 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -1,12 +1,12 @@  + @@ -307,6 +308,37 @@ Width="200" Margin="{StaticResource SettingItemMargin}" Style="{StaticResource DefComboBox}" /> + + + + + + + + + + + + diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 1e768442..637d1465 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -151,6 +151,8 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.defFingerprint, v => v.cmbdefFingerprint.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.defUserAgent, v => v.cmbdefUserAgent.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.mux4SboxProtocol, v => v.cmbmux4SboxProtocol.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.hyUpMbps, v => v.txtUpMbps.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.hyDownMbps, v => v.txtDownMbps.Text).DisposeWith(disposables); //this.Bind(ViewModel, vm => vm.Kcpmtu, v => v.txtKcpmtu.Text).DisposeWith(disposables); //this.Bind(ViewModel, vm => vm.Kcptti, v => v.txtKcptti.Text).DisposeWith(disposables);