26 #include <boost/lexical_cast.hpp> 41 , m_keyChain(keyChain)
42 , m_validator(validator)
49 for (
const auto& sp : m_fetchers) {
55 Controller::startCommand(
const shared_ptr<ControlCommand>& command,
57 const CommandSucceedCallback& onSuccess,
58 const CommandFailCallback& onFailure,
61 Name requestName = command->getRequestName(options.
getPrefix(), parameters);
67 processCommandResponse(data, command, onSuccess, onFailure);
80 Controller::processCommandResponse(
const Data& data,
81 const shared_ptr<ControlCommand>& command,
82 const CommandSucceedCallback& onSuccess,
83 const CommandFailCallback& onFailure)
86 [=] (
const Data& data) {
87 processValidatedCommandResponse(data, command, onSuccess, onFailure);
89 [=] (
const Data&,
const auto& error) {
97 Controller::processValidatedCommandResponse(
const Data& data,
98 const shared_ptr<ControlCommand>& command,
99 const CommandSucceedCallback& onSuccess,
100 const CommandFailCallback& onFailure)
104 response.
wireDecode(data.getContent().blockFromValue());
106 catch (
const tlv::Error& e) {
112 uint32_t code = response.getCode();
123 catch (
const tlv::Error& e) {
130 command->validateResponse(parameters);
132 catch (
const ControlCommand::ArgumentError& e) {
139 onSuccess(parameters);
143 Controller::fetchDataset(
const Name& prefix,
145 const DatasetFailCallback& onFailure,
146 const CommandOptions& options)
148 SegmentFetcher::Options fetcherOptions;
149 fetcherOptions.maxTimeout = options.getTimeout();
152 if (processResponse) {
153 fetcher->onComplete.connect(processResponse);
156 fetcher->onError.connect([=] (uint32_t code,
const std::string& msg) {
157 processDatasetFetchError(onFailure, code, msg);
161 auto it = m_fetchers.insert(fetcher).first;
162 fetcher->onComplete.connect([
this, it] (
ConstBufferPtr) { m_fetchers.erase(it); });
163 fetcher->onError.connect([
this, it] (uint32_t,
const std::string&) { m_fetchers.erase(it); });
167 Controller::processDatasetFetchError(
const DatasetFailCallback& onFailure,
168 uint32_t code, std::string msg)
170 BOOST_ASSERT(onFailure);
172 switch (static_cast<SegmentFetcher::ErrorCode>(code)) {
176 case SegmentFetcher::ErrorCode::INTEREST_TIMEOUT:
179 case SegmentFetcher::ErrorCode::DATA_HAS_NO_SEGMENT:
180 case SegmentFetcher::ErrorCode::FINALBLOCKID_NOT_SEGMENT:
183 case SegmentFetcher::ErrorCode::SEGMENT_VALIDATION_FAIL:
188 case SegmentFetcher::ErrorCode::NACK_ERROR:
void wireDecode(const Block &wire) final
Copyright (c) 2011-2015 Regents of the University of California.
The interface of signing key management.
represents parameters in a ControlCommand request or response
security::CommandInterestSigner m_signer
const security::SigningInfo & getSigningInfo() const
Utility class to fetch the latest version of a segmented object.
const time::milliseconds & getTimeout() const
Represents an Interest packet.
static const uint32_t ERROR_TIMEOUT
error code for timeout
represents a Network Nack
static const uint32_t ERROR_LBOUND
inclusive lower bound of error codes
mgmt::ControlResponse ControlResponse
contains options for ControlCommand execution
Copyright (c) 2011-2015 Regents of the University of California.
static shared_ptr< SegmentFetcher > start(Face &face, const Interest &baseInterest, security::v2::Validator &validator, const Options &options=Options())
Initiates segment fetching.
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
Provide a communication channel with local or remote NDN forwarder.
static const uint32_t ERROR_VALIDATION
error code for response validation failure
Controller(Face &face, KeyChain &keyChain, security::v2::Validator &validator=security::getAcceptAllValidator())
construct a Controller that uses face for transport, and uses the passed KeyChain to sign commands
Interest makeCommandInterest(const Name &name, const SigningInfo ¶ms=KeyChain::getDefaultSigningInfo())
Create CommandInterest.
Represents an absolute name.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
const Name & getPrefix() const
void wireDecode(const Block &block)
security::v2::Validator & m_validator
Interest & setInterestLifetime(time::milliseconds lifetime)
Set Interest's lifetime.
Represents a Data packet.
Interface for validating data and interest packets.
static const uint32_t ERROR_SERVER
error code for server error
static const uint32_t ERROR_NACK
error code for network Nack
shared_ptr< const Buffer > ConstBufferPtr