Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2018, Regents of the University of California. |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 20 | #ifndef NDNS_DAEMON_RRSET_HPP |
| 21 | #define NDNS_DAEMON_RRSET_HPP |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 22 | |
| 23 | #include "zone.hpp" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace ndns { |
| 27 | |
| 28 | /** |
| 29 | * @brief Resource Record Set (rrset) define the the entry's attributes in NDNS |
| 30 | * this class also reflects the table (rrset) schema in the database |
| 31 | * |
| 32 | * The class is copyable, since it may be assigned to another Rrset instance |
| 33 | * when resolving Response or Query from database |
| 34 | */ |
| 35 | class Rrset |
| 36 | { |
| 37 | public: |
| 38 | explicit |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 39 | Rrset(Zone* zone = nullptr); |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * @brief get the id |
| 43 | * |
| 44 | * Default value is 0, the database has to guarantee that id is greater than 0. |
| 45 | */ |
| 46 | uint64_t |
| 47 | getId() const |
| 48 | { |
| 49 | return m_id; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @brief set the id |
| 54 | * |
| 55 | * Default value is 0, the database has to guarantee that id is greater than 0. |
| 56 | */ |
| 57 | void |
| 58 | setId(uint64_t id) |
| 59 | { |
| 60 | m_id = id; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @brief get the zone where the record is stored |
| 65 | */ |
| 66 | Zone* |
| 67 | getZone() const |
| 68 | { |
| 69 | return m_zone; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @brief set the zone where the record is stored |
| 74 | */ |
| 75 | void |
| 76 | setZone(Zone* zone) |
| 77 | { |
| 78 | m_zone = zone; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @brief get the label of rrset |
| 83 | */ |
| 84 | const Name& |
| 85 | getLabel() const |
| 86 | { |
| 87 | return m_label; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @brief set the label of rrset |
| 92 | */ |
| 93 | void |
| 94 | setLabel(const Name& label) |
| 95 | { |
| 96 | m_label = label; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @brief get the type of this rrset |
| 101 | */ |
| 102 | const name::Component& |
| 103 | getType() const |
| 104 | { |
| 105 | return m_type; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @brief set the type of this rrset |
| 110 | */ |
| 111 | void |
| 112 | setType(const name::Component& type) |
| 113 | { |
| 114 | m_type = type; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @brief get version of the data |
| 119 | */ |
| 120 | const name::Component& |
| 121 | getVersion() const |
| 122 | { |
| 123 | return m_version; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @brief set version of the rrset |
| 128 | */ |
| 129 | void |
| 130 | setVersion(const name::Component& version) |
| 131 | { |
| 132 | m_version = version; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @brief get ttl of the rrset |
| 137 | */ |
| 138 | const time::seconds& |
| 139 | getTtl() const |
| 140 | { |
| 141 | return m_ttl; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @brief set ttl of the rrset |
| 146 | */ |
| 147 | void |
| 148 | setTtl(const time::seconds& ttl) |
| 149 | { |
| 150 | m_ttl = ttl; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @brief get wire formatted block of the Response |
| 155 | */ |
| 156 | const Block& |
| 157 | getData() const |
| 158 | { |
| 159 | return m_data; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @brief set wire formatted block of the Response |
| 164 | */ |
| 165 | void |
| 166 | setData(const Block& data) |
| 167 | { |
| 168 | m_data = data; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @brief compare two rrset instance |
| 173 | * |
| 174 | * Note that comparison ignores id, TTL, and Data when comparing RR sets |
| 175 | */ |
| 176 | bool |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 177 | operator==(const Rrset& other) const; |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * @brief compare two rrset instance |
| 181 | * |
| 182 | * Note that comparison ignores id, TTL, and Data when comparing RR sets |
| 183 | */ |
| 184 | bool |
| 185 | operator!=(const Rrset& other) const |
| 186 | { |
| 187 | return !(*this == other); |
| 188 | } |
| 189 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 190 | bool |
| 191 | operator<(const Rrset& other) const; |
| 192 | |
Shock Jiang | b7370c2 | 2014-09-05 14:43:22 -0700 | [diff] [blame] | 193 | private: |
| 194 | uint64_t m_id; |
| 195 | Zone* m_zone; |
| 196 | Name m_label; |
| 197 | name::Component m_type; |
| 198 | name::Component m_version; |
| 199 | time::seconds m_ttl; |
| 200 | Block m_data; |
| 201 | }; |
| 202 | |
| 203 | std::ostream& |
| 204 | operator<<(std::ostream& os, const Rrset& Rrset); |
| 205 | |
| 206 | } // namespace ndns |
| 207 | } // namespace ndn |
| 208 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 209 | #endif // NDNS_DAEMON_RRSET_HPP |