alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 7bc3d43 | 2021-10-25 21:08:04 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, 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/>. |
Davide Pesavento | 7bc3d43 | 2021-10-25 21:08:04 -0400 | [diff] [blame] | 20 | */ |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 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 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 25 | #include "manager-base.hpp" |
Davide Pesavento | 7bc3d43 | 2021-10-25 21:08:04 -0400 | [diff] [blame] | 26 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 27 | #include <ndn-cxx/security/key-chain.hpp> |
Davide Pesavento | 7bc3d43 | 2021-10-25 21:08:04 -0400 | [diff] [blame] | 28 | |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 29 | #include <boost/property_tree/ptree.hpp> |
| 30 | |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 31 | namespace nlsr::update { |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 32 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 33 | using ConfigSection = boost::property_tree::ptree; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 34 | |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 35 | class PrefixUpdateProcessor : public CommandManagerBase |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 36 | { |
| 37 | public: |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 38 | PrefixUpdateProcessor(ndn::mgmt::Dispatcher& dispatcher, |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 39 | ndn::security::ValidatorConfig& validator, |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 40 | NamePrefixList& namePrefixList, |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 41 | Lsdb& lsdb, const std::string& configFileName); |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 42 | |
| 43 | /*! \brief Load the validator's configuration from a section of a |
| 44 | * configuration file. |
| 45 | * \sa ConfFileProcessor::processConfFile |
| 46 | * \sa ConfFileProcessor::processConfSectionSecurity |
| 47 | * |
| 48 | * Loads the state of the validator for prefix update commands by |
| 49 | * reading a section from a configuration file. This function is |
| 50 | * expecting the section to be from a Boost property tree object. |
| 51 | * |
| 52 | * \throws PrefixUpdateProcessor::Error If configuration fails to load successfully |
| 53 | */ |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 54 | void |
| 55 | loadValidator(ConfigSection section, const std::string& filename); |
| 56 | |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 57 | /*! \brief Add or delete an advertise or withdrawn prefix to the nlsr |
| 58 | * configuration file |
| 59 | */ |
| 60 | bool |
| 61 | addOrDeletePrefix(const ndn::Name& prefix, bool addPrefix); |
| 62 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 63 | std::optional<bool> |
| 64 | afterAdvertise(const ndn::Name& prefix) override; |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 65 | |
Davide Pesavento | c1d0e8e | 2022-06-15 14:26:02 -0400 | [diff] [blame] | 66 | std::optional<bool> |
| 67 | afterWithdraw(const ndn::Name& prefix) override; |
Saurab Dulal | 7526cee | 2018-01-31 18:14:10 +0000 | [diff] [blame] | 68 | |
| 69 | /*! \brief Check if a prefix exists in the nlsr configuration file */ |
| 70 | bool |
| 71 | checkForPrefixInFile(const std::string prefix); |
| 72 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 73 | ndn::security::ValidatorConfig& |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 74 | getValidator() |
| 75 | { |
| 76 | return m_validator; |
| 77 | } |
| 78 | |
| 79 | private: |
Laqin Fan | 54a43f0 | 2017-03-08 12:31:30 -0600 | [diff] [blame] | 80 | /*! \brief an authorization function for prefix-update module and verb(advertise/withdraw) |
| 81 | * accept if the verb is advertise/withdraw |
| 82 | * reject if the verb is not advertise/withdraw |
| 83 | \retval an Authorization function |
| 84 | \sa Nlsr::getDispatcher() |
| 85 | */ |
| 86 | ndn::mgmt::Authorization |
| 87 | makeAuthorization(); |
| 88 | |
| 89 | private: |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 90 | ndn::security::ValidatorConfig& m_validator; |
dulalsaurab | 82a34c2 | 2019-02-04 17:31:21 +0000 | [diff] [blame] | 91 | const std::string& m_confFileNameDynamic; |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 92 | }; |
| 93 | |
Davide Pesavento | 384327d | 2025-01-02 01:40:23 -0500 | [diff] [blame] | 94 | } // namespace nlsr::update |
alvy | 297f416 | 2015-03-03 17:15:33 -0600 | [diff] [blame] | 95 | |
dmcoomes | e689dd6 | 2017-03-29 11:05:12 -0500 | [diff] [blame] | 96 | #endif // NLSR_UPDATE_PREFIX_UPDATE_PROCESSOR_HPP |