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,
61 Name requestName = command->getRequestName(options.
getPrefix(), parameters);
67 processCommandResponse(data, command, onSuccess, onFailure);
71 onFailure(
ControlResponse(Controller::ERROR_NACK,
"network Nack received"));
75 onFailure(
ControlResponse(Controller::ERROR_TIMEOUT,
"request timed out"));
80 Controller::processCommandResponse(
const Data& data,
81 const shared_ptr<ControlCommand>& command,
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,
112 uint32_t code = response.
getCode();
130 command->validateResponse(parameters);
139 onSuccess(parameters);
143 Controller::fetchDataset(
const Name& prefix,
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); });
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.
represents parameters in a ControlCommand request or response
static shared_ptr< SegmentFetcher > start(Face &face, const Interest &baseInterest, security::Validator &validator, const Options &options=Options())
Initiates segment fetching.
Interest makeCommandInterest(Name name, const SigningInfo ¶ms=SigningInfo())
Creates and signs a command Interest.
const Block & getBody() const
function< void(const ControlResponse &)> CommandFailCallback
a callback on command failure
const security::SigningInfo & getSigningInfo() const
security::InterestSigner m_signer
Controller(Face &face, KeyChain &keyChain, security::Validator &validator=security::getAcceptAllValidator())
construct a Controller that uses face for transport, and uses the passed KeyChain to sign commands ...
function< void(uint32_t code, const std::string &reason)> DatasetFailCallback
a callback on dataset retrieval failure
time::milliseconds maxTimeout
maximum allowed time between successful receipt of segments
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.
Provide a communication channel with local or remote NDN forwarder.
static const uint32_t ERROR_VALIDATION
error code for response validation failure
Represents an absolute name.
function< void(const ControlParameters &)> CommandSucceedCallback
a callback on command success
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)
Block blockFromValue() const
Return a new Block constructed from the TLV-VALUE of this Block.
const Block & getContent() const noexcept
Get the Content element.
security::Validator & m_validator
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
represents an error in ControlParameters
Represents a Data packet.
represents an error in TLV encoding or decoding
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