diff --git a/daemon/mgmt/command-authenticator.cpp b/daemon/mgmt/command-authenticator.cpp index b07d23d7..55e57b4c 100644 --- a/daemon/mgmt/command-authenticator.cpp +++ b/daemon/mgmt/command-authenticator.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -213,7 +213,7 @@ CommandAuthenticator::makeAuthorization(const std::string& module, const std::st m_validators[module]; // declares module, so that privilege is recognized return [module, self = shared_from_this()] (const Name&, const Interest& interest, - const ndn::mgmt::ControlParameters*, + const ndn::mgmt::ControlParametersBase*, const ndn::mgmt::AcceptContinuation& accept, const ndn::mgmt::RejectContinuation& reject) { auto validator = self->m_validators.at(module); diff --git a/daemon/mgmt/cs-manager.cpp b/daemon/mgmt/cs-manager.cpp index e203b450..a807df89 100644 --- a/daemon/mgmt/cs-manager.cpp +++ b/daemon/mgmt/cs-manager.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -40,16 +40,16 @@ CsManager::CsManager(Cs& cs, const ForwarderCounters& fwCounters, , m_fwCounters(fwCounters) { registerCommandHandler("config", - [this] (auto&&, auto&&, auto&&, auto&&... args) { changeConfig(std::forward(args)...); }); + [this] (auto&&, auto&&, auto&&... args) { changeConfig(std::forward(args)...); }); registerCommandHandler("erase", - [this] (auto&&, auto&&, auto&&, auto&&... args) { erase(std::forward(args)...); }); + [this] (auto&&, auto&&, auto&&... args) { erase(std::forward(args)...); }); registerStatusDatasetHandler("info", [this] (auto&&, auto&&, auto&&... args) { serveInfo(std::forward(args)...); }); } void CsManager::changeConfig(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { using ndn::nfd::CsFlagBit; @@ -74,7 +74,7 @@ CsManager::changeConfig(const ControlParameters& parameters, void CsManager::erase(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { size_t count = parameters.hasCount() ? parameters.getCount() : diff --git a/daemon/mgmt/cs-manager.hpp b/daemon/mgmt/cs-manager.hpp index 58fe362f..2ab6ddb3 100644 --- a/daemon/mgmt/cs-manager.hpp +++ b/daemon/mgmt/cs-manager.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -47,19 +47,20 @@ class CsManager final : public ManagerBase Dispatcher& dispatcher, CommandAuthenticator& authenticator); private: - /** \brief Process cs/config command. + /** + * \brief Process `cs/config` command. */ void - changeConfig(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + changeConfig(const ControlParameters& parameters, const CommandContinuation& done); - /** \brief Process cs/erase command. + /** + * \brief Process `cs/erase` command. */ void - erase(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + erase(const ControlParameters& parameters, const CommandContinuation& done); - /** \brief Serve CS information dataset. + /** + * \brief Serve CS information dataset. */ void serveInfo(ndn::mgmt::StatusDatasetContext& context) const; diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp index 24bfd7f0..e822f122 100644 --- a/daemon/mgmt/face-manager.cpp +++ b/daemon/mgmt/face-manager.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -50,11 +50,11 @@ FaceManager::FaceManager(FaceSystem& faceSystem, { // register handlers for ControlCommand registerCommandHandler("create", - [this] (auto&&, auto&&, auto&&, auto&&... args) { createFace(std::forward(args)...); }); + [this] (auto&&, auto&&, auto&&... args) { createFace(std::forward(args)...); }); registerCommandHandler("update", - [this] (auto&&, auto&&, auto&&... args) { updateFace(std::forward(args)...); }); + [this] (auto&&, auto&&... args) { updateFace(std::forward(args)...); }); registerCommandHandler("destroy", - [this] (auto&&, auto&&, auto&&, auto&&... args) { destroyFace(std::forward(args)...); }); + [this] (auto&&, auto&&, auto&&... args) { destroyFace(std::forward(args)...); }); // register handlers for StatusDataset registerStatusDatasetHandler("list", @@ -77,7 +77,7 @@ FaceManager::FaceManager(FaceSystem& faceSystem, void FaceManager::createFace(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { FaceUri remoteUri; if (!remoteUri.parse(parameters.getUri())) { @@ -203,7 +203,7 @@ makeCreateFaceResponse(const Face& face) void FaceManager::afterCreateFaceSuccess(const shared_ptr& face, const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { if (face->getId() != face::INVALID_FACEID) { // Face already exists NFD_LOG_TRACE("Attempted to create duplicate face of " << face->getId()); @@ -262,7 +262,7 @@ updateLinkServiceOptions(Face& face, const ControlParameters& parameters) void FaceManager::updateFace(const Interest& interest, const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { FaceId faceId = parameters.getFaceId(); if (faceId == face::INVALID_FACEID) { // Self-update @@ -336,7 +336,7 @@ FaceManager::updateFace(const Interest& interest, void FaceManager::destroyFace(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { Face* face = m_faceTable.get(parameters.getFaceId()); if (face != nullptr) { diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp index 8e72b9a3..af946bc2 100644 --- a/daemon/mgmt/face-manager.hpp +++ b/daemon/mgmt/face-manager.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -47,22 +47,22 @@ class FaceManager final : public ManagerBase private: // ControlCommand void createFace(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); void updateFace(const Interest& interest, const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); void destroyFace(const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); private: // helpers for ControlCommand void afterCreateFaceSuccess(const shared_ptr& face, const ControlParameters& parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); private: // StatusDataset void diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp index 9bbd5458..cdae3f66 100644 --- a/daemon/mgmt/fib-manager.cpp +++ b/daemon/mgmt/fib-manager.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -45,16 +45,16 @@ FibManager::FibManager(Fib& fib, const FaceTable& faceTable, , m_faceTable(faceTable) { registerCommandHandler("add-nexthop", - [this] (auto&&, auto&&, auto&&... args) { addNextHop(std::forward(args)...); }); + [this] (auto&&, auto&&... args) { addNextHop(std::forward(args)...); }); registerCommandHandler("remove-nexthop", - [this] (auto&&, auto&&, auto&&... args) { removeNextHop(std::forward(args)...); }); + [this] (auto&&, auto&&... args) { removeNextHop(std::forward(args)...); }); registerStatusDatasetHandler("list", [this] (auto&&, auto&&, auto&&... args) { listEntries(std::forward(args)...); }); } void FibManager::addNextHop(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { setFaceForSelfRegistration(interest, parameters); const Name& prefix = parameters.getName(); @@ -84,7 +84,7 @@ FibManager::addNextHop(const Interest& interest, ControlParameters parameters, void FibManager::removeNextHop(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { setFaceForSelfRegistration(interest, parameters); const Name& prefix = parameters.getName(); diff --git a/daemon/mgmt/fib-manager.hpp b/daemon/mgmt/fib-manager.hpp index ba490bfb..12a7b39d 100644 --- a/daemon/mgmt/fib-manager.hpp +++ b/daemon/mgmt/fib-manager.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -49,11 +49,11 @@ class FibManager final : public ManagerBase private: void addNextHop(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); void removeNextHop(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); void listEntries(ndn::mgmt::StatusDatasetContext& context); diff --git a/daemon/mgmt/manager-base.cpp b/daemon/mgmt/manager-base.cpp index 979fc168..cbc363bc 100644 --- a/daemon/mgmt/manager-base.cpp +++ b/daemon/mgmt/manager-base.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -82,33 +82,4 @@ ManagerBase::makeAuthorization(const std::string& verb) return m_authenticator->makeAuthorization(m_module, verb); } -bool -ManagerBase::validateParameters(const ControlCommand& command, - const ndn::mgmt::ControlParameters& parameters) -{ - BOOST_ASSERT(dynamic_cast(¶meters) != nullptr); - - try { - command.validateRequest(static_cast(parameters)); - } - catch (const ControlCommand::ArgumentError&) { - return false; - } - return true; -} - -void -ManagerBase::handleCommand(shared_ptr command, - const ControlCommandHandler& handler, - const Name& prefix, const Interest& interest, - const ndn::mgmt::ControlParameters& params, - const ndn::mgmt::CommandContinuation& done) -{ - BOOST_ASSERT(dynamic_cast(¶ms) != nullptr); - - ControlParameters parameters = static_cast(params); - command->applyDefaultsToRequest(parameters); - handler(*command, prefix, interest, parameters, done); -} - } // namespace nfd diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp index a664c9e0..53a5fc63 100644 --- a/daemon/mgmt/manager-base.hpp +++ b/daemon/mgmt/manager-base.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -38,7 +38,7 @@ namespace nfd { using ndn::mgmt::Dispatcher; -using ndn::nfd::ControlCommand; +using ndn::mgmt::CommandContinuation; using ndn::nfd::ControlParameters; using ndn::nfd::ControlResponse; @@ -76,16 +76,15 @@ class ManagerBase : noncopyable ~ManagerBase(); NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher - // difference from mgmt::ControlCommand: accepts nfd::ControlParameters - using ControlCommandHandler = std::function; + const CommandContinuation& done)>; template void registerCommandHandler(const std::string& verb, - const ControlCommandHandler& handler); + ControlCommandHandler handler); void registerStatusDatasetHandler(const std::string& verb, @@ -111,26 +110,6 @@ class ManagerBase : noncopyable virtual ndn::mgmt::Authorization makeAuthorization(const std::string& verb); - /** - * @brief Validates the @p parameters for a given @p command. - * - * @param parameters the original ControlParameters - * @return whether the original ControlParameters can be validated - */ - [[nodiscard]] static bool - validateParameters(const ControlCommand& command, - const ndn::mgmt::ControlParameters& parameters); - - /** - * @brief Handles a control command. - */ - static void - handleCommand(shared_ptr command, - const ControlCommandHandler& handler, - const Name& prefix, const Interest& interest, - const ndn::mgmt::ControlParameters& params, - const ndn::mgmt::CommandContinuation& done); - /** * @brief Generates the relative prefix for a handler by appending the verb name to the module name. * @@ -138,7 +117,7 @@ class ManagerBase : noncopyable * @return the generated relative prefix */ PartialName - makeRelPrefix(const std::string& verb) + makeRelPrefix(const std::string& verb) const { return PartialName(m_module).append(verb); } @@ -151,16 +130,30 @@ class ManagerBase : noncopyable template void -ManagerBase::registerCommandHandler(const std::string& verb, - const ControlCommandHandler& handler) +ManagerBase::registerCommandHandler(const std::string& verb, ControlCommandHandler handler) { - auto command = make_shared(); + auto validate = [] (const ndn::mgmt::ControlParametersBase& params) { + BOOST_ASSERT(dynamic_cast(¶ms) != nullptr); + try { + Command::validateRequest(static_cast(params)); + return true; + } + catch (const std::invalid_argument&) { + return false; + } + }; + + auto handle = [handler = std::move(handler)] (const Name& prefix, const Interest& interest, + const ndn::mgmt::ControlParametersBase& params, + const CommandContinuation& done) { + BOOST_ASSERT(dynamic_cast(¶ms) != nullptr); + ControlParameters parameters = static_cast(params); + Command::applyDefaultsToRequest(parameters); + handler(prefix, interest, parameters, done); + }; - m_dispatcher.addControlCommand( - makeRelPrefix(verb), - makeAuthorization(verb), - [=] (const auto& params) { return validateParameters(*command, params); }, - [=] (auto&&... args) { handleCommand(command, handler, std::forward(args)...); }); + m_dispatcher.addControlCommand(makeRelPrefix(verb), makeAuthorization(verb), + std::move(validate), std::move(handle)); } } // namespace nfd diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp index b3d515c7..865b30f2 100644 --- a/daemon/mgmt/rib-manager.cpp +++ b/daemon/mgmt/rib-manager.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -62,9 +62,9 @@ RibManager::RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain, , m_isLocalhopEnabled(false) { registerCommandHandler("register", - [this] (auto&&, auto&&, auto&&... args) { registerEntry(std::forward(args)...); }); + [this] (auto&&, auto&&... args) { registerEntry(std::forward(args)...); }); registerCommandHandler("unregister", - [this] (auto&&, auto&&, auto&&... args) { unregisterEntry(std::forward(args)...); }); + [this] (auto&&, auto&&... args) { unregisterEntry(std::forward(args)...); }); registerStatusDatasetHandler("list", [this] (auto&&, auto&&, auto&&... args) { listEntries(std::forward(args)...); }); } @@ -218,7 +218,7 @@ RibManager::registerTopPrefix(const Name& topPrefix) void RibManager::registerEntry(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { if (parameters.getName().size() > Fib::getMaxDepth()) { done(ControlResponse(414, "Route prefix cannot exceed " + std::to_string(Fib::getMaxDepth()) + @@ -248,7 +248,7 @@ RibManager::registerEntry(const Interest& interest, ControlParameters parameters void RibManager::unregisterEntry(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { setFaceForSelfRegistration(interest, parameters); @@ -304,7 +304,7 @@ ndn::mgmt::Authorization RibManager::makeAuthorization(const std::string&) { return [this] (const Name& prefix, const Interest& interest, - const ndn::mgmt::ControlParameters* params, + const ndn::mgmt::ControlParametersBase* params, const ndn::mgmt::AcceptContinuation& accept, const ndn::mgmt::RejectContinuation& reject) { BOOST_ASSERT(params != nullptr); diff --git a/daemon/mgmt/rib-manager.hpp b/daemon/mgmt/rib-manager.hpp index 114a7c4d..a7edc22c 100644 --- a/daemon/mgmt/rib-manager.hpp +++ b/daemon/mgmt/rib-manager.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -197,19 +197,22 @@ class RibManager final : public ManagerBase void registerTopPrefix(const Name& topPrefix); - /** \brief Serve rib/register command. + /** + * \brief Serve `rib/register` command. */ void registerEntry(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); - /** \brief Serve rib/unregister command. + /** + * \brief Serve `rib/unregister` command. */ void unregisterEntry(const Interest& interest, ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done); + const CommandContinuation& done); - /** \brief Serve rib/list dataset. + /** + * \brief Serve `rib/list` dataset. */ void listEntries(ndn::mgmt::StatusDatasetContext& context); diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp index af74ee18..e31ae762 100644 --- a/daemon/mgmt/strategy-choice-manager.cpp +++ b/daemon/mgmt/strategy-choice-manager.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -43,16 +43,16 @@ StrategyChoiceManager::StrategyChoiceManager(StrategyChoice& strategyChoice, , m_table(strategyChoice) { registerCommandHandler("set", - [this] (auto&&, auto&&, auto&&, auto&&... args) { setStrategy(std::forward(args)...); }); + [this] (auto&&, auto&&, auto&&... args) { setStrategy(std::forward(args)...); }); registerCommandHandler("unset", - [this] (auto&&, auto&&, auto&&, auto&&... args) { unsetStrategy(std::forward(args)...); }); + [this] (auto&&, auto&&, auto&&... args) { unsetStrategy(std::forward(args)...); }); registerStatusDatasetHandler("list", [this] (auto&&, auto&&, auto&&... args) { listChoices(std::forward(args)...); }); } void StrategyChoiceManager::setStrategy(ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { const Name& prefix = parameters.getName(); const Name& strategy = parameters.getStrategy(); @@ -72,7 +72,7 @@ StrategyChoiceManager::setStrategy(ControlParameters parameters, void StrategyChoiceManager::unsetStrategy(ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done) + const CommandContinuation& done) { const Name& prefix = parameters.getName(); // no need to test for ndn:/ , parameter validation takes care of that diff --git a/daemon/mgmt/strategy-choice-manager.hpp b/daemon/mgmt/strategy-choice-manager.hpp index 6c91af8c..658e4c17 100644 --- a/daemon/mgmt/strategy-choice-manager.hpp +++ b/daemon/mgmt/strategy-choice-manager.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2021, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -46,12 +46,10 @@ class StrategyChoiceManager final : public ManagerBase private: void - setStrategy(ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done); + setStrategy(ControlParameters parameters, const CommandContinuation& done); void - unsetStrategy(ControlParameters parameters, - const ndn::mgmt::CommandContinuation& done); + unsetStrategy(ControlParameters parameters, const CommandContinuation& done); void listChoices(ndn::mgmt::StatusDatasetContext& context); diff --git a/daemon/rib/fib-updater.cpp b/daemon/rib/fib-updater.cpp index a2657a1e..897b6fba 100644 --- a/daemon/rib/fib-updater.cpp +++ b/daemon/rib/fib-updater.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -26,14 +26,12 @@ #include "fib-updater.hpp" #include "common/logger.hpp" -#include +#include namespace nfd::rib { NFD_LOG_INIT(FibUpdater); -using ndn::nfd::ControlParameters; - constexpr int MAX_NUM_TIMEOUTS = 10; constexpr uint32_t ERROR_FACE_NOT_FOUND = 410; diff --git a/daemon/rib/readvertise/readvertise.cpp b/daemon/rib/readvertise/readvertise.cpp index f7eb4cda..164e26b7 100644 --- a/daemon/rib/readvertise/readvertise.cpp +++ b/daemon/rib/readvertise/readvertise.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -161,7 +161,7 @@ Readvertise::advertise(ReadvertisedRouteContainer::iterator rrIt) [=] { advertise(rrIt); }); }, [=] (const std::string& msg) { - NFD_LOG_DEBUG("advertise " << rrIt->prefix << " failure " << msg); + NFD_LOG_DEBUG("advertise " << rrIt->prefix << " failure: " << msg); rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2); rrIt->retryEvt = getScheduler().schedule(randomizeTimer(rrIt->retryDelay), [=] { advertise(rrIt); }); @@ -185,7 +185,7 @@ Readvertise::withdraw(ReadvertisedRouteContainer::iterator rrIt) m_rrs.erase(rrIt); }, [=] (const std::string& msg) { - NFD_LOG_DEBUG("withdraw " << rrIt->prefix << " failure " << msg); + NFD_LOG_DEBUG("withdraw " << rrIt->prefix << " failure: " << msg); rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2); rrIt->retryEvt = getScheduler().schedule(randomizeTimer(rrIt->retryDelay), [=] { withdraw(rrIt); }); diff --git a/docs/conf.py b/docs/conf.py index d1dd2114..978b6dfc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = 'Named Data Networking Forwarding Daemon (NFD)' -copyright = 'Copyright © 2014-2024 Named Data Networking Project.' +copyright = 'Copyright © 2014-2025 Named Data Networking Project.' author = 'Named Data Networking Project' # The short X.Y version. diff --git a/tests/daemon/mgmt/manager-base.t.cpp b/tests/daemon/mgmt/manager-base.t.cpp index cf249895..2fcdd622 100644 --- a/tests/daemon/mgmt/manager-base.t.cpp +++ b/tests/daemon/mgmt/manager-base.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -29,25 +29,22 @@ namespace nfd::tests { -class TestCommandVoidParameters : public ControlCommand +class TestCommandVoidParameters : public ndn::nfd::ControlCommand { -public: - TestCommandVoidParameters() - : ControlCommand("test-module", "test-void-parameters") - { - } + NDN_CXX_CONTROL_COMMAND(TestCommandVoidParameters, "test-module", "test-void-parameters"); }; -class TestCommandRequireName : public ControlCommand +const TestCommandVoidParameters::RequestFormat TestCommandVoidParameters::s_requestFormat; + +class TestCommandRequireName : public ndn::nfd::ControlCommand { -public: - TestCommandRequireName() - : ControlCommand("test-module", "test-require-name") - { - m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME); - } + NDN_CXX_CONTROL_COMMAND(TestCommandRequireName, "test-module", "test-require-name"); }; +const TestCommandRequireName::RequestFormat TestCommandRequireName::s_requestFormat = + RequestFormat() + .required(ndn::nfd::CONTROL_PARAMETER_NAME); + class DummyManager final : public ManagerBase { public: @@ -59,12 +56,12 @@ class DummyManager final : public ManagerBase private: ndn::mgmt::Authorization - makeAuthorization(const std::string& verb) final + makeAuthorization(const std::string&) final { return [] (const Name& prefix, const Interest& interest, - const ndn::mgmt::ControlParameters* params, - ndn::mgmt::AcceptContinuation accept, - ndn::mgmt::RejectContinuation reject) { + const ndn::mgmt::ControlParametersBase* params, + const ndn::mgmt::AcceptContinuation& accept, + const ndn::mgmt::RejectContinuation& reject) { accept("requester"); }; } @@ -98,6 +95,10 @@ BOOST_AUTO_TEST_CASE(RegisterCommandHandler) testRegisterCommandHandler("/localhost/nfd/test-module/test-require-name"); BOOST_CHECK(!wasHandlerCalled); + + testRegisterCommandHandler(Name("/localhost/nfd/test-module/test-require-name") + .append(ControlParameters().setName("test-name").wireEncode())); + BOOST_CHECK(wasHandlerCalled); } BOOST_AUTO_TEST_CASE(RegisterStatusDataset) @@ -149,19 +150,6 @@ BOOST_AUTO_TEST_CASE(ExtractSigner) .getDefaultKey().getDefaultCertificate().getName().toUri()); } -BOOST_AUTO_TEST_CASE(ValidateParameters) -{ - ControlParameters params; - TestCommandVoidParameters commandVoidParams; - TestCommandRequireName commandRequireName; - - BOOST_CHECK_EQUAL(ManagerBase::validateParameters(commandVoidParams, params), true); // succeeds - BOOST_CHECK_EQUAL(ManagerBase::validateParameters(commandRequireName, params), false); // fails - - params.setName("test-name"); - BOOST_CHECK_EQUAL(ManagerBase::validateParameters(commandRequireName, params), true); // succeeds -} - BOOST_AUTO_TEST_CASE(MakeRelPrefix) { auto generatedRelPrefix = m_manager.makeRelPrefix("test-verb"); diff --git a/tests/daemon/mgmt/manager-common-fixture.hpp b/tests/daemon/mgmt/manager-common-fixture.hpp index 954cef2e..c8f5498b 100644 --- a/tests/daemon/mgmt/manager-common-fixture.hpp +++ b/tests/daemon/mgmt/manager-common-fixture.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -112,7 +112,7 @@ class ManagerCommonFixture : public InterestSignerFixture * @brief Check a specified response data with the expected ControlResponse. * * @param idx the index of the specified Data in m_responses - * @param expectedDataName the expected name of this Data + * @param expectedName the expected name of this Data * @param expectedResponse the expected ControlResponse * @param expectedContentType the expected content type of this Data, use -1 to skip this check * @@ -157,7 +157,8 @@ operator<<(std::ostream& os, ManagerCommonFixture::CheckResponseResult result); class ManagerFixtureWithAuthenticator : public ManagerCommonFixture { public: - /** \brief Grant m_identityName privilege to sign commands for the management module. + /** + * \brief Grant m_identityName privilege to sign commands for the management module. */ void setPrivilege(const std::string& privilege); diff --git a/tests/tools/nfdc/rib-module.t.cpp b/tests/tools/nfdc/rib-module.t.cpp index f349dfd6..cc010183 100644 --- a/tests/tools/nfdc/rib-module.t.cpp +++ b/tests/tools/nfdc/rib-module.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -207,9 +207,8 @@ BOOST_AUTO_TEST_CASE(NormalByFaceId) } ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register"); - ndn::nfd::RibRegisterCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::RibRegisterCommand::validateRequest(req); + ndn::nfd::RibRegisterCommand::applyDefaultsToRequest(req); BOOST_CHECK_EQUAL(req.getName(), "/vxXoEaWeDB"); BOOST_CHECK_EQUAL(req.getFaceId(), 10156); BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC); @@ -235,9 +234,8 @@ BOOST_AUTO_TEST_CASE(NormalByFaceUri) } ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register"); - ndn::nfd::RibRegisterCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::RibRegisterCommand::validateRequest(req); + ndn::nfd::RibRegisterCommand::applyDefaultsToRequest(req); BOOST_CHECK_EQUAL(req.getName(), "/FLQAsaYnYf"); BOOST_CHECK_EQUAL(req.getFaceId(), 2249); BOOST_CHECK_EQUAL(req.getOrigin(), 17591); @@ -280,9 +278,8 @@ BOOST_AUTO_TEST_CASE(FaceNotExistFaceUri) } else if (Name("/localhost/nfd/faces/create").isPrefixOf(interest.getName())) { ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create"); - ndn::nfd::FaceCreateCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::FaceCreateCommand::validateRequest(req); + ndn::nfd::FaceCreateCommand::applyDefaultsToRequest(req); BOOST_CHECK_EQUAL(req.getUri(), "udp4://202.83.168.28:6363"); ControlParameters resp = req; @@ -297,15 +294,13 @@ BOOST_AUTO_TEST_CASE(FaceNotExistFaceUri) } else if (Name("/localhost/nfd/rib/register").isPrefixOf(interest.getName())) { ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register"); - ndn::nfd::RibRegisterCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::RibRegisterCommand::validateRequest(req); + ndn::nfd::RibRegisterCommand::applyDefaultsToRequest(req); BOOST_CHECK_EQUAL(req.getName(), "/634jfAfdf"); BOOST_CHECK_EQUAL(req.getFaceId(), 255); BOOST_CHECK_EQUAL(req.getOrigin(), 17591); BOOST_CHECK_EQUAL(req.getCost(), 702); - BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | - ndn::nfd::ROUTE_FLAG_CAPTURE); + BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE); BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true); BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), 727411987_ms); @@ -405,9 +400,8 @@ BOOST_AUTO_TEST_CASE(NormalByFaceId) } ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); - ndn::nfd::RibUnregisterCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::RibUnregisterCommand::validateRequest(req); + ndn::nfd::RibUnregisterCommand::applyDefaultsToRequest(req); BOOST_CHECK_EQUAL(req.getName(), "/2B5NUGjpt"); BOOST_CHECK_EQUAL(req.getFaceId(), 10156); BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC); @@ -429,9 +423,8 @@ BOOST_AUTO_TEST_CASE(NormalByFaceUri) } ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); - ndn::nfd::RibUnregisterCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::RibUnregisterCommand::validateRequest(req); + ndn::nfd::RibUnregisterCommand::applyDefaultsToRequest(req); BOOST_CHECK_EQUAL(req.getName(), "/wHdNn0BtUF"); BOOST_CHECK_EQUAL(req.getFaceId(), 2249); BOOST_CHECK_EQUAL(req.getOrigin(), 15246); @@ -454,9 +447,8 @@ BOOST_AUTO_TEST_CASE(MultipleFaces) } ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister"); - ndn::nfd::RibUnregisterCommand cmd; - cmd.validateRequest(req); - cmd.applyDefaultsToRequest(req); + ndn::nfd::RibUnregisterCommand::validateRequest(req); + ndn::nfd::RibUnregisterCommand::applyDefaultsToRequest(req); BOOST_TEST_INFO_SCOPE("FaceId=" << req.getFaceId()); BOOST_CHECK_EQUAL(req.getName(), "/nm5y8X8b2"); BOOST_CHECK(faceIds.erase(req.getFaceId())); diff --git a/tools/ndn-autoconfig/multicast-discovery.cpp b/tools/ndn-autoconfig/multicast-discovery.cpp index dca08fc2..0aba16e8 100644 --- a/tools/ndn-autoconfig/multicast-discovery.cpp +++ b/tools/ndn-autoconfig/multicast-discovery.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2024, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -28,6 +28,7 @@ #include #include +#include #include namespace ndn::autoconfig { diff --git a/tools/ndn-autoconfig/procedure.cpp b/tools/ndn-autoconfig/procedure.cpp index ebeaae29..5a4be6c1 100644 --- a/tools/ndn-autoconfig/procedure.cpp +++ b/tools/ndn-autoconfig/procedure.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -29,6 +29,8 @@ #include "multicast-discovery.hpp" #include "ndn-fch-discovery.hpp" +#include + namespace ndn::autoconfig { using nfd::ControlParameters; diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp index 58ce2c7c..f14d3f65 100644 --- a/tools/nfd-autoreg.cpp +++ b/tools/nfd-autoreg.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2023, Regents of the University of California, + * Copyright (c) 2014-2025, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -27,6 +27,7 @@ #include "core/version.hpp" #include +#include #include #include #include