mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-28 20:40:20 +00:00
QueryLogsSqlite: implemented support for new IDnsQueryLogs interface. Added maxQueueSize config option to prevent memory overflow due to high throughput.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Technitium DNS Server
|
Technitium DNS Server
|
||||||
Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
|
Copyright (C) 2025 Shreyas Zare (shreyas@technitium.com)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -34,13 +34,14 @@ using TechnitiumLibrary.Net.Dns.ResourceRecords;
|
|||||||
|
|
||||||
namespace QueryLogsSqlite
|
namespace QueryLogsSqlite
|
||||||
{
|
{
|
||||||
public sealed class App : IDnsApplication, IDnsQueryLogger
|
public sealed class App : IDnsApplication, IDnsQueryLogger, IDnsQueryLogs
|
||||||
{
|
{
|
||||||
#region variables
|
#region variables
|
||||||
|
|
||||||
IDnsServer _dnsServer;
|
IDnsServer _dnsServer;
|
||||||
|
|
||||||
bool _enableLogging;
|
bool _enableLogging;
|
||||||
|
int _maxQueueSize;
|
||||||
int _maxLogDays;
|
int _maxLogDays;
|
||||||
int _maxLogRecords;
|
int _maxLogRecords;
|
||||||
bool _useInMemoryDb;
|
bool _useInMemoryDb;
|
||||||
@@ -289,6 +290,7 @@ namespace QueryLogsSqlite
|
|||||||
JsonElement jsonConfig = jsonDocument.RootElement;
|
JsonElement jsonConfig = jsonDocument.RootElement;
|
||||||
|
|
||||||
_enableLogging = jsonConfig.GetPropertyValue("enableLogging", true);
|
_enableLogging = jsonConfig.GetPropertyValue("enableLogging", true);
|
||||||
|
_maxQueueSize = jsonConfig.GetPropertyValue("maxQueueSize", 200000);
|
||||||
_maxLogDays = jsonConfig.GetPropertyValue("maxLogDays", 0);
|
_maxLogDays = jsonConfig.GetPropertyValue("maxLogDays", 0);
|
||||||
_maxLogRecords = jsonConfig.GetPropertyValue("maxLogRecords", 0);
|
_maxLogRecords = jsonConfig.GetPropertyValue("maxLogRecords", 0);
|
||||||
_useInMemoryDb = jsonConfig.GetPropertyValue("useInMemoryDb", false);
|
_useInMemoryDb = jsonConfig.GetPropertyValue("useInMemoryDb", false);
|
||||||
@@ -458,12 +460,22 @@ CREATE TABLE IF NOT EXISTS dns_logs
|
|||||||
|
|
||||||
await File.WriteAllTextAsync(Path.Combine(dnsServer.ApplicationFolder, "dnsApp.config"), config);
|
await File.WriteAllTextAsync(Path.Combine(dnsServer.ApplicationFolder, "dnsApp.config"), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!jsonConfig.TryGetProperty("maxQueueSize", out _))
|
||||||
|
{
|
||||||
|
config = config.Replace("\"maxLogDays\"", "\"maxQueueSize\": 200000,\r\n \"maxLogDays\"");
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync(Path.Combine(dnsServer.ApplicationFolder, "dnsApp.config"), config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task InsertLogAsync(DateTime timestamp, DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, DnsDatagram response)
|
public Task InsertLogAsync(DateTime timestamp, DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, DnsDatagram response)
|
||||||
{
|
{
|
||||||
if (_enableLogging)
|
if (_enableLogging)
|
||||||
|
{
|
||||||
|
if (_queuedLogs.Count < _maxQueueSize)
|
||||||
_queuedLogs.Enqueue(new LogEntry(timestamp, request, remoteEP, protocol, response));
|
_queuedLogs.Enqueue(new LogEntry(timestamp, request, remoteEP, protocol, response));
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"enableLogging": true,
|
"enableLogging": true,
|
||||||
|
"maxQueueSize": 200000,
|
||||||
"maxLogDays": 7,
|
"maxLogDays": 7,
|
||||||
"maxLogRecords": 10000,
|
"maxLogRecords": 10000,
|
||||||
"useInMemoryDb": false,
|
"useInMemoryDb": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user