diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 7add585f..94a66fa5 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -300,6 +300,7 @@ public class Global EConfigType.VLESS, EConfigType.Shadowsocks, EConfigType.Trojan, + EConfigType.Hysteria2, EConfigType.WireGuard, EConfigType.SOCKS, EConfigType.HTTP, diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 5b34e9bf..5877d012 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -703,7 +703,7 @@ public static class ConfigHandler public static async Task AddHysteria2Server(Config config, ProfileItem profileItem, bool toFile = true) { profileItem.ConfigType = EConfigType.Hysteria2; - profileItem.CoreType = ECoreType.sing_box; + //profileItem.CoreType = ECoreType.sing_box; profileItem.Address = profileItem.Address.TrimEx(); profileItem.Id = profileItem.Id.TrimEx(); diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs index 9593b54e..54566238 100644 --- a/v2rayN/ServiceLib/Models/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs @@ -128,7 +128,8 @@ public class Outboundsettings4Ray public string? secretKey { get; set; } - public List? address { get; set; } + public Object? address { get; set; } + public int? port { get; set; } public List? peers { get; set; } @@ -139,6 +140,8 @@ public class Outboundsettings4Ray public List? reserved { get; set; } public int? workers { get; set; } + + public int? version { get; set; } } public class WireguardPeer4Ray @@ -336,6 +339,10 @@ public class StreamSettings4Ray public GrpcSettings4Ray? grpcSettings { get; set; } + public HysteriaSettings4Ray? hysteriaSettings { get; set; } + + public List? udpmasks { get; set; } + public Sockopt4Ray? sockopt { get; set; } } @@ -460,6 +467,32 @@ public class GrpcSettings4Ray public int? initial_windows_size { get; set; } } +public class HysteriaSettings4Ray +{ + public int version { get; set; } + public string? auth { get; set; } + public string? up { get; set; } + public string? down { get; set; } + public HysteriaUdpHop4Ray? udphop { get; set; } +} + +public class HysteriaUdpHop4Ray +{ + public string? ports { get; set; } + public int? interval { get; set; } +} + +public class UdpMasks4Ray +{ + public string type { get; set; } + public UdpMasksSettings4Ray? settings { get; set; } +} + +public class UdpMasksSettings4Ray +{ + public string? password { get; set; } +} + public class AccountsItem4Ray { public string user { get; set; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index 274431b3..3db5a420 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -178,6 +178,18 @@ public partial class CoreConfigV2rayService outbound.settings.vnext = null; break; } + case EConfigType.Hysteria2: + { + outbound.settings = new() + { + version = 2, + address = node.Address, + port = node.Port, + }; + outbound.settings.vnext = null; + outbound.settings.servers = null; + break; + } case EConfigType.WireGuard: { var address = node.Address; @@ -206,6 +218,10 @@ public partial class CoreConfigV2rayService } outbound.protocol = Global.ProtocolTypes[node.ConfigType]; + if (node.ConfigType == EConfigType.Hysteria2) + { + outbound.protocol = "hysteria"; + } await GenBoundStreamSettings(node, outbound); } catch (Exception ex) @@ -246,7 +262,12 @@ public partial class CoreConfigV2rayService try { var streamSettings = outbound.streamSettings; - streamSettings.network = node.GetNetwork(); + var network = node.GetNetwork(); + if (node.ConfigType == EConfigType.Hysteria2) + { + network = "hysteria"; + } + streamSettings.network = network; var host = node.RequestHost.TrimEx(); var path = node.Path.TrimEx(); var sni = node.Sni.TrimEx(); @@ -328,7 +349,7 @@ public partial class CoreConfigV2rayService } //streamSettings - switch (node.GetNetwork()) + switch (network) { case nameof(ETransport.kcp): KcpSettings4Ray kcpSettings = new() @@ -467,6 +488,35 @@ public partial class CoreConfigV2rayService streamSettings.grpcSettings = grpcSettings; break; + case "hysteria": + HysteriaUdpHop4Ray? udpHop = null; + if (node.Ports.IsNotEmpty() && + (node.Ports.Contains(':') || node.Ports.Contains('-') || node.Ports.Contains(','))) + { + udpHop = new() + { + ports = node.Ports.Replace(':', '-'), + interval = _config.HysteriaItem.HopInterval > 0 + ? _config.HysteriaItem.HopInterval + : null, + }; + } + HysteriaSettings4Ray hysteriaSettings = new() + { + version = 2, + auth = node.Id, + up = _config.HysteriaItem.UpMbps > 0 ? $"{_config.HysteriaItem.UpMbps}mbps" : null, + down = _config.HysteriaItem.DownMbps > 0 ? $"{_config.HysteriaItem.DownMbps}mbps" : null, + udphop = udpHop, + }; + streamSettings.hysteriaSettings = hysteriaSettings; + if (node.Path.IsNotEmpty()) + { + streamSettings.udpmasks = + [new() { type = "salamander", settings = new() { password = node.Path.TrimEx(), } }]; + } + break; + default: //tcp if (node.HeaderType == Global.TcpHeaderHttp) diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs index 680a637a..9220e8ae 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml.cs @@ -75,7 +75,6 @@ public partial class AddServerWindow : WindowBase gridHysteria2.IsVisible = true; sepa2.IsVisible = false; gridTransport.IsVisible = false; - cmbCoreType.IsEnabled = false; cmbFingerprint.IsEnabled = false; cmbFingerprint.SelectedValue = string.Empty; break; diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml index b5930e6a..ca59c472 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml @@ -43,11 +43,11 @@ + - diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index c49d4149..1136220d 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -70,7 +70,6 @@ public partial class AddServerWindow gridHysteria2.Visibility = Visibility.Visible; sepa2.Visibility = Visibility.Collapsed; gridTransport.Visibility = Visibility.Collapsed; - cmbCoreType.IsEnabled = false; cmbFingerprint.IsEnabled = false; cmbFingerprint.Text = string.Empty; break; diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index e331448f..1c49ca24 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -99,6 +99,10 @@ x:Name="menuAddTrojanServer" Height="{StaticResource MenuItemHeight}" Header="{x:Static resx:ResUI.menuAddTrojanServer}" /> + -