mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-02-19 14:27:02 +00:00
AllowedZoneManager: using LoadSpecialPrimaryZones() to bulk load and import to avoid loading delays due to indexing. Minor code refactoring changes done.
This commit is contained in:
@@ -76,9 +76,7 @@ namespace DnsServerCore.Dns.ZoneManagers
|
||||
|
||||
try
|
||||
{
|
||||
LogManager log = _dnsServer.LogManager;
|
||||
if (log != null)
|
||||
log.Write("DNS Server is loading allowed zone file: " + allowedZoneFile);
|
||||
_dnsServer.LogManager?.Write("DNS Server is loading allowed zone file: " + allowedZoneFile);
|
||||
|
||||
using (FileStream fS = new FileStream(allowedZoneFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
@@ -92,9 +90,15 @@ namespace DnsServerCore.Dns.ZoneManagers
|
||||
{
|
||||
case 1:
|
||||
int length = bR.ReadInt32();
|
||||
int i = 0;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
AllowZone(bR.ReadShortString());
|
||||
_zoneManager.LoadSpecialPrimaryZones(delegate ()
|
||||
{
|
||||
if (i++ < length)
|
||||
return bR.ReadShortString();
|
||||
|
||||
return null;
|
||||
}, _soaRecord, _nsRecord);
|
||||
|
||||
break;
|
||||
|
||||
@@ -103,19 +107,21 @@ namespace DnsServerCore.Dns.ZoneManagers
|
||||
}
|
||||
}
|
||||
|
||||
if (log != null)
|
||||
log.Write("DNS Server allowed zone file was loaded: " + allowedZoneFile);
|
||||
_dnsServer.LogManager?.Write("DNS Server allowed zone file was loaded: " + allowedZoneFile);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{ }
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager log = _dnsServer.LogManager;
|
||||
if (log != null)
|
||||
log.Write("DNS Server encountered an error while loading allowed zone file: " + allowedZoneFile + "\r\n" + ex.ToString());
|
||||
_dnsServer.LogManager?.Write("DNS Server encountered an error while loading allowed zone file: " + allowedZoneFile + "\r\n" + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void ImportZones(string[] domains)
|
||||
{
|
||||
_zoneManager.LoadSpecialPrimaryZones(domains, _soaRecord, _nsRecord);
|
||||
}
|
||||
|
||||
public bool AllowZone(string domain)
|
||||
{
|
||||
if (_zoneManager.CreateSpecialPrimaryZone(domain, _soaRecord, _nsRecord) != null)
|
||||
@@ -171,9 +177,7 @@ namespace DnsServerCore.Dns.ZoneManagers
|
||||
bW.WriteShortString(zone.Name);
|
||||
}
|
||||
|
||||
LogManager log = _dnsServer.LogManager;
|
||||
if (log != null)
|
||||
log.Write("DNS Server allowed zone file was saved: " + allowedZoneFile);
|
||||
_dnsServer.LogManager?.Write("DNS Server allowed zone file was saved: " + allowedZoneFile);
|
||||
}
|
||||
|
||||
public bool IsAllowed(DnsDatagram request)
|
||||
@@ -181,7 +185,7 @@ namespace DnsServerCore.Dns.ZoneManagers
|
||||
if (_zoneManager.TotalZones < 1)
|
||||
return false;
|
||||
|
||||
return _zoneManager.Query(request) is not null;
|
||||
return _zoneManager.Query(request, false) is not null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user