22 #ifndef NDN_MGMT_DISPATCHER_HPP 23 #define NDN_MGMT_DISPATCHER_HPP 25 #include "../face.hpp" 26 #include "../encoding/block.hpp" 27 #include "../security/key-chain.hpp" 28 #include "../ims/in-memory-storage-fifo.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,
116 typedef std::function<void(
const Name& prefix,
const Interest& interest,
131 class Error :
public std::runtime_error
135 Error(
const std::string& what)
136 : std::runtime_error(what)
150 size_t imsCapacity = 256);
176 addTopPrefix(
const Name& prefix,
bool wantRegister =
true,
190 removeTopPrefix(
const Name& prefix);
219 template<
typename CP>
222 const Authorization& authorization,
223 const ValidateParameters& validateParams,
224 const ControlCommandHandler& handler);
260 const Authorization& authorization,
261 const StatusDatasetHandler& handler);
285 addNotificationStream(
const PartialName& relPrefix);
288 typedef std::function<void(
const Name& prefix,
289 const Interest& interest)> InterestHandler;
291 typedef std::function<void(
const std::string& requester,
294 const shared_ptr<ControlParameters>&)> AuthorizationAcceptedCallback;
297 const Interest& interest)> AuthorizationRejectedCallback;
306 typedef std::function<shared_ptr<ControlParameters>(
const name::Component& component)>
307 ControlParametersParser;
310 isOverlappedWithOthers(
const PartialName& relPrefix);
331 queryStorage(
const Name& prefix,
const Interest& interest,
const InterestHandler& missContinuation);
333 enum class SendDestination {
358 SendDestination destination, time::milliseconds imsFresh);
366 sendOnFace(
const Data& data);
380 processControlCommandInterest(
const Name& prefix,
381 const Name& relPrefix,
383 const ControlParametersParser& parser,
384 const Authorization& authorization,
385 const AuthorizationAcceptedCallback& accepted,
386 const AuthorizationRejectedCallback& rejected);
399 processAuthorizedControlCommandInterest(
const std::string& requester,
402 const shared_ptr<ControlParameters>& parameters,
403 const ValidateParameters& validate,
404 const ControlCommandHandler& handler);
419 processStatusDatasetInterest(
const Name& prefix,
421 const Authorization& authorization,
422 const AuthorizationAcceptedCallback& accepted,
423 const AuthorizationRejectedCallback& rejected);
434 processAuthorizedStatusDatasetInterest(
const std::string& requester,
437 const StatusDatasetHandler& handler);
448 sendStatusDatasetSegment(
const Name& dataName,
const Block& content,
449 time::milliseconds imsFresh,
bool isFinalBlock);
455 struct TopPrefixEntry
459 const ndn::RegisteredPrefixId* registerPrefixId;
460 std::vector<const ndn::InterestFilterId*> interestFilters;
462 std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
465 KeyChain& m_keyChain;
468 typedef std::unordered_map<PartialName, InterestHandler> HandlerMap;
469 typedef HandlerMap::iterator HandlerMapIt;
470 HandlerMap m_handlers;
473 std::unordered_map<Name, uint64_t> m_streams;
479 template<
typename CP>
482 const Authorization& authorization,
483 const ValidateParameters& validateParams,
484 const ControlCommandHandler& handler)
486 if (!m_topLevelPrefixes.empty()) {
487 BOOST_THROW_EXCEPTION(std::domain_error(
"one or more top-level prefix has been added"));
490 if (isOverlappedWithOthers(relPrefix)) {
491 BOOST_THROW_EXCEPTION(std::out_of_range(
"relPrefix overlaps with another relPrefix"));
494 ControlParametersParser parser =
495 [] (
const name::Component& component) -> shared_ptr<ControlParameters> {
496 return make_shared<CP>(component.blockFromValue());
499 AuthorizationAcceptedCallback accepted =
500 bind(&Dispatcher::processAuthorizedControlCommandInterest,
this,
501 _1, _2, _3, _4, validateParams, handler);
503 AuthorizationRejectedCallback rejected =
504 bind(&Dispatcher::afterAuthorizationRejected,
this, _1, _2);
506 m_handlers[relPrefix] = bind(&Dispatcher::processControlCommandInterest,
this,
507 _1, relPrefix, _2, parser, authorization, accepted, rejected);
512 #endif // NDN_MGMT_DISPATCHER_HPP 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(RejectReply act)> RejectContinuation
a function to be called if authorization is rejected
std::function< void(const std::string &requester)> AcceptContinuation
a function to be called if authorization is successful
Authorization makeAcceptAllAuthorization()
Signing parameters passed to KeyChain.
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
Component holds a read-only name component value.
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