Fix udphop (#10550)

This commit is contained in:
DHR60
2026-11-08 08:02:49 +00:00
committed by GitHub
parent 54ecc045b5
commit 5ca37027fd
2 changed files with 42 additions and 39 deletions
@@ -319,6 +319,7 @@ public class StreamSettings4Ray
public GrpcSettings4Ray? grpcSettings { get; set; } public GrpcSettings4Ray? grpcSettings { get; set; }
public HysteriaSettings4Ray? hysteriaSettings { get; set; } public HysteriaSettings4Ray? hysteriaSettings { get; set; }
public MasqueSettings4Ray? masqueSettings { get; set; } public MasqueSettings4Ray? masqueSettings { get; set; }
public JsonObject? finalmask { get; set; } public JsonObject? finalmask { get; set; }
@@ -461,12 +462,6 @@ public class MasqueWarpSettings4Ray
public List<string>? address { get; set; } public List<string>? address { get; set; }
} }
public class UdpHop4Ray
{
public string? ports { get; set; }
public string? interval { get; set; }
}
public class Finalmask4Ray public class Finalmask4Ray
{ {
public List<Mask4Ray>? tcp { get; set; } public List<Mask4Ray>? tcp { get; set; }
@@ -491,6 +486,12 @@ public class MaskSettings4Ray
public List<string>? stunServers { get; set; } public List<string>? stunServers { get; set; }
public string? packetSize { get; set; } public string? packetSize { get; set; }
// udphop
public string? mode { get; set; }
public string? interval { get; set; }
// public List<string>? remoteIPs { get; set; }
public string? remotePorts { get; set; }
// fragment // fragment
public string? packets { get; set; } public string? packets { get; set; }
@@ -517,7 +518,6 @@ public class QuicParams4Ray
public string? congestion { get; set; } public string? congestion { get; set; }
public string? brutalUp { get; set; } public string? brutalUp { get; set; }
public string? brutalDown { get; set; } public string? brutalDown { get; set; }
public UdpHop4Ray? udpHop { get; set; }
} }
public class AccountsItem4Ray public class AccountsItem4Ray
@@ -394,17 +394,6 @@ public partial class CoreConfigV2rayService
}; };
var kcpFinalmask = new Finalmask4Ray(); var kcpFinalmask = new Finalmask4Ray();
if (Global.KcpHeaderMaskMap.TryGetValue(headerType, out var header))
{
kcpFinalmask.udp =
[
new Mask4Ray
{
type = "mkcp-legacy",
settings = new MaskSettings4Ray { header = header },
}
];
}
kcpFinalmask.udp ??= []; kcpFinalmask.udp ??= [];
if (kcpSeed.IsNullOrEmpty()) if (kcpSeed.IsNullOrEmpty())
{ {
@@ -421,7 +410,17 @@ public partial class CoreConfigV2rayService
settings = new MaskSettings4Ray { value = kcpSeed }, settings = new MaskSettings4Ray { value = kcpSeed },
}); });
} }
kcpFinalmask.udp?.Reverse(); if (Global.KcpHeaderMaskMap.TryGetValue(headerType, out var header))
{
kcpFinalmask.udp =
[
new Mask4Ray
{
type = "mkcp-legacy",
settings = new MaskSettings4Ray { header = header },
},
];
}
streamSettings.kcpSettings = kcpSettings; streamSettings.kcpSettings = kcpSettings;
streamSettings.finalmask = (JsonObject)JsonUtils.SerializeToNode(kcpFinalmask); streamSettings.finalmask = (JsonObject)JsonUtils.SerializeToNode(kcpFinalmask);
break; break;
@@ -522,16 +521,6 @@ public partial class CoreConfigV2rayService
: Global.Hysteria2DefaultHopInt).ToString(); : Global.Hysteria2DefaultHopInt).ToString();
var hy2Finalmask = new Finalmask4Ray(); var hy2Finalmask = new Finalmask4Ray();
var quicParams = new QuicParams4Ray(); var quicParams = new QuicParams4Ray();
if (!ports.IsNullOrEmpty() &&
(ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))
{
var udpHop = new UdpHop4Ray
{
ports = ports.Replace(':', '-'),
interval = hopInterval,
};
quicParams.udpHop = udpHop;
}
if (upMbps > 0 || downMbps > 0) if (upMbps > 0 || downMbps > 0)
{ {
quicParams.congestion = "brutal"; quicParams.congestion = "brutal";
@@ -544,15 +533,6 @@ public partial class CoreConfigV2rayService
} }
hy2Finalmask.quicParams = quicParams; hy2Finalmask.quicParams = quicParams;
hy2Finalmask.udp ??= []; hy2Finalmask.udp ??= [];
if (HyRealm.TryParse(protocolExtra.Hy2RealmUrl, out var realm)
&& realm is not null)
{
hy2Finalmask.udp.Add(new Mask4Ray
{
type = "realm",
settings = new MaskSettings4Ray { url = realm.ToUriForFinalmask(), stunServers = realm.StunList },
});
}
if (!protocolExtra.SalamanderPass.IsNullOrEmpty()) if (!protocolExtra.SalamanderPass.IsNullOrEmpty())
{ {
var isGecko = !protocolExtra.GeckoMinPacketSize.IsNullOrEmpty() || !protocolExtra.GeckoMaxPacketSize.IsNullOrEmpty(); var isGecko = !protocolExtra.GeckoMinPacketSize.IsNullOrEmpty() || !protocolExtra.GeckoMaxPacketSize.IsNullOrEmpty();
@@ -570,12 +550,35 @@ public partial class CoreConfigV2rayService
settings = salamanderSettings, settings = salamanderSettings,
}); });
} }
if (HyRealm.TryParse(protocolExtra.Hy2RealmUrl, out var realm)
&& realm is not null)
{
hy2Finalmask.udp.Add(new Mask4Ray
{
type = "realm",
settings = new MaskSettings4Ray { url = realm.ToUriForFinalmask(), stunServers = realm.StunList },
});
}
else if (!ports.IsNullOrEmpty()
&& (ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))
{
var udpHopFinalmask = new Mask4Ray
{
type = "udphop",
settings = new MaskSettings4Ray
{
mode = "intervallocal,intervalremote",
interval = hopInterval,
remotePorts = ports.Replace(':', '-'),
},
};
hy2Finalmask.udp.Add(udpHopFinalmask);
}
streamSettings.hysteriaSettings = new() streamSettings.hysteriaSettings = new()
{ {
version = 2, version = 2,
auth = _node.Password, auth = _node.Password,
}; };
hy2Finalmask.udp?.Reverse();
streamSettings.finalmask = (JsonObject)JsonUtils.SerializeToNode(hy2Finalmask); streamSettings.finalmask = (JsonObject)JsonUtils.SerializeToNode(hy2Finalmask);
break; break;