alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 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 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 22 | #ifndef NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP |
| 23 | #define NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 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> |
Junxiao Shi | 3e5120c | 2016-09-10 16:58:34 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/mgmt/nfd/control-command.hpp> |
| 32 | #include <ndn-cxx/mgmt/nfd/control-parameters.hpp> |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 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 | |
| 39 | namespace nlsr { |
| 40 | |
| 41 | class Lsdb; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 42 | |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 43 | namespace security { |
| 44 | class CertificateStore; |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 45 | } // namespace security |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 46 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 47 | namespace update { |
| 48 | |
| 49 | typedef boost::property_tree::ptree ConfigSection; |
| 50 | |
| 51 | class PrefixUpdateProcessor : boost::noncopyable |
| 52 | { |
| 53 | public: |
| 54 | class Error : public std::runtime_error |
| 55 | { |
| 56 | public: |
| 57 | explicit |
| 58 | Error(const std::string& what) |
| 59 | : std::runtime_error(what) |
| 60 | { |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | public: |
| 65 | PrefixUpdateProcessor(ndn::Face& face, |
| 66 | NamePrefixList& namePrefixList, |
| 67 | Lsdb& lsdb, |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 68 | const ndn::Name broadcastPrefix, |
| 69 | ndn::KeyChain& keyChain, |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 70 | std::shared_ptr<ndn::CertificateCacheTtl> certificateCache, |
Vince Lehman | c2acdcb | 2015-04-29 11:14:35 -0500 | [diff] [blame] | 71 | security::CertificateStore& certStore); |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 72 | |
| 73 | void |
| 74 | loadValidator(ConfigSection section, const std::string& filename); |
| 75 | |
| 76 | void |
| 77 | startListening(); |
| 78 | |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 79 | void |
| 80 | enable() |
| 81 | { |
| 82 | m_isEnabled = true; |
| 83 | } |
| 84 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 85 | private: |
| 86 | void |
| 87 | onInterest(const ndn::Interest& request); |
| 88 | |
| 89 | void |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 90 | sendNack(const ndn::Interest& request); |
| 91 | |
| 92 | void |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 93 | sendResponse(const std::shared_ptr<const ndn::Interest>& request, |
| 94 | uint32_t code, |
| 95 | const std::string& text); |
| 96 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 97 | /*! \brief adds desired name prefix to the advertised name prefix list |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 98 | */ |
| 99 | void |
| 100 | advertise(const std::shared_ptr<const ndn::Interest>& request, |
| 101 | const ndn::nfd::ControlParameters& parameters); |
| 102 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 103 | /*! \brief removes desired name prefix from the advertised name prefix list |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 104 | */ |
| 105 | void |
| 106 | withdraw(const std::shared_ptr<const ndn::Interest>& request, |
| 107 | const ndn::nfd::ControlParameters& parameters); |
| 108 | |
| 109 | void |
| 110 | onCommandValidated(const std::shared_ptr<const ndn::Interest>& request); |
| 111 | |
| 112 | void |
| 113 | onCommandValidationFailed(const std::shared_ptr<const ndn::Interest>& request, |
| 114 | const std::string& failureInfo); |
| 115 | |
| 116 | static bool |
| 117 | extractParameters(const ndn::name::Component& parameterComponent, |
| 118 | ndn::nfd::ControlParameters& extractedParameters); |
| 119 | |
| 120 | bool |
| 121 | validateParameters(const ndn::nfd::ControlCommand& command, |
| 122 | const ndn::nfd::ControlParameters& parameters); |
| 123 | |
| 124 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 125 | Validator& |
| 126 | getValidator() |
| 127 | { |
| 128 | return m_validator; |
| 129 | } |
| 130 | |
| 131 | private: |
| 132 | ndn::Face& m_face; |
| 133 | NamePrefixList& m_namePrefixList; |
| 134 | Lsdb& m_lsdb; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 135 | ndn::KeyChain& m_keyChain; |
| 136 | Validator m_validator; |
Vince Lehman | d33e5bc | 2015-06-22 15:27:50 -0500 | [diff] [blame] | 137 | bool m_isEnabled; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 138 | |
| 139 | const ndn::Name COMMAND_PREFIX; // /localhost/nlsr/prefix-update |
| 140 | |
| 141 | static const ndn::Name::Component MODULE_COMPONENT; |
| 142 | static const ndn::Name::Component ADVERTISE_VERB; |
| 143 | static const ndn::Name::Component WITHDRAW_VERB; |
| 144 | }; |
| 145 | |
| 146 | } // namespace update |
| 147 | } // namespace nlsr |
| 148 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 149 | #endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP |