add xray wireguard support

This commit is contained in:
DHR60 2025-04-09 12:50:54 +08:00
parent 75b399b48b
commit efe2124274
4 changed files with 47 additions and 7 deletions

View file

@ -1,3 +1,4 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
@ -86,7 +87,8 @@ public class JsonUtils
var options = new JsonSerializerOptions
{
WriteIndented = indented,
DefaultIgnoreCondition = nullValue ? JsonIgnoreCondition.Never : JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = nullValue ? JsonIgnoreCondition.Never : JsonIgnoreCondition.WhenWritingNull,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping // 避免转义加号
};
result = JsonSerializer.Serialize(obj, options);
}

View file

@ -101,7 +101,7 @@ public class CoreHandler
public async Task<int> LoadCoreConfigSpeedtest(List<ServerTestItem> selecteds)
{
var coreType = selecteds.Exists(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard) ? ECoreType.sing_box : ECoreType.Xray;
var coreType = selecteds.Exists(t => t.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC) ? ECoreType.sing_box : ECoreType.Xray;
var fileName = string.Format(Global.CoreSpeedtestConfigFileName, Utils.GetGuid(false));
var configPath = Utils.GetBinConfigPath(fileName);
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);

View file

@ -127,6 +127,26 @@ public class Outboundsettings4Ray
public int? userLevel { get; set; }
public FragmentItem4Ray? fragment { get; set; }
public string? secretKey { get; set; }
public List<string>? address { get; set; }
public List<WireguardPeer4Ray>? peers { get; set; }
public bool? noKernelTun { get; set; }
public int? mtu { get; set; }
public List<int>? reserved { get; set; }
public int? workers { get; set; }
}
public class WireguardPeer4Ray
{
public string endpoint { get; set; }
public string publicKey { get; set; }
}
public class VnextItem4Ray

View file

@ -120,7 +120,7 @@ public class CoreConfigV2rayService
{
continue;
}
if (it.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC or EConfigType.WireGuard)
if (it.ConfigType is EConfigType.Hysteria2 or EConfigType.TUIC)
{
continue;
}
@ -805,6 +805,26 @@ public class CoreConfigV2rayService
outbound.settings.vnext = null;
break;
}
case EConfigType.WireGuard:
{
var peer = new WireguardPeer4Ray
{
publicKey = node.PublicKey,
endpoint = node.Address + ":" + node.Port.ToString()
};
var setting = new Outboundsettings4Ray
{
address = Utils.String2List(node.RequestHost),
secretKey = node.Id,
reserved = Utils.String2List(node.Path)?.Select(int.Parse).ToList(),
mtu = node.ShortId.IsNullOrEmpty() ? Global.TunMtus.First() : node.ShortId.ToInt(),
peers = new List<WireguardPeer4Ray> { peer }
};
outbound.settings = setting;
outbound.settings.vnext = null;
outbound.settings.servers = null;
break;
}
}
outbound.protocol = Global.ProtocolTypes[node.ConfigType];
@ -1270,8 +1290,7 @@ public class CoreConfigV2rayService
if (prevNode is not null
&& prevNode.ConfigType != EConfigType.Custom
&& prevNode.ConfigType != EConfigType.Hysteria2
&& prevNode.ConfigType != EConfigType.TUIC
&& prevNode.ConfigType != EConfigType.WireGuard)
&& prevNode.ConfigType != EConfigType.TUIC)
{
var prevOutbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound);
await GenOutbound(prevNode, prevOutbound);
@ -1289,8 +1308,7 @@ public class CoreConfigV2rayService
if (nextNode is not null
&& nextNode.ConfigType != EConfigType.Custom
&& nextNode.ConfigType != EConfigType.Hysteria2
&& nextNode.ConfigType != EConfigType.TUIC
&& nextNode.ConfigType != EConfigType.WireGuard)
&& nextNode.ConfigType != EConfigType.TUIC)
{
var nextOutbound = JsonUtils.Deserialize<Outbounds4Ray>(txtOutbound);
await GenOutbound(nextNode, nextOutbound);