Skip to content

Commit

Permalink
Add authority for grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Mar 23, 2024
1 parent eac0c84 commit f59bbc9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
23 changes: 12 additions & 11 deletions v2rayN/v2rayN/Handler/CoreConfigV2ray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe
alpn = node.GetAlpn(),
fingerprint = node.fingerprint.IsNullOrEmpty() ? _config.coreBasicItem.defFingerprint : node.fingerprint
};
if (!string.IsNullOrWhiteSpace(sni))
if (!Utile.IsNullOrEmpty(sni))
{
tlsSettings.serverName = sni;
}
else if (!string.IsNullOrWhiteSpace(host))
else if (!Utile.IsNullOrEmpty(host))
{
tlsSettings.serverName = Utile.String2List(host)[0];
}
Expand Down Expand Up @@ -592,15 +592,15 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe
WsSettings4Ray wsSettings = new();
wsSettings.headers = new Headers4Ray();
string path = node.path;
if (!string.IsNullOrWhiteSpace(host))
if (!Utile.IsNullOrEmpty(host))
{
wsSettings.headers.Host = host;
}
if (!string.IsNullOrWhiteSpace(path))
if (!Utile.IsNullOrEmpty(path))
{
wsSettings.path = path;
}
if (!string.IsNullOrWhiteSpace(useragent))
if (!Utile.IsNullOrEmpty(useragent))
{
wsSettings.headers.UserAgent = useragent;
}
Expand All @@ -611,11 +611,11 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe
case nameof(ETransport.httpupgrade):
HttpupgradeSettings4Ray httpupgradeSettings = new();

if (!string.IsNullOrWhiteSpace(node.path))
if (!Utile.IsNullOrEmpty(node.path))
{
httpupgradeSettings.path = node.path;
}
if (!string.IsNullOrWhiteSpace(host))
if (!Utile.IsNullOrEmpty(host))
{
httpupgradeSettings.host = host;
}
Expand All @@ -626,7 +626,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe
case nameof(ETransport.h2):
HttpSettings4Ray httpSettings = new();

if (!string.IsNullOrWhiteSpace(host))
if (!Utile.IsNullOrEmpty(host))
{
httpSettings.host = Utile.String2List(host);
}
Expand All @@ -649,7 +649,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe
streamSettings.quicSettings = quicsettings;
if (node.streamSecurity == Global.StreamSecurity)
{
if (!string.IsNullOrWhiteSpace(sni))
if (!Utile.IsNullOrEmpty(sni))
{
streamSettings.tlsSettings.serverName = sni;
}
Expand All @@ -663,6 +663,7 @@ private int GenBoundStreamSettings(ProfileItem node, StreamSettings4Ray streamSe
case nameof(ETransport.grpc):
GrpcSettings4Ray grpcSettings = new()
{
authority = Utile.IsNullOrEmpty(host) ? null : host,
serviceName = node.path,
multiMode = (node.headerType == Global.GrpcMultiMode),
idle_timeout = _config.grpcItem.idle_timeout,
Expand Down Expand Up @@ -721,13 +722,13 @@ private int GenDns(V2rayConfig v2rayConfig)
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray);
var normalDNS = item?.normalDNS;
var domainStrategy4Freedom = item?.domainStrategy4Freedom;
if (string.IsNullOrWhiteSpace(normalDNS))
if (Utile.IsNullOrEmpty(normalDNS))
{
normalDNS = "1.1.1.1,8.8.8.8";
}

//Outbound Freedom domainStrategy
if (!string.IsNullOrWhiteSpace(domainStrategy4Freedom))
if (!Utile.IsNullOrEmpty(domainStrategy4Freedom))
{
var outbound = v2rayConfig.outbounds[1];
outbound.settings.domainStrategy = domainStrategy4Freedom;
Expand Down
4 changes: 3 additions & 1 deletion v2rayN/v2rayN/Handler/ShareHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ private static int GetStdTransport(ProfileItem item, string? securityDef, ref Di
case nameof(ETransport.grpc):
if (!Utile.IsNullOrEmpty(item.path))
{
dicQuery.Add("authority", Utile.UrlEncode(item.requestHost));
dicQuery.Add("serviceName", Utile.UrlEncode(item.path));
if (item.headerType is Global.GrpcGunMode or Global.GrpcMultiMode)
{
Expand Down Expand Up @@ -592,7 +593,7 @@ private static int GetStdTransport(ProfileItem item, string? securityDef, ref Di
break;

default:
if (!string.IsNullOrWhiteSpace(i.streamSecurity))
if (!Utile.IsNullOrEmpty(i.streamSecurity))
return null;
break;
}
Expand Down Expand Up @@ -981,6 +982,7 @@ private static int ResolveStdTransport(NameValueCollection query, ref ProfileIte
break;

case nameof(ETransport.grpc):
item.requestHost = Utile.UrlDecode(query["authority"] ?? "");
item.path = Utile.UrlDecode(query["serviceName"] ?? "");
item.headerType = Utile.UrlDecode(query["mode"] ?? Global.GrpcGunMode);
break;
Expand Down
3 changes: 2 additions & 1 deletion v2rayN/v2rayN/Model/V2rayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ public class QuicSettings4Ray

public class GrpcSettings4Ray
{
public string serviceName { get; set; }
public string? authority { get; set; }
public string? serviceName { get; set; }
public bool multiMode { get; set; }
public int idle_timeout { get; set; }
public int health_check_timeout { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1195,4 +1195,7 @@
<data name="SpeedtestingStop" xml:space="preserve">
<value>Test terminating...</value>
</data>
<data name="TransportRequestHostTip5" xml:space="preserve">
<value>*grpc Authority</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,7 @@
<data name="SpeedtestingStop" xml:space="preserve">
<value>测试终止中...</value>
</data>
<data name="TransportRequestHostTip5" xml:space="preserve">
<value>*grpc Authority</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1165,4 +1165,7 @@
<data name="SpeedtestingStop" xml:space="preserve">
<value>測試終止中...</value>
</data>
<data name="TransportRequestHostTip5" xml:space="preserve">
<value>*grpc Authority</value>
</data>
</root>
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Views/AddServerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ private void SetTips()
break;

case nameof(ETransport.grpc):
tipRequestHost.Text = ResUI.TransportRequestHostTip5;
tipPath.Text = ResUI.TransportPathTip4;
tipHeaderType.Text = ResUI.TransportHeaderTypeTip4;
labHeaderType.Visibility = Visibility.Hidden;
Expand Down

0 comments on commit f59bbc9

Please sign in to comment.