22 #ifndef NDN_MGMT_DISPATCHER_HPP 23 #define NDN_MGMT_DISPATCHER_HPP 25 #include "../encoding/block.hpp" 26 #include "../face.hpp" 27 #include "../ims/in-memory-storage-fifo.hpp" 28 #include "../security/key-chain.hpp" 33 #include <unordered_map> 74 typedef std::function<void(
const Name& prefix,
const Interest& interest,
76 const AcceptContinuation& accept,
104 typedef std::function<void(
const Name& prefix,
const Interest& interest,
117 typedef std::function<void(
const Name& prefix,
const Interest& interest,
141 size_t imsCapacity = 256);
167 addTopPrefix(
const Name& prefix,
bool wantRegister =
true,
181 removeTopPrefix(
const Name& prefix);
209 template<
typename CP>
212 const Authorization& authorization,
213 const ValidateParameters& validateParams,
214 const ControlCommandHandler& handler);
249 const Authorization& authorization,
250 const StatusDatasetHandler& handler);
273 addNotificationStream(
const PartialName& relPrefix);
276 typedef std::function<void(
const Name& prefix,
277 const Interest& interest)> InterestHandler;
279 typedef std::function<void(
const std::string& requester,
282 const shared_ptr<ControlParameters>&)> AuthorizationAcceptedCallback;
285 const Interest& interest)> AuthorizationRejectedCallback;
293 typedef std::function<shared_ptr<ControlParameters>(
const name::Component& comp)> ControlParametersParser;
296 isOverlappedWithOthers(
const PartialName& relPrefix)
const;
316 queryStorage(
const Name& prefix,
const Interest& interest,
const InterestHandler& missContinuation);
318 enum class SendDestination {
343 SendDestination destination, time::milliseconds imsFresh);
351 sendOnFace(
const Data& data);
365 processControlCommandInterest(
const Name& prefix,
366 const Name& relPrefix,
368 const ControlParametersParser& parser,
369 const Authorization& authorization,
370 const AuthorizationAcceptedCallback& accepted,
371 const AuthorizationRejectedCallback& rejected);
384 processAuthorizedControlCommandInterest(
const std::string& requester,
387 const shared_ptr<ControlParameters>& parameters,
388 const ValidateParameters& validate,
389 const ControlCommandHandler& handler);
404 processStatusDatasetInterest(
const Name& prefix,
406 const Authorization& authorization,
407 const AuthorizationAcceptedCallback& accepted,
408 const AuthorizationRejectedCallback& rejected);
419 processAuthorizedStatusDatasetInterest(
const std::string& requester,
422 const StatusDatasetHandler& handler);
433 sendStatusDatasetSegment(
const Name& dataName,
const Block& content,
434 time::milliseconds imsFresh,
bool isFinalBlock);
440 struct TopPrefixEntry
444 std::vector<const InterestFilterId*> interestFilters;
446 std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
449 KeyChain& m_keyChain;
452 std::unordered_map<PartialName, InterestHandler> m_handlers;
455 std::unordered_map<Name, uint64_t> m_streams;
461 template<
typename CP>
464 const Authorization& authorization,
465 const ValidateParameters& validateParams,
466 const ControlCommandHandler& handler)
468 if (!m_topLevelPrefixes.empty()) {
469 BOOST_THROW_EXCEPTION(std::domain_error(
"one or more top-level prefix has been added"));
472 if (isOverlappedWithOthers(relPrefix)) {
473 BOOST_THROW_EXCEPTION(std::out_of_range(
"relPrefix overlaps with another relPrefix"));
476 ControlParametersParser parser = [] (
const name::Component& comp) -> shared_ptr<ControlParameters> {
477 return make_shared<CP>(comp.blockFromValue());
480 AuthorizationAcceptedCallback accepted =
481 bind(&Dispatcher::processAuthorizedControlCommandInterest,
this,
482 _1, _2, _3, _4, validateParams, handler);
484 AuthorizationRejectedCallback rejected =
485 bind(&Dispatcher::afterAuthorizationRejected,
this, _1, _2);
487 m_handlers[relPrefix] = bind(&Dispatcher::processControlCommandInterest,
this,
488 _1, relPrefix, _2, parser, authorization, accepted, rejected);
494 #endif // NDN_MGMT_DISPATCHER_HPP constexpr nullopt_t nullopt
Copyright (c) 2013-2017 Regents of the University of California.
Provides in-memory storage employing First-In-First-Out (FIFO) replacement policy.
std::function< void(const Block ¬ification)> PostNotification
a function to post a notification
represents a dispatcher on server side of NFD Management protocol
RejectReply
indicate how to reply in case authorization is rejected
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
reply with a ControlResponse where StatusCode is 403
Represents a TLV element of NDN packet format.
Represents an Interest packet.
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
Authorization makeAcceptAllAuthorization()
return an Authorization that accepts all Interests, with empty string as requester ...
Signing parameters passed to KeyChain.
std::function< void(RejectReply reply)> RejectContinuation
a function to be called if authorization is rejected
Provide a communication channel with local or remote NDN forwarder.
Represents an absolute name.
std::function< void(const ControlResponse &resp)> CommandContinuation
a function to be called after ControlCommandHandler completes
base class for a struct that contains ControlCommand parameters
void addControlCommand(const PartialName &relPrefix, const Authorization &authorization, const ValidateParameters &validateParams, const ControlCommandHandler &handler)
register a ControlCommand
Represents a name component.
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters ¶ms, const CommandContinuation &done)> ControlCommandHandler
a function to handle an authorized ControlCommand
std::function< bool(const ControlParameters ¶ms)> ValidateParameters
a function to validate input ControlParameters
provides a context for generating response to a StatusDataset request
Represents a Data packet.
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 Name &prefix, const Interest &interest, StatusDatasetContext &context)> StatusDatasetHandler
a function to handle a StatusDataset request