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,
68 processCommandResponse(data, command, onSuccess, onFailure);
73 "received Nack: " + boost::lexical_cast<std::string>(nack.getReason())));
82 Controller::processCommandResponse(
const Data& data,
83 const shared_ptr<ControlCommand>& command,
84 const CommandSucceedCallback& onSuccess,
85 const CommandFailCallback& onFailure)
88 [=] (
const Data& data) {
89 processValidatedCommandResponse(data, command, onSuccess, onFailure);
91 [=] (
const Data&,
const auto& error) {
99 Controller::processValidatedCommandResponse(
const Data& data,
100 const shared_ptr<ControlCommand>& command,
101 const CommandSucceedCallback& onSuccess,
102 const CommandFailCallback& onFailure)
106 response.
wireDecode(data.getContent().blockFromValue());
108 catch (
const tlv::Error& e) {
114 uint32_t code = response.getCode();
125 catch (
const tlv::Error& e) {
132 command->validateResponse(parameters);
134 catch (
const ControlCommand::ArgumentError& e) {
141 onSuccess(parameters);
145 Controller::fetchDataset(
const Name& prefix,
147 const DatasetFailCallback& onFailure,
148 const CommandOptions& options)
150 SegmentFetcher::Options fetcherOptions;
151 fetcherOptions.maxTimeout = options.getTimeout();
154 if (processResponse) {
155 fetcher->onComplete.connect(processResponse);
158 fetcher->onError.connect([=] (uint32_t code,
const std::string& msg) {
159 processDatasetFetchError(onFailure, code, msg);
164 fetcher->onComplete.connect([
this, it] (
auto&&...) {
m_fetchers.erase(it); });
165 fetcher->onError.connect([
this, it] (
auto&&...) {
m_fetchers.erase(it); });
169 Controller::processDatasetFetchError(
const DatasetFailCallback& onFailure,
170 uint32_t code, std::string msg)
172 BOOST_ASSERT(onFailure);
178 case SegmentFetcher::ErrorCode::INTEREST_TIMEOUT:
181 case SegmentFetcher::ErrorCode::DATA_HAS_NO_SEGMENT:
182 case SegmentFetcher::ErrorCode::FINALBLOCKID_NOT_SEGMENT:
185 case SegmentFetcher::ErrorCode::SEGMENT_VALIDATION_FAIL:
190 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 an Interest.
Represents an Interest packet.
Interest & setName(const Name &name)
Set the Interest's name.
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
Represents a Network Nack.
void wireDecode(const Block &block)
Contains options for ControlCommand execution.
const Name & getPrefix() const
Returns the command prefix.
time::milliseconds getTimeout() const
Returns the command timeout.
const security::SigningInfo & getSigningInfo() const
Returns the signing parameters.
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 as transport and 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
void makeSignedInterest(Interest &interest, SigningInfo params=SigningInfo(), uint32_t signingFlags=WantNonce|WantTime)
Signs an Interest (following Packet Specification v0.3 or newer)
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