Skip to content

Commit

Permalink
Add Hy2 Port hopping URI support (#6848)
Browse files Browse the repository at this point in the history
  • Loading branch information
DHR60 authored Mar 3, 2025
1 parent 67fe6ac commit 8dcf5c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Hysteria2Fmt : BaseFmt
item.Path = Utils.UrlDecode(query["obfs-password"] ?? "");
item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";

item.Ports = Utils.UrlDecode(query["mport"] ?? "").Replace('-', ':');

return item;
}

Expand Down Expand Up @@ -53,6 +55,10 @@ public class Hysteria2Fmt : BaseFmt
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
}
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0");
if (Utils.IsNotEmpty(item.Ports))
{
dicQuery.Add("mport", Utils.UrlEncode(item.Ports.Replace(':', '-')));
}

return ToUri(EConfigType.Hysteria2, item.Address, item.Port, item.Id, dicQuery, remark);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,15 @@ private async Task<int> GenOutbound(ProfileItem node, Outbound4Sbox outbound)
if (node.Ports.IsNotEmpty())
{
outbound.server_port = null;
outbound.server_ports = node.Ports.Split(",").ToList();
outbound.server_ports = new List<string>();
var ports = node.Ports.Split(',')
.Select(p => p.Trim())
.Where(p => !string.IsNullOrEmpty(p))
.ToList();
foreach (var it in ports)
{
outbound.server_ports.Add(it.Contains('-') ? it.Replace('-', ':') : it);
}
outbound.hop_interval = _config.HysteriaItem.HopInterval > 0 ? $"{_config.HysteriaItem.HopInterval}s" : null;
}

Expand Down

0 comments on commit 8dcf5c5

Please # to comment.