* Fix

* Fix

* Use HashSet instead of List

* Use HashSet instead of List for sing-box
This commit is contained in:
DHR60
2026-08-26 11:41:52 +00:00
committed by GitHub
parent af0eb9ed14
commit e50c0a9170
2 changed files with 27 additions and 28 deletions

View File

@@ -306,8 +306,8 @@ public partial class CoreConfigSingboxService
}
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet) ?? [];
var expectedIPCidr = new List<string>();
var expectedIPsRegions = new List<string>();
var expectedIPCidr = new HashSet<string>();
var expectedIPsRegions = new HashSet<string>();
var regionName = string.Empty;
if (!string.IsNullOrEmpty(simpleDnsItem?.DirectExpectedIPs))
@@ -316,7 +316,7 @@ public partial class CoreConfigSingboxService
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Trim())
.Where(s => !string.IsNullOrEmpty(s))
.ToList();
.ToHashSet();
foreach (var ip in ipItems)
{
@@ -374,11 +374,11 @@ public partial class CoreConfigSingboxService
rule4ExpectedIPs.geosite = regionGeosite;
if (expectedIPsRegions.Count > 0)
{
rule4ExpectedIPs.geoip = expectedIPsRegions;
rule4ExpectedIPs.geoip = expectedIPsRegions.ToList();
}
if (expectedIPCidr.Count > 0)
{
rule4ExpectedIPs.ip_cidr = expectedIPCidr;
rule4ExpectedIPs.ip_cidr = expectedIPCidr.ToList();
}
_coreConfig.dns.rules.Add(rule4ExpectedIPs);
}

View File

@@ -159,16 +159,16 @@ public partial class CoreConfigV2rayService
var directDNSAddress = ParseDnsAddresses(simpleDNSItem?.DirectDNS, Global.DomainDirectDNSAddress.First());
var remoteDNSAddress = ParseDnsAddresses(simpleDNSItem?.RemoteDNS, Global.DomainRemoteDNSAddress.First());
var directDomainList = new List<string>();
var directGeositeList = new List<string>();
var proxyDomainList = new List<string>();
var proxyGeositeList = new List<string>();
var expectedDomainList = new List<string>();
var expectedIPs = new List<string>();
var directDomainList = new HashSet<string>();
var directGeositeList = new HashSet<string>();
var proxyDomainList = new HashSet<string>();
var proxyGeositeList = new HashSet<string>();
var expectedDomainList = new HashSet<string>();
var expectedIPs = new HashSet<string>();
var regionName = string.Empty;
var bootstrapDNSAddress = ParseDnsAddresses(simpleDNSItem?.BootstrapDNS, Global.DomainPureIPDNSAddress.First());
var dnsServerDomains = new List<string>();
var dnsServerDomains = new HashSet<string>();
foreach (var dns in directDNSAddress)
{
@@ -194,7 +194,6 @@ public partial class CoreConfigV2rayService
dnsServerDomains.Add($"full:{domain}");
}
}
dnsServerDomains = dnsServerDomains.Distinct().ToList();
if (!string.IsNullOrEmpty(simpleDNSItem?.DirectExpectedIPs))
{
@@ -202,7 +201,7 @@ public partial class CoreConfigV2rayService
.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Trim())
.Where(s => !string.IsNullOrEmpty(s))
.ToList();
.ToHashSet();
foreach (var region in from ip in expectedIPs
where ip.StartsWith(Global.GeoIPPrefix, StringComparison.OrdinalIgnoreCase)
@@ -269,15 +268,19 @@ public partial class CoreConfigV2rayService
}
}
if (context.ProtectDomainList.Count > 0)
{
directDomainList.AddRange(context.ProtectDomainList);
}
dnsItem.servers ??= [];
var directDnsTagIndex = 1;
if (dnsServerDomains.Count > 0)
{
AddDnsServers(bootstrapDNSAddress, dnsServerDomains);
}
if (context.ProtectDomainList.Count > 0)
{
AddDnsServers(directDNSAddress, context.ProtectDomainList, true);
}
if (simpleDNSItem.FakeIP == true)
{
var fakeIPMatchDomain = new HashSet<string>(proxyDomainList);
@@ -291,7 +294,7 @@ public partial class CoreConfigV2rayService
if (fakeIPMatchDomain.Count > 0)
{
GenFakeDns();
AddDnsServers(["fakedns"], fakeIPMatchDomain.ToList());
AddDnsServers(["fakedns"], fakeIPMatchDomain);
}
}
@@ -300,10 +303,6 @@ public partial class CoreConfigV2rayService
AddDnsServers(remoteDNSAddress, proxyGeositeList);
AddDnsServers(directDNSAddress, directGeositeList, true);
AddDnsServers(directDNSAddress, expectedDomainList, true, expectedIPs);
if (dnsServerDomains.Count > 0)
{
AddDnsServers(bootstrapDNSAddress, dnsServerDomains);
}
var useDirectDns = false;
@@ -345,7 +344,7 @@ public partial class CoreConfigV2rayService
return addresses.Count > 0 ? addresses : new List<string> { defaultAddress };
}
static DnsServer4Ray CreateDnsServer(string dnsAddress, List<string> domains, List<string>? expectedIPs = null)
static DnsServer4Ray CreateDnsServer(string dnsAddress, HashSet<string> domains, HashSet<string>? expectedIPs = null)
{
var (domain, scheme, port, path) = Utils.ParseUrl(dnsAddress);
var domainFinal = dnsAddress;
@@ -365,13 +364,13 @@ public partial class CoreConfigV2rayService
address = domainFinal,
port = portFinal,
skipFallback = true,
domains = domains.Count > 0 ? domains : null,
expectedIPs = expectedIPs?.Count > 0 ? expectedIPs : null
domains = domains.Count > 0 ? domains.ToList() : null,
expectedIPs = expectedIPs?.Count > 0 ? expectedIPs.ToList() : null
};
return dnsServer;
}
void AddDnsServers(List<string> dnsAddresses, List<string> domains, bool isDirectDns = false, List<string>? expectedIPs = null)
void AddDnsServers(List<string> dnsAddresses, HashSet<string> domains, bool isDirectDns = false, HashSet<string>? expectedIPs = null)
{
if (domains.Count <= 0)
{