rbnode_rrset.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // Copyright (C) 2012 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 __RBNODE_RRSET_H
  15. #define __RBNODE_RRSET_H
  16. #include <dns/messagerenderer.h>
  17. #include <dns/name.h>
  18. #include <dns/rrclass.h>
  19. #include <dns/rrset.h>
  20. #include <dns/rrttl.h>
  21. #include <dns/rrtype.h>
  22. #include <util/buffer.h>
  23. #include <string>
  24. #include <vector>
  25. namespace isc {
  26. namespace datasrc {
  27. namespace internal {
  28. /// \brief The actual content of \c RBNodeRRset
  29. ///
  30. /// This is defined in the namespace-scope (not hidden in the main class)
  31. /// so that the In-memory data source implementation can refer to it.
  32. struct RBNodeRRsetImpl;
  33. // Forward declaration of an opaque data type defined and used within the
  34. // implementation. This is public only because it needs to be used within
  35. // the in-memory data source implementation, but conceptually this is a
  36. // private type for the in-memory data source implementation.
  37. // Note that the definition of the structure is still hidden within the
  38. // implementation, so, basically, a normal application should never be able
  39. // to use it directly even if it peeks into the "internal" namespace.
  40. struct AdditionalNodeInfo;
  41. /// \brief Special RRset for optimizing memory datasource requirement
  42. ///
  43. /// To speed up the performance of the in-memory data source, at load time
  44. /// associate relevant "additional section" data with each RRset in the
  45. /// data source.
  46. ///
  47. /// This class, derived from AbstractRRset, holds a "const" pointer to the
  48. /// underlying RRset object. All calls to methods on the class are passed to
  49. /// the underlying object. However, there are some restrictions:
  50. ///
  51. /// - Calls to methods that change attributes of the underlying RRset (such as
  52. /// TTL or Name) cause an exception to be thrown. The in-memory data source
  53. /// does not allow modification of these attributes. In theory, it is a bad
  54. /// practice in that it doesn't preserve the assumed behavior of the base
  55. /// class. In practice, however, it should be acceptable because this
  56. /// class is effectively hidden from applications and will only be given
  57. /// to them as a const pointer to the base class via find() variants.
  58. /// So the application cannot call non const methods anyway unless it
  59. /// intentionally breaks the constness.
  60. ///
  61. /// - Calls that add the pointer to the associated RRSIG to the RRset are
  62. /// allowed (even though the pointer is to a "const" RRset). The reason here
  63. /// is that RRSIGs are added to the in-memory data source after the
  64. /// RBNodeRRset objects have been created. Thus there has to be the
  65. /// capability of modifying this information.
  66. ///
  67. /// The class is not derived from RRset itself to simplify coding: part of the
  68. /// loading of the memory data source is handled in the BIND 10 "libdns++"
  69. /// code, which creates RRsets and passes them to the data source code. This
  70. /// does not have to be altered if encapsulation, rather than inheritance, is
  71. /// used.
  72. ///
  73. /// \note This class is exposed in this separate header file so that test code
  74. /// can refer to its definition, and only for that purpose. Otherwise this is
  75. /// essentially a private class of the in-memory data source implementation,
  76. /// and an application shouldn't directly refer to this class.
  77. ///
  78. // Note: non-Doxygen-documented methods are documented in the base class.
  79. class RBNodeRRset : public isc::dns::AbstractRRset {
  80. private:
  81. // Note: The copy constructor and the assignment operator are intentionally
  82. // defined as private as we would normally not duplicate a RBNodeRRset.
  83. // (We use the "private" method instead of inheriting from
  84. // boost::noncopyable so as to avoid multiple inheritance.)
  85. RBNodeRRset(const RBNodeRRset& source);
  86. RBNodeRRset& operator=(const RBNodeRRset& source);
  87. public:
  88. /// \brief Usual Constructor
  89. ///
  90. /// Creates an RBNodeRRset from the pointer to the RRset passed to it.
  91. ///
  92. /// \param rrset Pointer to underlying RRset encapsulated by this object.
  93. explicit RBNodeRRset(const isc::dns::ConstRRsetPtr& rrset);
  94. /// \brief Destructor
  95. virtual ~RBNodeRRset();
  96. // Getter and Setter Methods
  97. //
  98. // The getter methods pass the call through to the underlying RRset. The
  99. // setter methods thrown an exception - this specialisation of the RRset
  100. // object does not expect the underlying RRset to be modified.
  101. virtual unsigned int getRdataCount() const;
  102. virtual const isc::dns::Name& getName() const;
  103. virtual const isc::dns::RRClass& getClass() const;
  104. virtual const isc::dns::RRType& getType() const;
  105. virtual const isc::dns::RRTTL& getTTL() const;
  106. virtual void setName(const isc::dns::Name&);
  107. virtual void setTTL(const isc::dns::RRTTL&);
  108. virtual std::string toText() const;
  109. virtual bool isSameKind(const AbstractRRset& other) const {
  110. // This code is an optimisation for comparing
  111. // RBNodeRRsets. However, in doing this optimisation,
  112. // semantically the code is not "is same kind" but is instead
  113. // "is identical object" in the case where RBNodeRRsets are compared.
  114. const RBNodeRRset* rb = dynamic_cast<const RBNodeRRset*>(&other);
  115. if (rb != NULL) {
  116. return (this == rb);
  117. } else {
  118. return (AbstractRRset::isSameKind(other));
  119. }
  120. }
  121. virtual unsigned int toWire(
  122. isc::dns::AbstractMessageRenderer& renderer) const;
  123. virtual unsigned int toWire(isc::util::OutputBuffer& buffer) const;
  124. virtual void addRdata(isc::dns::rdata::ConstRdataPtr);
  125. virtual void addRdata(const isc::dns::rdata::Rdata&);
  126. virtual isc::dns::RdataIteratorPtr getRdataIterator() const;
  127. virtual isc::dns::RRsetPtr getRRsig() const;
  128. virtual unsigned int getRRsigDataCount() const;
  129. // With all the RRsig methods, we have the problem that we store the
  130. // underlying RRset using a ConstRRsetPtr - a pointer to a "const" RRset -
  131. // but we need to modify it by adding or removing an RRSIG. We overcome
  132. // this by temporarily violating the "const" nature of the RRset to add the
  133. // data.
  134. virtual void addRRsig(const isc::dns::rdata::ConstRdataPtr& rdata);
  135. virtual void addRRsig(const isc::dns::rdata::RdataPtr& rdata);
  136. virtual void addRRsig(const AbstractRRset& sigs);
  137. virtual void addRRsig(const isc::dns::ConstRRsetPtr& sigs);
  138. virtual void addRRsig(const isc::dns::RRsetPtr& sigs);
  139. virtual void removeRRsig();
  140. /// \brief Associate a link to an RB node of the additional record.
  141. ///
  142. /// This method adds a given opaque object that holds a link to an RB node
  143. /// of the underlying in-memory data source that is corresponding to an
  144. /// RDATA of this RRset.
  145. ///
  146. /// This method is exposed as public so it can be used within the in-memory
  147. /// data source implementation, and only for that purpose.
  148. ///
  149. /// \param additional An opaque \c AdditionalNodeInfo object to be
  150. /// associated with this RRset.
  151. void addAdditionalNode(const AdditionalNodeInfo& additional);
  152. /// \brief Return a pointer to the list (vector) of additional RB nodes.
  153. ///
  154. /// This method returns a pointer to a vector storing the opaque
  155. /// \c AdditionalNodeInfo object that may be possibly set in this RRset.
  156. /// Not all RRsets are associated with additional nodes; if no
  157. /// such node is stored, this method returns NULL.
  158. ///
  159. /// Like \c addAdditionalNode(), this method is exposed as public only for
  160. /// the in-memory data source implementation.
  161. ///
  162. /// \return A pointer to the associated vector of \c AdditionalNodeInfo;
  163. /// NULL if no additional nodes are associated to this RRset.
  164. const std::vector<AdditionalNodeInfo>* getAdditionalNodes() const;
  165. /// \brief Copy the list of additional RB nodes to another RRset.
  166. ///
  167. /// This method copies the internal list (an STL vector in the actual
  168. /// implementation) of additional RB nodes for this RRset to another
  169. /// \c RBNodeRRset object. The copy destination is generally expected to
  170. /// be newly created and have an empty list, but this method does not
  171. /// check the condition. If the destination already has a non empty list,
  172. /// the existing entries will be lost.
  173. ///
  174. /// \param dst The \c RBNodeRRset object to which the additional
  175. /// RB node list is to be copied.
  176. void copyAdditionalNodes(RBNodeRRset& dst) const;
  177. /// \brief Return underlying RRset pointer
  178. ///
  179. /// ... mainly for testing.
  180. isc::dns::ConstRRsetPtr getUnderlyingRRset() const;
  181. private:
  182. RBNodeRRsetImpl* impl_;
  183. };
  184. } // namespace internal
  185. } // namespace datasrc
  186. } // namespace isc
  187. #endif // __RBNODE_RRSET_H