From 0367ac4d0f18cc306ef3241bf372bf9bb876ca3a Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 4 Feb 2024 16:55:43 +0530 Subject: [PATCH] AdvancedForwarding: code refactoring changes done. --- Apps/AdvancedForwardingApp/App.cs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Apps/AdvancedForwardingApp/App.cs b/Apps/AdvancedForwardingApp/App.cs index a126b709..58b06bc0 100644 --- a/Apps/AdvancedForwardingApp/App.cs +++ b/Apps/AdvancedForwardingApp/App.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com) 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 @@ -32,7 +32,7 @@ using TechnitiumLibrary.Net.Dns.ResourceRecords; namespace AdvancedForwarding { - public class App : IDnsApplication, IDnsAuthoritativeRequestHandler + public sealed class App : IDnsApplication, IDnsAuthoritativeRequestHandler { #region variables @@ -41,8 +41,8 @@ namespace AdvancedForwarding bool _enableForwarding; Dictionary _configProxyServers; Dictionary _configForwarders; - IReadOnlyDictionary _networkGroupMap; - IReadOnlyDictionary _groups; + Dictionary _networkGroupMap; + Dictionary _groups; #endregion @@ -61,7 +61,7 @@ namespace AdvancedForwarding #region private - private static IReadOnlyList GetUpdatedForwarderRecords(IReadOnlyList forwarderRecords, bool dnssecValidation, ConfigProxyServer configProxyServer) + private static List GetUpdatedForwarderRecords(IReadOnlyList forwarderRecords, bool dnssecValidation, ConfigProxyServer configProxyServer) { List newForwarderRecords = new List(forwarderRecords.Count); @@ -90,10 +90,9 @@ namespace AdvancedForwarding private Tuple ReadGroup(JsonElement jsonGroup) { - Group group; string name = jsonGroup.GetProperty("name").GetString(); - if ((_groups is not null) && _groups.TryGetValue(name, out group)) + if ((_groups is not null) && _groups.TryGetValue(name, out Group group)) group.ReloadConfig(_configProxyServers, _configForwarders, jsonGroup); else group = new Group(_dnsServer, _configProxyServers, _configForwarders, jsonGroup); @@ -218,7 +217,7 @@ namespace AdvancedForwarding readonly string _name; bool _enableForwarding; IReadOnlyList _forwardings; - IReadOnlyDictionary _adguardUpstreams; + Dictionary _adguardUpstreams; #endregion @@ -254,10 +253,9 @@ namespace AdvancedForwarding private Tuple ReadAdGuardUpstream(JsonElement jsonAdguardUpstream) { - AdGuardUpstream adGuardUpstream; string name = jsonAdguardUpstream.GetProperty("configFile").GetString(); - if ((_adguardUpstreams is not null) && _adguardUpstreams.TryGetValue(name, out adGuardUpstream)) + if ((_adguardUpstreams is not null) && _adguardUpstreams.TryGetValue(name, out AdGuardUpstream adGuardUpstream)) adGuardUpstream.ReloadConfig(_configProxyServers, jsonAdguardUpstream); else adGuardUpstream = new AdGuardUpstream(_dnsServer, _configProxyServers, jsonAdguardUpstream); @@ -344,7 +342,7 @@ namespace AdvancedForwarding #region variables IReadOnlyList _forwarderRecords; - readonly IReadOnlyDictionary _domainMap; + readonly Dictionary _domainMap; #endregion @@ -818,7 +816,7 @@ namespace AdvancedForwarding #region variables readonly string _name; - readonly IReadOnlyList _forwarderRecords; + readonly DnsForwarderRecordData[] _forwarderRecords; #endregion @@ -850,7 +848,7 @@ namespace AdvancedForwarding public string Name { get { return _name; } } - public IReadOnlyList ForwarderRecords + public DnsForwarderRecordData[] ForwarderRecords { get { return _forwarderRecords; } } #endregion