23 #include "../../face.hpp"
24 #include "../../security/key-chain.hpp"
25 #include "../../util/segment-fetcher.hpp"
37 ValidatorNull Controller::s_validatorNull;
41 , m_keyChain(keyChain)
42 , m_validator(validator)
47 Controller::startCommand(
const shared_ptr<ControlCommand>& command,
49 const CommandSucceedCallback& onSuccess1,
50 const CommandFailCallback& onFailure1,
58 Name requestName = command->getRequestName(options.
getPrefix(), parameters);
60 interest.setInterestLifetime(options.
getTimeout());
65 this->processCommandResponse(data, command, onSuccess, onFailure);
68 onFailure(
ControlResponse(Controller::ERROR_NACK,
"network Nack received"));
71 onFailure(
ControlResponse(Controller::ERROR_TIMEOUT,
"request timed out"));
76 Controller::processCommandResponse(
const Data& data,
77 const shared_ptr<ControlCommand>& command,
78 const CommandSucceedCallback& onSuccess,
79 const CommandFailCallback& onFailure)
82 [=] (
const shared_ptr<const Data>& data) {
83 this->processValidatedCommandResponse(*data, command, onSuccess, onFailure);
85 [=] (
const shared_ptr<const Data>&,
const std::string& msg) {
92 Controller::processValidatedCommandResponse(
const Data& data,
93 const shared_ptr<ControlCommand>& command,
94 const CommandSucceedCallback& onSuccess,
95 const CommandFailCallback& onFailure)
99 response.
wireDecode(data.getContent().blockFromValue());
101 catch (
const tlv::Error& e) {
106 uint32_t code = response.getCode();
116 catch (
const tlv::Error& e) {
122 command->validateResponse(parameters);
124 catch (
const ControlCommand::ArgumentError& e) {
129 onSuccess(parameters);
133 Controller::fetchDataset(
const Name& prefix,
134 const std::function<
void(
const ConstBufferPtr&)>& processResponse,
135 const DatasetFailCallback& onFailure,
136 const CommandOptions& options)
139 baseInterest.setInterestLifetime(options.getTimeout());
142 bind(&Controller::processDatasetFetchError,
this, onFailure, _1, _2));
146 Controller::processDatasetFetchError(
const DatasetFailCallback& onFailure,
147 uint32_t code, std::string msg)
149 switch (static_cast<SegmentFetcher::ErrorCode>(code)) {
153 case SegmentFetcher::ErrorCode::INTEREST_TIMEOUT:
156 case SegmentFetcher::ErrorCode::DATA_HAS_NO_SEGMENT:
159 case SegmentFetcher::ErrorCode::SEGMENT_VALIDATION_FAIL:
164 case SegmentFetcher::ErrorCode::NACK_ERROR:
void wireDecode(const Block &wire) final
void validate(const Data &data, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed)
Validate Data and call either onValidated or onValidationFailed.
Copyright (c) 2013-2016 Regents of the University of California.
ndn security v2 Validator
represents parameters in a ControlCommand request or response
Utility class to fetch latest version of the segmented data.
void sign(Data &data, const SigningInfo ¶ms=DEFAULT_SIGNING_INFO)
Sign data according to the supplied signing information.
function< void(const ControlResponse &)> CommandFailCallback
a callback on command failure
const Name & getPrefix() const
static const uint32_t ERROR_TIMEOUT
error code for timeout
function< void(const ControlParameters &)> CommandSucceedCallback
a callback on command success
static const uint32_t ERROR_LBOUND
inclusive lower bound of error codes
ndn::mgmt::ControlResponse ControlResponse
contains options for ControlCommand execution
Provide a communication channel with local or remote NDN forwarder.
static const uint32_t ERROR_VALIDATION
error code for response validation failure
static void fetch(Face &face, const Interest &baseInterest, Validator &validator, const CompleteCallback &completeCallback, const ErrorCallback &errorCallback)
Initiate segment fetching.
Controller(Face &face, security::v1::KeyChain &keyChain, security::Validator &validator=s_validatorNull)
construct a Controller that uses face for transport, and uses the passed KeyChain to sign commands ...
void wireDecode(const Block &block)
The packet signing interface.
security::Validator & m_validator
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
shared_ptr< const Buffer > ConstBufferPtr
security::v1::KeyChain & m_keyChain
const time::milliseconds & getTimeout() const
static const uint32_t ERROR_SERVER
error code for server error
static const uint32_t ERROR_NACK
error code for network Nack
const security::SigningInfo & getSigningInfo() const