DnsServerInternal.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using DnsServerCore.ApplicationCommon;
  16. using System;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using TechnitiumLibrary.Net.Dns;
  20. using TechnitiumLibrary.Net.Proxy;
  21. namespace DnsServerCore.Dns.Applications
  22. {
  23. class DnsServerInternal : IDnsServer
  24. {
  25. #region variables
  26. readonly DnsServer _dnsServer;
  27. readonly string _applicationName;
  28. readonly string _applicationFolder;
  29. IDnsCache _dnsCache;
  30. #endregion
  31. #region constructor
  32. public DnsServerInternal(DnsServer dnsServer, string applicationName, string applicationFolder)
  33. {
  34. _dnsServer = dnsServer;
  35. _applicationName = applicationName;
  36. _applicationFolder = applicationFolder;
  37. }
  38. #endregion
  39. #region public
  40. public Task<DnsDatagram> DirectQueryAsync(DnsQuestionRecord question, int timeout = 4000)
  41. {
  42. return _dnsServer.DirectQueryAsync(question, timeout, true);
  43. }
  44. public Task<DnsDatagram> DirectQueryAsync(DnsDatagram request, int timeout = 4000)
  45. {
  46. return _dnsServer.DirectQueryAsync(request, timeout, true);
  47. }
  48. public Task<DnsDatagram> ResolveAsync(DnsQuestionRecord question, CancellationToken cancellationToken = default)
  49. {
  50. return DirectQueryAsync(question);
  51. }
  52. public void WriteLog(string message)
  53. {
  54. _dnsServer.LogManager?.Write("DNS App [" + _applicationName + "]: " + message);
  55. }
  56. public void WriteLog(Exception ex)
  57. {
  58. _dnsServer.LogManager?.Write("DNS App [" + _applicationName + "]: " + ex.ToString());
  59. }
  60. #endregion
  61. #region properties
  62. public string ApplicationName
  63. { get { return _applicationName; } }
  64. public string ApplicationFolder
  65. { get { return _applicationFolder; } }
  66. public string ServerDomain
  67. { get { return _dnsServer.ServerDomain; } }
  68. public IDnsCache DnsCache
  69. {
  70. get
  71. {
  72. if (_dnsCache is null)
  73. _dnsCache = new ResolverDnsCache(_dnsServer.DnsApplicationManager, _dnsServer.AuthZoneManager, _dnsServer.CacheZoneManager, _dnsServer.LogManager, true);
  74. return _dnsCache;
  75. }
  76. }
  77. public NetProxy Proxy
  78. { get { return _dnsServer.Proxy; } }
  79. public bool PreferIPv6
  80. { get { return _dnsServer.PreferIPv6; } }
  81. public ushort UdpPayloadSize
  82. { get { return _dnsServer.UdpPayloadSize; } }
  83. #endregion
  84. }
  85. }