blob: 8a84f42f712995c3b9bba7fd7a851227de87cee4 [file] [log] [blame]
Shock Jiangcde28712014-10-19 21:17:20 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Alexander Afanasyev60514ec2020-06-03 14:18:53 -04003 * Copyright (c) 2014-2020, Regents of the University of California.
Shock Jiangcde28712014-10-19 21:17:20 -07004 *
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 Xia99c821a2017-04-07 11:01:08 -070028#include "validator/validator.hpp"
Shock Jiangcde28712014-10-19 21:17:20 -070029
30#include <ndn-cxx/security/key-chain.hpp>
31#include <ndn-cxx/face.hpp>
32
33#include <boost/asio.hpp>
34#include <boost/bind.hpp>
Shock Jiangcde28712014-10-19 21:17:20 -070035
36#include <sstream>
37#include <stdexcept>
38
39namespace ndn {
40namespace ndns {
41
42/**
43 * @brief provides authoritative name server.
44 *
45 * The authoritative name server handles NDNS query and update.
46 */
Davide Pesavento948c50c2020-12-26 21:30:45 -050047class NameServer : boost::noncopyable
Shock Jiangcde28712014-10-19 21:17:20 -070048{
49 DEFINE_ERROR(Error, std::runtime_error);
50
51public:
52 explicit
53 NameServer(const Name& zoneName, const Name& certName, Face& face, DbMgr& dbMgr,
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040054 KeyChain& keyChain, security::Validator& validator);
Shock Jiangcde28712014-10-19 21:17:20 -070055
56NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
57 void
Yumin Xia2c509c22017-02-09 14:37:36 -080058 onInterest(const Name& prefix, const Interest& interest);
Shock Jiangcde28712014-10-19 21:17:20 -070059
60 /**
61 * @brief handle NDNS query message
62 */
63 void
64 handleQuery(const Name& prefix, const Interest& interest, const label::MatchResult& re);
65
66 /**
67 * @brief handle NDNS update message
68 */
69 void
70 handleUpdate(const Name& prefix, const Interest& interest, const label::MatchResult& re);
71
72 void
73 onRegisterFailed(const ndn::Name& prefix, const std::string& reason);
74
75 void
76 doUpdate(const shared_ptr<const Interest>& interest, const shared_ptr<const Data>& data);
77
78public:
79 const Name&
80 getNdnsPrefix()
81 {
82 return m_ndnsPrefix;
83 }
84
Shock Jiangcde28712014-10-19 21:17:20 -070085 const Zone&
86 getZone() const
87 {
88 return m_zone;
89 }
90
91 const time::milliseconds&
92 getContentFreshness() const
93 {
94 return m_contentFreshness;
95 }
96
97 /**
98 * @brief set the Data fresh period
99 */
100 void
101 setContentFreshness(const time::milliseconds& contentFreshness)
102 {
103 BOOST_ASSERT(contentFreshness > time::milliseconds::zero());
104 m_contentFreshness = contentFreshness;
105 }
106
107private:
108 Zone m_zone;
109 DbMgr& m_dbMgr;
110
Shock Jiangcde28712014-10-19 21:17:20 -0700111 Name m_ndnsPrefix;
Shock Jiangcde28712014-10-19 21:17:20 -0700112 Name m_certName;
113
114 time::milliseconds m_contentFreshness;
115
116 Face& m_face;
117 KeyChain& m_keyChain;
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400118 security::Validator& m_validator;
Shock Jiangcde28712014-10-19 21:17:20 -0700119};
120
121} // namespace ndns
122} // namespace ndn
123
124#endif // NDNS_DAEMON_NAME_SERVER_HPP