Add authority for grpc

pull/4878/head
2dust 2024-03-23 18:26:44 +08:00
parent eac0c84e11
commit f59bbc9981
8 changed files with 36 additions and 13 deletions

View File

@ -533,11 +533,11 @@ namespace v2rayN.Handler
alpn = node.GetAlpn(), alpn = node.GetAlpn(),
fingerprint = node.fingerprint.IsNullOrEmpty() ? _config.coreBasicItem.defFingerprint : node.fingerprint fingerprint = node.fingerprint.IsNullOrEmpty() ? _config.coreBasicItem.defFingerprint : node.fingerprint
}; };
if (!string.IsNullOrWhiteSpace(sni)) if (!Utile.IsNullOrEmpty(sni))
{ {
tlsSettings.serverName = sni; tlsSettings.serverName = sni;
} }
else if (!string.IsNullOrWhiteSpace(host)) else if (!Utile.IsNullOrEmpty(host))
{ {
tlsSettings.serverName = Utile.String2List(host)[0]; tlsSettings.serverName = Utile.String2List(host)[0];
} }
@ -592,15 +592,15 @@ namespace v2rayN.Handler
WsSettings4Ray wsSettings = new(); WsSettings4Ray wsSettings = new();
wsSettings.headers = new Headers4Ray(); wsSettings.headers = new Headers4Ray();
string path = node.path; string path = node.path;
if (!string.IsNullOrWhiteSpace(host)) if (!Utile.IsNullOrEmpty(host))
{ {
wsSettings.headers.Host = host; wsSettings.headers.Host = host;
} }
if (!string.IsNullOrWhiteSpace(path)) if (!Utile.IsNullOrEmpty(path))
{ {
wsSettings.path = path; wsSettings.path = path;
} }
if (!string.IsNullOrWhiteSpace(useragent)) if (!Utile.IsNullOrEmpty(useragent))
{ {
wsSettings.headers.UserAgent = useragent; wsSettings.headers.UserAgent = useragent;
} }
@ -611,11 +611,11 @@ namespace v2rayN.Handler
case nameof(ETransport.httpupgrade): case nameof(ETransport.httpupgrade):
HttpupgradeSettings4Ray httpupgradeSettings = new(); HttpupgradeSettings4Ray httpupgradeSettings = new();
if (!string.IsNullOrWhiteSpace(node.path)) if (!Utile.IsNullOrEmpty(node.path))
{ {
httpupgradeSettings.path = node.path; httpupgradeSettings.path = node.path;
} }
if (!string.IsNullOrWhiteSpace(host)) if (!Utile.IsNullOrEmpty(host))
{ {
httpupgradeSettings.host = host; httpupgradeSettings.host = host;
} }
@ -626,7 +626,7 @@ namespace v2rayN.Handler
case nameof(ETransport.h2): case nameof(ETransport.h2):
HttpSettings4Ray httpSettings = new(); HttpSettings4Ray httpSettings = new();
if (!string.IsNullOrWhiteSpace(host)) if (!Utile.IsNullOrEmpty(host))
{ {
httpSettings.host = Utile.String2List(host); httpSettings.host = Utile.String2List(host);
} }
@ -649,7 +649,7 @@ namespace v2rayN.Handler
streamSettings.quicSettings = quicsettings; streamSettings.quicSettings = quicsettings;
if (node.streamSecurity == Global.StreamSecurity) if (node.streamSecurity == Global.StreamSecurity)
{ {
if (!string.IsNullOrWhiteSpace(sni)) if (!Utile.IsNullOrEmpty(sni))
{ {
streamSettings.tlsSettings.serverName = sni; streamSettings.tlsSettings.serverName = sni;
} }
@ -663,6 +663,7 @@ namespace v2rayN.Handler
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
GrpcSettings4Ray grpcSettings = new() GrpcSettings4Ray grpcSettings = new()
{ {
authority = Utile.IsNullOrEmpty(host) ? null : host,
serviceName = node.path, serviceName = node.path,
multiMode = (node.headerType == Global.GrpcMultiMode), multiMode = (node.headerType == Global.GrpcMultiMode),
idle_timeout = _config.grpcItem.idle_timeout, idle_timeout = _config.grpcItem.idle_timeout,
@ -721,13 +722,13 @@ namespace v2rayN.Handler
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray);
var normalDNS = item?.normalDNS; var normalDNS = item?.normalDNS;
var domainStrategy4Freedom = item?.domainStrategy4Freedom; var domainStrategy4Freedom = item?.domainStrategy4Freedom;
if (string.IsNullOrWhiteSpace(normalDNS)) if (Utile.IsNullOrEmpty(normalDNS))
{ {
normalDNS = "1.1.1.1,8.8.8.8"; normalDNS = "1.1.1.1,8.8.8.8";
} }
//Outbound Freedom domainStrategy //Outbound Freedom domainStrategy
if (!string.IsNullOrWhiteSpace(domainStrategy4Freedom)) if (!Utile.IsNullOrEmpty(domainStrategy4Freedom))
{ {
var outbound = v2rayConfig.outbounds[1]; var outbound = v2rayConfig.outbounds[1];
outbound.settings.domainStrategy = domainStrategy4Freedom; outbound.settings.domainStrategy = domainStrategy4Freedom;

View File

@ -364,6 +364,7 @@ namespace v2rayN.Handler
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
if (!Utile.IsNullOrEmpty(item.path)) if (!Utile.IsNullOrEmpty(item.path))
{ {
dicQuery.Add("authority", Utile.UrlEncode(item.requestHost));
dicQuery.Add("serviceName", Utile.UrlEncode(item.path)); dicQuery.Add("serviceName", Utile.UrlEncode(item.path));
if (item.headerType is Global.GrpcGunMode or Global.GrpcMultiMode) if (item.headerType is Global.GrpcGunMode or Global.GrpcMultiMode)
{ {
@ -592,7 +593,7 @@ namespace v2rayN.Handler
break; break;
default: default:
if (!string.IsNullOrWhiteSpace(i.streamSecurity)) if (!Utile.IsNullOrEmpty(i.streamSecurity))
return null; return null;
break; break;
} }
@ -981,6 +982,7 @@ namespace v2rayN.Handler
break; break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
item.requestHost = Utile.UrlDecode(query["authority"] ?? "");
item.path = Utile.UrlDecode(query["serviceName"] ?? ""); item.path = Utile.UrlDecode(query["serviceName"] ?? "");
item.headerType = Utile.UrlDecode(query["mode"] ?? Global.GrpcGunMode); item.headerType = Utile.UrlDecode(query["mode"] ?? Global.GrpcGunMode);
break; break;

View File

@ -639,7 +639,8 @@ namespace v2rayN.Model
public class GrpcSettings4Ray public class GrpcSettings4Ray
{ {
public string serviceName { get; set; } public string? authority { get; set; }
public string? serviceName { get; set; }
public bool multiMode { get; set; } public bool multiMode { get; set; }
public int idle_timeout { get; set; } public int idle_timeout { get; set; }
public int health_check_timeout { get; set; } public int health_check_timeout { get; set; }

View File

@ -3283,6 +3283,15 @@ namespace v2rayN.Resx {
} }
} }
/// <summary>
/// 查找类似 *grpc Authority 的本地化字符串。
/// </summary>
public static string TransportRequestHostTip5 {
get {
return ResourceManager.GetString("TransportRequestHostTip5", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Ungrouped 的本地化字符串。 /// 查找类似 Ungrouped 的本地化字符串。
/// </summary> /// </summary>

View File

@ -1195,4 +1195,7 @@
<data name="SpeedtestingStop" xml:space="preserve"> <data name="SpeedtestingStop" xml:space="preserve">
<value>Test terminating...</value> <value>Test terminating...</value>
</data> </data>
<data name="TransportRequestHostTip5" xml:space="preserve">
<value>*grpc Authority</value>
</data>
</root> </root>

View File

@ -1192,4 +1192,7 @@
<data name="SpeedtestingStop" xml:space="preserve"> <data name="SpeedtestingStop" xml:space="preserve">
<value>测试终止中...</value> <value>测试终止中...</value>
</data> </data>
<data name="TransportRequestHostTip5" xml:space="preserve">
<value>*grpc Authority</value>
</data>
</root> </root>

View File

@ -1165,4 +1165,7 @@
<data name="SpeedtestingStop" xml:space="preserve"> <data name="SpeedtestingStop" xml:space="preserve">
<value>測試終止中...</value> <value>測試終止中...</value>
</data> </data>
<data name="TransportRequestHostTip5" xml:space="preserve">
<value>*grpc Authority</value>
</data>
</root> </root>

View File

@ -346,6 +346,7 @@ namespace v2rayN.Views
break; break;
case nameof(ETransport.grpc): case nameof(ETransport.grpc):
tipRequestHost.Text = ResUI.TransportRequestHostTip5;
tipPath.Text = ResUI.TransportPathTip4; tipPath.Text = ResUI.TransportPathTip4;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip4; tipHeaderType.Text = ResUI.TransportHeaderTypeTip4;
labHeaderType.Visibility = Visibility.Hidden; labHeaderType.Visibility = Visibility.Hidden;