Add Hy2 Port hopping URI support

This commit is contained in:
DHR60 2025-03-02 15:13:23 +08:00
parent 438eaba4d5
commit d1e25f6913
2 changed files with 15 additions and 1 deletions

View file

@ -24,6 +24,8 @@ namespace ServiceLib.Handler.Fmt
item.Path = Utils.UrlDecode(query["obfs-password"] ?? ""); item.Path = Utils.UrlDecode(query["obfs-password"] ?? "");
item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false"; item.AllowInsecure = (query["insecure"] ?? "") == "1" ? "true" : "false";
item.Ports = Utils.UrlDecode(query["mport"] ?? "").Replace('-', ':');
return item; return item;
} }
@ -53,6 +55,10 @@ namespace ServiceLib.Handler.Fmt
dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path)); dicQuery.Add("obfs-password", Utils.UrlEncode(item.Path));
} }
dicQuery.Add("insecure", item.AllowInsecure.ToLower() == "true" ? "1" : "0"); 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); return ToUri(EConfigType.Hysteria2, item.Address, item.Port, item.Id, dicQuery, remark);
} }

View file

@ -733,7 +733,15 @@ namespace ServiceLib.Services.CoreConfig
if (node.Ports.IsNotEmpty()) if (node.Ports.IsNotEmpty())
{ {
outbound.server_port = null; 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; outbound.hop_interval = _config.HysteriaItem.HopInterval > 0 ? $"{_config.HysteriaItem.HopInterval}s" : null;
} }