Skip to content

Commit

Permalink
Add obfs 4 hysteria2
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 22, 2024
1 parent d76679c commit ff91a5d
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ public static int AddHysteria2Server(Config config, ProfileItem profileItem, boo

profileItem.address = profileItem.address.TrimEx();
profileItem.id = profileItem.id.TrimEx();
profileItem.path = profileItem.path.TrimEx();
profileItem.network = string.Empty;

if (Utils.IsNullOrEmpty(profileItem.streamSecurity))
Expand Down
9 changes: 9 additions & 0 deletions v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ private int GenOutbound(ProfileItem node, Outbound4Sbox outbound)

outbound.password = node.id;

if (!Utils.IsNullOrEmpty(node.path))
{
outbound.obfs = new()
{
type = "salamander",
password = node.path.TrimEx(),
};
}

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;

Expand Down
6 changes: 6 additions & 0 deletions v2rayN/v2rayN/Handler/ShareHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ private static string ShareHysteria2(ProfileItem item)
{
dicQuery.Add("alpn", Utils.UrlEncode(item.alpn));
}
if (!Utils.IsNullOrEmpty(item.path))
{
dicQuery.Add("obfs", "salamander");
dicQuery.Add("obfs-password", Utils.UrlEncode(item.path));
}
dicQuery.Add("insecure", item.allowInsecure.ToLower() == "true" ? "1" : "0");

string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
Expand Down Expand Up @@ -883,6 +888,7 @@ private static ProfileItem ResolveHysteria2(string result)

var query = Utils.ParseQueryString(url.Query);
ResolveStdTransport(query, ref item);
item.path = Utils.UrlDecode(query["obfs-password"] ?? "");
item.allowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";

return item;
Expand Down
7 changes: 7 additions & 0 deletions v2rayN/v2rayN/Mode/SingboxConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class Outbound4Sbox
public Tls4Sbox tls { get; set; }
public Multiplex4Sbox multiplex { get; set; }
public Transport4Sbox transport { get; set; }
public HyObfs4Sbox obfs { get; set; }
}

public class Tls4Sbox
Expand Down Expand Up @@ -174,6 +175,12 @@ public class Headers4Sbox
public string? Host { get; set; }
}

public class HyObfs4Sbox
{
public string? type { get; set; }
public string? password { get; set; }
}

public class Server4Sbox
{
public string tag { get; set; }
Expand Down
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 @@ -1180,4 +1180,7 @@
<data name="TbLocalAddress" xml:space="preserve">
<value>Address(Ip,Ipv6)</value>
</data>
<data name="TbPath7" xml:space="preserve">
<value>obfs password</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 @@ -1177,4 +1177,7 @@
<data name="TbLocalAddress" xml:space="preserve">
<value>Address(Ip,Ipv6)</value>
</data>
<data name="TbPath7" xml:space="preserve">
<value>混淆密码(obfs password)</value>
</data>
</root>
16 changes: 16 additions & 0 deletions v2rayN/v2rayN/Views/AddServerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180" />
Expand All @@ -449,6 +450,21 @@
Width="400"
Margin="{StaticResource ServerItemMargin}"
Style="{StaticResource DefTextBox}" />

<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource ServerItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbPath7}" />
<TextBox
x:Name="txtPath7"
Grid.Row="2"
Grid.Column="1"
Width="400"
Margin="{StaticResource ServerItemMargin}"
Style="{StaticResource DefTextBox}" />
</Grid>
<Grid
x:Name="gridTuic"
Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Views/AddServerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public AddServerWindow(ProfileItem profileItem)

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

case EConfigType.Tuic:
Expand Down

0 comments on commit ff91a5d

Please sign in to comment.