nameserver_address_store.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // $Id$
  15. #ifndef __NAMESERVER_ADDRESS_STORE_H
  16. #define __NAMESERVER_ADDRESS_STORE_H
  17. #include <string>
  18. #include <vector>
  19. #include <boost/shared_ptr.hpp>
  20. #include "nsas_types.h"
  21. namespace isc {
  22. // Some forward declarations, so we do not need to include so many headers
  23. namespace dns {
  24. class RRClass;
  25. }
  26. namespace nsas {
  27. class ResolverInterface;
  28. template<class T> class HashTable;
  29. template<class T> class LruList;
  30. class ZoneEntry;
  31. class NameserverEntry;
  32. class AddressRequestCallback;
  33. /// \brief Nameserver Address Store
  34. ///
  35. /// This class implements the bare bones of the nameserver address store - the
  36. /// storage of nameserver information. An additional layer above it implements
  37. /// the logic for sending queries for the nameserver addresses if they are not
  38. /// in the store.
  39. class NameserverAddressStore {
  40. public:
  41. /// \brief Constructor
  42. ///
  43. /// The constructor sizes all the tables. As there are various
  44. /// relationships between the table sizes, and as some values are best as
  45. /// prime numbers, the table sizes are determined by compile-time values.
  46. ///
  47. /// \param resolver Which resolver object (or resolver-like, in case of
  48. /// tests) should it use to ask questions.
  49. /// \param zonehashsize Size of the zone hash table. The default value of
  50. /// 1009 is the first prime number above 1000.
  51. /// \param nshash size Size of the nameserver hash table. The default
  52. /// value of 3001 is the first prime number over 3000, and by implication,
  53. /// there is an assumption that there will be more nameservers than zones
  54. /// in the store.
  55. NameserverAddressStore(boost::shared_ptr<ResolverInterface> resolver,
  56. uint32_t zonehashsize = 1009, uint32_t nshashsize = 3001);
  57. /// \brief Destructor
  58. ///
  59. /// Empty virtual destructor.
  60. virtual ~NameserverAddressStore()
  61. {}
  62. /// \brief Lookup Address for a Zone
  63. ///
  64. /// Looks up the address of a nameserver in the zone.
  65. ///
  66. /// \param zone Name of zone for which an address is required.
  67. /// \param class_code Class of the zone.
  68. /// \param callback Callback object used to pass the result back to the
  69. /// caller.
  70. /// \param family Which address is requested.
  71. void lookup(const std::string& zone, const dns::RRClass& class_code,
  72. boost::shared_ptr<AddressRequestCallback> callback, AddressFamily
  73. family = ANY_OK);
  74. /// \brief Protected Members
  75. ///
  76. /// These members should be private. However, with so few public methods
  77. /// and with a lot of internal processing, the testing of this class is
  78. /// problematical.
  79. ///
  80. /// To get round this, a number of elements are declared protected. This
  81. /// means that tests can be carried out by testing a subclass. The subclass
  82. /// does not override the main class methods, but does contain additional
  83. /// methods to set up data and examine the internal state of the class.
  84. //@{
  85. protected:
  86. // Zone and nameserver hash tables
  87. boost::shared_ptr<HashTable<ZoneEntry> > zone_hash_;
  88. boost::shared_ptr<HashTable<NameserverEntry> > nameserver_hash_;
  89. // ... and the LRU lists
  90. boost::shared_ptr<LruList<ZoneEntry> > zone_lru_;
  91. boost::shared_ptr<LruList<NameserverEntry> > nameserver_lru_;
  92. // The resolver we use
  93. private:
  94. boost::shared_ptr<ResolverInterface> resolver_;
  95. //}@
  96. };
  97. } // namespace nsas
  98. } // namespace isc
  99. #endif // __NAMESERVER_ADDRESS_STORE_H