mirror of
https://github.com/2dust/v2rayN.git
synced 2026-04-14 11:35:44 +00:00
Add sing-box send-through (#9081)
* Add sing-box send-through * Perf resx
This commit is contained in:
parent
6c8f22ab86
commit
6b07ca63a0
13 changed files with 118 additions and 62 deletions
36
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
36
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
|
@ -4014,24 +4014,6 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 Local outbound address (SendThrough) 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
public static string TbSettingsSendThrough {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("TbSettingsSendThrough", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查找类似 Only applies to Xray. Fill in a local IPv4 address; leave empty to disable. 的本地化字符串。
|
|
||||||
/// </summary>
|
|
||||||
public static string TbSettingsSendThroughTip {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("TbSettingsSendThroughTip", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Enable Log 的本地化字符串。
|
/// 查找类似 Enable Log 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -4176,6 +4158,24 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Local outbound address (SendThrough) 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbSettingsSendThrough {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbSettingsSendThrough", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 For multi-interface environments, enter the local machine's IPv4 address 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbSettingsSendThroughTip {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbSettingsSendThroughTip", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Set Win10 UWP Loopback 的本地化字符串。
|
/// 查找类似 Set Win10 UWP Loopback 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1698,4 +1698,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>Legacy TUN Protect</value>
|
<value>Legacy TUN Protect</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
|
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1695,4 +1695,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>Legacy TUN Protect</value>
|
<value>Legacy TUN Protect</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
|
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1698,4 +1698,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>Legacy TUN Protect</value>
|
<value>Legacy TUN Protect</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
|
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1324,7 +1324,7 @@
|
||||||
<value>Local outbound address (SendThrough)</value>
|
<value>Local outbound address (SendThrough)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
<value>Only applies to Xray. Fill in a local IPv4 address; leave empty to disable.</value>
|
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
|
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
|
||||||
<value>Please fill in the correct IPv4 address for SendThrough.</value>
|
<value>Please fill in the correct IPv4 address for SendThrough.</value>
|
||||||
|
|
@ -1707,4 +1707,4 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>Legacy TUN Protect</value>
|
<value>Legacy TUN Protect</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1698,4 +1698,7 @@
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>Устаревшая защита TUN (Legacy Protect)</value>
|
<value>Устаревшая защита TUN (Legacy Protect)</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
|
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
|
|
@ -1321,7 +1321,7 @@
|
||||||
<value>本地出站地址 (SendThrough)</value>
|
<value>本地出站地址 (SendThrough)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
<value>仅对 Xray 生效,填写本机 IPv4;留空则不设置。</value>
|
<value>用于多网口环境,请填写本机 IPv4 地址</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
|
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
|
||||||
<value>请填写正确的 SendThrough IPv4 地址。</value>
|
<value>请填写正确的 SendThrough IPv4 地址。</value>
|
||||||
|
|
@ -1704,4 +1704,4 @@
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>旧版 TUN 保护</value>
|
<value>旧版 TUN 保护</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1695,4 +1695,7 @@
|
||||||
<data name="TbLegacyProtect" xml:space="preserve">
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
<value>Legacy TUN Protect</value>
|
<value>Legacy TUN Protect</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbSettingsSendThroughTip" xml:space="preserve">
|
||||||
|
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -57,6 +57,8 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||||
|
|
||||||
ConvertGeo2Ruleset();
|
ConvertGeo2Ruleset();
|
||||||
|
|
||||||
|
ApplyOutboundSendThrough();
|
||||||
|
|
||||||
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
||||||
ret.Success = true;
|
ret.Success = true;
|
||||||
|
|
||||||
|
|
@ -221,6 +223,7 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||||
_coreConfig.route.rules.Add(rule);
|
_coreConfig.route.rules.Add(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplyOutboundSendThrough();
|
||||||
ret.Success = true;
|
ret.Success = true;
|
||||||
ret.Data = JsonUtils.Serialize(_coreConfig);
|
ret.Data = JsonUtils.Serialize(_coreConfig);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -279,6 +282,7 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||||
listen_port = port,
|
listen_port = port,
|
||||||
type = EInboundProtocol.mixed.ToString(),
|
type = EInboundProtocol.mixed.ToString(),
|
||||||
});
|
});
|
||||||
|
ApplyOutboundSendThrough();
|
||||||
|
|
||||||
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
||||||
ret.Success = true;
|
ret.Success = true;
|
||||||
|
|
|
||||||
|
|
@ -58,4 +58,40 @@ public partial class CoreConfigSingboxService
|
||||||
|
|
||||||
return JsonUtils.Serialize(fullConfigTemplateNode);
|
return JsonUtils.Serialize(fullConfigTemplateNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyOutboundSendThrough()
|
||||||
|
{
|
||||||
|
var sendThrough = _config.CoreBasicItem.SendThrough?.TrimEx();
|
||||||
|
foreach (var outbound in _coreConfig.outbounds ?? [])
|
||||||
|
{
|
||||||
|
outbound.inet4_bind_address = ShouldApplySendThrough(outbound, sendThrough) ? sendThrough : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool ShouldApplySendThrough(Outbound4Sbox outbound, string? sendThrough)
|
||||||
|
{
|
||||||
|
if (sendThrough.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outbound.type is "direct" or "block" or "dns" or "selector" or "urltest")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!outbound.detour.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var outboundAddress = outbound.server ?? string.Empty;
|
||||||
|
|
||||||
|
if (outboundAddress.Equals("localhost", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !IPAddress.TryParse(outboundAddress, out var address) || !IPAddress.IsLoopback(address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -407,43 +407,4 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion public gen function
|
#endregion public gen function
|
||||||
|
|
||||||
private void ApplyOutboundSendThrough()
|
|
||||||
{
|
|
||||||
var sendThrough = _config.CoreBasicItem.SendThrough?.TrimEx();
|
|
||||||
foreach (var outbound in _coreConfig.outbounds ?? [])
|
|
||||||
{
|
|
||||||
outbound.sendThrough = ShouldApplySendThrough(outbound, sendThrough) ? sendThrough : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool ShouldApplySendThrough(Outbounds4Ray outbound, string? sendThrough)
|
|
||||||
{
|
|
||||||
if (sendThrough.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outbound.protocol is "freedom" or "blackhole" or "dns" or "loopback")
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outbound.streamSettings?.sockopt?.dialerProxy.IsNullOrEmpty() == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var outboundAddress = outbound.settings?.servers?.FirstOrDefault()?.address
|
|
||||||
?? outbound.settings?.vnext?.FirstOrDefault()?.address
|
|
||||||
?? outbound.settings?.address?.ToString()
|
|
||||||
?? string.Empty;
|
|
||||||
|
|
||||||
if (outboundAddress.Equals("localhost", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !IPAddress.TryParse(outboundAddress, out var address) || !IPAddress.IsLoopback(address);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,4 +127,43 @@ public partial class CoreConfigV2rayService
|
||||||
|
|
||||||
return JsonUtils.Serialize(fullConfigTemplateNode);
|
return JsonUtils.Serialize(fullConfigTemplateNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyOutboundSendThrough()
|
||||||
|
{
|
||||||
|
var sendThrough = _config.CoreBasicItem.SendThrough?.TrimEx();
|
||||||
|
foreach (var outbound in _coreConfig.outbounds ?? [])
|
||||||
|
{
|
||||||
|
outbound.sendThrough = ShouldApplySendThrough(outbound, sendThrough) ? sendThrough : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool ShouldApplySendThrough(Outbounds4Ray outbound, string? sendThrough)
|
||||||
|
{
|
||||||
|
if (sendThrough.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outbound.protocol is "freedom" or "blackhole" or "dns" or "loopback")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outbound.streamSettings?.sockopt?.dialerProxy.IsNullOrEmpty() == false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var outboundAddress = outbound.settings?.servers?.FirstOrDefault()?.address
|
||||||
|
?? outbound.settings?.vnext?.FirstOrDefault()?.address
|
||||||
|
?? outbound.settings?.address?.ToString()
|
||||||
|
?? string.Empty;
|
||||||
|
|
||||||
|
if (outboundAddress.Equals("localhost", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !IPAddress.TryParse(outboundAddress, out var address) || !IPAddress.IsLoopback(address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
</Folder>
|
</Folder>
|
||||||
<Project Path="AmazTool/AmazTool.csproj" />
|
<Project Path="AmazTool/AmazTool.csproj" />
|
||||||
<Project Path="GlobalHotKeys/src/GlobalHotKeys/GlobalHotKeys.csproj" />
|
<Project Path="GlobalHotKeys/src/GlobalHotKeys/GlobalHotKeys.csproj" />
|
||||||
|
<Project Path="ServiceLib.Tests/ServiceLib.Tests.csproj" />
|
||||||
<Project Path="ServiceLib/ServiceLib.csproj" />
|
<Project Path="ServiceLib/ServiceLib.csproj" />
|
||||||
<Project Path="v2rayN.Desktop/v2rayN.Desktop.csproj" />
|
<Project Path="v2rayN.Desktop/v2rayN.Desktop.csproj" />
|
||||||
<Project Path="v2rayN/v2rayN.csproj" />
|
<Project Path="v2rayN/v2rayN.csproj" />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue