blob: 09c3101b59c7e03d37cc380f8594de40cdfee901 [file] [log] [blame]
Shock Jiangcde28712014-10-19 21:17:20 -07001/* -*- 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
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"
28#include "validator.hpp"
29#include "common.hpp"
30
31#include <ndn-cxx/security/key-chain.hpp>
32#include <ndn-cxx/face.hpp>
33
34#include <boost/asio.hpp>
35#include <boost/bind.hpp>
36#include <boost/noncopyable.hpp>
37
38#include <sstream>
39#include <stdexcept>
40
41namespace ndn {
42namespace ndns {
43
44/**
45 * @brief provides authoritative name server.
46 *
47 * The authoritative name server handles NDNS query and update.
48 */
49class NameServer : noncopyable
50{
51 DEFINE_ERROR(Error, std::runtime_error);
52
53public:
54 explicit
55 NameServer(const Name& zoneName, const Name& certName, Face& face, DbMgr& dbMgr,
56 KeyChain& keyChain, Validator& validator);
57
58NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
59 void
60 onInterest(const Name& prefix, const Interest &interest);
61
62 /**
63 * @brief handle NDNS query message
64 */
65 void
66 handleQuery(const Name& prefix, const Interest& interest, const label::MatchResult& re);
67
68 /**
69 * @brief handle NDNS update message
70 */
71 void
72 handleUpdate(const Name& prefix, const Interest& interest, const label::MatchResult& re);
73
74 void
75 onRegisterFailed(const ndn::Name& prefix, const std::string& reason);
76
77 void
78 doUpdate(const shared_ptr<const Interest>& interest, const shared_ptr<const Data>& data);
79
80public:
81 const Name&
82 getNdnsPrefix()
83 {
84 return m_ndnsPrefix;
85 }
86
87 const Name&
88 getKeyPrefix() const
89 {
90 return m_keyPrefix;
91 }
92
93 void
94 setKeyPrefix(const Name& keyPrefix)
95 {
96 m_keyPrefix = keyPrefix;
97 }
98
99 const Zone&
100 getZone() const
101 {
102 return m_zone;
103 }
104
105 const time::milliseconds&
106 getContentFreshness() const
107 {
108 return m_contentFreshness;
109 }
110
111 /**
112 * @brief set the Data fresh period
113 */
114 void
115 setContentFreshness(const time::milliseconds& contentFreshness)
116 {
117 BOOST_ASSERT(contentFreshness > time::milliseconds::zero());
118 m_contentFreshness = contentFreshness;
119 }
120
121private:
122 Zone m_zone;
123 DbMgr& m_dbMgr;
124
125 // Name m_hint;
126
127 Name m_ndnsPrefix;
128 Name m_keyPrefix;
129 Name m_certName;
130
131 time::milliseconds m_contentFreshness;
132
133 Face& m_face;
134 KeyChain& m_keyChain;
135 Validator& m_validator;
136};
137
138} // namespace ndns
139} // namespace ndn
140
141#endif // NDNS_DAEMON_NAME_SERVER_HPP