DnsServerInternal.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2024 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.Net.Mail;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. using TechnitiumLibrary.Net.Dns;
  21. using TechnitiumLibrary.Net.Proxy;
  22. namespace DnsServerCore.Dns.Applications
  23. {
  24. class DnsServerInternal : IDnsServer
  25. {
  26. #region variables
  27. readonly DnsServer _dnsServer;
  28. readonly string _applicationName;
  29. readonly string _applicationFolder;
  30. IDnsCache _dnsCache;
  31. #endregion
  32. #region constructor
  33. public DnsServerInternal(DnsServer dnsServer, string applicationName, string applicationFolder)
  34. {
  35. _dnsServer = dnsServer;
  36. _applicationName = applicationName;
  37. _applicationFolder = applicationFolder;
  38. }
  39. #endregion
  40. #region public
  41. public Task<DnsDatagram> DirectQueryAsync(DnsQuestionRecord question, int timeout = 4000)
  42. {
  43. return _dnsServer.DirectQueryAsync(question, timeout, true);
  44. }
  45. public Task<DnsDatagram> DirectQueryAsync(DnsDatagram request, int timeout = 4000)
  46. {
  47. return _dnsServer.DirectQueryAsync(request, timeout, true);
  48. }
  49. public Task<DnsDatagram> ResolveAsync(DnsQuestionRecord question, CancellationToken cancellationToken = default)
  50. {
  51. return DirectQueryAsync(question);
  52. }
  53. public void WriteLog(string message)
  54. {
  55. _dnsServer.LogManager?.Write("DNS App [" + _applicationName + "]: " + message);
  56. }
  57. public void WriteLog(Exception ex)
  58. {
  59. _dnsServer.LogManager?.Write("DNS App [" + _applicationName + "]: " + ex.ToString());
  60. }
  61. #endregion
  62. #region properties
  63. public string ApplicationName
  64. { get { return _applicationName; } }
  65. public string ApplicationFolder
  66. { get { return _applicationFolder; } }
  67. public string ServerDomain
  68. { get { return _dnsServer.ServerDomain; } }
  69. public MailAddress ResponsiblePerson
  70. { get { return _dnsServer.ResponsiblePerson; } }
  71. public IDnsCache DnsCache
  72. {
  73. get
  74. {
  75. if (_dnsCache is null)
  76. _dnsCache = new ResolverDnsCache(_dnsServer, true);
  77. return _dnsCache;
  78. }
  79. }
  80. public NetProxy Proxy
  81. { get { return _dnsServer.Proxy; } }
  82. public bool PreferIPv6
  83. { get { return _dnsServer.PreferIPv6; } }
  84. public ushort UdpPayloadSize
  85. { get { return _dnsServer.UdpPayloadSize; } }
  86. #endregion
  87. }
  88. }