Added Hysteria2 support (using sing-box)

pull/4457/head
2dust 2023-11-28 15:45:53 +08:00
parent 7037009ce4
commit 81efd25e0a
13 changed files with 89 additions and 12 deletions

View File

@ -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";

View File

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

View File

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

View File

@ -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;

View File

@ -30,7 +30,7 @@ namespace v2rayN.Handler
_selecteds = new List<ServerTestItem>();
foreach (var it in selecteds)
{
if (it.configType == EConfigType.Custom)
if (it.configType == EConfigType.Custom || it.configType == EConfigType.Hysteria2)
{
continue;
}

View File

@ -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<InItem> inbound { get; set; }
public List<KeyEventItem> globalHotkeys { get; set; }
public List<CoreTypeItem> coreTypeItem { get; set; }

View File

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

View File

@ -2563,6 +2563,15 @@ namespace v2rayN.Resx {
}
}
/// <summary>
/// 查找类似 Hysteria Max bandwidth (Up/Dw) 的本地化字符串。
/// </summary>
public static string TbSettingsHysteriaBandwidth {
get {
return ResourceManager.GetString("TbSettingsHysteriaBandwidth", resourceCulture);
}
}
/// <summary>
/// 查找类似 Ignore Geo files when updating core 的本地化字符串。
/// </summary>

View File

@ -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>

View File

@ -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>

View File

@ -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;

View File

@ -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}"
@ -68,6 +68,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@ -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>

View File

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