blob: 55e26bfbfce56f55f3aaa3382545fa34ef420c48 [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu0a312e52015-07-22 13:14:53 -07003 * Copyright (c) 2014-2015, Regents of the University of California.
Yingdi Yu77627ab2015-07-21 16:13:49 -07004 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07005 * This file is part of ndn-tools (Named Data Networking Essential Tools).
6 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
Yingdi Yu77627ab2015-07-21 16:13:49 -07007 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07008 * ndn-tools 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.
Yingdi Yu77627ab2015-07-21 16:13:49 -070011 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070012 * ndn-tools 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.
Yingdi Yu77627ab2015-07-21 16:13:49 -070015 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070016 * You should have received a copy of the GNU General Public License along with
17 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu77627ab2015-07-21 16:13:49 -070018 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070019 * @author Yingdi Yu <yingdi@cs.ucla.edu>
Yingdi Yu77627ab2015-07-21 16:13:49 -070020 */
21
Yingdi Yu0a312e52015-07-22 13:14:53 -070022#ifndef NDN_TOOLS_PIB_PIB_HPP
23#define NDN_TOOLS_PIB_PIB_HPP
Yingdi Yu77627ab2015-07-21 16:13:49 -070024
25#include "pib-db.hpp"
26#include "pib-validator.hpp"
27#include "cert-publisher.hpp"
28
29#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/util/in-memory-storage-persistent.hpp>
31
32#include "get-query-processor.hpp"
33#include "default-query-processor.hpp"
34#include "list-query-processor.hpp"
35#include "update-query-processor.hpp"
36#include "delete-query-processor.hpp"
37
38#include <ndn-cxx/security/sec-tpm.hpp>
39
40namespace ndn {
41namespace pib {
42
43/// @brief implements the PIB service
44class Pib : noncopyable
45{
46public:
47 class Error : public std::runtime_error
48 {
49 public:
50 explicit
51 Error(const std::string& what)
52 : std::runtime_error(what)
53 {
54 }
55 };
56
57 /**
58 * @brief Constructor
59 *
60 * @param face The face pib used to receive queries and serve certificates.
61 * @param dbDir Absolute path to the directory of the pib database.
62 * @param tpmLocator URI to locate the TPM for pib service.
63 * @param owner Owner of the pib database.
64 */
65 Pib(Face& face,
66 const std::string& dbDir,
67 const std::string& tpmLocator,
68 const std::string& owner);
69
70 ~Pib();
71
72 void
73 setMgmtCert(std::shared_ptr<IdentityCertificate> mgmtCert);
74
75PUBLIC_WITH_TESTS_ELSE_PROTECTED:
76 PibDb&
77 getDb()
78 {
79 return m_db;
80 }
81
82 SecTpm&
83 getTpm()
84 {
85 return *m_tpm;
86 }
87
88 util::InMemoryStoragePersistent&
89 getResponseCache()
90 {
91 return m_responseCache;
92 }
93
94 const std::string&
95 getOwner() const
96 {
97 return m_owner;
98 }
99
100 const IdentityCertificate&
101 getMgmtCert() const
102 {
103 BOOST_ASSERT(m_mgmtCert != nullptr);
104 return *m_mgmtCert;
105 }
106
107private: // initialization
108 /// @brief initialize the PIB's own TPM.
109 void
110 initializeTpm(const std::string& tpmLocator);
111
112 /// @brief initialize management certificate
113 void
114 initializeMgmtCert();
115
116 std::shared_ptr<IdentityCertificate>
117 prepareCertificate(const Name& keyName, const KeyParams& keyParams,
118 const time::system_clock::TimePoint& notBefore,
119 const time::system_clock::TimePoint& notAfter,
120 const Name& signerName = EMPTY_SIGNER_NAME);
121
122 /// @brief register prefix for PIB query and management certificate
123 void
124 registerPrefix();
125
126 template<class Processor>
127 const InterestFilterId*
128 registerProcessor(const Name& prefix, Processor& process);
129
130 template<class Processor>
131 const InterestFilterId*
132 registerSignedCommandProcessor(const Name& prefix, Processor& process);
133
134 template<class Processor>
135 void
136 processCommand(Processor& process, const Interest& interest);
137
138 void
139 returnResult(const Name& dataName, const Block& content);
140
141private:
142
143 static const Name EMPTY_SIGNER_NAME;
144 static const Name PIB_PREFIX;
145 static const name::Component MGMT_LABEL;
146
147 PibDb m_db;
148 std::unique_ptr<SecTpm> m_tpm;
149 std::string m_owner;
150 std::shared_ptr<IdentityCertificate> m_mgmtCert;
151
152 PibValidator m_validator;
153
154 Face& m_face;
155 CertPublisher m_certPublisher;
156 util::InMemoryStoragePersistent m_responseCache;
157
158 const RegisteredPrefixId* m_pibPrefixId;
159 const InterestFilterId* m_pibMgmtFilterId;
160 const InterestFilterId* m_pibGetFilterId;
161 const InterestFilterId* m_pibDefaultFilterId;
162 const InterestFilterId* m_pibListFilterId;
163 const InterestFilterId* m_pibUpdateFilterId;
164 const InterestFilterId* m_pibDeleteFilterId;
165
166PUBLIC_WITH_TESTS_ELSE_PRIVATE:
167
168 GetQueryProcessor m_getProcessor;
169 DefaultQueryProcessor m_defaultProcessor;
170 ListQueryProcessor m_listProcessor;
171 UpdateQueryProcessor m_updateProcessor;
172 DeleteQueryProcessor m_deleteProcessor;
173};
174
175} // namespace pib
176} // namespace ndn
177
Yingdi Yu0a312e52015-07-22 13:14:53 -0700178#endif // NDN_TOOLS_PIB_PIB_HPP