Refactor transport

This commit is contained in:
DHR60 2026-03-28 21:18:58 +08:00
parent 0db611b7a9
commit 060310118b
19 changed files with 1342 additions and 619 deletions

@ -1 +1 @@
Subproject commit 50f615b671ff8d4a6a850aed19da5f94f58b5d96 Subproject commit ffb2850df0991495d0918e13cc5701737f26175a

View file

@ -293,13 +293,11 @@ public class Global
public static readonly List<string> Networks = public static readonly List<string> Networks =
[ [
"tcp", "tcp",
"kcp",
"ws",
"httpupgrade",
"xhttp", "xhttp",
"h2", "kcp",
"quic", "grpc",
"grpc" "ws",
"httpupgrade"
]; ];
public static readonly List<string> KcpHeaderTypes = public static readonly List<string> KcpHeaderTypes =

View file

@ -340,8 +340,9 @@ public class CoreConfigContextBuilder
} }
// xhttp downloadSettings address protect // xhttp downloadSettings address protect
if (!string.IsNullOrEmpty(node.Extra) var xhttpExtra = node.GetTransportExtra().XhttpExtra;
&& JsonUtils.ParseJson(node.Extra) is JsonObject extra if (!string.IsNullOrEmpty(xhttpExtra)
&& JsonUtils.ParseJson(xhttpExtra) is JsonObject extra
&& extra.TryGetPropertyValue("downloadSettings", out var dsNode) && extra.TryGetPropertyValue("downloadSettings", out var dsNode)
&& dsNode is JsonObject downloadSettings && dsNode is JsonObject downloadSettings
&& downloadSettings.TryGetPropertyValue("address", out var dAddrNode) && downloadSettings.TryGetPropertyValue("address", out var dAddrNode)

View file

@ -20,7 +20,7 @@ public class NodeValidator
[EConfigType.VMess, EConfigType.VLESS, EConfigType.Trojan, EConfigType.Shadowsocks]; [EConfigType.VMess, EConfigType.VLESS, EConfigType.Trojan, EConfigType.Shadowsocks];
private static readonly HashSet<string> SingboxShadowsocksAllowedTransports = private static readonly HashSet<string> SingboxShadowsocksAllowedTransports =
[nameof(ETransport.tcp), nameof(ETransport.ws), nameof(ETransport.quic)]; [nameof(ETransport.tcp), nameof(ETransport.ws)];
public static NodeValidatorResult Validate(ProfileItem item, ECoreType coreType) public static NodeValidatorResult Validate(ProfileItem item, ECoreType coreType)
{ {
@ -141,9 +141,10 @@ public class NodeValidator
v.Assert(!item.PublicKey.IsNullOrEmpty(), string.Format(ResUI.MsgInvalidProperty, "PublicKey")); v.Assert(!item.PublicKey.IsNullOrEmpty(), string.Format(ResUI.MsgInvalidProperty, "PublicKey"));
} }
if (item.Network == nameof(ETransport.xhttp) && !item.Extra.IsNullOrEmpty()) var transport = item.GetTransportExtra();
if (item.Network == nameof(ETransport.xhttp) && !transport.XhttpExtra.IsNullOrEmpty())
{ {
if (JsonUtils.ParseJson(item.Extra) is not JsonObject) if (JsonUtils.ParseJson(transport.XhttpExtra) is not JsonObject)
{ {
v.Error(string.Format(ResUI.MsgInvalidProperty, "XHTTP Extra")); v.Error(string.Format(ResUI.MsgInvalidProperty, "XHTTP Extra"));
} }

View file

@ -236,9 +236,6 @@ public static class ConfigHandler
item.Password = profileItem.Password; item.Password = profileItem.Password;
item.Network = profileItem.Network; item.Network = profileItem.Network;
item.HeaderType = profileItem.HeaderType;
item.RequestHost = profileItem.RequestHost;
item.Path = profileItem.Path;
item.StreamSecurity = profileItem.StreamSecurity; item.StreamSecurity = profileItem.StreamSecurity;
item.Sni = profileItem.Sni; item.Sni = profileItem.Sni;
@ -250,7 +247,6 @@ public static class ConfigHandler
item.ShortId = profileItem.ShortId; item.ShortId = profileItem.ShortId;
item.SpiderX = profileItem.SpiderX; item.SpiderX = profileItem.SpiderX;
item.Mldsa65Verify = profileItem.Mldsa65Verify; item.Mldsa65Verify = profileItem.Mldsa65Verify;
item.Extra = profileItem.Extra;
item.MuxEnabled = profileItem.MuxEnabled; item.MuxEnabled = profileItem.MuxEnabled;
item.Cert = profileItem.Cert; item.Cert = profileItem.Cert;
item.CertSha = profileItem.CertSha; item.CertSha = profileItem.CertSha;
@ -297,9 +293,6 @@ public static class ConfigHandler
VmessSecurity = profileItem.GetProtocolExtra().VmessSecurity?.TrimEx() VmessSecurity = profileItem.GetProtocolExtra().VmessSecurity?.TrimEx()
}); });
profileItem.Network = profileItem.Network.TrimEx(); profileItem.Network = profileItem.Network.TrimEx();
profileItem.HeaderType = profileItem.HeaderType.TrimEx();
profileItem.RequestHost = profileItem.RequestHost.TrimEx();
profileItem.Path = profileItem.Path.TrimEx();
profileItem.StreamSecurity = profileItem.StreamSecurity.TrimEx(); profileItem.StreamSecurity = profileItem.StreamSecurity.TrimEx();
if (!Global.VmessSecurities.Contains(profileItem.GetProtocolExtra().VmessSecurity)) if (!Global.VmessSecurities.Contains(profileItem.GetProtocolExtra().VmessSecurity))
@ -751,10 +744,12 @@ public static class ConfigHandler
profileItem.Password = profileItem.Password.TrimEx(); profileItem.Password = profileItem.Password.TrimEx();
profileItem.Network = string.Empty; profileItem.Network = string.Empty;
if (!Global.TuicCongestionControls.Contains(profileItem.HeaderType)) var congestionControl = profileItem.GetProtocolExtra().CongestionControl;
if (!Global.TuicCongestionControls.Contains(congestionControl))
{ {
profileItem.HeaderType = Global.TuicCongestionControls.FirstOrDefault()!; congestionControl = Global.TuicCongestionControls.FirstOrDefault()!;
} }
profileItem.SetProtocolExtra(profileItem.GetProtocolExtra() with { CongestionControl = congestionControl });
if (profileItem.StreamSecurity.IsNullOrEmpty()) if (profileItem.StreamSecurity.IsNullOrEmpty())
{ {
@ -996,9 +991,6 @@ public static class ConfigHandler
profileItem.Address = profileItem.Address.TrimEx(); profileItem.Address = profileItem.Address.TrimEx();
profileItem.Password = profileItem.Password.TrimEx(); profileItem.Password = profileItem.Password.TrimEx();
profileItem.Network = profileItem.Network.TrimEx(); profileItem.Network = profileItem.Network.TrimEx();
profileItem.HeaderType = profileItem.HeaderType.TrimEx();
profileItem.RequestHost = profileItem.RequestHost.TrimEx();
profileItem.Path = profileItem.Path.TrimEx();
profileItem.StreamSecurity = profileItem.StreamSecurity.TrimEx(); profileItem.StreamSecurity = profileItem.StreamSecurity.TrimEx();
var vlessEncryption = profileItem.GetProtocolExtra().VlessEncryption?.TrimEx(); var vlessEncryption = profileItem.GetProtocolExtra().VlessEncryption?.TrimEx();
@ -1067,7 +1059,7 @@ public static class ConfigHandler
/// <returns>0 if successful</returns> /// <returns>0 if successful</returns>
public static async Task<int> AddServerCommon(Config config, ProfileItem profileItem, bool toFile = true) public static async Task<int> AddServerCommon(Config config, ProfileItem profileItem, bool toFile = true)
{ {
profileItem.ConfigVersion = 3; profileItem.ConfigVersion = 4;
if (profileItem.StreamSecurity.IsNotEmpty()) if (profileItem.StreamSecurity.IsNotEmpty())
{ {
@ -1135,6 +1127,8 @@ public static class ConfigHandler
var oProtocolExtra = o.GetProtocolExtra(); var oProtocolExtra = o.GetProtocolExtra();
var nProtocolExtra = n.GetProtocolExtra(); var nProtocolExtra = n.GetProtocolExtra();
var oTransport = oProtocolExtra.Transport ?? new TransportExtra();
var nTransport = nProtocolExtra.Transport ?? new TransportExtra();
return o.ConfigType == n.ConfigType return o.ConfigType == n.ConfigType
&& AreEqual(o.Address, n.Address) && AreEqual(o.Address, n.Address)
@ -1145,9 +1139,21 @@ public static class ConfigHandler
&& AreEqual(oProtocolExtra.SsMethod, nProtocolExtra.SsMethod) && AreEqual(oProtocolExtra.SsMethod, nProtocolExtra.SsMethod)
&& AreEqual(oProtocolExtra.VmessSecurity, nProtocolExtra.VmessSecurity) && AreEqual(oProtocolExtra.VmessSecurity, nProtocolExtra.VmessSecurity)
&& AreEqual(o.Network, n.Network) && AreEqual(o.Network, n.Network)
&& AreEqual(o.HeaderType, n.HeaderType) && AreEqual(oTransport.TcpHeaderType, nTransport.TcpHeaderType)
&& AreEqual(o.RequestHost, n.RequestHost) && AreEqual(oTransport.TcpHost, nTransport.TcpHost)
&& AreEqual(o.Path, n.Path) && AreEqual(oTransport.WsHost, nTransport.WsHost)
&& AreEqual(oTransport.WsPath, nTransport.WsPath)
&& AreEqual(oTransport.HttpupgradeHost, nTransport.HttpupgradeHost)
&& AreEqual(oTransport.HttpupgradePath, nTransport.HttpupgradePath)
&& AreEqual(oTransport.XhttpHost, nTransport.XhttpHost)
&& AreEqual(oTransport.XhttpPath, nTransport.XhttpPath)
&& AreEqual(oTransport.XhttpMode, nTransport.XhttpMode)
&& AreEqual(oTransport.XhttpExtra, nTransport.XhttpExtra)
&& AreEqual(oTransport.GrpcAuthority, nTransport.GrpcAuthority)
&& AreEqual(oTransport.GrpcServiceName, nTransport.GrpcServiceName)
&& AreEqual(oTransport.GrpcMode, nTransport.GrpcMode)
&& AreEqual(oTransport.KcpHeaderType, nTransport.KcpHeaderType)
&& AreEqual(oTransport.KcpSeed, nTransport.KcpSeed)
&& (o.ConfigType == EConfigType.Trojan || o.StreamSecurity == n.StreamSecurity) && (o.ConfigType == EConfigType.Trojan || o.StreamSecurity == n.StreamSecurity)
&& AreEqual(oProtocolExtra.Flow, nProtocolExtra.Flow) && AreEqual(oProtocolExtra.Flow, nProtocolExtra.Flow)
&& AreEqual(oProtocolExtra.SalamanderPass, nProtocolExtra.SalamanderPass) && AreEqual(oProtocolExtra.SalamanderPass, nProtocolExtra.SalamanderPass)

View file

@ -21,6 +21,8 @@ public class BaseFmt
protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery) protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
{ {
var transport = item.GetTransportExtra();
if (item.StreamSecurity.IsNotEmpty()) if (item.StreamSecurity.IsNotEmpty())
{ {
dicQuery.Add("security", item.StreamSecurity); dicQuery.Add("security", item.StreamSecurity);
@ -87,54 +89,70 @@ public class BaseFmt
dicQuery.Add("fm", Utils.UrlEncode(finalmask)); dicQuery.Add("fm", Utils.UrlEncode(finalmask));
} }
dicQuery.Add("type", item.Network.IsNotEmpty() ? item.Network : nameof(ETransport.tcp)); var network = item.GetNetwork();
if (!Global.Networks.Contains(network))
{
network = nameof(ETransport.tcp);
}
switch (item.Network) dicQuery.Add("type", network);
switch (network)
{ {
case nameof(ETransport.tcp): case nameof(ETransport.tcp):
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None); dicQuery.Add("headerType", transport.TcpHeaderType.IsNotEmpty() ? transport.TcpHeaderType : Global.None);
if (item.RequestHost.IsNotEmpty()) if (transport.TcpHost.IsNotEmpty())
{ {
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost)); dicQuery.Add("host", Utils.UrlEncode(transport.TcpHost));
} }
break; break;
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None); dicQuery.Add("headerType", transport.KcpHeaderType.IsNotEmpty() ? transport.KcpHeaderType : Global.None);
if (item.Path.IsNotEmpty()) if (transport.KcpSeed.IsNotEmpty())
{ {
dicQuery.Add("seed", Utils.UrlEncode(item.Path)); dicQuery.Add("seed", Utils.UrlEncode(transport.KcpSeed));
} }
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
case nameof(ETransport.httpupgrade): if (transport.WsHost.IsNotEmpty())
if (item.RequestHost.IsNotEmpty())
{ {
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost)); dicQuery.Add("host", Utils.UrlEncode(transport.WsHost));
} }
if (item.Path.IsNotEmpty()) if (transport.WsPath.IsNotEmpty())
{ {
dicQuery.Add("path", Utils.UrlEncode(item.Path)); dicQuery.Add("path", Utils.UrlEncode(transport.WsPath));
}
break;
case nameof(ETransport.httpupgrade):
if (transport.HttpupgradeHost.IsNotEmpty())
{
dicQuery.Add("host", Utils.UrlEncode(transport.HttpupgradeHost));
}
if (transport.HttpupgradePath.IsNotEmpty())
{
dicQuery.Add("path", Utils.UrlEncode(transport.HttpupgradePath));
} }
break; break;
case nameof(ETransport.xhttp): case nameof(ETransport.xhttp):
if (item.RequestHost.IsNotEmpty()) if (transport.XhttpHost.IsNotEmpty())
{ {
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost)); dicQuery.Add("host", Utils.UrlEncode(transport.XhttpHost));
} }
if (item.Path.IsNotEmpty()) if (transport.XhttpPath.IsNotEmpty())
{ {
dicQuery.Add("path", Utils.UrlEncode(item.Path)); dicQuery.Add("path", Utils.UrlEncode(transport.XhttpPath));
} }
if (item.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(item.HeaderType)) if (transport.XhttpMode.IsNotEmpty() && Global.XhttpMode.Contains(transport.XhttpMode))
{ {
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType)); dicQuery.Add("mode", Utils.UrlEncode(transport.XhttpMode));
} }
if (item.Extra.IsNotEmpty()) if (transport.XhttpExtra.IsNotEmpty())
{ {
var node = JsonUtils.ParseJson(item.Extra); var node = JsonUtils.ParseJson(transport.XhttpExtra);
var extra = node != null var extra = node != null
? JsonUtils.Serialize(node, new JsonSerializerOptions ? JsonUtils.Serialize(node, new JsonSerializerOptions
{ {
@ -142,38 +160,19 @@ public class BaseFmt
DefaultIgnoreCondition = JsonIgnoreCondition.Never, DefaultIgnoreCondition = JsonIgnoreCondition.Never,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}) })
: item.Extra; : transport.XhttpExtra;
dicQuery.Add("extra", Utils.UrlEncode(extra)); dicQuery.Add("extra", Utils.UrlEncode(extra));
} }
break; break;
case nameof(ETransport.http):
case nameof(ETransport.h2):
dicQuery["type"] = nameof(ETransport.http);
if (item.RequestHost.IsNotEmpty())
{
dicQuery.Add("host", Utils.UrlEncode(item.RequestHost));
}
if (item.Path.IsNotEmpty())
{
dicQuery.Add("path", Utils.UrlEncode(item.Path));
}
break;
case nameof(ETransport.quic):
dicQuery.Add("headerType", item.HeaderType.IsNotEmpty() ? item.HeaderType : Global.None);
dicQuery.Add("quicSecurity", Utils.UrlEncode(item.RequestHost));
dicQuery.Add("key", Utils.UrlEncode(item.Path));
break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
if (item.Path.IsNotEmpty()) if (transport.GrpcServiceName.IsNotEmpty())
{ {
dicQuery.Add("authority", Utils.UrlEncode(item.RequestHost)); dicQuery.Add("authority", Utils.UrlEncode(transport.GrpcAuthority));
dicQuery.Add("serviceName", Utils.UrlEncode(item.Path)); dicQuery.Add("serviceName", Utils.UrlEncode(transport.GrpcServiceName));
if (item.HeaderType is Global.GrpcGunMode or Global.GrpcMultiMode) if (transport.GrpcMode is Global.GrpcGunMode or Global.GrpcMultiMode)
{ {
dicQuery.Add("mode", Utils.UrlEncode(item.HeaderType)); dicQuery.Add("mode", Utils.UrlEncode(transport.GrpcMode));
} }
} }
break; break;
@ -216,6 +215,8 @@ public class BaseFmt
protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem item) protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem item)
{ {
var transport = item.GetTransportExtra();
item.StreamSecurity = GetQueryValue(query, "security"); item.StreamSecurity = GetQueryValue(query, "security");
item.Sni = GetQueryValue(query, "sni"); item.Sni = GetQueryValue(query, "sni");
item.Alpn = GetQueryDecoded(query, "alpn"); item.Alpn = GetQueryDecoded(query, "alpn");
@ -258,36 +259,56 @@ public class BaseFmt
item.AllowInsecure = string.Empty; item.AllowInsecure = string.Empty;
} }
item.Network = GetQueryValue(query, "type", nameof(ETransport.tcp)); var net = GetQueryValue(query, "type", nameof(ETransport.tcp));
if (!Global.Networks.Contains(net))
{
net = nameof(ETransport.tcp);
}
item.Network = net;
switch (item.Network) switch (item.Network)
{ {
case nameof(ETransport.tcp): case nameof(ETransport.tcp):
item.HeaderType = GetQueryValue(query, "headerType", Global.None); transport = transport with
item.RequestHost = GetQueryDecoded(query, "host"); {
TcpHeaderType = GetQueryValue(query, "headerType", Global.None),
TcpHost = GetQueryDecoded(query, "host"),
};
break; break;
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
item.HeaderType = GetQueryValue(query, "headerType", Global.None); var kcpSeed = GetQueryDecoded(query, "seed");
item.Path = GetQueryDecoded(query, "seed"); transport = transport with
{
KcpHeaderType = GetQueryValue(query, "headerType", Global.None),
KcpSeed = kcpSeed,
};
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
transport = transport with
{
WsHost = GetQueryDecoded(query, "host"),
WsPath = GetQueryDecoded(query, "path", "/"),
};
break;
case nameof(ETransport.httpupgrade): case nameof(ETransport.httpupgrade):
item.RequestHost = GetQueryDecoded(query, "host"); transport = transport with
item.Path = GetQueryDecoded(query, "path", "/"); {
HttpupgradeHost = GetQueryDecoded(query, "host"),
HttpupgradePath = GetQueryDecoded(query, "path", "/"),
};
break; break;
case nameof(ETransport.xhttp): case nameof(ETransport.xhttp):
item.RequestHost = GetQueryDecoded(query, "host"); var xhttpExtra = GetQueryDecoded(query, "extra");
item.Path = GetQueryDecoded(query, "path", "/"); if (xhttpExtra.IsNotEmpty())
item.HeaderType = GetQueryDecoded(query, "mode");
var extraDecoded = GetQueryDecoded(query, "extra");
if (extraDecoded.IsNotEmpty())
{ {
var node = JsonUtils.ParseJson(extraDecoded); var node = JsonUtils.ParseJson(xhttpExtra);
if (node != null) if (node != null)
{ {
extraDecoded = JsonUtils.Serialize(node, new JsonSerializerOptions xhttpExtra = JsonUtils.Serialize(node, new JsonSerializerOptions
{ {
WriteIndented = true, WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.Never, DefaultIgnoreCondition = JsonIgnoreCondition.Never,
@ -295,31 +316,32 @@ public class BaseFmt
}); });
} }
} }
item.Extra = extraDecoded;
break;
case nameof(ETransport.http): transport = transport with
case nameof(ETransport.h2): {
item.Network = nameof(ETransport.h2); XhttpHost = GetQueryDecoded(query, "host"),
item.RequestHost = GetQueryDecoded(query, "host"); XhttpPath = GetQueryDecoded(query, "path", "/"),
item.Path = GetQueryDecoded(query, "path", "/"); XhttpMode = GetQueryDecoded(query, "mode"),
break; XhttpExtra = xhttpExtra,
};
case nameof(ETransport.quic):
item.HeaderType = GetQueryValue(query, "headerType", Global.None);
item.RequestHost = GetQueryValue(query, "quicSecurity", Global.None);
item.Path = GetQueryDecoded(query, "key");
break; break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
item.RequestHost = GetQueryDecoded(query, "authority"); transport = transport with
item.Path = GetQueryDecoded(query, "serviceName"); {
item.HeaderType = GetQueryDecoded(query, "mode", Global.GrpcGunMode); GrpcAuthority = GetQueryDecoded(query, "authority"),
GrpcServiceName = GetQueryDecoded(query, "serviceName"),
GrpcMode = GetQueryDecoded(query, "mode", Global.GrpcGunMode),
};
break; break;
default: default:
item.Network = nameof(ETransport.tcp);
break; break;
} }
item.SetTransportExtra(transport);
return 0; return 0;
} }

View file

@ -42,31 +42,28 @@ public class ShadowsocksFmt : BaseFmt
//url = Utile.Base64Encode(url); //url = Utile.Base64Encode(url);
//new Sip002 //new Sip002
var pw = Utils.Base64Encode($"{item.GetProtocolExtra().SsMethod}:{item.Password}", true); var pw = Utils.Base64Encode($"{item.GetProtocolExtra().SsMethod}:{item.Password}", true);
var transport = item.GetTransportExtra();
// plugin // plugin
var plugin = string.Empty; var plugin = string.Empty;
var pluginArgs = string.Empty; var pluginArgs = string.Empty;
if (item.Network == nameof(ETransport.tcp) && item.HeaderType == Global.TcpHeaderHttp) if (item.Network == nameof(ETransport.tcp) && transport.TcpHeaderType == Global.TcpHeaderHttp)
{ {
plugin = "obfs-local"; plugin = "obfs-local";
pluginArgs = $"obfs=http;obfs-host={item.RequestHost};"; pluginArgs = $"obfs=http;obfs-host={transport.TcpHost};";
} }
else else
{ {
if (item.Network == nameof(ETransport.ws)) if (item.Network == nameof(ETransport.ws))
{ {
pluginArgs += "mode=websocket;"; pluginArgs += "mode=websocket;";
pluginArgs += $"host={item.RequestHost};"; pluginArgs += $"host={transport.WsHost};";
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172 // https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
// Equal signs and commas [and backslashes] must be escaped with a backslash. // Equal signs and commas [and backslashes] must be escaped with a backslash.
var path = item.Path.Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,"); var path = (transport.WsPath ?? string.Empty).Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,");
pluginArgs += $"path={path};"; pluginArgs += $"path={path};";
} }
else if (item.Network == nameof(ETransport.quic))
{
pluginArgs += "mode=quic;";
}
if (item.StreamSecurity == Global.StreamSecurity) if (item.StreamSecurity == Global.StreamSecurity)
{ {
pluginArgs += "tls;"; pluginArgs += "tls;";
@ -213,8 +210,11 @@ public class ShadowsocksFmt : BaseFmt
{ {
obfsHost = obfsHost.Replace("obfs-host=", ""); obfsHost = obfsHost.Replace("obfs-host=", "");
item.Network = Global.DefaultNetwork; item.Network = Global.DefaultNetwork;
item.HeaderType = Global.TcpHeaderHttp; item.SetTransportExtra(item.GetTransportExtra() with
item.RequestHost = obfsHost; {
TcpHeaderType = Global.TcpHeaderHttp,
TcpHost = obfsHost,
});
} }
} }
// Parse v2ray-plugin // Parse v2ray-plugin
@ -231,21 +231,20 @@ public class ShadowsocksFmt : BaseFmt
if (modeValue == "websocket") if (modeValue == "websocket")
{ {
item.Network = nameof(ETransport.ws); item.Network = nameof(ETransport.ws);
var t = item.GetTransportExtra();
if (!host.IsNullOrEmpty()) if (!host.IsNullOrEmpty())
{ {
item.RequestHost = host.Replace("host=", ""); var wsHost = host.Replace("host=", "");
item.Sni = item.RequestHost; t = t with { WsHost = wsHost };
item.Sni = wsHost;
} }
if (!path.IsNullOrEmpty()) if (!path.IsNullOrEmpty())
{ {
var pathValue = path.Replace("path=", ""); var pathValue = path.Replace("path=", "");
pathValue = pathValue.Replace("\\=", "=").Replace("\\,", ",").Replace("\\\\", "\\"); pathValue = pathValue.Replace("\\=", "=").Replace("\\,", ",").Replace("\\\\", "\\");
item.Path = pathValue; t = t with { WsPath = pathValue };
} }
} item.SetTransportExtra(t);
else if (modeValue == "quic")
{
item.Network = nameof(ETransport.quic);
} }
if (hasTls) if (hasTls)

View file

@ -26,6 +26,7 @@ public class VmessFmt : BaseFmt
var vmessQRCode = new VmessQRCode var vmessQRCode = new VmessQRCode
{ {
// vmess link keeps shared transport keys; map from new transport model on export.
v = 2, v = 2,
ps = item.Remarks.TrimEx(), ps = item.Remarks.TrimEx(),
add = item.Address, add = item.Address,
@ -34,9 +35,32 @@ public class VmessFmt : BaseFmt
aid = int.TryParse(item.GetProtocolExtra()?.AlterId, out var result) ? result : 0, aid = int.TryParse(item.GetProtocolExtra()?.AlterId, out var result) ? result : 0,
scy = item.GetProtocolExtra().VmessSecurity ?? "", scy = item.GetProtocolExtra().VmessSecurity ?? "",
net = item.Network, net = item.Network,
type = item.HeaderType, type = item.GetNetwork() switch
host = item.RequestHost, {
path = item.Path, nameof(ETransport.tcp) => item.GetTransportExtra().TcpHeaderType,
nameof(ETransport.kcp) => item.GetTransportExtra().KcpHeaderType,
nameof(ETransport.xhttp) => item.GetTransportExtra().XhttpMode,
nameof(ETransport.grpc) => item.GetTransportExtra().GrpcMode,
_ => Global.None,
},
host = item.GetNetwork() switch
{
nameof(ETransport.tcp) => item.GetTransportExtra().TcpHost,
nameof(ETransport.ws) => item.GetTransportExtra().WsHost,
nameof(ETransport.httpupgrade) => item.GetTransportExtra().HttpupgradeHost,
nameof(ETransport.xhttp) => item.GetTransportExtra().XhttpHost,
nameof(ETransport.grpc) => item.GetTransportExtra().GrpcAuthority,
_ => null,
},
path = item.GetNetwork() switch
{
nameof(ETransport.kcp) => item.GetTransportExtra().KcpSeed,
nameof(ETransport.ws) => item.GetTransportExtra().WsPath,
nameof(ETransport.httpupgrade) => item.GetTransportExtra().HttpupgradePath,
nameof(ETransport.xhttp) => item.GetTransportExtra().XhttpPath,
nameof(ETransport.grpc) => item.GetTransportExtra().GrpcServiceName,
_ => null,
},
tls = item.StreamSecurity, tls = item.StreamSecurity,
sni = item.Sni, sni = item.Sni,
alpn = item.Alpn, alpn = item.Alpn,
@ -70,7 +94,10 @@ public class VmessFmt : BaseFmt
} }
item.Network = Global.DefaultNetwork; item.Network = Global.DefaultNetwork;
item.HeaderType = Global.None; var transport = new TransportExtra
{
TcpHeaderType = Global.None,
};
//item.ConfigVersion = vmessQRCode.v; //item.ConfigVersion = vmessQRCode.v;
item.Remarks = Utils.ToString(vmessQRCode.ps); item.Remarks = Utils.ToString(vmessQRCode.ps);
@ -88,11 +115,26 @@ public class VmessFmt : BaseFmt
} }
if (vmessQRCode.type.IsNotEmpty()) if (vmessQRCode.type.IsNotEmpty())
{ {
item.HeaderType = vmessQRCode.type; transport = item.GetNetwork() switch
{
nameof(ETransport.tcp) => transport with { TcpHeaderType = vmessQRCode.type },
nameof(ETransport.kcp) => transport with { KcpHeaderType = vmessQRCode.type },
nameof(ETransport.xhttp) => transport with { XhttpMode = vmessQRCode.type },
nameof(ETransport.grpc) => transport with { GrpcMode = vmessQRCode.type },
_ => transport,
};
} }
transport = item.GetNetwork() switch
item.RequestHost = Utils.ToString(vmessQRCode.host); {
item.Path = Utils.ToString(vmessQRCode.path); nameof(ETransport.tcp) => transport with { TcpHost = Utils.ToString(vmessQRCode.host) },
nameof(ETransport.kcp) => transport with { KcpSeed = Utils.ToString(vmessQRCode.path) },
nameof(ETransport.ws) => transport with { WsHost = Utils.ToString(vmessQRCode.host), WsPath = Utils.ToString(vmessQRCode.path) },
nameof(ETransport.httpupgrade) => transport with { HttpupgradeHost = Utils.ToString(vmessQRCode.host), HttpupgradePath = Utils.ToString(vmessQRCode.path) },
nameof(ETransport.xhttp) => transport with { XhttpHost = Utils.ToString(vmessQRCode.host), XhttpPath = Utils.ToString(vmessQRCode.path) },
nameof(ETransport.grpc) => transport with { GrpcAuthority = Utils.ToString(vmessQRCode.host), GrpcServiceName = Utils.ToString(vmessQRCode.path) },
_ => transport,
};
item.SetTransportExtra(transport);
item.StreamSecurity = Utils.ToString(vmessQRCode.tls); item.StreamSecurity = Utils.ToString(vmessQRCode.tls);
item.Sni = Utils.ToString(vmessQRCode.sni); item.Sni = Utils.ToString(vmessQRCode.sni);
item.Alpn = Utils.ToString(vmessQRCode.alpn); item.Alpn = Utils.ToString(vmessQRCode.alpn);

View file

@ -309,8 +309,15 @@ public sealed class AppManager
public async Task MigrateProfileExtra() public async Task MigrateProfileExtra()
{ {
await MigrateProfileExtraGroup(); await MigrateProfileExtraGroupV2ToV3();
await MigrateProfileExtraV2ToV3();
await MigrateProfileTransportV3ToV4();
}
private async Task MigrateProfileExtraV2ToV3()
{
const int pageSize = 100; const int pageSize = 100;
var offset = 0; var offset = 0;
@ -326,7 +333,7 @@ public sealed class AppManager
break; break;
} }
var batchSuccessCount = await MigrateProfileExtraSub(batch); var batchSuccessCount = await MigrateProfileExtraV2ToV3Sub(batch);
// Only increment offset by the number of failed items that remain in the result set // Only increment offset by the number of failed items that remain in the result set
// Successfully updated items are automatically excluded from future queries due to ConfigVersion = 3 // Successfully updated items are automatically excluded from future queries due to ConfigVersion = 3
@ -336,7 +343,123 @@ public sealed class AppManager
//await ProfileGroupItemManager.Instance.ClearAll(); //await ProfileGroupItemManager.Instance.ClearAll();
} }
private async Task<int> MigrateProfileExtraSub(List<ProfileItem> batch) private async Task MigrateProfileTransportV3ToV4()
{
const int pageSize = 100;
var offset = 0;
while (true)
{
var sql = $"SELECT * FROM ProfileItem WHERE ConfigVersion = 3 LIMIT {pageSize} OFFSET {offset}";
var batch = await SQLiteHelper.Instance.QueryAsync<ProfileItem>(sql);
if (batch is null || batch.Count == 0)
{
break;
}
var updateProfileItems = new List<ProfileItem>();
foreach (var item in batch)
{
try
{
var extra = item.GetProtocolExtra();
var transport = extra.Transport ?? new TransportExtra();
var network = item.GetNetwork();
switch (network)
{
case nameof(ETransport.tcp):
transport = transport with
{
TcpHeaderType = item.HeaderType.NullIfEmpty(),
TcpHost = item.RequestHost.NullIfEmpty(),
};
break;
case nameof(ETransport.ws):
transport = transport with
{
WsHost = item.RequestHost.NullIfEmpty(),
WsPath = item.Path.NullIfEmpty(),
};
break;
case nameof(ETransport.httpupgrade):
transport = transport with
{
HttpupgradeHost = item.RequestHost.NullIfEmpty(),
HttpupgradePath = item.Path.NullIfEmpty(),
};
break;
case nameof(ETransport.xhttp):
transport = transport with
{
XhttpHost = item.RequestHost.NullIfEmpty(),
XhttpPath = item.Path.NullIfEmpty(),
XhttpMode = item.HeaderType.NullIfEmpty(),
XhttpExtra = item.Extra.NullIfEmpty(),
};
break;
case nameof(ETransport.grpc):
transport = transport with
{
GrpcAuthority = item.RequestHost.NullIfEmpty(),
GrpcServiceName = item.Path.NullIfEmpty(),
GrpcMode = item.HeaderType.NullIfEmpty(),
};
break;
case nameof(ETransport.kcp):
transport = transport with
{
KcpHeaderType = item.HeaderType.NullIfEmpty(),
KcpSeed = item.Path.NullIfEmpty(),
};
break;
default:
item.Network = Global.DefaultNetwork;
transport = transport with
{
TcpHeaderType = item.HeaderType.NullIfEmpty(),
TcpHost = item.RequestHost.NullIfEmpty(),
};
break;
}
item.SetProtocolExtra(extra with { Transport = transport });
item.ConfigVersion = 4;
updateProfileItems.Add(item);
}
catch (Exception ex)
{
Logging.SaveLog($"MigrateProfileTransportV3ToV4 Error: {ex}");
}
}
if (updateProfileItems.Count > 0)
{
try
{
var count = await SQLiteHelper.Instance.UpdateAllAsync(updateProfileItems);
offset += batch.Count - count;
}
catch (Exception ex)
{
Logging.SaveLog($"MigrateProfileTransportV3ToV4 update error: {ex}");
offset += batch.Count;
}
}
else
{
offset += batch.Count;
}
}
}
private async Task<int> MigrateProfileExtraV2ToV3Sub(List<ProfileItem> batch)
{ {
var updateProfileItems = new List<ProfileItem>(); var updateProfileItems = new List<ProfileItem>();
@ -434,7 +557,7 @@ public sealed class AppManager
} }
} }
private async Task<bool> MigrateProfileExtraGroup() private async Task<bool> MigrateProfileExtraGroupV2ToV3()
{ {
var list = await SQLiteHelper.Instance.TableAsync<ProfileGroupItem>().ToListAsync(); var list = await SQLiteHelper.Instance.TableAsync<ProfileGroupItem>().ToListAsync();
var groupItems = new ConcurrentDictionary<string, ProfileGroupItem>(list.Where(t => !string.IsNullOrEmpty(t.IndexId)).ToDictionary(t => t.IndexId!)); var groupItems = new ConcurrentDictionary<string, ProfileGroupItem>(list.Where(t => !string.IsNullOrEmpty(t.IndexId)).ToDictionary(t => t.IndexId!));

View file

@ -9,7 +9,7 @@ public class ProfileItem
{ {
IndexId = string.Empty; IndexId = string.Empty;
ConfigType = EConfigType.VMess; ConfigType = EConfigType.VMess;
ConfigVersion = 3; ConfigVersion = 4;
Subid = string.Empty; Subid = string.Empty;
Address = string.Empty; Address = string.Empty;
Port = 0; Port = 0;
@ -17,9 +17,6 @@ public class ProfileItem
Username = string.Empty; Username = string.Empty;
Network = string.Empty; Network = string.Empty;
Remarks = string.Empty; Remarks = string.Empty;
HeaderType = string.Empty;
RequestHost = string.Empty;
Path = string.Empty;
StreamSecurity = string.Empty; StreamSecurity = string.Empty;
AllowInsecure = string.Empty; AllowInsecure = string.Empty;
} }
@ -142,6 +139,16 @@ public class ProfileItem
return _protocolExtraCache ??= JsonUtils.Deserialize<ProtocolExtraItem>(ProtoExtra) ?? new ProtocolExtraItem(); return _protocolExtraCache ??= JsonUtils.Deserialize<ProtocolExtraItem>(ProtoExtra) ?? new ProtocolExtraItem();
} }
public TransportExtra GetTransportExtra()
{
return GetProtocolExtra().Transport ?? new TransportExtra();
}
public void SetTransportExtra(TransportExtra transportExtra)
{
SetProtocolExtra(GetProtocolExtra() with { Transport = transportExtra });
}
#endregion function #endregion function
[PrimaryKey] [PrimaryKey]
@ -160,8 +167,11 @@ public class ProfileItem
public string Password { get; set; } public string Password { get; set; }
public string Username { get; set; } public string Username { get; set; }
public string Network { get; set; } public string Network { get; set; }
[Obsolete("Use TransportExtra.TcpHeaderType/XhttpMode/GrpcMode/KcpHeaderType instead.")]
public string HeaderType { get; set; } public string HeaderType { get; set; }
[Obsolete("Use TransportExtra.TcpHost/WsHost/HttpupgradeHost/XhttpHost/GrpcAuthority instead.")]
public string RequestHost { get; set; } public string RequestHost { get; set; }
[Obsolete("Use TransportExtra.WsPath/HttpupgradePath/XhttpPath/GrpcServiceName/KcpSeed instead.")]
public string Path { get; set; } public string Path { get; set; }
public string StreamSecurity { get; set; } public string StreamSecurity { get; set; }
public string AllowInsecure { get; set; } public string AllowInsecure { get; set; }
@ -172,6 +182,7 @@ public class ProfileItem
public string ShortId { get; set; } public string ShortId { get; set; }
public string SpiderX { get; set; } public string SpiderX { get; set; }
public string Mldsa65Verify { get; set; } public string Mldsa65Verify { get; set; }
[Obsolete("Use TransportExtra.XhttpExtra instead.")]
public string Extra { get; set; } public string Extra { get; set; }
public bool? MuxEnabled { get; set; } public bool? MuxEnabled { get; set; }
public string Cert { get; set; } public string Cert { get; set; }

View file

@ -2,6 +2,8 @@ namespace ServiceLib.Models;
public record ProtocolExtraItem public record ProtocolExtraItem
{ {
public TransportExtra? Transport { get; init; }
public bool? Uot { get; init; } public bool? Uot { get; init; }
public string? CongestionControl { get; init; } public string? CongestionControl { get; init; }

View file

@ -0,0 +1,25 @@
namespace ServiceLib.Models;
public record TransportExtra
{
public string? TcpHeaderType { get; init; }
public string? TcpHost { get; init; }
public string? WsHost { get; init; }
public string? WsPath { get; init; }
public string? HttpupgradeHost { get; init; }
public string? HttpupgradePath { get; init; }
public string? XhttpHost { get; init; }
public string? XhttpPath { get; init; }
public string? XhttpMode { get; init; }
public string? XhttpExtra { get; init; }
public string? GrpcAuthority { get; init; }
public string? GrpcServiceName { get; init; }
public string? GrpcMode { get; init; }
public string? KcpHeaderType { get; init; }
public string? KcpSeed { get; init; }
}

View file

@ -84,6 +84,8 @@ public partial class CoreConfigSingboxService
try try
{ {
var protocolExtra = _node.GetProtocolExtra(); var protocolExtra = _node.GetProtocolExtra();
var transportExtra = _node.GetTransportExtra();
var network = _node.GetNetwork();
outbound.server = _node.Address; outbound.server = _node.Address;
outbound.server_port = _node.Port; outbound.server_port = _node.Port;
outbound.type = Global.ProtocolTypes[_node.ConfigType]; outbound.type = Global.ProtocolTypes[_node.ConfigType];
@ -114,27 +116,23 @@ public partial class CoreConfigSingboxService
outbound.password = _node.Password; outbound.password = _node.Password;
outbound.udp_over_tcp = protocolExtra.Uot == true ? true : null; outbound.udp_over_tcp = protocolExtra.Uot == true ? true : null;
if (_node.Network == nameof(ETransport.tcp) && _node.HeaderType == Global.TcpHeaderHttp) if (network == nameof(ETransport.tcp) && transportExtra.TcpHeaderType == Global.TcpHeaderHttp)
{ {
outbound.plugin = "obfs-local"; outbound.plugin = "obfs-local";
outbound.plugin_opts = $"obfs=http;obfs-host={_node.RequestHost};"; outbound.plugin_opts = $"obfs=http;obfs-host={transportExtra.TcpHost};";
} }
else else
{ {
var pluginArgs = string.Empty; var pluginArgs = string.Empty;
if (_node.Network == nameof(ETransport.ws)) if (network == nameof(ETransport.ws))
{ {
pluginArgs += "mode=websocket;"; pluginArgs += "mode=websocket;";
pluginArgs += $"host={_node.RequestHost};"; pluginArgs += $"host={transportExtra.WsHost};";
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172 // https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
// Equal signs and commas [and backslashes] must be escaped with a backslash. // Equal signs and commas [and backslashes] must be escaped with a backslash.
var path = _node.Path.Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,"); var path = (transportExtra.WsPath ?? string.Empty).Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,");
pluginArgs += $"path={path};"; pluginArgs += $"path={path};";
} }
else if (_node.Network == nameof(ETransport.quic))
{
pluginArgs += "mode=quic;";
}
if (_node.StreamSecurity == Global.StreamSecurity) if (_node.StreamSecurity == Global.StreamSecurity)
{ {
pluginArgs += "tls;"; pluginArgs += "tls;";
@ -381,9 +379,18 @@ public partial class CoreConfigSingboxService
{ {
serverName = _node.Sni; serverName = _node.Sni;
} }
else if (_node.RequestHost.IsNotEmpty()) else
{ {
serverName = Utils.String2List(_node.RequestHost)?.First(); var host = _node.GetNetwork() switch
{
nameof(ETransport.tcp) => _node.GetTransportExtra().TcpHost,
nameof(ETransport.ws) => _node.GetTransportExtra().WsHost,
nameof(ETransport.httpupgrade) => _node.GetTransportExtra().HttpupgradeHost,
nameof(ETransport.xhttp) => _node.GetTransportExtra().XhttpHost,
nameof(ETransport.grpc) => _node.GetTransportExtra().GrpcAuthority,
_ => null,
};
serverName = Utils.String2List(host)?.First();
} }
var tls = new Tls4Sbox() var tls = new Tls4Sbox()
{ {
@ -438,27 +445,21 @@ public partial class CoreConfigSingboxService
try try
{ {
var transport = new Transport4Sbox(); var transport = new Transport4Sbox();
var transportExtra = _node.GetTransportExtra();
switch (_node.GetNetwork()) switch (_node.GetNetwork())
{ {
case nameof(ETransport.h2):
transport.type = nameof(ETransport.http);
transport.host = _node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(_node.RequestHost);
transport.path = _node.Path.NullIfEmpty();
break;
case nameof(ETransport.tcp): //http case nameof(ETransport.tcp): //http
if (_node.HeaderType == Global.TcpHeaderHttp) if (transportExtra.TcpHeaderType == Global.TcpHeaderHttp)
{ {
transport.type = nameof(ETransport.http); transport.type = nameof(ETransport.http);
transport.host = _node.RequestHost.IsNullOrEmpty() ? null : Utils.String2List(_node.RequestHost); transport.host = transportExtra.TcpHost.IsNullOrEmpty() ? null : Utils.String2List(transportExtra.TcpHost);
transport.path = _node.Path.NullIfEmpty();
} }
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
transport.type = nameof(ETransport.ws); transport.type = nameof(ETransport.ws);
var wsPath = _node.Path; var wsPath = transportExtra.WsPath;
// Parse eh and ed parameters from path using regex // Parse eh and ed parameters from path using regex
if (!wsPath.IsNullOrEmpty()) if (!wsPath.IsNullOrEmpty())
@ -487,29 +488,25 @@ public partial class CoreConfigSingboxService
} }
transport.path = wsPath.NullIfEmpty(); transport.path = wsPath.NullIfEmpty();
if (_node.RequestHost.IsNotEmpty()) if (transportExtra.WsHost.IsNotEmpty())
{ {
transport.headers = new() transport.headers = new()
{ {
Host = _node.RequestHost Host = transportExtra.WsHost
}; };
} }
break; break;
case nameof(ETransport.httpupgrade): case nameof(ETransport.httpupgrade):
transport.type = nameof(ETransport.httpupgrade); transport.type = nameof(ETransport.httpupgrade);
transport.path = _node.Path.NullIfEmpty(); transport.path = transportExtra.HttpupgradePath.NullIfEmpty();
transport.host = _node.RequestHost.NullIfEmpty(); transport.host = transportExtra.HttpupgradeHost.NullIfEmpty();
break; break;
case nameof(ETransport.quic):
transport.type = nameof(ETransport.quic);
break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
transport.type = nameof(ETransport.grpc); transport.type = nameof(ETransport.grpc);
transport.service_name = _node.Path; transport.service_name = transportExtra.GrpcServiceName;
transport.idle_timeout = _config.GrpcItem.IdleTimeout?.ToString("##s"); transport.idle_timeout = _config.GrpcItem.IdleTimeout?.ToString("##s");
transport.ping_timeout = _config.GrpcItem.HealthCheckTimeout?.ToString("##s"); transport.ping_timeout = _config.GrpcItem.HealthCheckTimeout?.ToString("##s");
transport.permit_without_stream = _config.GrpcItem.PermitWithoutStream; transport.permit_without_stream = _config.GrpcItem.PermitWithoutStream;

View file

@ -348,8 +348,48 @@ public partial class CoreConfigV2rayService
network = "hysteria"; network = "hysteria";
} }
streamSettings.network = network; streamSettings.network = network;
var host = _node.RequestHost.TrimEx(); var transport = _node.GetTransportExtra();
var path = _node.Path.TrimEx(); var host = string.Empty;
var path = string.Empty;
var kcpSeed = string.Empty;
var headerType = string.Empty;
var xhttpExtra = string.Empty;
switch (network)
{
case nameof(ETransport.tcp):
host = transport.TcpHost?.TrimEx() ?? string.Empty;
headerType = transport.TcpHeaderType?.TrimEx() ?? string.Empty;
break;
case nameof(ETransport.kcp):
kcpSeed = transport.KcpSeed?.TrimEx() ?? string.Empty;
headerType = transport.KcpHeaderType?.TrimEx() ?? string.Empty;
break;
case nameof(ETransport.ws):
host = transport.WsHost?.TrimEx() ?? string.Empty;
path = transport.WsPath?.TrimEx() ?? string.Empty;
break;
case nameof(ETransport.httpupgrade):
host = transport.HttpupgradeHost?.TrimEx() ?? string.Empty;
path = transport.HttpupgradePath?.TrimEx() ?? string.Empty;
break;
case nameof(ETransport.xhttp):
host = transport.XhttpHost?.TrimEx() ?? string.Empty;
path = transport.XhttpPath?.TrimEx() ?? string.Empty;
headerType = transport.XhttpMode?.TrimEx() ?? string.Empty;
xhttpExtra = transport.XhttpExtra?.TrimEx() ?? string.Empty;
break;
case nameof(ETransport.grpc):
host = transport.GrpcAuthority?.TrimEx() ?? string.Empty;
path = transport.GrpcServiceName?.TrimEx() ?? string.Empty;
headerType = transport.GrpcMode?.TrimEx() ?? string.Empty;
break;
}
var sni = _node.Sni.TrimEx(); var sni = _node.Sni.TrimEx();
var useragent = _config.CoreBasicItem.DefUserAgent ?? string.Empty; var useragent = _config.CoreBasicItem.DefUserAgent ?? string.Empty;
@ -435,19 +475,19 @@ public partial class CoreConfigV2rayService
kcpSettings.readBufferSize = _config.KcpItem.ReadBufferSize; kcpSettings.readBufferSize = _config.KcpItem.ReadBufferSize;
kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize; kcpSettings.writeBufferSize = _config.KcpItem.WriteBufferSize;
var kcpFinalmask = new Finalmask4Ray(); var kcpFinalmask = new Finalmask4Ray();
if (Global.KcpHeaderMaskMap.TryGetValue(_node.HeaderType, out var header)) if (Global.KcpHeaderMaskMap.TryGetValue(headerType, out var header))
{ {
kcpFinalmask.udp = kcpFinalmask.udp =
[ [
new Mask4Ray new Mask4Ray
{ {
type = header, type = header,
settings = _node.HeaderType == "dns" && !host.IsNullOrEmpty() ? new MaskSettings4Ray { domain = host } : null settings = null
} }
]; ];
} }
kcpFinalmask.udp ??= []; kcpFinalmask.udp ??= [];
if (path.IsNullOrEmpty()) if (kcpSeed.IsNullOrEmpty())
{ {
kcpFinalmask.udp.Add(new Mask4Ray kcpFinalmask.udp.Add(new Mask4Ray
{ {
@ -459,7 +499,7 @@ public partial class CoreConfigV2rayService
kcpFinalmask.udp.Add(new Mask4Ray kcpFinalmask.udp.Add(new Mask4Ray
{ {
type = "mkcp-aes128gcm", type = "mkcp-aes128gcm",
settings = new MaskSettings4Ray { password = path } settings = new MaskSettings4Ray { password = kcpSeed }
}); });
} }
streamSettings.kcpSettings = kcpSettings; streamSettings.kcpSettings = kcpSettings;
@ -517,63 +557,25 @@ public partial class CoreConfigV2rayService
{ {
xhttpSettings.host = host; xhttpSettings.host = host;
} }
if (_node.HeaderType.IsNotEmpty() && Global.XhttpMode.Contains(_node.HeaderType)) if (headerType.IsNotEmpty() && Global.XhttpMode.Contains(headerType))
{ {
xhttpSettings.mode = _node.HeaderType; xhttpSettings.mode = headerType;
} }
if (_node.Extra.IsNotEmpty()) if (xhttpExtra.IsNotEmpty())
{ {
xhttpSettings.extra = JsonUtils.ParseJson(_node.Extra); xhttpSettings.extra = JsonUtils.ParseJson(xhttpExtra);
} }
streamSettings.xhttpSettings = xhttpSettings; streamSettings.xhttpSettings = xhttpSettings;
FillOutboundMux(outbound); FillOutboundMux(outbound);
break; break;
//h2
case nameof(ETransport.h2):
HttpSettings4Ray httpSettings = new();
if (host.IsNotEmpty())
{
httpSettings.host = Utils.String2List(host);
}
httpSettings.path = path;
streamSettings.httpSettings = httpSettings;
break;
//quic
case nameof(ETransport.quic):
QuicSettings4Ray quicsettings = new()
{
security = host,
key = path,
header = new Header4Ray
{
type = _node.HeaderType
}
};
streamSettings.quicSettings = quicsettings;
if (_node.StreamSecurity == Global.StreamSecurity)
{
if (sni.IsNotEmpty())
{
streamSettings.tlsSettings.serverName = sni;
}
else
{
streamSettings.tlsSettings.serverName = _node.Address;
}
}
break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
GrpcSettings4Ray grpcSettings = new() GrpcSettings4Ray grpcSettings = new()
{ {
authority = host.NullIfEmpty(), authority = host.NullIfEmpty(),
serviceName = path, serviceName = path,
multiMode = _node.HeaderType == Global.GrpcMultiMode, multiMode = headerType == Global.GrpcMultiMode,
idle_timeout = _config.GrpcItem.IdleTimeout, idle_timeout = _config.GrpcItem.IdleTimeout,
health_check_timeout = _config.GrpcItem.HealthCheckTimeout, health_check_timeout = _config.GrpcItem.HealthCheckTimeout,
permit_without_stream = _config.GrpcItem.PermitWithoutStream, permit_without_stream = _config.GrpcItem.PermitWithoutStream,
@ -641,13 +643,13 @@ public partial class CoreConfigV2rayService
default: default:
//tcp //tcp
if (_node.HeaderType == Global.TcpHeaderHttp) if (headerType == Global.TcpHeaderHttp)
{ {
TcpSettings4Ray tcpSettings = new() TcpSettings4Ray tcpSettings = new()
{ {
header = new Header4Ray header = new Header4Ray
{ {
type = _node.HeaderType type = headerType
} }
}; };

View file

@ -73,6 +73,167 @@ public class AddServerViewModel : MyReactiveObject
[Reactive] [Reactive]
public bool NaiveQuic { get; set; } public bool NaiveQuic { get; set; }
[Reactive]
public string TcpHeaderType { get; set; }
[Reactive]
public string TcpHost { get; set; }
[Reactive]
public string WsHost { get; set; }
[Reactive]
public string WsPath { get; set; }
[Reactive]
public string HttpupgradeHost { get; set; }
[Reactive]
public string HttpupgradePath { get; set; }
[Reactive]
public string XhttpHost { get; set; }
[Reactive]
public string XhttpPath { get; set; }
[Reactive]
public string XhttpMode { get; set; }
[Reactive]
public string XhttpExtra { get; set; }
[Reactive]
public string GrpcAuthority { get; set; }
[Reactive]
public string GrpcServiceName { get; set; }
[Reactive]
public string GrpcMode { get; set; }
[Reactive]
public string KcpHeaderType { get; set; }
[Reactive]
public string KcpSeed { get; set; }
public string TransportHeaderType
{
get => SelectedSource.GetNetwork() switch
{
nameof(ETransport.tcp) => TcpHeaderType,
nameof(ETransport.kcp) => KcpHeaderType,
nameof(ETransport.xhttp) => XhttpMode,
nameof(ETransport.grpc) => GrpcMode,
_ => string.Empty,
};
set
{
switch (SelectedSource.GetNetwork())
{
case nameof(ETransport.tcp):
TcpHeaderType = value;
break;
case nameof(ETransport.kcp):
KcpHeaderType = value;
break;
case nameof(ETransport.xhttp):
XhttpMode = value;
break;
case nameof(ETransport.grpc):
GrpcMode = value;
break;
}
this.RaisePropertyChanged();
}
}
public string TransportHost
{
get => SelectedSource.GetNetwork() switch
{
nameof(ETransport.tcp) => TcpHost,
nameof(ETransport.ws) => WsHost,
nameof(ETransport.httpupgrade) => HttpupgradeHost,
nameof(ETransport.xhttp) => XhttpHost,
nameof(ETransport.grpc) => GrpcAuthority,
_ => string.Empty,
};
set
{
switch (SelectedSource.GetNetwork())
{
case nameof(ETransport.tcp):
TcpHost = value;
break;
case nameof(ETransport.ws):
WsHost = value;
break;
case nameof(ETransport.httpupgrade):
HttpupgradeHost = value;
break;
case nameof(ETransport.xhttp):
XhttpHost = value;
break;
case nameof(ETransport.grpc):
GrpcAuthority = value;
break;
}
this.RaisePropertyChanged();
}
}
public string TransportPath
{
get => SelectedSource.GetNetwork() switch
{
nameof(ETransport.kcp) => KcpSeed,
nameof(ETransport.ws) => WsPath,
nameof(ETransport.httpupgrade) => HttpupgradePath,
nameof(ETransport.xhttp) => XhttpPath,
nameof(ETransport.grpc) => GrpcServiceName,
_ => string.Empty,
};
set
{
switch (SelectedSource.GetNetwork())
{
case nameof(ETransport.kcp):
KcpSeed = value;
break;
case nameof(ETransport.ws):
WsPath = value;
break;
case nameof(ETransport.httpupgrade):
HttpupgradePath = value;
break;
case nameof(ETransport.xhttp):
XhttpPath = value;
break;
case nameof(ETransport.grpc):
GrpcServiceName = value;
break;
}
this.RaisePropertyChanged();
}
}
public string TransportExtraText
{
get => SelectedSource.GetNetwork() == nameof(ETransport.xhttp)
? XhttpExtra
: string.Empty;
set
{
if (SelectedSource.GetNetwork() == nameof(ETransport.xhttp))
{
XhttpExtra = value;
}
this.RaisePropertyChanged();
}
}
public ReactiveCommand<Unit, Unit> FetchCertCmd { get; } public ReactiveCommand<Unit, Unit> FetchCertCmd { get; }
public ReactiveCommand<Unit, Unit> FetchCertChainCmd { get; } public ReactiveCommand<Unit, Unit> FetchCertChainCmd { get; }
public ReactiveCommand<Unit, Unit> SaveCmd { get; } public ReactiveCommand<Unit, Unit> SaveCmd { get; }
@ -101,14 +262,21 @@ public class AddServerViewModel : MyReactiveObject
this.WhenAnyValue(x => x.CertSha) this.WhenAnyValue(x => x.CertSha)
.Subscribe(_ => UpdateCertTip()); .Subscribe(_ => UpdateCertTip());
this.WhenAnyValue(x => x.SelectedSource.Network)
.Subscribe(_ =>
{
this.RaisePropertyChanged(nameof(TransportHeaderType));
this.RaisePropertyChanged(nameof(TransportHost));
this.RaisePropertyChanged(nameof(TransportPath));
this.RaisePropertyChanged(nameof(TransportExtraText));
});
this.WhenAnyValue(x => x.Cert) this.WhenAnyValue(x => x.Cert)
.Subscribe(_ => UpdateCertSha()); .Subscribe(_ => UpdateCertSha());
if (profileItem.IndexId.IsNullOrEmpty()) if (profileItem.IndexId.IsNullOrEmpty())
{ {
profileItem.Network = Global.DefaultNetwork; profileItem.Network = Global.DefaultNetwork;
profileItem.HeaderType = Global.None;
profileItem.RequestHost = "";
profileItem.StreamSecurity = ""; profileItem.StreamSecurity = "";
SelectedSource = profileItem; SelectedSource = profileItem;
} }
@ -121,6 +289,7 @@ public class AddServerViewModel : MyReactiveObject
CertSha = SelectedSource?.CertSha?.ToString() ?? string.Empty; CertSha = SelectedSource?.CertSha?.ToString() ?? string.Empty;
var protocolExtra = SelectedSource?.GetProtocolExtra(); var protocolExtra = SelectedSource?.GetProtocolExtra();
var transport = protocolExtra?.Transport ?? new TransportExtra();
Ports = protocolExtra?.Ports ?? string.Empty; Ports = protocolExtra?.Ports ?? string.Empty;
AlterId = int.TryParse(protocolExtra?.AlterId, out var result) ? result : 0; AlterId = int.TryParse(protocolExtra?.AlterId, out var result) ? result : 0;
Flow = protocolExtra?.Flow ?? string.Empty; Flow = protocolExtra?.Flow ?? string.Empty;
@ -139,6 +308,23 @@ public class AddServerViewModel : MyReactiveObject
CongestionControl = protocolExtra?.CongestionControl ?? string.Empty; CongestionControl = protocolExtra?.CongestionControl ?? string.Empty;
InsecureConcurrency = protocolExtra?.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null; InsecureConcurrency = protocolExtra?.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null;
NaiveQuic = protocolExtra?.NaiveQuic ?? false; NaiveQuic = protocolExtra?.NaiveQuic ?? false;
TcpHeaderType = transport.TcpHeaderType ?? Global.None;
TcpHost = transport.TcpHost ?? string.Empty;
WsHost = transport.WsHost ?? string.Empty;
WsPath = transport.WsPath ?? string.Empty;
HttpupgradeHost = transport.HttpupgradeHost ?? string.Empty;
HttpupgradePath = transport.HttpupgradePath ?? string.Empty;
XhttpHost = transport.XhttpHost ?? string.Empty;
XhttpPath = transport.XhttpPath ?? string.Empty;
XhttpMode = transport.XhttpMode ?? string.Empty;
XhttpExtra = transport.XhttpExtra ?? string.Empty;
GrpcAuthority = transport.GrpcAuthority ?? string.Empty;
GrpcServiceName = transport.GrpcServiceName ?? string.Empty;
GrpcMode = transport.GrpcMode.IsNullOrEmpty() ? Global.GrpcGunMode : transport.GrpcMode;
KcpHeaderType = transport.KcpHeaderType.IsNullOrEmpty() ? Global.None : transport.KcpHeaderType;
KcpSeed = transport.KcpSeed ?? string.Empty;
} }
private async Task SaveServerAsync() private async Task SaveServerAsync()
@ -185,8 +371,33 @@ public class AddServerViewModel : MyReactiveObject
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType); SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
SelectedSource.Cert = Cert.IsNullOrEmpty() ? string.Empty : Cert; SelectedSource.Cert = Cert.IsNullOrEmpty() ? string.Empty : Cert;
SelectedSource.CertSha = CertSha.IsNullOrEmpty() ? string.Empty : CertSha; SelectedSource.CertSha = CertSha.IsNullOrEmpty() ? string.Empty : CertSha;
if (!Global.Networks.Contains(SelectedSource.Network))
{
SelectedSource.Network = Global.DefaultNetwork;
}
var transport = new TransportExtra
{
TcpHeaderType = TcpHeaderType.NullIfEmpty(),
TcpHost = TcpHost.NullIfEmpty(),
WsHost = WsHost.NullIfEmpty(),
WsPath = WsPath.NullIfEmpty(),
HttpupgradeHost = HttpupgradeHost.NullIfEmpty(),
HttpupgradePath = HttpupgradePath.NullIfEmpty(),
XhttpHost = XhttpHost.NullIfEmpty(),
XhttpPath = XhttpPath.NullIfEmpty(),
XhttpMode = XhttpMode.NullIfEmpty(),
XhttpExtra = XhttpExtra.NullIfEmpty(),
GrpcAuthority = GrpcAuthority.NullIfEmpty(),
GrpcServiceName = GrpcServiceName.NullIfEmpty(),
GrpcMode = GrpcMode.NullIfEmpty(),
KcpHeaderType = KcpHeaderType.NullIfEmpty(),
KcpSeed = KcpSeed.NullIfEmpty(),
};
SelectedSource.SetProtocolExtra(SelectedSource.GetProtocolExtra() with SelectedSource.SetProtocolExtra(SelectedSource.GetProtocolExtra() with
{ {
Transport = transport,
Ports = Ports.NullIfEmpty(), Ports = Ports.NullIfEmpty(),
AlterId = AlterId > 0 ? AlterId.ToString() : null, AlterId = AlterId > 0 ? AlterId.ToString() : null,
Flow = Flow.NullIfEmpty(), Flow = Flow.NullIfEmpty(),
@ -261,7 +472,7 @@ public class AddServerViewModel : MyReactiveObject
var serverName = SelectedSource.Sni; var serverName = SelectedSource.Sni;
if (serverName.IsNullOrEmpty()) if (serverName.IsNullOrEmpty())
{ {
serverName = SelectedSource.RequestHost; serverName = GetCurrentTransportHost();
} }
if (serverName.IsNullOrEmpty()) if (serverName.IsNullOrEmpty())
{ {
@ -286,7 +497,7 @@ public class AddServerViewModel : MyReactiveObject
var serverName = SelectedSource.Sni; var serverName = SelectedSource.Sni;
if (serverName.IsNullOrEmpty()) if (serverName.IsNullOrEmpty())
{ {
serverName = SelectedSource.RequestHost; serverName = GetCurrentTransportHost();
} }
if (serverName.IsNullOrEmpty()) if (serverName.IsNullOrEmpty())
{ {
@ -301,4 +512,17 @@ public class AddServerViewModel : MyReactiveObject
Cert = CertPemManager.ConcatenatePemChain(certs); Cert = CertPemManager.ConcatenatePemChain(certs);
UpdateCertTip(certError); UpdateCertTip(certError);
} }
private string GetCurrentTransportHost()
{
return SelectedSource.GetNetwork() switch
{
nameof(ETransport.tcp) => TcpHost,
nameof(ETransport.ws) => WsHost,
nameof(ETransport.httpupgrade) => HttpupgradeHost,
nameof(ETransport.xhttp) => XhttpHost,
nameof(ETransport.grpc) => GrpcAuthority,
_ => string.Empty,
};
}
} }

View file

@ -690,128 +690,258 @@
<Grid <Grid
x:Name="gridTransport" x:Name="gridTransport"
Grid.Row="4" Grid.Row="4"
ColumnDefinitions="300,Auto,Auto" RowDefinitions="Auto,Auto,Auto">
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<TextBlock <TextBlock
Grid.Row="0" Grid.Row="0"
Grid.ColumnSpan="2"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Text="{x:Static resx:ResUI.GbTransport}" /> Text="{x:Static resx:ResUI.GbTransport}" />
<TextBlock <Grid Grid.Row="1" ColumnDefinitions="300,Auto,Auto">
Grid.Row="1" <TextBlock
Grid.Column="0" Grid.Column="0"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbNetwork}" /> Text="{x:Static resx:ResUI.TbNetwork}" />
<ComboBox
x:Name="cmbNetwork"
Grid.Row="1"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="1"
Grid.Column="2"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TipNetwork}" />
<TextBlock
x:Name="labHeaderType"
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbHeaderType}" />
<StackPanel
Grid.Row="2"
Grid.Column="1"
VerticalAlignment="Center"
Orientation="Horizontal">
<ComboBox <ComboBox
x:Name="cmbHeaderType" x:Name="cmbNetwork"
Grid.Column="1"
Width="200" Width="200"
Margin="{StaticResource Margin4}" /> Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Column="2"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TipNetwork}" />
</Grid>
<Button <Grid Grid.Row="2">
x:Name="btnExtra" <Grid
Margin="{StaticResource MarginLr8}" x:Name="gridTransportTcp"
Classes="IconButton"> ColumnDefinitions="300,Auto"
<Button.Content> IsVisible="False"
<PathIcon Data="{StaticResource SemiIconMore}"> RowDefinitions="Auto,Auto">
<PathIcon.RenderTransform> <TextBlock
<RotateTransform Angle="90" /> Grid.Row="0"
</PathIcon.RenderTransform> Grid.Column="0"
</PathIcon> Margin="{StaticResource Margin4}"
</Button.Content> VerticalAlignment="Center"
<Button.Flyout> Text="{x:Static resx:ResUI.TbHeaderType}" />
<Flyout> <ComboBox
<StackPanel> x:Name="cmbHeaderTypeTcp"
<TextBlock Grid.Row="0"
Margin="{StaticResource Margin4}" Grid.Column="1"
VerticalAlignment="Center" Width="200"
Text="{x:Static resx:ResUI.TransportExtraTip}" /> Margin="{StaticResource Margin4}" />
<views:JsonEditor <TextBlock
x:Name="txtExtra" Grid.Row="1"
Width="400" Grid.Column="0"
MinHeight="100" Margin="{StaticResource Margin4}"
Margin="{StaticResource Margin4}" VerticalAlignment="Center"
HorizontalAlignment="Stretch" Text="{x:Static resx:ResUI.TbRequestHost}" />
VerticalAlignment="Center" /> <TextBox
</StackPanel> x:Name="txtRequestHostTcp"
</Flyout> Grid.Row="1"
</Button.Flyout> Grid.Column="1"
</Button> Width="400"
</StackPanel> Margin="{StaticResource Margin4}" />
<TextBlock </Grid>
x:Name="tipHeaderType"
Grid.Row="2"
Grid.Column="2"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbHeaderType}" />
<TextBlock <Grid
Grid.Row="3" x:Name="gridTransportXhttp"
Grid.Column="0" ColumnDefinitions="300,Auto"
Margin="{StaticResource Margin4}" IsVisible="False"
VerticalAlignment="Center" RowDefinitions="Auto,Auto,Auto,Auto">
Text="{x:Static resx:ResUI.TbRequestHost}" /> <TextBlock
<TextBox Grid.Row="0"
x:Name="txtRequestHost" Grid.Column="0"
Grid.Row="3" Margin="{StaticResource Margin4}"
Grid.Column="1" VerticalAlignment="Center"
Width="400" Text="{x:Static resx:ResUI.TbHeaderType}" />
Margin="{StaticResource Margin4}" /> <ComboBox
<TextBlock x:Name="cmbHeaderTypeXhttp"
x:Name="tipRequestHost" Grid.Row="0"
Grid.Row="3" Grid.Column="1"
Grid.Column="2" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}" />
VerticalAlignment="Center" <TextBlock
Text="{x:Static resx:ResUI.TbRequestHost}" /> Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostXhttp"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathXhttp"
Grid.Row="2"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="3"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Top"
Text="{x:Static resx:ResUI.TransportExtraTip}"
TextWrapping="Wrap" />
<views:JsonEditor
x:Name="txtExtraXhttp"
Grid.Row="3"
Grid.Column="1"
Width="400"
MinHeight="100"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
</Grid>
<TextBlock <Grid
Grid.Row="4" x:Name="gridTransportKcp"
Grid.Column="0" ColumnDefinitions="300,Auto"
Margin="{StaticResource Margin4}" IsVisible="False"
VerticalAlignment="Center" RowDefinitions="Auto,Auto">
Text="{x:Static resx:ResUI.TbPath}" /> <TextBlock
<TextBox Grid.Row="0"
x:Name="txtPath" Grid.Column="0"
Grid.Row="4" Margin="{StaticResource Margin4}"
Grid.Column="1" VerticalAlignment="Center"
Width="400" Text="{x:Static resx:ResUI.TbHeaderType}" />
Margin="{StaticResource Margin4}" /> <ComboBox
<TextBlock x:Name="cmbHeaderTypeKcp"
x:Name="tipPath" Grid.Row="0"
Grid.Row="4" Grid.Column="1"
Grid.Column="2" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}" />
VerticalAlignment="Center" <TextBlock
Text="{x:Static resx:ResUI.TbPath}" /> Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="Seed" />
<TextBox
x:Name="txtKcpSeed"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
</Grid>
<Grid
x:Name="gridTransportGrpc"
ColumnDefinitions="300,Auto"
IsVisible="False"
RowDefinitions="Auto,Auto,Auto">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbHeaderType}" />
<ComboBox
x:Name="cmbHeaderTypeGrpc"
Grid.Row="0"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostGrpc"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathGrpc"
Grid.Row="2"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
</Grid>
<Grid
x:Name="gridTransportWs"
ColumnDefinitions="300,Auto"
IsVisible="False"
RowDefinitions="Auto,Auto">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostWs"
Grid.Row="0"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathWs"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
</Grid>
<Grid
x:Name="gridTransportHttpupgrade"
ColumnDefinitions="300,Auto"
IsVisible="False"
RowDefinitions="Auto,Auto">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostHttpupgrade"
Grid.Row="0"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathHttpupgrade"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}" />
</Grid>
</Grid>
</Grid> </Grid>
<Grid <Grid

View file

@ -201,10 +201,26 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
break; break;
} }
this.Bind(ViewModel, vm => vm.SelectedSource.Network, v => v.cmbNetwork.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Network, v => v.cmbNetwork.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TcpHeaderType, v => v.cmbHeaderTypeTcp.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.RequestHost, v => v.txtRequestHost.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TcpHost, v => v.txtRequestHostTcp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Extra, v => v.txtExtra.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.KcpHeaderType, v => v.cmbHeaderTypeKcp.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KcpSeed, v => v.txtKcpSeed.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.WsHost, v => v.txtRequestHostWs.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.WsPath, v => v.txtPathWs.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.HttpupgradeHost, v => v.txtRequestHostHttpupgrade.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.HttpupgradePath, v => v.txtPathHttpupgrade.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpMode, v => v.cmbHeaderTypeXhttp.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpHost, v => v.txtRequestHostXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpPath, v => v.txtPathXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpExtra, v => v.txtExtraXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GrpcMode, v => v.cmbHeaderTypeGrpc.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GrpcAuthority, v => v.txtRequestHostGrpc.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GrpcServiceName, v => v.txtPathGrpc.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables);
@ -285,99 +301,60 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
private void SetHeaderType() private void SetHeaderType()
{ {
var lstHeaderType = new List<string>(); cmbHeaderTypeTcp.ItemsSource = new List<string> { Global.None, Global.TcpHeaderHttp };
var network = cmbNetwork.SelectedItem.ToString(); var kcpHeaderTypes = new List<string> { Global.None };
if (network.IsNullOrEmpty()) kcpHeaderTypes.AddRange(Global.KcpHeaderTypes);
{ cmbHeaderTypeKcp.ItemsSource = kcpHeaderTypes;
lstHeaderType.Add(Global.None);
cmbHeaderType.ItemsSource = lstHeaderType;
cmbHeaderType.SelectedIndex = 0;
return;
}
if (network == nameof(ETransport.tcp)) cmbHeaderTypeXhttp.ItemsSource = Global.XhttpMode;
{ cmbHeaderTypeGrpc.ItemsSource = new List<string> { Global.GrpcGunMode, Global.GrpcMultiMode };
lstHeaderType.Add(Global.None);
lstHeaderType.Add(Global.TcpHeaderHttp); SetTransportGridVisibility();
}
else if (network is nameof(ETransport.kcp) or nameof(ETransport.quic))
{
lstHeaderType.Add(Global.None);
lstHeaderType.AddRange(Global.KcpHeaderTypes);
}
else if (network is nameof(ETransport.xhttp))
{
lstHeaderType.AddRange(Global.XhttpMode);
}
else if (network == nameof(ETransport.grpc))
{
lstHeaderType.Add(Global.GrpcGunMode);
lstHeaderType.Add(Global.GrpcMultiMode);
}
else
{
lstHeaderType.Add(Global.None);
}
cmbHeaderType.ItemsSource = lstHeaderType;
cmbHeaderType.SelectedIndex = 0;
} }
private void SetTips() private void SetTips()
{ {
var network = cmbNetwork.SelectedItem.ToString(); SetTransportGridVisibility();
}
private void SetTransportGridVisibility()
{
var network = cmbNetwork.SelectedItem?.ToString();
if (network.IsNullOrEmpty()) if (network.IsNullOrEmpty())
{ {
network = Global.DefaultNetwork; network = Global.DefaultNetwork;
} }
labHeaderType.IsVisible = true;
btnExtra.IsVisible = false; gridTransportTcp.IsVisible = false;
tipRequestHost.Text = gridTransportKcp.IsVisible = false;
tipPath.Text = gridTransportWs.IsVisible = false;
tipHeaderType.Text = string.Empty; gridTransportHttpupgrade.IsVisible = false;
gridTransportXhttp.IsVisible = false;
gridTransportGrpc.IsVisible = false;
switch (network) switch (network)
{ {
case nameof(ETransport.tcp): case nameof(ETransport.tcp):
tipRequestHost.Text = ResUI.TransportRequestHostTip1; gridTransportTcp.IsVisible = true;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip1;
break; break;
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
tipHeaderType.Text = ResUI.TransportHeaderTypeTip2; gridTransportKcp.IsVisible = true;
tipPath.Text = ResUI.TransportPathTip5;
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
gridTransportWs.IsVisible = true;
break;
case nameof(ETransport.httpupgrade): case nameof(ETransport.httpupgrade):
tipRequestHost.Text = ResUI.TransportRequestHostTip2; gridTransportHttpupgrade.IsVisible = true;
tipPath.Text = ResUI.TransportPathTip1;
break; break;
case nameof(ETransport.xhttp): case nameof(ETransport.xhttp):
tipRequestHost.Text = ResUI.TransportRequestHostTip2; gridTransportXhttp.IsVisible = true;
tipPath.Text = ResUI.TransportPathTip1;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip5;
labHeaderType.IsVisible = false;
btnExtra.IsVisible = true;
break; break;
case nameof(ETransport.h2):
tipRequestHost.Text = ResUI.TransportRequestHostTip3;
tipPath.Text = ResUI.TransportPathTip2;
break;
case nameof(ETransport.quic):
tipRequestHost.Text = ResUI.TransportRequestHostTip4;
tipPath.Text = ResUI.TransportPathTip3;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip3;
break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
tipRequestHost.Text = ResUI.TransportRequestHostTip5; gridTransportGrpc.IsVisible = true;
tipPath.Text = ResUI.TransportPathTip4; break;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip4; default:
labHeaderType.IsVisible = false; gridTransportTcp.IsVisible = true;
break; break;
} }
} }

View file

@ -150,7 +150,7 @@
<Grid <Grid
x:Name="gridVMess" x:Name="gridVMess"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -234,7 +234,7 @@
<Grid <Grid
x:Name="gridSs" x:Name="gridSs"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -308,7 +308,7 @@
<Grid <Grid
x:Name="gridSocks" x:Name="gridSocks"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -353,7 +353,7 @@
<Grid <Grid
x:Name="gridVLESS" x:Name="gridVLESS"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -437,7 +437,7 @@
<Grid <Grid
x:Name="gridTrojan" x:Name="gridTrojan"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -497,7 +497,7 @@
<Grid <Grid
x:Name="gridHysteria2" x:Name="gridHysteria2"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -610,7 +610,7 @@
<Grid <Grid
x:Name="gridTuic" x:Name="gridTuic"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -670,7 +670,7 @@
<Grid <Grid
x:Name="gridWireguard" x:Name="gridWireguard"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -767,7 +767,7 @@
<Grid <Grid
x:Name="gridAnytls" x:Name="gridAnytls"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -796,7 +796,7 @@
<Grid <Grid
x:Name="gridNaive" x:Name="gridNaive"
Grid.Row="2" Grid.Row="2"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -907,143 +907,325 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock <TextBlock
Grid.Row="0" Grid.Row="0"
Grid.ColumnSpan="2"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource ModuleTitle}" Style="{StaticResource ModuleTitle}"
Text="{x:Static resx:ResUI.GbTransport}" /> Text="{x:Static resx:ResUI.GbTransport}" />
<TextBlock <Grid Grid.Row="1">
Grid.Row="1" <Grid.ColumnDefinitions>
Grid.Column="0" <ColumnDefinition Width="300" />
Margin="{StaticResource Margin4}" <ColumnDefinition Width="Auto" />
VerticalAlignment="Center" <ColumnDefinition Width="Auto" />
Style="{StaticResource ToolbarTextBlock}" </Grid.ColumnDefinitions>
Text="{x:Static resx:ResUI.TbNetwork}" /> <TextBlock
<ComboBox Grid.Column="0"
x:Name="cmbNetwork" Margin="{StaticResource Margin4}"
Grid.Row="1" VerticalAlignment="Center"
Grid.Column="1" Style="{StaticResource ToolbarTextBlock}"
Width="200" Text="{x:Static resx:ResUI.TbNetwork}" />
Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="1"
Grid.Column="2"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TipNetwork}" />
<TextBlock
x:Name="labHeaderType"
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbHeaderType}" />
<StackPanel
Grid.Row="2"
Grid.Column="1"
VerticalAlignment="Center"
Orientation="Horizontal">
<ComboBox <ComboBox
x:Name="cmbHeaderType" x:Name="cmbNetwork"
Grid.Column="1"
Width="200" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Column="2"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TipNetwork}" />
</Grid>
<materialDesign:PopupBox <Grid Grid.Row="2">
x:Name="popExtra" <Grid x:Name="gridTransportTcp" Visibility="Collapsed">
HorizontalAlignment="Right" <Grid.ColumnDefinitions>
StaysOpen="True" <ColumnDefinition Width="300" />
Style="{StaticResource MaterialDesignToolForegroundPopupBox}"> <ColumnDefinition Width="Auto" />
<StackPanel> </Grid.ColumnDefinitions>
<TextBlock <Grid.RowDefinitions>
Margin="{StaticResource Margin4}" <RowDefinition Height="Auto" />
VerticalAlignment="Center" <RowDefinition Height="Auto" />
Style="{StaticResource ToolbarTextBlock}" </Grid.RowDefinitions>
Text="{x:Static resx:ResUI.TransportExtraTip}" /> <TextBlock
<TextBox Grid.Row="0"
x:Name="txtExtra" Grid.Column="0"
Width="400" Margin="{StaticResource Margin4}"
Margin="{StaticResource Margin4}" VerticalAlignment="Center"
VerticalAlignment="Center" Style="{StaticResource ToolbarTextBlock}"
AcceptsReturn="True" Text="{x:Static resx:ResUI.TbHeaderType}" />
MinLines="6" <ComboBox
Style="{StaticResource MyOutlinedTextBox}" x:Name="cmbHeaderTypeTcp"
TextWrapping="Wrap" /> Grid.Row="0"
</StackPanel> Grid.Column="1"
</materialDesign:PopupBox> Width="200"
</StackPanel> Margin="{StaticResource Margin4}"
<TextBlock Style="{StaticResource DefComboBox}" />
x:Name="tipHeaderType" <TextBlock
Grid.Row="2" Grid.Row="1"
Grid.Column="2" Grid.Column="0"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
VerticalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}" Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbHeaderType}" /> Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostTcp"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
</Grid>
<TextBlock <Grid x:Name="gridTransportXhttp" Visibility="Collapsed">
Grid.Row="3" <Grid.ColumnDefinitions>
Grid.Column="0" <ColumnDefinition Width="300" />
Margin="{StaticResource Margin4}" <ColumnDefinition Width="Auto" />
VerticalAlignment="Center" </Grid.ColumnDefinitions>
Style="{StaticResource ToolbarTextBlock}" <Grid.RowDefinitions>
Text="{x:Static resx:ResUI.TbRequestHost}" /> <RowDefinition Height="Auto" />
<TextBox <RowDefinition Height="Auto" />
x:Name="txtRequestHost" <RowDefinition Height="Auto" />
Grid.Row="3" <RowDefinition Height="Auto" />
Grid.Column="1" </Grid.RowDefinitions>
Width="400" <TextBlock
Margin="{StaticResource Margin4}" Grid.Row="0"
Style="{StaticResource DefTextBox}" /> Grid.Column="0"
<TextBlock Margin="{StaticResource Margin4}"
x:Name="tipRequestHost" VerticalAlignment="Center"
Grid.Row="3" Style="{StaticResource ToolbarTextBlock}"
Grid.Column="2" Text="{x:Static resx:ResUI.TbHeaderType}" />
Margin="{StaticResource Margin4}" <ComboBox
VerticalAlignment="Center" x:Name="cmbHeaderTypeXhttp"
Style="{StaticResource ToolbarTextBlock}" Grid.Row="0"
Text="{x:Static resx:ResUI.TbRequestHost}" /> Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostXhttp"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathXhttp"
Grid.Row="2"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="3"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Top"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TransportExtraTip}"
TextWrapping="Wrap" />
<TextBox
x:Name="txtExtraXhttp"
Grid.Row="3"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
AcceptsReturn="True"
MinLines="6"
Style="{StaticResource MyOutlinedTextBox}"
TextWrapping="Wrap" />
</Grid>
<TextBlock <Grid x:Name="gridTransportKcp" Visibility="Collapsed">
Grid.Row="4" <Grid.ColumnDefinitions>
Grid.Column="0" <ColumnDefinition Width="300" />
Margin="{StaticResource Margin4}" <ColumnDefinition Width="Auto" />
VerticalAlignment="Center" </Grid.ColumnDefinitions>
Style="{StaticResource ToolbarTextBlock}" <Grid.RowDefinitions>
Text="{x:Static resx:ResUI.TbPath}" /> <RowDefinition Height="Auto" />
<TextBox <RowDefinition Height="Auto" />
x:Name="txtPath" </Grid.RowDefinitions>
Grid.Row="4" <TextBlock
Grid.Column="1" Grid.Row="0"
Width="400" Grid.Column="0"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" /> VerticalAlignment="Center"
<TextBlock Style="{StaticResource ToolbarTextBlock}"
x:Name="tipPath" Text="{x:Static resx:ResUI.TbHeaderType}" />
Grid.Row="4" <ComboBox
Grid.Column="2" x:Name="cmbHeaderTypeKcp"
Margin="{StaticResource Margin4}" Grid.Row="0"
VerticalAlignment="Center" Grid.Column="1"
Style="{StaticResource ToolbarTextBlock}" Width="200"
Text="{x:Static resx:ResUI.TbPath}" /> Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="Seed" />
<TextBox
x:Name="txtKcpSeed"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
</Grid>
<Grid x:Name="gridTransportGrpc" Visibility="Collapsed">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbHeaderType}" />
<ComboBox
x:Name="cmbHeaderTypeGrpc"
Grid.Row="0"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostGrpc"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathGrpc"
Grid.Row="2"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
</Grid>
<Grid x:Name="gridTransportWs" Visibility="Collapsed">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostWs"
Grid.Row="0"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathWs"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
</Grid>
<Grid x:Name="gridTransportHttpupgrade" Visibility="Collapsed">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbRequestHost}" />
<TextBox
x:Name="txtRequestHostHttpupgrade"
Grid.Row="0"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbPath}" />
<TextBox
x:Name="txtPathHttpupgrade"
Grid.Row="1"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
Style="{StaticResource DefTextBox}" />
</Grid>
</Grid>
</Grid> </Grid>
<Grid x:Name="gridFinalmask" Grid.Row="5"> <Grid x:Name="gridFinalmask" Grid.Row="5">
@ -1117,7 +1299,7 @@
<Grid <Grid
x:Name="gridTlsMore" x:Name="gridTlsMore"
Grid.Row="8" Grid.Row="8"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -1306,7 +1488,7 @@
<Grid <Grid
x:Name="gridRealityMore" x:Name="gridRealityMore"
Grid.Row="8" Grid.Row="8"
Visibility="Hidden"> Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />

View file

@ -19,6 +19,10 @@ public partial class AddServerWindow
cmbCoreType.ItemsSource = Global.CoreTypes.AppendEmpty(); cmbCoreType.ItemsSource = Global.CoreTypes.AppendEmpty();
cmbNetwork.ItemsSource = Global.Networks; cmbNetwork.ItemsSource = Global.Networks;
if (ViewModel.SelectedSource.Network.IsNullOrEmpty() || !Global.Networks.Contains(ViewModel.SelectedSource.Network))
{
ViewModel.SelectedSource.Network = Global.DefaultNetwork;
}
cmbFingerprint.ItemsSource = Global.Fingerprints; cmbFingerprint.ItemsSource = Global.Fingerprints;
cmbFingerprint2.ItemsSource = Global.Fingerprints; cmbFingerprint2.ItemsSource = Global.Fingerprints;
cmbAllowInsecure.ItemsSource = Global.AllowInsecure; cmbAllowInsecure.ItemsSource = Global.AllowInsecure;
@ -114,7 +118,7 @@ public partial class AddServerWindow
} }
cmbStreamSecurity.ItemsSource = lstStreamSecurity; cmbStreamSecurity.ItemsSource = lstStreamSecurity;
gridTlsMore.Visibility = Visibility.Hidden; gridTlsMore.Visibility = Visibility.Collapsed;
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
@ -195,10 +199,26 @@ public partial class AddServerWindow
break; break;
} }
this.Bind(ViewModel, vm => vm.SelectedSource.Network, v => v.cmbNetwork.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Network, v => v.cmbNetwork.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.HeaderType, v => v.cmbHeaderType.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TcpHeaderType, v => v.cmbHeaderTypeTcp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.RequestHost, v => v.txtRequestHost.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TcpHost, v => v.txtRequestHostTcp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Path, v => v.txtPath.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Extra, v => v.txtExtra.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.KcpHeaderType, v => v.cmbHeaderTypeKcp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KcpSeed, v => v.txtKcpSeed.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.WsHost, v => v.txtRequestHostWs.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.WsPath, v => v.txtPathWs.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.HttpupgradeHost, v => v.txtRequestHostHttpupgrade.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.HttpupgradePath, v => v.txtPathHttpupgrade.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpMode, v => v.cmbHeaderTypeXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpHost, v => v.txtRequestHostXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpPath, v => v.txtPathXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.XhttpExtra, v => v.txtExtraXhttp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GrpcMode, v => v.cmbHeaderTypeGrpc.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GrpcAuthority, v => v.txtRequestHostGrpc.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.GrpcServiceName, v => v.txtPathGrpc.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.StreamSecurity, v => v.cmbStreamSecurity.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.SelectedSource.Sni, v => v.txtSNI.Text).DisposeWith(disposables);
@ -259,17 +279,17 @@ public partial class AddServerWindow
if (security == Global.StreamSecurityReality) if (security == Global.StreamSecurityReality)
{ {
gridRealityMore.Visibility = Visibility.Visible; gridRealityMore.Visibility = Visibility.Visible;
gridTlsMore.Visibility = Visibility.Hidden; gridTlsMore.Visibility = Visibility.Collapsed;
} }
else if (security == Global.StreamSecurity) else if (security == Global.StreamSecurity)
{ {
gridRealityMore.Visibility = Visibility.Hidden; gridRealityMore.Visibility = Visibility.Collapsed;
gridTlsMore.Visibility = Visibility.Visible; gridTlsMore.Visibility = Visibility.Visible;
} }
else else
{ {
gridRealityMore.Visibility = Visibility.Hidden; gridRealityMore.Visibility = Visibility.Collapsed;
gridTlsMore.Visibility = Visibility.Hidden; gridTlsMore.Visibility = Visibility.Collapsed;
} }
} }
@ -281,99 +301,60 @@ public partial class AddServerWindow
private void SetHeaderType() private void SetHeaderType()
{ {
var lstHeaderType = new List<string>(); cmbHeaderTypeTcp.ItemsSource = new List<string> { Global.None, Global.TcpHeaderHttp };
var network = cmbNetwork.SelectedItem.ToString(); var kcpHeaderTypes = new List<string> { Global.None };
if (network.IsNullOrEmpty()) kcpHeaderTypes.AddRange(Global.KcpHeaderTypes);
{ cmbHeaderTypeKcp.ItemsSource = kcpHeaderTypes;
lstHeaderType.Add(Global.None);
cmbHeaderType.ItemsSource = lstHeaderType;
cmbHeaderType.SelectedIndex = 0;
return;
}
if (network == nameof(ETransport.tcp)) cmbHeaderTypeXhttp.ItemsSource = Global.XhttpMode;
{ cmbHeaderTypeGrpc.ItemsSource = new List<string> { Global.GrpcGunMode, Global.GrpcMultiMode };
lstHeaderType.Add(Global.None);
lstHeaderType.Add(Global.TcpHeaderHttp); SetTransportGridVisibility();
}
else if (network is nameof(ETransport.kcp) or nameof(ETransport.quic))
{
lstHeaderType.Add(Global.None);
lstHeaderType.AddRange(Global.KcpHeaderTypes);
}
else if (network is nameof(ETransport.xhttp))
{
lstHeaderType.AddRange(Global.XhttpMode);
}
else if (network == nameof(ETransport.grpc))
{
lstHeaderType.Add(Global.GrpcGunMode);
lstHeaderType.Add(Global.GrpcMultiMode);
}
else
{
lstHeaderType.Add(Global.None);
}
cmbHeaderType.ItemsSource = lstHeaderType;
cmbHeaderType.SelectedIndex = 0;
} }
private void SetTips() private void SetTips()
{ {
var network = cmbNetwork.SelectedItem.ToString(); SetTransportGridVisibility();
}
private void SetTransportGridVisibility()
{
var network = cmbNetwork.SelectedItem?.ToString();
if (network.IsNullOrEmpty()) if (network.IsNullOrEmpty())
{ {
network = Global.DefaultNetwork; network = Global.DefaultNetwork;
} }
labHeaderType.Visibility = Visibility.Visible;
popExtra.Visibility = Visibility.Hidden; gridTransportTcp.Visibility = Visibility.Collapsed;
tipRequestHost.Text = gridTransportKcp.Visibility = Visibility.Collapsed;
tipPath.Text = gridTransportWs.Visibility = Visibility.Collapsed;
tipHeaderType.Text = string.Empty; gridTransportHttpupgrade.Visibility = Visibility.Collapsed;
gridTransportXhttp.Visibility = Visibility.Collapsed;
gridTransportGrpc.Visibility = Visibility.Collapsed;
switch (network) switch (network)
{ {
case nameof(ETransport.tcp): case nameof(ETransport.tcp):
tipRequestHost.Text = ResUI.TransportRequestHostTip1; gridTransportTcp.Visibility = Visibility.Visible;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip1;
break; break;
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
tipHeaderType.Text = ResUI.TransportHeaderTypeTip2; gridTransportKcp.Visibility = Visibility.Visible;
tipPath.Text = ResUI.TransportPathTip5;
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
gridTransportWs.Visibility = Visibility.Visible;
break;
case nameof(ETransport.httpupgrade): case nameof(ETransport.httpupgrade):
tipRequestHost.Text = ResUI.TransportRequestHostTip2; gridTransportHttpupgrade.Visibility = Visibility.Visible;
tipPath.Text = ResUI.TransportPathTip1;
break; break;
case nameof(ETransport.xhttp): case nameof(ETransport.xhttp):
tipRequestHost.Text = ResUI.TransportRequestHostTip2; gridTransportXhttp.Visibility = Visibility.Visible;
tipPath.Text = ResUI.TransportPathTip1;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip5;
labHeaderType.Visibility = Visibility.Hidden;
popExtra.Visibility = Visibility.Visible;
break; break;
case nameof(ETransport.h2):
tipRequestHost.Text = ResUI.TransportRequestHostTip3;
tipPath.Text = ResUI.TransportPathTip2;
break;
case nameof(ETransport.quic):
tipRequestHost.Text = ResUI.TransportRequestHostTip4;
tipPath.Text = ResUI.TransportPathTip3;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip3;
break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
tipRequestHost.Text = ResUI.TransportRequestHostTip5; gridTransportGrpc.Visibility = Visibility.Visible;
tipPath.Text = ResUI.TransportPathTip4; break;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip4; default:
labHeaderType.Visibility = Visibility.Hidden; gridTransportTcp.Visibility = Visibility.Visible;
break; break;
} }
} }