AdvancedForwarding: updated adguard upstream implementation to support multiple forwarders.

This commit is contained in:
Shreyas Zare
2024-02-17 17:22:29 +05:30
parent a1ec420f83
commit 2db9e9ee83
2 changed files with 49 additions and 2 deletions

View File

@@ -547,6 +547,8 @@ namespace AdvancedForwarding
{
#region variables
static readonly char[] _popWordSeperator = new char[] { ' ' };
readonly IDnsServer _dnsServer;
readonly string _name;
@@ -666,7 +668,28 @@ namespace AdvancedForwarding
}
else
{
forwardings.Add(new Forwarding(domains, NameServerAddress.Parse(forwarder), _dnssecValidation, _configProxyServer));
List<DnsForwarderRecordData> forwarderRecords = new List<DnsForwarderRecordData>();
string word = PopWord(ref forwarder);
while (word.Length > 0)
{
string nextWord = PopWord(ref forwarder);
if (nextWord.StartsWith('('))
{
word += " " + nextWord;
nextWord = PopWord(ref forwarder);
}
forwarderRecords.Add(GetForwarderRecord(NameServerAddress.Parse(word), _dnssecValidation, _configProxyServer));
word = nextWord;
}
if (forwarderRecords.Count == 0)
throw new FormatException("Invalid AdGuard Upstreams config file format: missing upstream servers.");
forwardings.Add(new Forwarding(forwarderRecords, domains));
}
}
else
@@ -689,6 +712,30 @@ namespace AdvancedForwarding
}
}
private static string PopWord(ref string line)
{
if (line.Length == 0)
return line;
line = line.TrimStart(_popWordSeperator);
int i = line.IndexOfAny(_popWordSeperator);
string word;
if (i < 0)
{
word = line;
line = "";
}
else
{
word = line.Substring(0, i);
line = line.Substring(i + 1);
}
return word;
}
#endregion
#region public

View File

@@ -4,7 +4,7 @@
# Example:
# 8.8.8.8
# udp://9.9.9.9
# [/host.com/example.com/]tls://1.1.1.1
# [/host.com/example.com/]https://cloudflare-dns.com/dns-query (1.1.1.1) tls://1.1.1.1
# [/maps.host.com/]#
# [/home/]192.168.10.2
# [/test.com/]https://dns.quad9.net/dns-query (9.9.9.9)