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);
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: