blob: a53b0aaf18e014d3255e20c76ee0e1cc9dc7d23e [file] [log] [blame]
Yingdi Yu6ff31932015-03-23 13:30:07 -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 NSL (NDN Signature Logger).
6 * See AUTHORS.md for complete list of NSL authors and contributors.
7 *
8 * NSL 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 * NSL 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 * NSL, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of nsl authors and contributors.
20 */
21
22#ifndef NSL_CORE_LOGGER_HPP
23#define NSL_CORE_LOGGER_HPP
24
25#include "common.hpp"
26#include "logger-response.hpp"
27#include "db.hpp"
28#include "policy-checker.hpp"
29#include "merkle-tree.hpp"
30#include "util/non-negative-integer.hpp"
31#include <ndn-cxx/face.hpp>
32#include <ndn-cxx/security/key-chain.hpp>
33#include <ndn-cxx/security/validator-config.hpp>
34
35namespace nsl {
36
37class Logger
38{
39public:
40 class Error : public std::runtime_error
41 {
42 public:
43 explicit
44 Error(const std::string& what)
45 : std::runtime_error(what)
46 {
47 }
48 };
49
50public:
51 Logger(ndn::Face& face, const std::string& configFile);
52
53 NonNegativeInteger
54 addSelfSignedCert(ndn::IdentityCertificate& cert, const Timestamp& timestamp);
55
56NSL_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
57 void
58 initializeKeys();
59
60 void
61 loadConfiguration(const std::string& filename);
62
63 void
64 onSubTreeInterest(const ndn::InterestFilter& interestFilter, const Interest& interest);
65
66 void
67 onLeafInterest(const ndn::InterestFilter& interestFilter, const Interest& interest);
68
69 void
70 onLogRequestInterest(const ndn::InterestFilter& interestFilter, const Interest& interest);
71
72 void
73 requestValidatedCallback(const shared_ptr<const Interest>& interest);
74
75 void
76 dataReceivedCallback(const Interest& interest, Data& data,
77 const NonNegativeInteger& signerSeqNo,
78 const Interest& reqInterest);
79
80 void
81 dataTimeoutCallback(const Interest& interest, int nRetrials,
82 const NonNegativeInteger& signerSeqNo,
83 const Interest& reqInterest);
84
85 void
86 makeLogResponse(const Interest& reqInterest, const LoggerResponse& response);
87
88 const Name&
89 getLoggerName() const
90 {
91 return m_loggerName;
92 }
93
94 const Name&
95 getTreePrefix() const
96 {
97 return m_treePrefix;
98 }
99
100 const Name&
101 getLeafPrefix() const
102 {
103 return m_leafPrefix;
104 }
105
106 const Name&
107 getLogPrefix() const
108 {
109 return m_logPrefix;
110 }
111
112 Db&
113 getDb()
114 {
115 return m_db;
116 }
117
118private:
119 static const int N_DATA_FETCHING_RETRIAL;
120
121private:
122 ndn::Face& m_face;
123 Name m_loggerName;
124 Name m_treePrefix;
125 Name m_leafPrefix;
126 Name m_logPrefix;
127
128 Db m_db;
129 MerkleTree m_merkleTree;
130
131 ndn::KeyChain m_keyChain;
132 shared_ptr<ndn::IdentityCertificate> m_dskCert;
133
134 ndn::ValidatorConfig m_validator;
135 PolicyChecker m_policyChecker;
136};
137
138} // namespace nsl
139
140#endif // NSL_CORE_LOGGER_HPP