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