26 #include <boost/lexical_cast.hpp>
41 , m_keyChain(keyChain)
42 , m_validator(validator)
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);
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);
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:
Represents a Data packet.
Provide a communication channel with local or remote NDN forwarder.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Represents an Interest packet.
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
Represents an absolute name.
represents a Network Nack
void wireDecode(const Block &block)
contains options for ControlCommand execution
const Name & getPrefix() const
const time::milliseconds & getTimeout() const
const security::SigningInfo & getSigningInfo() const
represents parameters in a ControlCommand request or response
void wireDecode(const Block &wire) final
static const uint32_t ERROR_TIMEOUT
error code for timeout
static const uint32_t ERROR_SERVER
error code for server error
static const uint32_t ERROR_LBOUND
inclusive lower bound of error codes
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
static const uint32_t ERROR_VALIDATION
error code for response validation failure
security::InterestSigner m_signer
static const uint32_t ERROR_NACK
error code for network Nack
std::set< shared_ptr< util::SegmentFetcher > > m_fetchers
security::Validator & m_validator
Interest makeCommandInterest(Name name, const SigningInfo ¶ms=SigningInfo())
Creates and signs a command Interest.
Interface for validating data and interest packets.
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
Utility class to fetch the latest version of a segmented object.
static shared_ptr< SegmentFetcher > start(Face &face, const Interest &baseInterest, security::Validator &validator, const Options &options=Options())
Initiates segment fetching.
ErrorCode
Error codes passed to onError.
mgmt::ControlResponse ControlResponse
shared_ptr< const Buffer > ConstBufferPtr