Skip to content

Commit

Permalink
Added Hysteria2 support (using sing-box)
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Nov 28, 2023
1 parent 7037009 commit 81efd25
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 12 deletions.
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ internal class Global
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 = "[email protected]";
Expand Down
14 changes: 12 additions & 2 deletions v2rayN/v2rayN/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public static int LoadConfig(ref Config config)
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,
Expand All @@ -196,6 +196,16 @@ public static int LoadConfig(ref Config config)
};
}

if (config.hysteriaItem == null)
{
config.hysteriaItem = new()
{
up_mbps = 100,
down_mbps = 100
};
}


LazyConfig.Instance.SetConfig(config);
return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ private int outbound(ProfileItem node, SingboxConfig singboxConfig)

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);
}

Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Handler/ShareHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private static int GetStdTransport(ProfileItem item, string? securityDef, ref Di
{
profileItem = ResolveStdVLESS(result);
}
else if (result.StartsWith(Global.hysteria2Protocol))
else if (result.StartsWith(Global.hysteria2Protocol) || result.StartsWith(Global.hysteria2Protocol2))
{
msg = ResUI.ConfigurationFormatIncorrect;

Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Handler/SpeedtestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SpeedtestHandler(Config config, CoreHandler coreHandler, List<ProfileItem
_selecteds = new List<ServerTestItem>();
foreach (var it in selecteds)
{
if (it.configType == EConfigType.Custom)
if (it.configType == EConfigType.Custom || it.configType == EConfigType.Hysteria2)
{
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion v2rayN/v2rayN/Mode/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class Config
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<InItem> inbound { get; set; }
public List<KeyEventItem> globalHotkeys { get; set; }
public List<CoreTypeItem> coreTypeItem { get; set; }
Expand Down
9 changes: 8 additions & 1 deletion v2rayN/v2rayN/Mode/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,19 @@ public class ColumnItem
}

[Serializable]
public class Mux4Sbox
public class Mux4SboxItem
{
public string protocol { get; set; }
public int max_connections { get; set; }
public int min_streams { get; set; }
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; }
}
}
9 changes: 9 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,7 @@
<data name="menuAddHysteria2Server" xml:space="preserve">
<value>Add [Trojan] server</value>
</data>
<data name="TbSettingsHysteriaBandwidth" xml:space="preserve">
<value>Hysteria Max bandwidth (Up/Dw)</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1138,4 +1138,7 @@
<data name="menuAddHysteria2Server" xml:space="preserve">
<value>添加[Hysteria2]服务器</value>
</data>
<data name="TbSettingsHysteriaBandwidth" xml:space="preserve">
<value>Hysteria 最大带宽(Up/Dw)</value>
</data>
</root>
10 changes: 8 additions & 2 deletions v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class OptionSettingViewModel : ReactiveObject
[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

Expand Down Expand Up @@ -120,7 +122,9 @@ public OptionSettingViewModel(Window view)
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

Expand Down Expand Up @@ -274,7 +278,9 @@ private void SaveSetting()
_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;
Expand Down
40 changes: 36 additions & 4 deletions v2rayN/v2rayN/Views/OptionSettingWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow
x:Class="v2rayN.Views.OptionSettingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuSetting}"
Expand Down Expand Up @@ -68,6 +68,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -307,6 +308,37 @@
Width="200"
Margin="{StaticResource SettingItemMargin}"
Style="{StaticResource DefComboBox}" />


<TextBlock
Grid.Row="15"
Grid.Column="0"
Margin="{StaticResource SettingItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsHysteriaBandwidth}" />

<StackPanel
Grid.Row="15"
Grid.Column="1"
Orientation="Horizontal">

<TextBox
x:Name="txtUpMbps"
Width="90"
Margin="{StaticResource SettingItemMargin}"
materialDesign:HintAssist.Hint="Up"
Style="{StaticResource DefTextBox}" />
<TextBox
x:Name="txtDownMbps"
Width="90"
Margin="{StaticResource SettingItemMargin}"
materialDesign:HintAssist.Hint="Down"
Style="{StaticResource DefTextBox}" />

</StackPanel>


</Grid>
</ScrollViewer>
</TabItem>
Expand Down
2 changes: 2 additions & 0 deletions v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public OptionSettingWindow()
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);
Expand Down

0 comments on commit 81efd25

Please sign in to comment.