From 8dcf5c5b901b8e84a7817e316b8fab4770435108 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 3 Mar 2025 14:11:53 +0800 Subject: [PATCH] Add Hy2 Port hopping URI support (#6848) --- v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs | 6 ++++++ .../Services/CoreConfig/CoreConfigSingboxService.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs index b57abe0a..be6630e1 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs @@ -24,6 +24,8 @@ namespace ServiceLib.Handler.Fmt item.Path = Utils.UrlDecode(query["obfs-password"] ?? ""); item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false"; + item.Ports = Utils.UrlDecode(query["mport"] ?? "").Replace('-', ':'); + return item; } @@ -53,6 +55,10 @@ namespace ServiceLib.Handler.Fmt 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); } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 39c6f0fd..f4b9658c 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -733,7 +733,15 @@ namespace ServiceLib.Services.CoreConfig if (node.Ports.IsNotEmpty()) { outbound.server_port = null; - outbound.server_ports = node.Ports.Split(",").ToList(); + outbound.server_ports = new List(); + 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; }