diff --git a/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs b/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs index db149f31..eb2c2404 100644 --- a/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs +++ b/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs @@ -842,4 +842,38 @@ public class CoreConfigSingboxServiceTests await transport.early_data_header_name.Should().BeEqualTo("Sec-WebSocket-Protocol"); await transport.path.Should().BeEqualTo(expectedPath); } + + [Test] + public async Task GenerateClientSpeedtestConfig_ShouldInheritProxyDialStrategy() + { + var config = CoreConfigTestFactory.CreateConfig(ECoreType.sing_box); + config.SimpleDNSItem.Strategy4ProxyDial = "UseIPv6v4"; + CoreConfigTestFactory.BindAppManagerConfig(config); + + var node = CoreConfigTestFactory.CreateSocksNode(ECoreType.sing_box); + var context = CoreConfigTestFactory.CreateContext(config, node, ECoreType.sing_box); + + var normal = new CoreConfigSingboxService(context).GenerateClientConfigContent(); + await normal.Success.Should().BeTrue().Because($"ret msg: {normal.Msg}"); + var normalCfg = JsonUtils.Deserialize(normal.Data!.ToString())!; + await normalCfg.route.default_domain_resolver!.strategy.Should().BeEqualTo("prefer_ipv6"); + + var speedtest = new CoreConfigSingboxService(context).GenerateClientSpeedtestConfig( + [ + new() + { + IndexId = node.IndexId, + Address = node.Address, + Port = node.Port, + ConfigType = node.ConfigType, + Profile = node, + CoreType = ECoreType.sing_box, + } + ]); + + await speedtest.Success.Should().BeTrue().Because($"ret msg: {speedtest.Msg}"); + var speedtestCfg = JsonUtils.Deserialize(speedtest.Data!.ToString())!; + await speedtestCfg.route.default_domain_resolver.Should().NotBeNull(); + await speedtestCfg.route.default_domain_resolver!.strategy.Should().BeEqualTo("prefer_ipv6"); + } } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index b9771235..7ff730e2 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -542,6 +542,7 @@ public partial class CoreConfigSingboxService _coreConfig.route.default_domain_resolver = new() { server = Global.SingboxDirectDNSTag, + strategy = GetDefaultDomainResolverStrategy(), }; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 8914b087..d7d9ab8e 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -10,13 +10,12 @@ public partial class CoreConfigSingboxService var simpleDnsItem = context.SimpleDnsItem; var defaultDomainResolverTag = Global.SingboxDirectDNSTag; - var dialDnsStrategy = Utils.DomainStrategy4Sbox(simpleDnsItem.Strategy4ProxyDial); + var dialDnsStrategy = GetDefaultDomainResolverStrategy(); var rawDNSItem = context.RawDnsItem; if (rawDNSItem is { Enabled: true }) { defaultDomainResolverTag = Global.SingboxLocalDNSTag; - dialDnsStrategy = rawDNSItem.DomainStrategy4Freedom.IsNullOrEmpty() ? null : rawDNSItem.DomainStrategy4Freedom; } else if (!simpleDnsItem.Strategy4Freedom.IsNullOrEmpty()) { @@ -613,4 +612,15 @@ public partial class CoreConfigSingboxService return tag; } + + private string? GetDefaultDomainResolverStrategy() + { + var rawDNSItem = context.RawDnsItem; + if (rawDNSItem is { Enabled: true }) + { + return rawDNSItem.DomainStrategy4Freedom.IsNullOrEmpty() ? null : rawDNSItem.DomainStrategy4Freedom; + } + + return Utils.DomainStrategy4Sbox(context.SimpleDnsItem.Strategy4ProxyDial); + } }