rbnode_rrset.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. // With all the RRsig methods, we have the problem that we store the
  129. // underlying RRset using a ConstRRsetPtr - a pointer to a "const" RRset -
  130. // but we need to modify it by adding or removing an RRSIG. We overcome
  131. // this by temporarily violating the "const" nature of the RRset to add the
  132. // data.
  133. virtual void addRRsig(const isc::dns::rdata::ConstRdataPtr& rdata);
  134. virtual void addRRsig(const isc::dns::rdata::RdataPtr& rdata);
  135. virtual void addRRsig(const AbstractRRset& sigs);
  136. virtual void addRRsig(const isc::dns::ConstRRsetPtr& sigs);
  137. virtual void addRRsig(const isc::dns::RRsetPtr& sigs);
  138. virtual void removeRRsig();
  139. /// \brief Associate a link to an RB node of the additional record.
  140. ///
  141. /// This method adds a given opaque object that holds a link to an RB node
  142. /// of the underlying in-memory data source that is corresponding to an
  143. /// RDATA of this RRset.
  144. ///
  145. /// This method is exposed as public so it can be used within the in-memory
  146. /// data source implementation, and only for that purpose.
  147. ///
  148. /// \param additional An opaque \c AdditionalNodeInfo object to be
  149. /// associated with this RRset.
  150. void addAdditionalNode(const AdditionalNodeInfo& additional);
  151. /// \brief Return a pointer to the list (vector) of additional RB nodes.
  152. ///
  153. /// This method returns a pointer to a vector storing the opaque
  154. /// \c AdditionalNodeInfo object that may be possibly set in this RRset.
  155. /// Not all RRsets are associated with additional nodes; if no
  156. /// such node is stored, this method returns NULL.
  157. ///
  158. /// Like \c addAdditionalNode(), this method is exposed as public only for
  159. /// the in-memory data source implementation.
  160. ///
  161. /// \return A pointer to the associated vector of \c AdditionalNodeInfo;
  162. /// NULL if no additional nodes are associated to this RRset.
  163. const std::vector<AdditionalNodeInfo>* getAdditionalNodes() const;
  164. /// \brief Copy the list of additional RB nodes to another RRset.
  165. ///
  166. /// This method copies the internal list (an STL vector in the actual
  167. /// implementation) of additional RB nodes for this RRset to another
  168. /// \c RBNodeRRset object. The copy destination is generally expected to
  169. /// be newly created and have an empty list, but this method does not
  170. /// check the condition. If the destination already has a non empty list,
  171. /// the existing entries will be lost.
  172. ///
  173. /// \param dst The \c RBNodeRRset object to which the additional
  174. /// RB node list is to be copied.
  175. void copyAdditionalNodes(RBNodeRRset& dst) const;
  176. /// \brief Return underlying RRset pointer
  177. ///
  178. /// ... mainly for testing.
  179. isc::dns::ConstRRsetPtr getUnderlyingRRset() const;
  180. private:
  181. RBNodeRRsetImpl* impl_;
  182. };
  183. } // namespace internal
  184. } // namespace datasrc
  185. } // namespace isc
  186. #endif // __RBNODE_RRSET_H