rrset_entry.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 __RRSET_ENTRY_H
  16. #define __RRSET_ENTRY_H
  17. #include <dns/rrset.h>
  18. #include <dns/message.h>
  19. #include <dns/rrttl.h>
  20. #include <nsas/nsas_entry.h>
  21. #include <nsas/fetchable.h>
  22. #include "cache_entry_key.h"
  23. using namespace isc::nsas;
  24. namespace isc {
  25. namespace cache {
  26. /// \enum RRset Trustworthiness
  27. /// For detail of RRset trustworthiness, please refer to
  28. /// RFC2181 section5.4.1.
  29. /// Bigger value is more trustworthy.
  30. enum RRsetTrustLevel {
  31. /// Default trust for RRset.
  32. RRSET_TRUST_DEFAULT = 0,
  33. /// Additional information from non-authoritative answer.
  34. RRSET_TRUST_ADDITIONAL_NONAA,
  35. /// Data from the authority section of a non-authoritative answer
  36. RRSET_TRUST_AUTHORITY_NONAA,
  37. /// Additional information from an authoritative answer.
  38. RRSET_TRUST_ADDITIONAL_AA,
  39. /// Non-authoritative data from the answer section of authoritative
  40. /// answers
  41. RRSET_TRUST_NONAUTH_ANSWER_AA,
  42. /// Data from the answer section of a non-authoritative answer.
  43. RRSET_TRUST_ANSWER_NONAA,
  44. /// Glue from a primary zone, or glue from a zone transfer.
  45. RRSET_TRUST_PRIM_GLUE,
  46. /// Data from the authority section of an authoritative answer.
  47. RRSET_TRUST_AUTHORITY_AA,
  48. /// Authoritative data included in the answer section of
  49. /// an authoritative reply.
  50. RRSET_TRUST_ANSWER_AA,
  51. /// Data from a primary zone file, other than glue data.
  52. RRSET_TRUST_PRIM_ZONE_NONGLUE
  53. };
  54. /// \brief RRset Entry
  55. /// The object of RRsetEntry represents one cached RRset.
  56. /// Each RRset entry may be refered using shared_ptr by several message
  57. /// entries.
  58. class RRsetEntry : public NsasEntry<RRsetEntry>
  59. {
  60. ///
  61. /// \name Constructors and Destructor
  62. ///
  63. /// Note: The copy constructor and the assignment operator are intentionally
  64. /// defined as private to make it uncopyable
  65. //@{
  66. private:
  67. RRsetEntry(const RRsetEntry&);
  68. RRsetEntry& operator=(const RRsetEntry&);
  69. public:
  70. /// \brief Constructor
  71. /// \param rrset The RRset used to initialize the RRset entry.
  72. /// \param level trustworthiness of the RRset.
  73. RRsetEntry(const isc::dns::RRset& rrset, const RRsetTrustLevel& level);
  74. /// The destructor.
  75. ~RRsetEntry() {}
  76. //@}
  77. /// \brief Return a pointer to a generated RRset
  78. ///
  79. /// \return Pointer to the generated RRset
  80. isc::dns::RRsetPtr getRRset();
  81. /// \brief Get the expiration time of the RRset.
  82. ///
  83. /// \return The expiration time of the RRset
  84. ///
  85. /// \todo RRsig expiration processing
  86. time_t getExpireTime() const;
  87. /// \brief Get the ttl of the RRset.
  88. ///
  89. /// \return The TTL of the RRset
  90. uint32_t getTTL() {
  91. updateTTL();
  92. return (rrset_->getTTL().getValue());
  93. }
  94. /// \brief Get the hash key
  95. ///
  96. /// \return return hash key
  97. HashKey hashKey() const {
  98. return (hash_key_);
  99. }
  100. /// \brief get RRset trustworthiness
  101. ///
  102. /// \return return the trust level
  103. RRsetTrustLevel getTrustLevel() const {
  104. return (trust_level_);
  105. }
  106. private:
  107. /// \brief Update TTL according to expiration time
  108. void updateTTL();
  109. private:
  110. std::string entry_name_; // The entry name for this rrset entry.
  111. time_t expire_time_; // Expiration time of rrset.
  112. RRsetTrustLevel trust_level_; // RRset trustworthiness.
  113. boost::shared_ptr<isc::dns::RRset> rrset_;
  114. HashKey hash_key_; // RRsetEntry hash key
  115. };
  116. typedef boost::shared_ptr<RRsetEntry> RRsetEntryPtr;
  117. } // namespace cache
  118. } // namespace isc
  119. #endif // __RRSET_ENTRY_H