blob: 0daa27f44e84cd1649b111b34d2648acf1969e65 [file] [log] [blame]
Yumin Xiaf853ad72016-11-03 21:14:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Junxiao Shi81e98762022-01-11 18:17:24 +00003 * Copyright (c) 2014-2022, Regents of the University of California.
Yumin Xiaf853ad72016-11-03 21:14:07 -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_RRSET_FACTORY_HPP
21#define NDNS_DAEMON_RRSET_FACTORY_HPP
22
Yumin Xiaf853ad72016-11-03 21:14:07 -070023#include "rrset.hpp"
24#include "logger.hpp"
25#include "daemon/db-mgr.hpp"
Yumin Xiaa484ba72016-11-10 20:40:12 -080026#include "ndns-enum.hpp"
Yumin Xiaf853ad72016-11-03 21:14:07 -070027
28#include <ndn-cxx/link.hpp>
29#include <ndn-cxx/security/key-chain.hpp>
30
Davide Pesavento948c50c2020-12-26 21:30:45 -050031#include <boost/filesystem/path.hpp>
Yumin Xiaf853ad72016-11-03 21:14:07 -070032
33namespace ndn {
34namespace ndns {
35
36class RrsetFactory
37{
38public:
39 /** @brief Represents an error might be thrown during runtime
40 */
41 class Error : public std::runtime_error
42 {
43 public:
Davide Pesavento948c50c2020-12-26 21:30:45 -050044 using std::runtime_error::runtime_error;
Yumin Xiaf853ad72016-11-03 21:14:07 -070045 };
46
47public:
Yumin Xiab87b9d92016-11-14 23:41:25 -080048 RrsetFactory(const boost::filesystem::path& dbFile,
Yumin Xiaf853ad72016-11-03 21:14:07 -070049 const Name& zoneName,
50 KeyChain& keyChain,
51 const Name& inputDskCertName);
52
53 void
54 checkZoneKey();
55
56 Rrset
57 generateNsRrset(const Name& label,
Yumin Xia55a7cc42017-05-14 18:43:34 -070058 uint64_t version,
Yumin Xiaf853ad72016-11-03 21:14:07 -070059 time::seconds ttl,
Junxiao Shi81e98762022-01-11 18:17:24 +000060 std::vector<Name> delegations);
Yumin Xiaf853ad72016-11-03 21:14:07 -070061
62 Rrset
63 generateTxtRrset(const Name& label,
Yumin Xia55a7cc42017-05-14 18:43:34 -070064 uint64_t version,
Yumin Xiaf853ad72016-11-03 21:14:07 -070065 time::seconds ttl,
66 const std::vector<std::string>& contents);
67
68 Rrset
Yumin Xiaacd21332016-11-28 22:54:48 -080069 generateAuthRrset(const Name& label,
Yumin Xia55a7cc42017-05-14 18:43:34 -070070 uint64_t version,
Yumin Xiaacd21332016-11-28 22:54:48 -080071 time::seconds ttl);
72
73 Rrset
Yumin Xiaf853ad72016-11-03 21:14:07 -070074 generateCertRrset(const Name& label,
Yumin Xia55a7cc42017-05-14 18:43:34 -070075 uint64_t version,
Yumin Xiaf853ad72016-11-03 21:14:07 -070076 time::seconds ttl,
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040077 const ndn::security::Certificate& cert);
Yumin Xiaf853ad72016-11-03 21:14:07 -070078
Yumin Xia55a7cc42017-05-14 18:43:34 -070079 /**
80 * @brief DoE records are just txt records of all entries of a zone
81 * which means the any range showed in this record does not exist
82 */
83 Rrset
84 generateDoeRrset(const Name& label,
85 uint64_t version,
86 time::seconds ttl,
87 const Name& lowerLabel,
88 const Name& upperLabel);
89
Yumin Xiaf853ad72016-11-03 21:14:07 -070090 static std::vector<std::string>
91 wireDecodeTxt(const Block& wire);
92
93NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
94 // only used for database-test-data unit test
95 void
96 onlyCheckZone();
97
98private:
99 std::pair<Rrset, Name>
100 generateBaseRrset(const Name& label,
101 const name::Component& type,
Yumin Xia55a7cc42017-05-14 18:43:34 -0700102 uint64_t version,
Yumin Xiaf853ad72016-11-03 21:14:07 -0700103 const time::seconds& ttl);
104
105 bool
106 matchCertificate(const Name& certName, const Name& identity);
107
108 template<encoding::Tag TAG>
Davide Pesavento98026122022-03-14 22:00:03 -0400109 size_t
110 wireEncode(EncodingImpl<TAG>& encoder, const std::vector<Block>& rrs) const;
Yumin Xiaf853ad72016-11-03 21:14:07 -0700111
Davide Pesavento98026122022-03-14 22:00:03 -0400112 Block
Yumin Xiaf853ad72016-11-03 21:14:07 -0700113 wireEncode(const std::vector<Block>& rrs) const;
114
115 void
116 sign(Data& data);
117
Yumin Xia3c6b1fd2016-12-11 19:08:47 -0800118 void
Davide Pesavento98026122022-03-14 22:00:03 -0400119 setContentType(Data& data, NdnsContentType contentType, const time::seconds& ttl);
Yumin Xiaf853ad72016-11-03 21:14:07 -0700120
121private:
122 KeyChain& m_keyChain;
123 std::string m_dbFile;
124 Zone m_zone;
125 Name m_dskCertName;
126 Name m_dskName;
127 bool m_checked;
128};
129
130} // namespace ndns
131} // namespace ndn
132
133#endif // NDNS_DAEMON_RRSET_FACTORY_HPP