chunks: switch to v2::ValidatorNull
refs #4089 Change-Id: If23ca4d202ad1b61ee1e56ba0e15a8750c184e03
This commit is contained in:
1 parent
c9575a6aa3
commit
f860649549
4 files changed
+58
-62
No files matched your search
@@ -1,8 +1,8 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2016, Regents of the University of California,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University.
|
||||
* Copyright (c) 2016-2017, Regents of the University of California,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University.
|
||||
*
|
||||
* This file is part of ndn-tools (Named Data Networking Essential Tools).
|
||||
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
|
||||
@@ -28,10 +28,10 @@
|
||||
#include "tools/chunks/catchunks/pipeline-interests.hpp"
|
||||
|
||||
#include "tests/test-common.hpp"
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
#include <ndn-cxx/security/validator-null.hpp>
|
||||
|
||||
#include <boost/test/output_test_stream.hpp>
|
||||
#include <ndn-cxx/security/validator-null.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
|
||||
namespace ndn {
|
||||
namespace chunks {
|
||||
@@ -65,9 +65,8 @@ BOOST_AUTO_TEST_CASE(OutputDataSequential)
|
||||
};
|
||||
|
||||
util::DummyClientFace face;
|
||||
ValidatorNull validator;
|
||||
output_test_stream output("");
|
||||
Consumer cons(validator, false, output);
|
||||
Consumer cons(security::v2::getAcceptAllValidator(), false, output);
|
||||
|
||||
auto interest = makeInterest(name);
|
||||
|
||||
@@ -105,9 +104,8 @@ BOOST_AUTO_TEST_CASE(OutputDataUnordered)
|
||||
};;
|
||||
|
||||
util::DummyClientFace face;
|
||||
ValidatorNull validator;
|
||||
output_test_stream output("");
|
||||
Consumer cons(validator, false, output);
|
||||
Consumer cons(security::v2::getAcceptAllValidator(), false, output);
|
||||
|
||||
auto interest = makeInterest(name);
|
||||
std::vector<shared_ptr<Data>> dataStore;
|
||||
@@ -198,8 +196,7 @@ BOOST_FIXTURE_TEST_CASE(RunBasic, UnitTestTimeFixture)
|
||||
{
|
||||
boost::asio::io_service io;
|
||||
util::DummyClientFace face(io);
|
||||
ValidatorNull validator;
|
||||
Consumer consumer(validator, false);
|
||||
Consumer consumer(security::v2::getAcceptAllValidator(), false);
|
||||
|
||||
Name prefix("/ndn/chunks/test");
|
||||
auto discover = make_unique<DiscoverVersionDummy>(prefix, face, Options());
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
namespace ndn {
|
||||
namespace chunks {
|
||||
|
||||
Consumer::Consumer(Validator& validator, bool isVerbose, std::ostream& os)
|
||||
Consumer::Consumer(security::v2::Validator& validator, bool isVerbose, std::ostream& os)
|
||||
: m_validator(validator)
|
||||
, m_outputStream(os)
|
||||
, m_nextToPrint(0)
|
||||
@@ -47,49 +47,44 @@ Consumer::run(unique_ptr<DiscoverVersion> discover, unique_ptr<PipelineInterests
|
||||
m_bufferedData.clear();
|
||||
|
||||
m_discover->onDiscoverySuccess.connect(bind(&Consumer::startPipeline, this, _1));
|
||||
m_discover->onDiscoveryFailure.connect(bind(&Consumer::onFailure, this, _1));
|
||||
m_discover->onDiscoveryFailure.connect([] (const std::string& msg) {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(msg));
|
||||
});
|
||||
m_discover->run();
|
||||
}
|
||||
|
||||
void
|
||||
Consumer::startPipeline(const Data& data)
|
||||
{
|
||||
m_validator.validate(data,
|
||||
bind(&Consumer::onDataValidated, this, _1),
|
||||
bind(&Consumer::onFailure, this, _2));
|
||||
this->handleData(data);
|
||||
|
||||
m_pipeline->run(data,
|
||||
bind(&Consumer::onData, this, _1, _2),
|
||||
bind(&Consumer::onFailure, this, _1));
|
||||
[this] (const Interest&, const Data& data) { this->handleData(data); },
|
||||
[] (const std::string& msg) { BOOST_THROW_EXCEPTION(std::runtime_error(msg)); });
|
||||
}
|
||||
|
||||
void
|
||||
Consumer::onData(const Interest& interest, const Data& data)
|
||||
Consumer::handleData(const Data& data)
|
||||
{
|
||||
auto dataPtr = data.shared_from_this();
|
||||
|
||||
m_validator.validate(data,
|
||||
bind(&Consumer::onDataValidated, this, _1),
|
||||
bind(&Consumer::onFailure, this, _2));
|
||||
}
|
||||
[this, dataPtr] (const Data& data) {
|
||||
if (data.getContentType() == ndn::tlv::ContentType_Nack) {
|
||||
if (m_isVerbose) {
|
||||
std::cerr << "Application level NACK: " << data << std::endl;
|
||||
}
|
||||
m_pipeline->cancel();
|
||||
BOOST_THROW_EXCEPTION(ApplicationNackError(data));
|
||||
}
|
||||
|
||||
void
|
||||
Consumer::onDataValidated(shared_ptr<const Data> data)
|
||||
{
|
||||
if (data->getContentType() == ndn::tlv::ContentType_Nack) {
|
||||
if (m_isVerbose)
|
||||
std::cerr << "Application level NACK: " << *data << std::endl;
|
||||
|
||||
m_pipeline->cancel();
|
||||
throw ApplicationNackError(*data);
|
||||
}
|
||||
|
||||
m_bufferedData[getSegmentFromPacket(*data)] = data;
|
||||
writeInOrderData();
|
||||
}
|
||||
|
||||
void
|
||||
Consumer::onFailure(const std::string& reason)
|
||||
{
|
||||
throw std::runtime_error(reason);
|
||||
// 'data' passed to callback comes from DataValidationState and was not created with make_shared
|
||||
m_bufferedData[getSegmentFromPacket(data)] = dataPtr;
|
||||
writeInOrderData();
|
||||
},
|
||||
[this] (const Data& data, const security::v2::ValidationError& error) {
|
||||
BOOST_THROW_EXCEPTION(DataValidationError(error));
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2016, Regents of the University of California,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University.
|
||||
* Copyright (c) 2016-2017, Regents of the University of California,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University.
|
||||
*
|
||||
* This file is part of ndn-tools (Named Data Networking Essential Tools).
|
||||
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
|
||||
@@ -31,7 +31,8 @@
|
||||
#include "discover-version.hpp"
|
||||
#include "pipeline-interests.hpp"
|
||||
|
||||
#include <ndn-cxx/security/validator.hpp>
|
||||
#include <ndn-cxx/security/v2/validation-error.hpp>
|
||||
#include <ndn-cxx/security/v2/validator.hpp>
|
||||
|
||||
namespace ndn {
|
||||
namespace chunks {
|
||||
@@ -56,10 +57,20 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DataValidationError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
DataValidationError(const security::v2::ValidationError& error)
|
||||
: std::runtime_error(boost::lexical_cast<std::string>(error))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create the consumer
|
||||
*/
|
||||
Consumer(Validator& validator, bool isVerbose, std::ostream& os = std::cout);
|
||||
Consumer(security::v2::Validator& validator, bool isVerbose, std::ostream& os = std::cout);
|
||||
|
||||
/**
|
||||
* @brief Run the consumer
|
||||
@@ -72,20 +83,14 @@ private:
|
||||
startPipeline(const Data& data);
|
||||
|
||||
void
|
||||
onData(const Interest& interest, const Data& data);
|
||||
|
||||
void
|
||||
onDataValidated(shared_ptr<const Data> data);
|
||||
|
||||
void
|
||||
onFailure(const std::string& reason);
|
||||
handleData(const Data& data);
|
||||
|
||||
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
|
||||
void
|
||||
writeInOrderData();
|
||||
|
||||
private:
|
||||
Validator& m_validator;
|
||||
security::v2::Validator& m_validator;
|
||||
std::ostream& m_outputStream;
|
||||
unique_ptr<DiscoverVersion> m_discover;
|
||||
unique_ptr<PipelineInterests> m_pipeline;
|
||||
|
||||
@@ -27,18 +27,18 @@
|
||||
* @author Weiwei Liu
|
||||
*/
|
||||
|
||||
#include "core/version.hpp"
|
||||
#include "options.hpp"
|
||||
#include "aimd-statistics-collector.hpp"
|
||||
#include "aimd-rtt-estimator.hpp"
|
||||
#include "consumer.hpp"
|
||||
#include "discover-version-fixed.hpp"
|
||||
#include "discover-version-iterative.hpp"
|
||||
#include "pipeline-interests-fixed-window.hpp"
|
||||
#include "pipeline-interests-aimd.hpp"
|
||||
#include "aimd-rtt-estimator.hpp"
|
||||
#include "aimd-statistics-collector.hpp"
|
||||
#include "pipeline-interests-fixed-window.hpp"
|
||||
#include "options.hpp"
|
||||
#include "core/version.hpp"
|
||||
|
||||
#include <ndn-cxx/security/validator-null.hpp>
|
||||
#include <fstream>
|
||||
#include <ndn-cxx/security/validator-null.hpp>
|
||||
|
||||
namespace ndn {
|
||||
namespace chunks {
|
||||
@@ -267,8 +267,7 @@ main(int argc, char** argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
ValidatorNull validator;
|
||||
Consumer consumer(validator, options.isVerbose);
|
||||
Consumer consumer(security::v2::getAcceptAllValidator(), options.isVerbose);
|
||||
|
||||
BOOST_ASSERT(discover != nullptr);
|
||||
BOOST_ASSERT(pipeline != nullptr);
|
||||
|
||||
Reference in new issue
Block a user