Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 26 | #ifndef NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP |
| 27 | #define NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 28 | |
| 29 | #include "module.hpp" |
| 30 | #include <ndn-cxx/security/validator.hpp> |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 34 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 35 | |
| 36 | using ndn::nfd::ForwarderStatus; |
| 37 | |
| 38 | class NfdIdCollector; |
| 39 | |
| 40 | /** \brief provides access to NFD forwarder general status |
| 41 | * \sa https://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus |
| 42 | */ |
| 43 | class ForwarderGeneralModule : public Module, noncopyable |
| 44 | { |
| 45 | public: |
| 46 | ForwarderGeneralModule(); |
| 47 | |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 48 | void |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 49 | fetchStatus(Controller& controller, |
| 50 | const function<void()>& onSuccess, |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 51 | const Controller::DatasetFailCallback& onFailure, |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 52 | const CommandOptions& options) override; |
| 53 | |
| 54 | void |
| 55 | setNfdIdCollector(const NfdIdCollector& nfdIdCollector) |
| 56 | { |
| 57 | m_nfdIdCollector = &nfdIdCollector; |
| 58 | } |
| 59 | |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 60 | void |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 61 | formatStatusXml(std::ostream& os) const override; |
| 62 | |
| 63 | /** \brief format a single status item as XML |
| 64 | * \param os output stream |
| 65 | * \param item status item |
| 66 | * \param nfdId NFD's signing certificate name |
| 67 | */ |
| 68 | void |
| 69 | formatItemXml(std::ostream& os, const ForwarderStatus& item, const Name& nfdId) const; |
| 70 | |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 71 | void |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 72 | formatStatusText(std::ostream& os) const override; |
| 73 | |
| 74 | /** \brief format a single status item as text |
| 75 | * \param os output stream |
| 76 | * \param item status item |
| 77 | * \param nfdId NFD's signing certificate name |
| 78 | */ |
| 79 | void |
| 80 | formatItemText(std::ostream& os, const ForwarderStatus& item, const Name& nfdId) const; |
| 81 | |
| 82 | private: |
| 83 | const Name& |
| 84 | getNfdId() const; |
| 85 | |
| 86 | private: |
| 87 | const NfdIdCollector* m_nfdIdCollector; |
| 88 | ForwarderStatus m_status; |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | /** \brief a validator that can collect NFD's signing certificate name |
| 93 | * |
| 94 | * This validator redirects all validation requests to an inner validator. |
| 95 | * For the first Data packet accepted by the inner validator that has a Name in KeyLocator, |
| 96 | * this Name is collected as NFD's signing certificate name. |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 97 | * |
| 98 | * \todo #4089 re-implement as v2 ValidationPolicy |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 99 | */ |
| 100 | class NfdIdCollector : public ndn::Validator |
| 101 | { |
| 102 | public: |
| 103 | explicit |
| 104 | NfdIdCollector(unique_ptr<ndn::Validator> inner); |
| 105 | |
| 106 | bool |
| 107 | hasNfdId() const |
| 108 | { |
| 109 | return m_hasNfdId; |
| 110 | } |
| 111 | |
| 112 | const Name& |
| 113 | getNfdId() const; |
| 114 | |
| 115 | protected: |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 116 | void |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 117 | checkPolicy(const Interest& interest, int nSteps, |
| 118 | const ndn::OnInterestValidated& accept, |
| 119 | const ndn::OnInterestValidationFailed& reject, |
| 120 | std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override |
| 121 | { |
| 122 | BOOST_ASSERT(nSteps == 0); |
| 123 | m_inner->validate(interest, accept, reject); |
| 124 | } |
| 125 | |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 126 | void |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 127 | checkPolicy(const Data& data, int nSteps, |
| 128 | const ndn::OnDataValidated& accept, |
| 129 | const ndn::OnDataValidationFailed& reject, |
| 130 | std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps) override; |
| 131 | |
| 132 | private: |
| 133 | unique_ptr<ndn::Validator> m_inner; |
| 134 | bool m_hasNfdId; |
| 135 | Name m_nfdId; |
| 136 | }; |
| 137 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 138 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 139 | } // namespace tools |
| 140 | } // namespace nfd |
| 141 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 142 | #endif // NFD_TOOLS_NFDC_FORWARDER_GENERAL_MODULE_HPP |