blob: 08b910ea06d89fd63a0a4bbf388d5649f3a3b575 [file] [log] [blame]
Yingdi Yu6ff31932015-03-23 13:30:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yu6ff31932015-03-23 13:30:07 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
Yingdi Yu6ff31932015-03-23 13:30:07 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
Yingdi Yu6ff31932015-03-23 13:30:07 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Yingdi Yu6ff31932015-03-23 13:30:07 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu6ff31932015-03-23 13:30:07 -070020 */
21
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070022#ifndef NDN_DELOREAN_CORE_LOGGER_HPP
23#define NDN_DELOREAN_CORE_LOGGER_HPP
Yingdi Yu6ff31932015-03-23 13:30:07 -070024
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"
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070031
Yingdi Yu6ff31932015-03-23 13:30:07 -070032#include <ndn-cxx/face.hpp>
33#include <ndn-cxx/security/key-chain.hpp>
34#include <ndn-cxx/security/validator-config.hpp>
35
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070036namespace ndn {
37namespace delorean {
Yingdi Yu6ff31932015-03-23 13:30:07 -070038
39class Logger
40{
41public:
42 class Error : public std::runtime_error
43 {
44 public:
45 explicit
46 Error(const std::string& what)
47 : std::runtime_error(what)
48 {
49 }
50 };
51
52public:
53 Logger(ndn::Face& face, const std::string& configFile);
54
55 NonNegativeInteger
56 addSelfSignedCert(ndn::IdentityCertificate& cert, const Timestamp& timestamp);
57
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070058NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yu6ff31932015-03-23 13:30:07 -070059 void
60 initializeKeys();
61
62 void
63 loadConfiguration(const std::string& filename);
64
65 void
66 onSubTreeInterest(const ndn::InterestFilter& interestFilter, const Interest& interest);
67
68 void
69 onLeafInterest(const ndn::InterestFilter& interestFilter, const Interest& interest);
70
71 void
72 onLogRequestInterest(const ndn::InterestFilter& interestFilter, const Interest& interest);
73
74 void
75 requestValidatedCallback(const shared_ptr<const Interest>& interest);
76
77 void
78 dataReceivedCallback(const Interest& interest, Data& data,
79 const NonNegativeInteger& signerSeqNo,
80 const Interest& reqInterest);
81
82 void
83 dataTimeoutCallback(const Interest& interest, int nRetrials,
84 const NonNegativeInteger& signerSeqNo,
85 const Interest& reqInterest);
86
87 void
88 makeLogResponse(const Interest& reqInterest, const LoggerResponse& response);
89
90 const Name&
91 getLoggerName() const
92 {
93 return m_loggerName;
94 }
95
96 const Name&
97 getTreePrefix() const
98 {
99 return m_treePrefix;
100 }
101
102 const Name&
103 getLeafPrefix() const
104 {
105 return m_leafPrefix;
106 }
107
108 const Name&
109 getLogPrefix() const
110 {
111 return m_logPrefix;
112 }
113
114 Db&
115 getDb()
116 {
117 return m_db;
118 }
119
120private:
121 static const int N_DATA_FETCHING_RETRIAL;
122
123private:
124 ndn::Face& m_face;
125 Name m_loggerName;
126 Name m_treePrefix;
127 Name m_leafPrefix;
128 Name m_logPrefix;
129
130 Db m_db;
131 MerkleTree m_merkleTree;
132
133 ndn::KeyChain m_keyChain;
134 shared_ptr<ndn::IdentityCertificate> m_dskCert;
135
136 ndn::ValidatorConfig m_validator;
137 PolicyChecker m_policyChecker;
138};
139
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -0700140} // namespace delorean
141} // namespace ndn
Yingdi Yu6ff31932015-03-23 13:30:07 -0700142
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700143#endif // NDN_DELOREAN_CORE_LOGGER_HPP