Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
Davide Pesavento | bc92d5c | 2021-05-09 01:21:33 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, Regents of the University of California. |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -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 | |
| 20 | #ifndef NDNS_DAEMON_NAME_SERVER_HPP |
| 21 | #define NDNS_DAEMON_NAME_SERVER_HPP |
| 22 | |
| 23 | #include "zone.hpp" |
| 24 | #include "rrset.hpp" |
| 25 | #include "db-mgr.hpp" |
| 26 | #include "ndns-label.hpp" |
| 27 | #include "ndns-tlv.hpp" |
Yumin Xia | 99c821a | 2017-04-07 11:01:08 -0700 | [diff] [blame] | 28 | #include "validator/validator.hpp" |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 29 | |
| 30 | #include <ndn-cxx/security/key-chain.hpp> |
| 31 | #include <ndn-cxx/face.hpp> |
| 32 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 33 | #include <sstream> |
| 34 | #include <stdexcept> |
| 35 | |
| 36 | namespace ndn { |
| 37 | namespace ndns { |
| 38 | |
| 39 | /** |
| 40 | * @brief provides authoritative name server. |
| 41 | * |
| 42 | * The authoritative name server handles NDNS query and update. |
| 43 | */ |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 44 | class NameServer : boost::noncopyable |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 45 | { |
| 46 | DEFINE_ERROR(Error, std::runtime_error); |
| 47 | |
| 48 | public: |
| 49 | explicit |
| 50 | NameServer(const Name& zoneName, const Name& certName, Face& face, DbMgr& dbMgr, |
Alexander Afanasyev | 60514ec | 2020-06-03 14:18:53 -0400 | [diff] [blame] | 51 | KeyChain& keyChain, security::Validator& validator); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 52 | |
| 53 | NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 54 | void |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 55 | onInterest(const Name& prefix, const Interest& interest); |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * @brief handle NDNS query message |
| 59 | */ |
| 60 | void |
| 61 | handleQuery(const Name& prefix, const Interest& interest, const label::MatchResult& re); |
| 62 | |
| 63 | /** |
| 64 | * @brief handle NDNS update message |
| 65 | */ |
| 66 | void |
| 67 | handleUpdate(const Name& prefix, const Interest& interest, const label::MatchResult& re); |
| 68 | |
| 69 | void |
| 70 | onRegisterFailed(const ndn::Name& prefix, const std::string& reason); |
| 71 | |
| 72 | void |
| 73 | doUpdate(const shared_ptr<const Interest>& interest, const shared_ptr<const Data>& data); |
| 74 | |
| 75 | public: |
| 76 | const Name& |
| 77 | getNdnsPrefix() |
| 78 | { |
| 79 | return m_ndnsPrefix; |
| 80 | } |
| 81 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 82 | const Zone& |
| 83 | getZone() const |
| 84 | { |
| 85 | return m_zone; |
| 86 | } |
| 87 | |
| 88 | const time::milliseconds& |
| 89 | getContentFreshness() const |
| 90 | { |
| 91 | return m_contentFreshness; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @brief set the Data fresh period |
| 96 | */ |
| 97 | void |
| 98 | setContentFreshness(const time::milliseconds& contentFreshness) |
| 99 | { |
| 100 | BOOST_ASSERT(contentFreshness > time::milliseconds::zero()); |
| 101 | m_contentFreshness = contentFreshness; |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | Zone m_zone; |
| 106 | DbMgr& m_dbMgr; |
| 107 | |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 108 | Name m_ndnsPrefix; |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 109 | Name m_certName; |
| 110 | |
| 111 | time::milliseconds m_contentFreshness; |
| 112 | |
| 113 | Face& m_face; |
| 114 | KeyChain& m_keyChain; |
Alexander Afanasyev | 60514ec | 2020-06-03 14:18:53 -0400 | [diff] [blame] | 115 | security::Validator& m_validator; |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } // namespace ndns |
| 119 | } // namespace ndn |
| 120 | |
| 121 | #endif // NDNS_DAEMON_NAME_SERVER_HPP |