fix(dns): inherit proxy dial strategy in speedtest config (#10558)

GenMinimizedDns rebuilt route.default_domain_resolver with only a server, so speedtest configs dropped the user's Strategy4ProxyDial preference while normal configs applied it. Reuse the same resolver strategy selection for both normal and minimized configs, and add a regression test comparing both configs for UseIPv6v4.
This commit is contained in:
Henglie
2026-11-10 14:48:12 +08:00
committed by GitHub
parent cc28308bd4
commit cdcac0404a
3 changed files with 47 additions and 2 deletions
@@ -842,4 +842,38 @@ public class CoreConfigSingboxServiceTests
await transport.early_data_header_name.Should().BeEqualTo("Sec-WebSocket-Protocol"); await transport.early_data_header_name.Should().BeEqualTo("Sec-WebSocket-Protocol");
await transport.path.Should().BeEqualTo(expectedPath); 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<SingboxConfig>(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<SingboxConfig>(speedtest.Data!.ToString())!;
await speedtestCfg.route.default_domain_resolver.Should().NotBeNull();
await speedtestCfg.route.default_domain_resolver!.strategy.Should().BeEqualTo("prefer_ipv6");
}
} }
@@ -542,6 +542,7 @@ public partial class CoreConfigSingboxService
_coreConfig.route.default_domain_resolver = new() _coreConfig.route.default_domain_resolver = new()
{ {
server = Global.SingboxDirectDNSTag, server = Global.SingboxDirectDNSTag,
strategy = GetDefaultDomainResolverStrategy(),
}; };
} }
@@ -10,13 +10,12 @@ public partial class CoreConfigSingboxService
var simpleDnsItem = context.SimpleDnsItem; var simpleDnsItem = context.SimpleDnsItem;
var defaultDomainResolverTag = Global.SingboxDirectDNSTag; var defaultDomainResolverTag = Global.SingboxDirectDNSTag;
var dialDnsStrategy = Utils.DomainStrategy4Sbox(simpleDnsItem.Strategy4ProxyDial); var dialDnsStrategy = GetDefaultDomainResolverStrategy();
var rawDNSItem = context.RawDnsItem; var rawDNSItem = context.RawDnsItem;
if (rawDNSItem is { Enabled: true }) if (rawDNSItem is { Enabled: true })
{ {
defaultDomainResolverTag = Global.SingboxLocalDNSTag; defaultDomainResolverTag = Global.SingboxLocalDNSTag;
dialDnsStrategy = rawDNSItem.DomainStrategy4Freedom.IsNullOrEmpty() ? null : rawDNSItem.DomainStrategy4Freedom;
} }
else if (!simpleDnsItem.Strategy4Freedom.IsNullOrEmpty()) else if (!simpleDnsItem.Strategy4Freedom.IsNullOrEmpty())
{ {
@@ -613,4 +612,15 @@ public partial class CoreConfigSingboxService
return tag; 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);
}
} }