blob: 6dc6c096be672d5f18de5bce78a0799f17ede235 [file] [log] [blame]
alvy297f4162015-03-03 17:15:33 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, The University of Memphis,
4 * Regents of the University of California,
5 * Arizona Board of Regents.
6 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22#ifndef UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
23#define UPDATE_PREFIX_UPDATE_PROCESSOR_HPP
24
25#include "name-prefix-list.hpp"
26#include "test-access-control.hpp"
27#include "validator.hpp"
28
29#include <ndn-cxx/face.hpp>
30#include <ndn-cxx/interest.hpp>
31#include <ndn-cxx/management/nfd-control-command.hpp>
32#include <ndn-cxx/management/nfd-control-parameters.hpp>
33#include <ndn-cxx/security/certificate-cache-ttl.hpp>
34#include <ndn-cxx/security/key-chain.hpp>
35
36#include <boost/noncopyable.hpp>
37#include <boost/property_tree/ptree.hpp>
38
39namespace nlsr {
40
41class Lsdb;
42class SyncLogicHandler;
43
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050044namespace security {
45 class CertificateStore;
46}
47
alvy297f4162015-03-03 17:15:33 -060048namespace update {
49
50typedef boost::property_tree::ptree ConfigSection;
51
52class PrefixUpdateProcessor : boost::noncopyable
53{
54public:
55 class Error : public std::runtime_error
56 {
57 public:
58 explicit
59 Error(const std::string& what)
60 : std::runtime_error(what)
61 {
62 }
63 };
64
65public:
66 PrefixUpdateProcessor(ndn::Face& face,
67 NamePrefixList& namePrefixList,
68 Lsdb& lsdb,
69 SyncLogicHandler& sync,
70 const ndn::Name broadcastPrefix,
71 ndn::KeyChain& keyChain,
Vince Lehmanc2acdcb2015-04-29 11:14:35 -050072 ndn::shared_ptr<ndn::CertificateCacheTtl> certificateCache,
73 security::CertificateStore& certStore);
alvy297f4162015-03-03 17:15:33 -060074
75 void
76 loadValidator(ConfigSection section, const std::string& filename);
77
78 void
79 startListening();
80
81private:
82 void
83 onInterest(const ndn::Interest& request);
84
85 void
86 sendResponse(const std::shared_ptr<const ndn::Interest>& request,
87 uint32_t code,
88 const std::string& text);
89
90 /** \brief adds desired name prefix to the advertised name prefix list
91 */
92 void
93 advertise(const std::shared_ptr<const ndn::Interest>& request,
94 const ndn::nfd::ControlParameters& parameters);
95
96 /** \brief removes desired name prefix from the advertised name prefix list
97 */
98 void
99 withdraw(const std::shared_ptr<const ndn::Interest>& request,
100 const ndn::nfd::ControlParameters& parameters);
101
102 void
103 onCommandValidated(const std::shared_ptr<const ndn::Interest>& request);
104
105 void
106 onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request,
107 const std::string& failureInfo);
108
109 static bool
110 extractParameters(const ndn::name::Component& parameterComponent,
111 ndn::nfd::ControlParameters& extractedParameters);
112
113 bool
114 validateParameters(const ndn::nfd::ControlCommand& command,
115 const ndn::nfd::ControlParameters& parameters);
116
117PUBLIC_WITH_TESTS_ELSE_PRIVATE:
118 Validator&
119 getValidator()
120 {
121 return m_validator;
122 }
123
124private:
125 ndn::Face& m_face;
126 NamePrefixList& m_namePrefixList;
127 Lsdb& m_lsdb;
128 SyncLogicHandler& m_sync;
129 ndn::KeyChain& m_keyChain;
130 Validator m_validator;
131
132 const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update
133
134 static const ndn::Name::Component MODULE_COMPONENT;
135 static const ndn::Name::Component ADVERTISE_VERB;
136 static const ndn::Name::Component WITHDRAW_VERB;
137};
138
139} // namespace update
140} // namespace nlsr
141
142#endif // UPDATE_PREFIX_UPDATE_PROCESSOR_HPP