nameserver_address.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_H
  16. #define __NAMESERVER_ADDRESS_H
  17. #include <boost/shared_ptr.hpp>
  18. #include "asiolink.h"
  19. #include "nameserver_entry.h"
  20. namespace isc {
  21. namespace nsas {
  22. /// \brief Empty \c NameserverEntry pointer exception
  23. ///
  24. /// Thrown if the the \c NameservrEntry pointer in the \c boost::shared_ptr that passed
  25. /// into \c NameserverAddress' constructor is NULL
  26. class NullNameserverEntryPointer : public isc::Exception {
  27. public:
  28. NullNameserverEntryPointer(const char* file, size_t line, const char* what) :
  29. isc::Exception(file, line, what)
  30. {}
  31. };
  32. /// \brief Nameserver Address
  33. ///
  34. /// This class implements the object that returned from NSAS when the resolver
  35. /// request an address for the name server. It contains one IOAddress object
  36. /// that can be used by resolver. When the resolver get query back from the name
  37. /// server, it should update the name server's RTT(Round Trip Time) with this
  38. /// object.
  39. class NameserverAddress {
  40. public:
  41. /// \brief Constructor
  42. ///
  43. /// The NameserverAddress object will contain one shared_ptr object that
  44. /// pointed to NameserverEntry which contains the address as well as it's
  45. /// corresponding index. The user can update it's RTT with the index later.
  46. ///
  47. /// \param namerserver A shared_ptr that points to a NameserverEntry object
  48. /// the shared_ptr can avoid the NameserverEntry object being dropped while the
  49. /// request is processing.
  50. /// \param index The address's index in NameserverEntry's addresses vector
  51. /// \param family Address family, AF_INET or AF_INET6
  52. NameserverAddress(boost::shared_ptr<NameserverEntry>& nameserver, uint32_t index, short family):
  53. ns_(nameserver), index_(index), family_(family)
  54. {
  55. if(!ns_.get()) {
  56. isc_throw(NullNameserverEntryPointer, "NULL NameserverEntry pointer.");
  57. }
  58. }
  59. /// \brief Default Constructor
  60. ///
  61. NameserverAddress(): index_(0), family_(AF_INET)
  62. {
  63. }
  64. /// \brief Destructor
  65. ///
  66. /// Empty destructor.
  67. ~NameserverAddress()
  68. {
  69. }
  70. /// \brief Return address
  71. ///
  72. asiolink::IOAddress getAddress() const {
  73. return ns_.get()->getAddressAtIndex(index_, family_);
  74. }
  75. /// \brief Update Round-trip Time
  76. ///
  77. /// When the user get one request back from the name server, it should
  78. /// update the address's RTT.
  79. /// \param rtt The new Round-Trip Time
  80. void updateRTT(uint32_t rtt) {
  81. ns_.get()->updateAddressRTTAtIndex(rtt, index_, family_);
  82. }
  83. private:
  84. boost::shared_ptr<NameserverEntry> ns_; ///< Shared-pointer to NameserverEntry object
  85. uint32_t index_; ///< The address index in NameserverEntry
  86. short family_; ///< Address family AF_INET or AF_INET6
  87. };
  88. } // namespace nsas
  89. } // namespace isc
  90. #endif//__NAMESERVER_ADDRESS_H