22 #ifndef NDN_CXX_MGMT_DISPATCHER_HPP
23 #define NDN_CXX_MGMT_DISPATCHER_HPP
33 #include <unordered_map>
147 size_t imsCapacity = 256);
212 template<
typename CP>
279 using InterestHandler = std::function<void(
const Name& prefix,
const Interest&)>;
281 using AuthorizationAcceptedCallback = std::function<void(
const std::string& requester,
284 const shared_ptr<ControlParameters>&)>;
293 using ControlParametersParser = std::function<shared_ptr<ControlParameters>(
const name::Component&)>;
296 isOverlappedWithOthers(
const PartialName& relPrefix)
const;
316 queryStorage(
const Name& prefix,
const Interest& interest,
const InterestHandler& missContinuation);
318 enum class SendDestination {
342 SendDestination destination);
350 sendOnFace(
const Data& data);
364 processControlCommandInterest(
const Name& prefix,
365 const Name& relPrefix,
367 const ControlParametersParser& parser,
369 const AuthorizationAcceptedCallback& accepted,
370 const AuthorizationRejectedCallback& rejected);
383 processAuthorizedControlCommandInterest(
const std::string& requester,
386 const shared_ptr<ControlParameters>& parameters,
403 processStatusDatasetInterest(
const Name& prefix,
406 const AuthorizationAcceptedCallback& accepted,
407 const AuthorizationRejectedCallback& rejected);
417 processAuthorizedStatusDatasetInterest(
const Name& prefix,
429 sendStatusDatasetSegment(
const Name& dataName,
const Block& content,
bool isFinalBlock);
435 struct TopPrefixEntry
438 std::vector<ScopedInterestFilterHandle> interestFilters;
440 std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
446 std::unordered_map<PartialName, InterestHandler> m_handlers;
449 std::unordered_map<Name, uint64_t> m_streams;
455 template<
typename CP>
462 if (!m_topLevelPrefixes.empty()) {
463 NDN_THROW(std::domain_error(
"one or more top-level prefix has been added"));
466 if (isOverlappedWithOthers(relPrefix)) {
467 NDN_THROW(std::out_of_range(
"relPrefix overlaps with another relPrefix"));
470 ControlParametersParser parser = [] (
const name::Component& comp) -> shared_ptr<ControlParameters> {
471 return make_shared<CP>(comp.blockFromValue());
473 AuthorizationAcceptedCallback accepted = [
this, validate = std::move(validate),
474 handle = std::move(handle)] (
auto&&... args) {
475 processAuthorizedControlCommandInterest(std::forward<decltype(args)>(args)..., validate, handle);
477 AuthorizationRejectedCallback rejected = [
this] (
auto&&... args) {
478 afterAuthorizationRejected(std::forward<decltype(args)>(args)...);
481 m_handlers[relPrefix] = [
this, relPrefix,
482 parser = std::move(parser),
483 authorize = std::move(authorize),
484 accepted = std::move(accepted),
485 rejected = std::move(rejected)] (
const auto& prefix,
const auto& interest) {
486 processControlCommandInterest(prefix, relPrefix, interest, parser, authorize, accepted, rejected);
Represents a TLV element of the NDN packet format.
Represents a Data packet.
Provide a communication channel with local or remote NDN forwarder.
Provides in-memory storage employing First-In-First-Out (FIFO) replacement policy.
Represents an Interest packet.
Represents an absolute name.
Base class for a struct that contains ControlCommand parameters.
Implements a request dispatcher on server side of NFD Management protocol.
PostNotification addNotificationStream(const PartialName &relPrefix)
Register a NotificationStream.
Dispatcher(Face &face, KeyChain &keyChain, const security::SigningInfo &signingInfo=security::SigningInfo(), size_t imsCapacity=256)
Constructor.
void addStatusDataset(const PartialName &relPrefix, Authorization authorize, StatusDatasetHandler handle)
Register a StatusDataset or a prefix under which StatusDatasets can be requested.
void addControlCommand(const PartialName &relPrefix, Authorization authorize, ValidateParameters validate, ControlCommandHandler handle)
Register a ControlCommand.
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.
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 ControlParameters *params, const AcceptContinuation &accept, const RejectContinuation &reject)> Authorization
A function that performs authorization.
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(const ControlParameters ¶ms)> ValidateParameters
A function to validate input ControlParameters.
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters ¶ms, const CommandContinuation &done)> ControlCommandHandler
A function to handle an authorized ControlCommand.
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 ControlCommandHandler completes.
std::function< void(const Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
A function to handle a StatusDataset request.