26 #ifndef NDN_MGMT_DISPATCHER_HPP 27 #define NDN_MGMT_DISPATCHER_HPP 29 #include "../face.hpp" 30 #include "../security/key-chain.hpp" 31 #include "../encoding/block.hpp" 36 #include <unordered_map> 77 typedef std::function<void(
const Name& prefix,
const Interest& interest,
79 AcceptContinuation accept,
107 typedef std::function<void(
const Name& prefix,
const Interest& interest,
119 typedef std::function<void(
const Name& prefix,
const Interest& interest,
134 class Error :
public std::runtime_error
138 Error(
const std::string& what)
139 : std::runtime_error(what)
177 addTopPrefix(
const Name& prefix,
bool wantRegister =
true,
191 removeTopPrefix(
const Name& prefix);
217 template<
typename CP>
220 Authorization authorization,
221 ValidateParameters validateParams,
222 ControlCommandHandler handler);
257 Authorization authorization,
258 StatusDatasetHandler handler);
282 addNotificationStream(
const PartialName& relPrefix);
285 typedef std::function<void(
const Name& prefix,
286 const Interest& interest)> InterestHandler;
288 typedef std::function<void(
const std::string& requester,
294 const Interest& interest)> AuthorizationRejectedCallback;
303 typedef std::function<shared_ptr<ControlParameters>(
const name::Component& component)>
304 ControlParametersParser;
307 isOverlappedWithOthers(
const PartialName& relPrefix);
319 sendData(
const Name& dataName,
const Block& content,
334 processControlCommandInterest(
const Name& prefix,
335 const Name& relPrefix,
337 const ControlParametersParser& parser,
338 const Authorization& authorization,
339 const AuthorizationAcceptedCallback& accepted,
340 const AuthorizationRejectedCallback& rejected);
353 processAuthorizedControlCommandInterest(
const std::string& requester,
357 const ValidateParameters& validate,
358 const ControlCommandHandler& handler);
373 processStatusDatasetInterest(
const Name& prefix,
375 const Authorization& authorization,
376 const AuthorizationAcceptedCallback& accepted,
377 const AuthorizationRejectedCallback& rejected);
388 processAuthorizedStatusDatasetInterest(
const std::string& requester,
391 const StatusDatasetHandler& handler);
397 struct TopPrefixEntry
401 const ndn::RegisteredPrefixId* registerPrefixId;
402 std::vector<const ndn::InterestFilterId*> interestFilters;
404 std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
410 typedef std::unordered_map<PartialName, InterestHandler> HandlerMap;
412 HandlerMap m_handlers;
415 std::unordered_map<Name, uint64_t> m_streams;
418 template<
typename CP>
421 Authorization authorization,
422 ValidateParameters validateParams,
423 ControlCommandHandler handler)
425 if (!m_topLevelPrefixes.empty()) {
426 throw std::domain_error(
"one or more top-level prefix has been added");
429 if (isOverlappedWithOthers(relPrefix)) {
430 throw std::out_of_range(
"relPrefix overlaps with another relPrefix");
433 ControlParametersParser parser =
434 [] (
const name::Component& component) -> shared_ptr<ControlParameters> {
435 return make_shared<CP>(component.blockFromValue());
438 AuthorizationAcceptedCallback accepted =
439 bind(&Dispatcher::processAuthorizedControlCommandInterest,
this,
440 _1, _2, _3, _4, validateParams, handler);
442 AuthorizationRejectedCallback rejected =
443 bind(&Dispatcher::afterAuthorizationRejected,
this, _1, _2);
445 m_handlers[relPrefix] = bind(&Dispatcher::processControlCommandInterest,
this,
446 _1, relPrefix, _2, parser, authorization, accepted, rejected);
451 #endif // NDN_MGMT_DISPATCHER_HPP Copyright (c) 2011-2015 Regents of the University of California.
void addControlCommand(const PartialName &relPrefix, Authorization authorization, ValidateParameters validateParams, ControlCommandHandler handler)
register a ControlCommand
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
reply with a ControlResponse where StatusCode is 403
The packet signing interface.
Class representing a wire element of NDN-TLV 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.
Table::const_iterator iterator
Abstraction to communicate with local or remote NDN forwarder.
Name abstraction to represent 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
Component holds a read-only name component value.
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, CommandContinuation done)> ControlCommandHandler
a function to handle an authorized ControlCommand
std::function< void(const Name &prefix, const Interest &interest, const ControlParameters *params, AcceptContinuation accept, 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