Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2020, Regents of the University of California. |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -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_ZONE_HPP |
| 21 | #define NDNS_DAEMON_ZONE_HPP |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 22 | |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 23 | #include "common.hpp" |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 24 | |
| 25 | namespace ndn { |
| 26 | namespace ndns { |
| 27 | |
| 28 | /** |
| 29 | * @brief DNS Zone abstraction, which delegates records |
| 30 | * @see http://en.wikipedia.org/wiki/DNS_zone |
| 31 | * @see http://irl.cs.ucla.edu/data/files/theses/afanasyev-thesis.pdf |
| 32 | * |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 33 | * This class is copyable, since it may be assigned to another Zone instance |
| 34 | * when resolving Response or Query from database |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 35 | */ |
| 36 | class Zone |
| 37 | { |
| 38 | public: |
| 39 | Zone(); |
| 40 | |
| 41 | /** |
| 42 | * @brief create a Zone instance |
| 43 | */ |
| 44 | explicit |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 45 | Zone(const Name& name, const time::seconds& ttl = time::seconds(3600)); |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 46 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 47 | /** |
| 48 | * @brief get name of the zone |
| 49 | */ |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 50 | const Name& |
| 51 | getName() const |
| 52 | { |
| 53 | return m_name; |
| 54 | } |
| 55 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 56 | /** |
| 57 | * @brief set name of the zone |
| 58 | */ |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 59 | void |
| 60 | setName(const Name& name) |
| 61 | { |
| 62 | m_name = name; |
| 63 | } |
| 64 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 65 | /** |
| 66 | * @brief get the id when the rr is stored in the database |
| 67 | * default value is 0, the database has to guarantee that id is greater than 0. |
| 68 | */ |
| 69 | uint64_t |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 70 | getId() const |
| 71 | { |
| 72 | return m_id; |
| 73 | } |
| 74 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 75 | /** |
| 76 | * @brief set the id when the rr is stored in the database |
| 77 | * default value is 0, the database has to guarantee that id is greater than 0. |
| 78 | */ |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 79 | void |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 80 | setId(uint64_t id) |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 81 | { |
| 82 | m_id = id; |
| 83 | } |
| 84 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 85 | /** |
| 86 | * @brief get default ttl of resource record delegated in this zone, measured by seconds. |
| 87 | * default 3600 (seconds) |
| 88 | */ |
| 89 | const time::seconds& |
| 90 | getTtl() const |
| 91 | { |
| 92 | return m_ttl; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @brief set default ttl of resource record delegated in this zone, measured by seconds. |
| 97 | * default 3600 (seconds) |
| 98 | */ |
| 99 | void |
| 100 | setTtl(const time::seconds& ttl) |
| 101 | { |
| 102 | m_ttl = ttl; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @brief two zones are equal if they have the same name. Zone's name is unique |
| 107 | */ |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 108 | bool |
| 109 | operator==(const Zone& other) const |
| 110 | { |
| 111 | return (m_name == other.getName()); |
| 112 | } |
| 113 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 114 | bool |
| 115 | operator!=(const Zone& other) const |
| 116 | { |
| 117 | return (m_name != other.getName()); |
| 118 | } |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 119 | |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 120 | private: |
| 121 | uint64_t m_id; |
| 122 | |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 123 | Name m_name; |
Shock Jiang | fc171d9 | 2014-09-26 09:33:40 -0700 | [diff] [blame] | 124 | |
| 125 | time::seconds m_ttl; |
Shock Jiang | 30ad892 | 2014-09-04 15:08:52 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | std::ostream& |
| 129 | operator<<(std::ostream& os, const Zone& zone); |
| 130 | |
| 131 | } // namespace ndns |
| 132 | } // namespace ndn |
| 133 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 134 | #endif // NDNS_DAEMON_ZONE_HPP |