mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
Perf routing
This commit is contained in:
parent
0fac18ba95
commit
81d59ce773
2 changed files with 29 additions and 24 deletions
|
|
@ -298,7 +298,7 @@ public partial class CoreConfigSingboxService
|
|||
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet) ?? [];
|
||||
var expectedIPCidr = new List<string>();
|
||||
var expectedIPsRegions = new List<string>();
|
||||
var regionNames = new HashSet<string>();
|
||||
var regionName = string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(simpleDnsItem?.DirectExpectedIPs))
|
||||
{
|
||||
|
|
@ -313,13 +313,13 @@ public partial class CoreConfigSingboxService
|
|||
if (ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var region = ip["geoip:".Length..];
|
||||
if (!string.IsNullOrEmpty(region))
|
||||
if (string.IsNullOrEmpty(region))
|
||||
{
|
||||
expectedIPsRegions.Add(region);
|
||||
regionNames.Add(region);
|
||||
regionNames.Add($"geolocation-{region}");
|
||||
regionNames.Add($"tld-{region}");
|
||||
continue;
|
||||
}
|
||||
|
||||
expectedIPsRegions.Add(region);
|
||||
regionName = region;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -352,19 +352,24 @@ public partial class CoreConfigSingboxService
|
|||
rule.server = Global.SingboxDirectDNSTag;
|
||||
rule.strategy = Utils.DomainStrategy4Sbox(simpleDnsItem.Strategy4Freedom);
|
||||
|
||||
if (expectedIPsRegions.Count > 0 && rule.geosite?.Count > 0)
|
||||
if (expectedIPsRegions.Count > 0 && rule.geosite?.Count > 0 && !regionName.IsNullOrEmpty())
|
||||
{
|
||||
var geositeSet = new HashSet<string>(rule.geosite);
|
||||
if (regionNames.Intersect(geositeSet).Any())
|
||||
var regionGeosite = rule.geosite.Where(g => g.EndsWith($"-{regionName}", StringComparison.OrdinalIgnoreCase)
|
||||
|| g.EndsWith($"@{regionName}", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
if (regionGeosite.Count > 0)
|
||||
{
|
||||
rule.geosite.RemoveAll(regionGeosite.Contains);
|
||||
var rule4ExpectedIPs = JsonUtils.DeepCopy(rule);
|
||||
rule4ExpectedIPs.geosite = regionGeosite;
|
||||
if (expectedIPsRegions.Count > 0)
|
||||
{
|
||||
rule.geoip = expectedIPsRegions;
|
||||
rule4ExpectedIPs.geoip = expectedIPsRegions;
|
||||
}
|
||||
if (expectedIPCidr.Count > 0)
|
||||
{
|
||||
rule.ip_cidr = expectedIPCidr;
|
||||
rule4ExpectedIPs.ip_cidr = expectedIPCidr;
|
||||
}
|
||||
_coreConfig.dns.rules.Add(rule4ExpectedIPs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public partial class CoreConfigV2rayService
|
|||
var proxyGeositeList = new List<string>();
|
||||
var expectedDomainList = new List<string>();
|
||||
var expectedIPs = new List<string>();
|
||||
var regionNames = new HashSet<string>();
|
||||
var regionName = string.Empty;
|
||||
|
||||
var bootstrapDNSAddress = ParseDnsAddresses(simpleDNSItem?.BootstrapDNS, Global.DomainPureIPDNSAddress.First());
|
||||
var dnsServerDomains = new List<string>();
|
||||
|
|
@ -160,18 +160,14 @@ public partial class CoreConfigV2rayService
|
|||
.Where(s => !string.IsNullOrEmpty(s))
|
||||
.ToList();
|
||||
|
||||
foreach (var ip in expectedIPs)
|
||||
foreach (var region in from ip in expectedIPs
|
||||
where ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase)
|
||||
select ip["geoip:".Length..]
|
||||
into region
|
||||
where !string.IsNullOrEmpty(region)
|
||||
select region)
|
||||
{
|
||||
if (ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var region = ip["geoip:".Length..];
|
||||
if (!string.IsNullOrEmpty(region))
|
||||
{
|
||||
regionNames.Add($"geosite:{region}");
|
||||
regionNames.Add($"geosite:geolocation-{region}");
|
||||
regionNames.Add($"geosite:tld-{region}");
|
||||
}
|
||||
}
|
||||
regionName = region;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +199,11 @@ public partial class CoreConfigV2rayService
|
|||
{
|
||||
if (normalizedDomain.StartsWith("geosite:") || normalizedDomain.StartsWith("ext:"))
|
||||
{
|
||||
(regionNames.Contains(normalizedDomain) ? expectedDomainList : directGeositeList).Add(normalizedDomain);
|
||||
var isExpectedDomain = !regionName.IsNullOrEmpty()
|
||||
|| normalizedDomain.EndsWith($"-{regionName}")
|
||||
|| normalizedDomain.EndsWith($"@{regionName}");
|
||||
var targetList = isExpectedDomain ? expectedDomainList : directGeositeList;
|
||||
targetList.Add(normalizedDomain);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue