**breaking** Add KeyChain parameter to the producer API
Applications must be able to specify the KeyChain instance to use Change-Id: If5054dbb8c00e2d18af8bf6a9199ded7266688f3
This commit is contained in:
@@ -32,8 +32,9 @@ namespace psync {
|
||||
|
||||
NDN_LOG_INIT(psync.FullProducer);
|
||||
|
||||
FullProducer::FullProducer(const size_t expectedNumEntries,
|
||||
ndn::Face& face,
|
||||
FullProducer::FullProducer(ndn::Face& face,
|
||||
ndn::KeyChain& keyChain,
|
||||
size_t expectedNumEntries,
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
const UpdateCallback& onUpdateCallBack,
|
||||
@@ -41,8 +42,8 @@ FullProducer::FullProducer(const size_t expectedNumEntries,
|
||||
ndn::time::milliseconds syncReplyFreshness,
|
||||
CompressionScheme ibltCompression,
|
||||
CompressionScheme contentCompression)
|
||||
: ProducerBase(expectedNumEntries, face, syncPrefix, userPrefix, syncReplyFreshness,
|
||||
ibltCompression, contentCompression)
|
||||
: ProducerBase(face, keyChain, expectedNumEntries, syncPrefix, userPrefix,
|
||||
syncReplyFreshness, ibltCompression, contentCompression)
|
||||
, m_syncInterestLifetime(syncInterestLifetime)
|
||||
, m_onUpdate(onUpdateCallBack)
|
||||
, m_jitter(100, 500)
|
||||
|
||||
@@ -42,12 +42,13 @@ class FullProducer : public ProducerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief constructor
|
||||
* @brief Constructor
|
||||
*
|
||||
* Registers syncPrefix in NFD and sends a sync interest
|
||||
* Registers syncPrefix in NFD and sends a sync interest.
|
||||
*
|
||||
* @param expectedNumEntries expected entries in IBF
|
||||
* @param face application's face
|
||||
* @param face Application's face
|
||||
* @param keyChain KeyChain instance to use for signing
|
||||
* @param expectedNumEntries Expected number of entries in IBF
|
||||
* @param syncPrefix The prefix of the sync group
|
||||
* @param userPrefix The prefix of the first user in the group
|
||||
* @param onUpdateCallBack The call back to be called when there is new data
|
||||
@@ -56,8 +57,9 @@ public:
|
||||
* @param ibltCompression Compression scheme to use for IBF
|
||||
* @param contentCompression Compression scheme to use for Data content
|
||||
*/
|
||||
FullProducer(size_t expectedNumEntries,
|
||||
ndn::Face& face,
|
||||
FullProducer(ndn::Face& face,
|
||||
ndn::KeyChain& keyChain,
|
||||
size_t expectedNumEntries,
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
const UpdateCallback& onUpdateCallBack,
|
||||
|
||||
@@ -32,16 +32,17 @@ NDN_LOG_INIT(psync.PartialProducer);
|
||||
const ndn::name::Component HELLO{"hello"};
|
||||
const ndn::name::Component SYNC{"sync"};
|
||||
|
||||
PartialProducer::PartialProducer(size_t expectedNumEntries,
|
||||
ndn::Face& face,
|
||||
PartialProducer::PartialProducer(ndn::Face& face,
|
||||
ndn::KeyChain& keyChain,
|
||||
size_t expectedNumEntries,
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
ndn::time::milliseconds helloReplyFreshness,
|
||||
ndn::time::milliseconds syncReplyFreshness,
|
||||
CompressionScheme ibltCompression)
|
||||
: ProducerBase(expectedNumEntries, face, syncPrefix,
|
||||
userPrefix, syncReplyFreshness, ibltCompression)
|
||||
, m_helloReplyFreshness(helloReplyFreshness)
|
||||
: ProducerBase(face, keyChain, expectedNumEntries, syncPrefix, userPrefix,
|
||||
syncReplyFreshness, ibltCompression, CompressionScheme::NONE)
|
||||
, m_helloReplyFreshness(helloReplyFreshness)
|
||||
{
|
||||
m_registeredPrefix = m_face.registerPrefix(m_syncPrefix,
|
||||
[this] (const ndn::Name& syncPrefix) {
|
||||
|
||||
@@ -43,21 +43,23 @@ class PartialProducer : public ProducerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief constructor
|
||||
* @brief Constructor
|
||||
*
|
||||
* Registers syncPrefix in NFD and sets internal filters for
|
||||
* "sync" and "hello" under syncPrefix
|
||||
* "sync" and "hello" under syncPrefix.
|
||||
*
|
||||
* @param expectedNumEntries expected entries in IBF
|
||||
* @param face application's face
|
||||
* @param face Application's face
|
||||
* @param keyChain KeyChain instance to use for signing
|
||||
* @param expectedNumEntries Expected number of entries in IBF
|
||||
* @param syncPrefix The prefix of the sync group
|
||||
* @param userPrefix The prefix of the first user in the group
|
||||
* @param syncReplyFreshness freshness of sync data
|
||||
* @param helloReplyFreshness freshness of hello data
|
||||
* @param ibltCompression Compression scheme to use for IBF
|
||||
*/
|
||||
PartialProducer(size_t expectedNumEntries,
|
||||
ndn::Face& face,
|
||||
PartialProducer(ndn::Face& face,
|
||||
ndn::KeyChain& keyChain,
|
||||
size_t expectedNumEntries,
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
ndn::time::milliseconds helloReplyFreshness = HELLO_REPLY_FRESHNESS,
|
||||
|
||||
@@ -30,23 +30,25 @@ namespace psync {
|
||||
|
||||
NDN_LOG_INIT(psync.ProducerBase);
|
||||
|
||||
ProducerBase::ProducerBase(size_t expectedNumEntries,
|
||||
ndn::Face& face,
|
||||
ProducerBase::ProducerBase(ndn::Face& face,
|
||||
ndn::KeyChain& keyChain,
|
||||
size_t expectedNumEntries,
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
ndn::time::milliseconds syncReplyFreshness,
|
||||
CompressionScheme ibltCompression,
|
||||
CompressionScheme contentCompression)
|
||||
: m_iblt(expectedNumEntries, ibltCompression)
|
||||
: m_face(face)
|
||||
, m_keyChain(keyChain)
|
||||
, m_scheduler(m_face.getIoService())
|
||||
, m_rng(ndn::random::getRandomNumberEngine())
|
||||
, m_iblt(expectedNumEntries, ibltCompression)
|
||||
, m_segmentPublisher(m_face, m_keyChain)
|
||||
, m_expectedNumEntries(expectedNumEntries)
|
||||
, m_threshold(expectedNumEntries / 2)
|
||||
, m_face(face)
|
||||
, m_scheduler(m_face.getIoService())
|
||||
, m_syncPrefix(syncPrefix)
|
||||
, m_userPrefix(userPrefix)
|
||||
, m_syncReplyFreshness(syncReplyFreshness)
|
||||
, m_segmentPublisher(m_face, m_keyChain)
|
||||
, m_rng(ndn::random::getRandomNumberEngine())
|
||||
, m_ibltCompression(ibltCompression)
|
||||
, m_contentCompression(contentCompression)
|
||||
{
|
||||
|
||||
+23
-22
@@ -56,23 +56,26 @@ public:
|
||||
|
||||
PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
|
||||
/**
|
||||
* @brief constructor
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param expectedNumEntries expected number entries in IBF
|
||||
* @param face application's face
|
||||
* @param face Application's face
|
||||
* @param keyChain KeyChain instance to use for signing
|
||||
* @param expectedNumEntries Expected number of entries in IBF
|
||||
* @param syncPrefix The prefix of the sync group
|
||||
* @param userPrefix The prefix of the first user in the group
|
||||
* @param syncReplyFreshness freshness of sync data
|
||||
* @param syncReplyFreshness FreshnessPeriod of sync data
|
||||
* @param ibltCompression Compression scheme to use for IBF
|
||||
* @param contentCompression Compression scheme to use for Data content
|
||||
*/
|
||||
ProducerBase(size_t expectedNumEntries,
|
||||
ndn::Face& face,
|
||||
ProducerBase(ndn::Face& face,
|
||||
ndn::KeyChain& keyChain,
|
||||
size_t expectedNumEntries,
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
|
||||
CompressionScheme ibltCompression = CompressionScheme::NONE,
|
||||
CompressionScheme contentCompression = CompressionScheme::NONE);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Returns the current sequence number of the given prefix
|
||||
@@ -152,11 +155,12 @@ PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
|
||||
onRegisterFailed(const ndn::Name& prefix, const std::string& msg) const;
|
||||
|
||||
PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
|
||||
ndn::Face& m_face;
|
||||
ndn::KeyChain& m_keyChain;
|
||||
ndn::Scheduler m_scheduler;
|
||||
ndn::random::RandomNumberEngine& m_rng;
|
||||
|
||||
detail::IBLT m_iblt;
|
||||
uint32_t m_expectedNumEntries;
|
||||
// Threshold is used check if the differences are greater
|
||||
// than it and whether we need to update the other side.
|
||||
uint32_t m_threshold;
|
||||
|
||||
// prefix and sequence number
|
||||
std::map<ndn::Name, uint64_t> m_prefixes;
|
||||
@@ -165,20 +169,17 @@ PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
|
||||
bm::unordered_set_of<ndn::Name, std::hash<ndn::Name>>>;
|
||||
HashNameBiMap m_biMap;
|
||||
|
||||
ndn::Face& m_face;
|
||||
ndn::KeyChain m_keyChain;
|
||||
ndn::Scheduler m_scheduler;
|
||||
|
||||
ndn::Name m_syncPrefix;
|
||||
ndn::Name m_userPrefix;
|
||||
|
||||
ndn::time::milliseconds m_syncReplyFreshness;
|
||||
|
||||
SegmentPublisher m_segmentPublisher;
|
||||
|
||||
ndn::random::RandomNumberEngine& m_rng;
|
||||
CompressionScheme m_ibltCompression;
|
||||
CompressionScheme m_contentCompression;
|
||||
const size_t m_expectedNumEntries;
|
||||
// Threshold is used check if the differences are greater
|
||||
// than it and whether we need to update the other side.
|
||||
const size_t m_threshold;
|
||||
const ndn::Name m_syncPrefix;
|
||||
const ndn::Name m_userPrefix;
|
||||
const ndn::time::milliseconds m_syncReplyFreshness;
|
||||
const CompressionScheme m_ibltCompression;
|
||||
const CompressionScheme m_contentCompression;
|
||||
};
|
||||
|
||||
} // namespace psync
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <PSync/full-producer.hpp>
|
||||
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
#include <ndn-cxx/util/logger.hpp>
|
||||
#include <ndn-cxx/util/random.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
@@ -42,17 +43,15 @@ public:
|
||||
*/
|
||||
Producer(const ndn::Name& syncPrefix, const std::string& userPrefix,
|
||||
int numDataStreams, int maxNumPublish)
|
||||
: m_scheduler(m_face.getIoService())
|
||||
, m_fullProducer(80, m_face, syncPrefix, userPrefix,
|
||||
: m_fullProducer(m_face, m_keyChain, 80, syncPrefix, userPrefix,
|
||||
std::bind(&Producer::processSyncUpdate, this, _1),
|
||||
1600_ms, 1600_ms)
|
||||
, m_numDataStreams(numDataStreams)
|
||||
, m_maxNumPublish(maxNumPublish)
|
||||
, m_rng(ndn::random::getRandomNumberEngine())
|
||||
, m_rangeUniformRandom(0, 60000)
|
||||
{
|
||||
// Add user prefixes and schedule updates for them in specified interval
|
||||
for (int i = 0; i < m_numDataStreams; i++) {
|
||||
for (int i = 0; i < numDataStreams; i++) {
|
||||
ndn::Name prefix(userPrefix + "-" + std::to_string(i));
|
||||
m_fullProducer.addUserNode(prefix);
|
||||
m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)),
|
||||
@@ -93,11 +92,10 @@ private:
|
||||
|
||||
private:
|
||||
ndn::Face m_face;
|
||||
ndn::Scheduler m_scheduler;
|
||||
ndn::KeyChain m_keyChain;
|
||||
ndn::Scheduler m_scheduler{m_face.getIoService()};
|
||||
|
||||
psync::FullProducer m_fullProducer;
|
||||
|
||||
int m_numDataStreams;
|
||||
uint64_t m_maxNumPublish;
|
||||
|
||||
ndn::random::RandomNumberEngine& m_rng;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <PSync/partial-producer.hpp>
|
||||
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
#include <ndn-cxx/util/logger.hpp>
|
||||
#include <ndn-cxx/util/random.hpp>
|
||||
#include <ndn-cxx/util/scheduler.hpp>
|
||||
@@ -37,16 +38,14 @@ public:
|
||||
* IBF size is set to 40 in m_producer as the expected number of update to IBF in a sync cycle
|
||||
*/
|
||||
PSyncPartialProducer(const ndn::Name& syncPrefix, const std::string& userPrefix,
|
||||
int nDataStreams, int maxNumPublish)
|
||||
: m_scheduler(m_face.getIoService())
|
||||
, m_producer(40, m_face, syncPrefix, userPrefix + "-0")
|
||||
, m_nDataStreams(nDataStreams)
|
||||
int numDataStreams, int maxNumPublish)
|
||||
: m_producer(m_face, m_keyChain, 40, syncPrefix, userPrefix + "-0")
|
||||
, m_maxNumPublish(maxNumPublish)
|
||||
, m_rng(ndn::random::getRandomNumberEngine())
|
||||
, m_rangeUniformRandom(0, 60000)
|
||||
{
|
||||
// Add user prefixes and schedule updates for them
|
||||
for (int i = 0; i < m_nDataStreams; i++) {
|
||||
for (int i = 0; i < numDataStreams; i++) {
|
||||
ndn::Name updateName(userPrefix + "-" + std::to_string(i));
|
||||
|
||||
// Add the user prefix to the producer
|
||||
@@ -84,11 +83,10 @@ private:
|
||||
|
||||
private:
|
||||
ndn::Face m_face;
|
||||
ndn::Scheduler m_scheduler;
|
||||
ndn::KeyChain m_keyChain;
|
||||
ndn::Scheduler m_scheduler{m_face.getIoService()};
|
||||
|
||||
psync::PartialProducer m_producer;
|
||||
|
||||
int m_nDataStreams;
|
||||
uint64_t m_maxNumPublish;
|
||||
|
||||
ndn::random::RandomNumberEngine& m_rng;
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
#include "tests/clock-fixture.hpp"
|
||||
|
||||
namespace ndn::tests {
|
||||
namespace psync::tests {
|
||||
|
||||
ClockFixture::ClockFixture()
|
||||
: m_steadyClock(make_shared<time::UnitTestSteadyClock>())
|
||||
, m_systemClock(make_shared<time::UnitTestSystemClock>())
|
||||
: m_steadyClock(std::make_shared<time::UnitTestSteadyClock>())
|
||||
, m_systemClock(std::make_shared<time::UnitTestSystemClock>())
|
||||
{
|
||||
time::setCustomClocks(m_steadyClock, m_systemClock);
|
||||
}
|
||||
@@ -49,4 +49,4 @@ ClockFixture::advanceClocks(time::nanoseconds tick, time::nanoseconds total)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ndn::tests
|
||||
} // namespace psync::tests
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
|
||||
#include <ndn-cxx/util/time-unit-test-clock.hpp>
|
||||
|
||||
namespace ndn::tests {
|
||||
namespace psync::tests {
|
||||
|
||||
namespace time = ndn::time;
|
||||
|
||||
/** \brief A test fixture that overrides steady clock and system clock.
|
||||
*/
|
||||
@@ -72,10 +74,10 @@ private:
|
||||
}
|
||||
|
||||
protected:
|
||||
shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
|
||||
shared_ptr<time::UnitTestSystemClock> m_systemClock;
|
||||
std::shared_ptr<time::UnitTestSteadyClock> m_steadyClock;
|
||||
std::shared_ptr<time::UnitTestSystemClock> m_systemClock;
|
||||
};
|
||||
|
||||
} // namespace ndn::tests
|
||||
} // namespace psync::tests
|
||||
|
||||
#endif // PSYNC_TESTS_CLOCK_FIXTURE_HPP
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
namespace ndn::tests {
|
||||
namespace psync::tests {
|
||||
|
||||
class IoFixture : public ClockFixture
|
||||
{
|
||||
@@ -46,6 +46,6 @@ protected:
|
||||
boost::asio::io_service m_io;
|
||||
};
|
||||
|
||||
} // namespace ndn::tests
|
||||
} // namespace psync::tests
|
||||
|
||||
#endif // PSYNC_TESTS_IO_FIXTURE_HPP
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2013-2022 Regents of the University of California.
|
||||
*
|
||||
* This file is part of PSync.
|
||||
*
|
||||
* PSync is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU Lesser General Public License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PSYNC_TESTS_KEY_CHAIN_FIXTURE_HPP
|
||||
#define PSYNC_TESTS_KEY_CHAIN_FIXTURE_HPP
|
||||
|
||||
#include <ndn-cxx/security/key-chain.hpp>
|
||||
|
||||
namespace psync::tests {
|
||||
|
||||
/**
|
||||
* @brief A fixture providing an in-memory KeyChain.
|
||||
*/
|
||||
class KeyChainFixture
|
||||
{
|
||||
protected:
|
||||
ndn::KeyChain m_keyChain{"pib-memory:", "tpm-memory:"};
|
||||
};
|
||||
|
||||
} // namespace psync::tests
|
||||
|
||||
#endif // PSYNC_TESTS_KEY_CHAIN_FIXTURE_HPP
|
||||
@@ -22,55 +22,50 @@
|
||||
|
||||
#include "tests/boost-test.hpp"
|
||||
#include "tests/io-fixture.hpp"
|
||||
#include "tests/key-chain-fixture.hpp"
|
||||
|
||||
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
|
||||
namespace psync {
|
||||
|
||||
using namespace ndn;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestFullProducer)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Constructor)
|
||||
class FullProducerFixture : public tests::IoFixture, public tests::KeyChainFixture
|
||||
{
|
||||
util::DummyClientFace face({true, true});
|
||||
BOOST_CHECK_NO_THROW(FullProducer(40, face, Name("/psync"), Name("/testUser"), nullptr));
|
||||
}
|
||||
protected:
|
||||
util::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(TestFullProducer, FullProducerFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(OnInterest)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser");
|
||||
util::DummyClientFace face({true, true});
|
||||
|
||||
FullProducer node(40, face, syncPrefix, userNode, nullptr);
|
||||
FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
|
||||
|
||||
Name syncInterestName(syncPrefix);
|
||||
syncInterestName.append("malicious-IBF");
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
|
||||
BOOST_CHECK_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName)));
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::IoFixture)
|
||||
BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser");
|
||||
util::DummyClientFace face(m_io, {true, true});
|
||||
FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr, 8_s);
|
||||
|
||||
FullProducer node(40, face, syncPrefix, userNode, nullptr, 8_s);
|
||||
advanceClocks(10_ms);
|
||||
face.sentInterests.clear();
|
||||
m_face.sentInterests.clear();
|
||||
|
||||
// full sync sends the next one in interest lifetime / 2 +- jitter
|
||||
advanceClocks(6_s);
|
||||
BOOST_CHECK_EQUAL(face.sentInterests.size(), 1);
|
||||
BOOST_CHECK_EQUAL(m_face.sentInterests.size(), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser");
|
||||
util::DummyClientFace face({true, true});
|
||||
|
||||
FullProducer node(40, face, syncPrefix, userNode, nullptr);
|
||||
FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
|
||||
|
||||
Name syncInterestName(syncPrefix);
|
||||
node.m_iblt.appendToName(syncInterestName);
|
||||
|
||||
@@ -24,24 +24,26 @@
|
||||
|
||||
#include "tests/boost-test.hpp"
|
||||
#include "tests/io-fixture.hpp"
|
||||
#include "tests/key-chain-fixture.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
|
||||
namespace psync {
|
||||
|
||||
using ndn::Name;
|
||||
using ndn::util::DummyClientFace;
|
||||
using namespace ndn;
|
||||
|
||||
class FullSyncFixture : public ndn::tests::IoFixture
|
||||
class FullSyncFixture : public tests::IoFixture, public tests::KeyChainFixture
|
||||
{
|
||||
protected:
|
||||
void
|
||||
addNode(int id)
|
||||
{
|
||||
BOOST_ASSERT(id >= 0 && id < MAX_NODES);
|
||||
faces[id] = std::make_shared<DummyClientFace>(m_io, DummyClientFace::Options{true, true});
|
||||
userPrefixes[id] = "/userPrefix" + std::to_string(id);
|
||||
nodes[id] = std::make_shared<FullProducer>(40, *faces[id], syncPrefix, userPrefixes[id],
|
||||
faces[id] = std::make_shared<util::DummyClientFace>(m_io, m_keyChain,
|
||||
util::DummyClientFace::Options{true, true});
|
||||
nodes[id] = std::make_shared<FullProducer>(*faces[id], m_keyChain, 40, syncPrefix, userPrefixes[id],
|
||||
[] (const auto&) {});
|
||||
}
|
||||
|
||||
@@ -170,8 +172,8 @@ protected:
|
||||
protected:
|
||||
const Name syncPrefix = "/psync";
|
||||
static constexpr int MAX_NODES = 4;
|
||||
std::array<std::shared_ptr<DummyClientFace>, MAX_NODES> faces;
|
||||
std::array<Name, MAX_NODES> userPrefixes;
|
||||
std::array<std::shared_ptr<util::DummyClientFace>, MAX_NODES> faces;
|
||||
std::array<std::shared_ptr<FullProducer>, MAX_NODES> nodes;
|
||||
static constexpr uint64_t NOT_EXIST = std::numeric_limits<uint64_t>::max();
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, The University of Memphis
|
||||
* Copyright (c) 2014-2022, The University of Memphis
|
||||
*
|
||||
* This file is part of PSync.
|
||||
* See AUTHORS.md for complete list of PSync authors and contributors.
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "PSync/partial-producer.hpp"
|
||||
|
||||
#include "tests/boost-test.hpp"
|
||||
#include "tests/key-chain-fixture.hpp"
|
||||
|
||||
#include <ndn-cxx/name.hpp>
|
||||
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
|
||||
@@ -29,24 +29,23 @@ namespace psync {
|
||||
|
||||
using namespace ndn;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestPartialProducer)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Constructor)
|
||||
class PartialProducerFixture : public tests::KeyChainFixture
|
||||
{
|
||||
util::DummyClientFace face({true, true});
|
||||
BOOST_CHECK_NO_THROW(PartialProducer(40, face, Name("/psync"), Name("/testUser")));
|
||||
}
|
||||
protected:
|
||||
util::DummyClientFace m_face{m_keyChain, {true, true}};
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(TestPartialProducer, PartialProducerFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RegisterPrefix)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser");
|
||||
util::DummyClientFace face({true, true});
|
||||
PartialProducer producer(40, face, syncPrefix, userNode);
|
||||
PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
|
||||
|
||||
face.processEvents(-1_ms);
|
||||
m_face.processEvents(-1_ms);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
|
||||
auto interest = face.sentInterests.front();
|
||||
BOOST_REQUIRE_EQUAL(m_face.sentInterests.size(), 1);
|
||||
auto interest = m_face.sentInterests.front();
|
||||
BOOST_CHECK_EQUAL(interest.getName().at(3), name::Component("register"));
|
||||
nfd::ControlParameters params(interest.getName().at(4).blockFromValue());
|
||||
BOOST_CHECK_EQUAL(params.getName(), syncPrefix);
|
||||
@@ -55,8 +54,7 @@ BOOST_AUTO_TEST_CASE(RegisterPrefix)
|
||||
BOOST_AUTO_TEST_CASE(PublishName)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser"), nonUser("/testUser2");
|
||||
util::DummyClientFace face({true, true});
|
||||
PartialProducer producer(40, face, syncPrefix, userNode);
|
||||
PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
|
||||
|
||||
BOOST_CHECK_EQUAL(producer.getSeqNo(userNode).value_or(-1), 0);
|
||||
producer.publishName(userNode);
|
||||
@@ -75,8 +73,7 @@ BOOST_AUTO_TEST_CASE(PublishName)
|
||||
BOOST_AUTO_TEST_CASE(SameSyncInterest)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser");
|
||||
util::DummyClientFace face({true, true});
|
||||
PartialProducer producer(40, face, syncPrefix, userNode);
|
||||
PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
|
||||
|
||||
Name syncInterestName(syncPrefix);
|
||||
syncInterestName.append("sync");
|
||||
@@ -91,29 +88,28 @@ BOOST_AUTO_TEST_CASE(SameSyncInterest)
|
||||
syncInterest.setInterestLifetime(1_s);
|
||||
syncInterest.setNonce(1);
|
||||
BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
|
||||
face.processEvents(10_ms);
|
||||
m_face.processEvents(10_ms);
|
||||
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
|
||||
|
||||
face.processEvents(500_ms);
|
||||
m_face.processEvents(500_ms);
|
||||
|
||||
// Same interest again - size of pending interest should remain same, but expirationEvent should change
|
||||
syncInterest.setNonce(2);
|
||||
BOOST_CHECK_NO_THROW(producer.onSyncInterest(syncInterestPrefix, syncInterest));
|
||||
face.processEvents(10_ms);
|
||||
m_face.processEvents(10_ms);
|
||||
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
|
||||
|
||||
face.processEvents(500_ms);
|
||||
m_face.processEvents(500_ms);
|
||||
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 1);
|
||||
|
||||
face.processEvents(500_ms);
|
||||
m_face.processEvents(500_ms);
|
||||
BOOST_CHECK_EQUAL(producer.m_pendingEntries.size(), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(OnSyncInterest)
|
||||
{
|
||||
Name syncPrefix("/psync"), userNode("/testUser");
|
||||
util::DummyClientFace face({true, true});
|
||||
PartialProducer producer(40, face, syncPrefix, userNode);
|
||||
PartialProducer producer(m_face, m_keyChain, 40, syncPrefix, userNode);
|
||||
|
||||
// Sync interest with no bloom filter attached
|
||||
Name syncInterestName(syncPrefix);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "tests/boost-test.hpp"
|
||||
#include "tests/io-fixture.hpp"
|
||||
#include "tests/key-chain-fixture.hpp"
|
||||
|
||||
#include <ndn-cxx/name.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
@@ -30,12 +31,12 @@ namespace psync {
|
||||
|
||||
using namespace ndn;
|
||||
|
||||
class PartialSyncFixture : public tests::IoFixture
|
||||
class PartialSyncFixture : public tests::IoFixture, public tests::KeyChainFixture
|
||||
{
|
||||
public:
|
||||
PartialSyncFixture()
|
||||
{
|
||||
producer = make_shared<PartialProducer>(40, face, syncPrefix, userPrefix);
|
||||
producer = make_shared<PartialProducer>(face, m_keyChain, 40, syncPrefix, userPrefix);
|
||||
addUserNodes("testUser", 10);
|
||||
}
|
||||
|
||||
@@ -51,9 +52,8 @@ public:
|
||||
void
|
||||
addConsumer(int id, const std::vector<std::string>& subscribeTo, bool linkToProducer = true)
|
||||
{
|
||||
consumerFaces[id] =
|
||||
std::make_shared<util::DummyClientFace>(m_io, util::DummyClientFace::Options{true, true});
|
||||
|
||||
consumerFaces[id] = std::make_shared<util::DummyClientFace>(m_io, m_keyChain,
|
||||
util::DummyClientFace::Options{true, true});
|
||||
if (linkToProducer) {
|
||||
face.linkTo(*consumerFaces[id]);
|
||||
}
|
||||
@@ -131,7 +131,8 @@ public:
|
||||
producer->updateSeqNo(prefix, seq);
|
||||
}
|
||||
|
||||
util::DummyClientFace face{m_io, {true, true}};
|
||||
protected:
|
||||
util::DummyClientFace face{m_io, m_keyChain, {true, true}};
|
||||
Name syncPrefix{"psync"};
|
||||
Name userPrefix{"testUser-0"};
|
||||
|
||||
@@ -288,8 +289,8 @@ BOOST_AUTO_TEST_CASE(ReplicatedProducer)
|
||||
// Link to first producer goes down
|
||||
face.unlink();
|
||||
|
||||
util::DummyClientFace face2(m_io, {true, true});
|
||||
PartialProducer replicatedProducer(40, face2, syncPrefix, userPrefix);
|
||||
util::DummyClientFace face2(m_io, m_keyChain, {true, true});
|
||||
PartialProducer replicatedProducer(face2, m_keyChain, 40, syncPrefix, userPrefix);
|
||||
for (int i = 1; i < 10; i++) {
|
||||
replicatedProducer.addUserNode("testUser-" + std::to_string(i));
|
||||
}
|
||||
|
||||
@@ -20,28 +20,27 @@
|
||||
#include "PSync/producer-base.hpp"
|
||||
|
||||
#include "tests/boost-test.hpp"
|
||||
#include "tests/key-chain-fixture.hpp"
|
||||
|
||||
#include <ndn-cxx/data.hpp>
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
|
||||
namespace psync {
|
||||
|
||||
using namespace ndn;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestProducerBase)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Constructor)
|
||||
class ProducerBaseFixture : public tests::KeyChainFixture
|
||||
{
|
||||
util::DummyClientFace face;
|
||||
BOOST_CHECK_NO_THROW(ProducerBase(40, face, Name("/psync"), Name("/testUser")));
|
||||
}
|
||||
protected:
|
||||
util::DummyClientFace m_face;
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(TestProducerBase, ProducerBaseFixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Basic)
|
||||
{
|
||||
util::DummyClientFace face;
|
||||
Name userNode("/testUser");
|
||||
ProducerBase producerBase(40, face, Name("/psync"), userNode);
|
||||
ProducerBase producerBase(m_face, m_keyChain, 40, Name("/psync"), userNode);
|
||||
|
||||
// Hash table size should be 40 + 40/2 = 60 (which is perfectly divisible by N_HASH = 3)
|
||||
BOOST_CHECK_EQUAL(producerBase.m_iblt.getHashTable().size(), 60);
|
||||
BOOST_CHECK_EQUAL(producerBase.getSeqNo(userNode).value(), 0);
|
||||
@@ -67,16 +66,14 @@ BOOST_AUTO_TEST_CASE(Basic)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ApplicationNack)
|
||||
{
|
||||
util::DummyClientFace face;
|
||||
ProducerBase producerBase(40, face, Name("/psync"), Name("/testUser"));
|
||||
ProducerBase producerBase(m_face, m_keyChain, 40, Name("/psync"), Name("/testUser"));
|
||||
|
||||
BOOST_CHECK_EQUAL(face.sentData.size(), 0);
|
||||
producerBase.m_syncReplyFreshness = 1_s;
|
||||
BOOST_CHECK_EQUAL(m_face.sentData.size(), 0);
|
||||
producerBase.sendApplicationNack(Name("test"));
|
||||
face.processEvents(10_ms);
|
||||
m_face.processEvents(10_ms);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(face.sentData.size(), 1);
|
||||
BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), tlv::ContentType_Nack);
|
||||
BOOST_REQUIRE_EQUAL(m_face.sentData.size(), 1);
|
||||
BOOST_CHECK_EQUAL(m_face.sentData.front().getContentType(), tlv::ContentType_Nack);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014-2020, The University of Memphis
|
||||
* Copyright (c) 2014-2022, The University of Memphis
|
||||
*
|
||||
* This file is part of PSync.
|
||||
* See AUTHORS.md for complete list of PSync authors and contributors.
|
||||
@@ -22,9 +22,8 @@
|
||||
|
||||
#include "tests/boost-test.hpp"
|
||||
#include "tests/io-fixture.hpp"
|
||||
#include "tests/key-chain-fixture.hpp"
|
||||
|
||||
#include <ndn-cxx/data.hpp>
|
||||
#include <ndn-cxx/interest.hpp>
|
||||
#include <ndn-cxx/security/validator-null.hpp>
|
||||
#include <ndn-cxx/util/dummy-client-face.hpp>
|
||||
#include <ndn-cxx/util/segment-fetcher.hpp>
|
||||
@@ -33,16 +32,14 @@ namespace psync {
|
||||
|
||||
using namespace ndn;
|
||||
|
||||
class SegmentPublisherFixture : public tests::IoFixture
|
||||
class SegmentPublisherFixture : public tests::IoFixture, public tests::KeyChainFixture
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
SegmentPublisherFixture()
|
||||
: face(m_io, util::DummyClientFace::Options{true, true})
|
||||
, publisher(face, keyChain)
|
||||
{
|
||||
face.setInterestFilter(InterestFilter("/hello/world"),
|
||||
bind(&SegmentPublisherFixture::onInterest, this, _1, _2),
|
||||
[] (auto&&...) { BOOST_CHECK(false); });
|
||||
m_face.setInterestFilter(InterestFilter("/hello/world"),
|
||||
bind(&SegmentPublisherFixture::onInterest, this, _1, _2),
|
||||
[] (auto&&...) { BOOST_CHECK(false); });
|
||||
advanceClocks(10_ms);
|
||||
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
@@ -58,7 +55,7 @@ public:
|
||||
void
|
||||
expressInterest(const Interest& interest)
|
||||
{
|
||||
fetcher = util::SegmentFetcher::start(face, interest, security::getAcceptAllValidator());
|
||||
fetcher = util::SegmentFetcher::start(m_face, interest, security::getAcceptAllValidator());
|
||||
fetcher->onComplete.connect([this] (auto&&...) { numComplete++; });
|
||||
fetcher->onError.connect([] (auto&&...) { BOOST_CHECK(false); });
|
||||
|
||||
@@ -82,16 +79,17 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
util::DummyClientFace face;
|
||||
KeyChain keyChain;
|
||||
SegmentPublisher publisher;
|
||||
protected:
|
||||
util::DummyClientFace m_face{m_io, m_keyChain, {true, true}};
|
||||
SegmentPublisher publisher{m_face, m_keyChain};
|
||||
shared_ptr<util::SegmentFetcher> fetcher;
|
||||
Name dataName;
|
||||
time::milliseconds freshness = 1_s;
|
||||
detail::State state;
|
||||
|
||||
int numComplete = 0;
|
||||
int numRepliesFromStore = 0;
|
||||
|
||||
static constexpr time::milliseconds freshness = 1_s;
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(TestSegmentPublisher, SegmentPublisherFixture)
|
||||
@@ -120,10 +118,10 @@ BOOST_AUTO_TEST_CASE(Basic)
|
||||
BOOST_CHECK_EQUAL(numRepliesFromStore, 2);
|
||||
|
||||
numRepliesFromStore = 0;
|
||||
face.expressInterest(Interest("/hello/world/").setCanBePrefix(true),
|
||||
[this] (auto&&...) { this->numComplete++; },
|
||||
[] (auto&&...) { BOOST_CHECK(false); },
|
||||
[] (auto&&...) { BOOST_CHECK(false); });
|
||||
m_face.expressInterest(Interest("/hello/world/").setCanBePrefix(true),
|
||||
[this] (auto&&...) { this->numComplete++; },
|
||||
[] (auto&&...) { BOOST_CHECK(false); },
|
||||
[] (auto&&...) { BOOST_CHECK(false); });
|
||||
advanceClocks(10_ms);
|
||||
BOOST_CHECK_EQUAL(numComplete, 4);
|
||||
BOOST_CHECK_EQUAL(numRepliesFromStore, 1);
|
||||
|
||||
Reference in New Issue
Block a user