nameserver_address.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef __NAMESERVER_ADDRESS_H
  15. #define __NAMESERVER_ADDRESS_H
  16. #include <boost/shared_ptr.hpp>
  17. #include <exceptions/exceptions.h>
  18. #include "asiolink.h"
  19. #include "address_entry.h"
  20. #include "nsas_types.h"
  21. namespace isc {
  22. namespace nsas {
  23. class ZoneEntry;
  24. class NameserverEntry;
  25. /// \brief Empty \c NameserverEntry pointer exception
  26. ///
  27. /// Thrown if the the \c NameservrEntry pointer in the \c boost::shared_ptr that passed
  28. /// into \c NameserverAddress' constructor is NULL
  29. class NullNameserverEntryPointer : public isc::Exception {
  30. public:
  31. NullNameserverEntryPointer(const char* file, size_t line,
  32. const char* what) :
  33. isc::Exception(file, line, what)
  34. {}
  35. };
  36. /// \brief Nameserver Address
  37. ///
  38. /// This class implements the object that returned from NSAS when the resolver
  39. /// request an address for the name server. It contains one address
  40. /// that can be used by resolver. When the resolver get query back from the name
  41. /// server, it should update the name server's RTT(Round Trip Time) with this
  42. /// object.
  43. ///
  44. /// It is not thread safe, only reentrant. It is expected to be kept inside
  45. /// the resolver and used only once for the address and once for the update.
  46. class NameserverAddress {
  47. public:
  48. /// \brief Constructor
  49. ///
  50. /// The NameserverAddress object will contain one shared_ptr object that
  51. /// pointed to NameserverEntry which contains the address as well as it's
  52. /// corresponding index. The user can update it's RTT with the index later.
  53. ///
  54. /// \param namerserver A shared_ptr that points to a NameserverEntry object
  55. /// the shared_ptr can avoid the NameserverEntry object being dropped while the
  56. /// request is processing.
  57. /// \param index The address's index in NameserverEntry's addresses vector
  58. /// \param family Address family, V4_ONLY or V6_ONLY
  59. NameserverAddress(const boost::shared_ptr<NameserverEntry> nameserver,
  60. const AddressEntry& address, AddressFamily family):
  61. ns_(nameserver), address_(address), family_(family)
  62. {
  63. if(!ns_) {
  64. isc_throw(NullNameserverEntryPointer, "NULL NameserverEntry pointer.");
  65. }
  66. }
  67. /// \brief Default Constructor
  68. NameserverAddress() : address_(asiolink::IOAddress("::1")) { }
  69. /// \brief Return address
  70. ///
  71. asiolink::IOAddress getAddress() const {
  72. return (address_.getAddress());
  73. }
  74. /// \brief Update Round-trip Time
  75. ///
  76. /// When the user get one request back from the name server, it should
  77. /// update the address's RTT.
  78. /// \param rtt The new Round-Trip Time
  79. void updateRTT(uint32_t rtt) const;
  80. /// Short access to the AddressEntry inside.
  81. //@{
  82. const AddressEntry& getAddressEntry() const {
  83. return (address_);
  84. }
  85. AddressEntry& getAddressEntry() {
  86. return (address_);
  87. }
  88. //@}
  89. private:
  90. /*
  91. * Note: Previous implementation used index into the entry. That is wrong,
  92. * as the list of addresses may change. Thil would cause setting a
  93. * different address or a crash.
  94. */
  95. boost::shared_ptr<NameserverEntry> ns_; ///< Shared-pointer to NameserverEntry object
  96. AddressEntry address_; ///< The address
  97. AddressFamily family_; ///< The address family (V4_ONLY or V6_ONLY)
  98. };
  99. } // namespace nsas
  100. } // namespace isc
  101. #endif//__NAMESERVER_ADDRESS_H