22#ifndef NDN_CXX_MGMT_DISPATCHER_HPP
23#define NDN_CXX_MGMT_DISPATCHER_HPP
32#include <unordered_map>
152 size_t imsCapacity = 256);
217 template<
typename ParametersType,
218 std::enable_if_t<std::is_convertible_v<ParametersType*, ControlParametersBase*>,
int> = 0>
225 checkPrefix(relPrefix);
227 auto relPrefixLen = relPrefix.
size();
228 ParametersParser parse = [relPrefixLen] (
const Name& prefix,
229 const auto& interest) -> ControlParametersPtr {
234 m_handlers[relPrefix] = [
this,
235 parser = std::move(parse),
236 authorizer = std::move(authorize),
237 validator = std::move(validate),
238 handler = std::move(handle)] (
const auto& prefix,
const auto& interest) {
239 processCommand(prefix, interest, parser, authorizer, std::move(validator), std::move(handler));
266 template<
typename Command>
270 auto relPrefix = Command::getName();
271 checkPrefix(relPrefix);
273 ParametersParser parse = [] (
const Name& prefix,
const auto& interest) {
274 return Command::parseRequest(interest, prefix.
size());
277 auto& reqParams =
static_cast<typename Command::RequestParameters&
>(params);
278 Command::validateRequest(reqParams);
279 Command::applyDefaultsToRequest(reqParams);
284 m_handlers[relPrefix] = [
this,
285 parser = std::move(parse),
286 authorizer = std::move(authorize),
287 validator = std::move(validate),
288 handler = std::move(handle)] (
const auto& prefix,
const auto& interest) {
289 processCommand(prefix, interest, parser, authorizer, std::move(validator), std::move(handler));
356 using ControlParametersPtr = shared_ptr<ControlParametersBase>;
357 using InterestHandler = std::function<void(
const Name& prefix,
const Interest&)>;
364 using ParametersParser = std::function<ControlParametersPtr(
const Name& prefix,
const Interest&)>;
387 queryStorage(
const Name& prefix,
const Interest& interest,
const InterestHandler& missContinuation);
389 enum class SendDestination {
413 SendDestination destination);
419 sendOnFace(
const Data& data);
432 processCommand(
const Name& prefix,
434 const ParametersParser& parse,
449 processAuthorizedCommand(
const Name& prefix,
451 const ControlParametersPtr& parameters,
456 sendControlResponse(
const ControlResponse& resp,
const Interest& interest,
bool isNack =
false);
467 processStatusDatasetInterest(
const Name& prefix,
480 processAuthorizedStatusDatasetInterest(
const Name& prefix,
492 sendStatusDatasetSegment(
const Name& dataName,
const Block& content,
bool isFinalBlock);
502 struct TopPrefixEntry
505 std::vector<ScopedInterestFilterHandle> interestFilters;
507 std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
509 std::unordered_map<PartialName, InterestHandler> m_handlers;
512 std::unordered_map<Name, uint64_t> m_streams;
515 InMemoryStorageFifo m_storage;
Represents a TLV element of the NDN packet format.
Block blockFromValue() const
Return a new Block constructed from the TLV-VALUE of this Block.
const Block & get(uint32_t type) const
Return the first sub-element of the specified TLV-TYPE.
Represents a Data packet.
Provide a communication channel with local or remote NDN forwarder.
Represents an Interest packet.
Represents an absolute name.
size_t size() const noexcept
Returns the number of components.
Base class for a struct that contains the parameters for a ControlCommand.
Implements a request dispatcher on server side of NFD Management protocol.
PostNotification addNotificationStream(const PartialName &relPrefix)
Register a NotificationStream.
void addStatusDataset(const PartialName &relPrefix, Authorization authorize, StatusDatasetHandler handle)
Register a StatusDataset or a prefix under which StatusDatasets can be requested.
void addControlCommand(Authorization authorize, ControlCommandHandler handle)
Register a ControlCommand (new style).
void addTopPrefix(const Name &prefix, bool wantRegister=true, const security::SigningInfo &signingInfo=security::SigningInfo())
Add a top-level prefix.
void removeTopPrefix(const Name &prefix)
Remove a top-level prefix.
void addControlCommand(const PartialName &relPrefix, Authorization authorize, ValidateParameters validate, ControlCommandHandler handle)
Register a ControlCommand (old style).
Provides a context for generating the response to a StatusDataset request.
Represents a name component.
The main interface for signing key management.
Signing parameters passed to KeyChain.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
std::function< void(const std::string &requester)> AcceptContinuation
A function to be called if authorization is successful.
std::function< void(const Name &prefix, const Interest &interest, const ControlParametersBase ¶ms, const CommandContinuation &done)> ControlCommandHandler
A function to handle an authorized ControlCommand.
std::function< void(const Block ¬ification)> PostNotification
A function to post a notification.
std::function< void(RejectReply)> RejectContinuation
A function to be called if authorization is rejected.
RejectReply
Indicates how to reply in case authorization is rejected.
@ STATUS403
Reply with a ControlResponse where StatusCode is 403.
std::function< bool(ControlParametersBase ¶ms)> ValidateParameters
A function to validate and normalize the incoming request parameters.
std::function< void(const Name &prefix, const Interest &interest, const ControlParametersBase *params, const AcceptContinuation &accept, const RejectContinuation &reject)> Authorization
A function that performs authorization.
Authorization makeAcceptAllAuthorization()
Return an Authorization that accepts all Interests, with empty string as requester.
std::function< void(const ControlResponse &resp)> CommandContinuation
A function to be called after a ControlCommandHandler completes.
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
A function to handle a StatusDataset request.