full-producer: gather constructor args into Options struct
refs #5069
Change-Id: I168efffe739a19273b596a7b1cee2f4ade147d75
diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp
index fa11120..59907ee 100644
--- a/PSync/full-producer.cpp
+++ b/PSync/full-producer.cpp
@@ -33,6 +33,24 @@
FullProducer::FullProducer(ndn::Face& face,
ndn::KeyChain& keyChain,
+ const ndn::Name& syncPrefix,
+ const Options& opts)
+ : ProducerBase(face, keyChain, opts.ibfCount, syncPrefix, opts.syncDataFreshness,
+ opts.ibfCompression, opts.contentCompression)
+ , m_syncInterestLifetime(opts.syncInterestLifetime)
+ , m_onUpdate(opts.onUpdate)
+{
+ m_registeredPrefix = m_face.setInterestFilter(ndn::InterestFilter(m_syncPrefix).allowLoopback(false),
+ [this] (auto&&... args) { onSyncInterest(std::forward<decltype(args)>(args)...); },
+ [] (auto&&... args) { onRegisterFailed(std::forward<decltype(args)>(args)...); });
+
+ // Should we do this after setInterestFilter success call back
+ // (Currently following ChronoSync's way)
+ sendSyncInterest();
+}
+
+FullProducer::FullProducer(ndn::Face& face,
+ ndn::KeyChain& keyChain,
size_t expectedNumEntries,
const ndn::Name& syncPrefix,
const ndn::Name& userPrefix,
@@ -41,20 +59,11 @@
ndn::time::milliseconds syncReplyFreshness,
CompressionScheme ibltCompression,
CompressionScheme contentCompression)
- : ProducerBase(face, keyChain, expectedNumEntries, syncPrefix,
- syncReplyFreshness, ibltCompression, contentCompression)
- , m_syncInterestLifetime(syncInterestLifetime)
- , m_onUpdate(std::move(onUpdateCb))
+ : FullProducer(face, keyChain, syncPrefix,
+ Options{std::move(onUpdateCb), static_cast<uint32_t>(expectedNumEntries), ibltCompression,
+ syncInterestLifetime, syncReplyFreshness, contentCompression})
{
addUserNode(userPrefix);
-
- m_registeredPrefix = m_face.setInterestFilter(ndn::InterestFilter(m_syncPrefix).allowLoopback(false),
- [this] (auto&&... args) { onSyncInterest(std::forward<decltype(args)>(args)...); },
- [] (auto&&... args) { onRegisterFailed(std::forward<decltype(args)>(args)...); });
-
- // Should we do this after setInterestFilter success call back
- // (Currently following ChronoSync's way)
- sendSyncInterest();
}
FullProducer::~FullProducer()
diff --git a/PSync/full-producer.hpp b/PSync/full-producer.hpp
index 46a00e5..4644727 100644
--- a/PSync/full-producer.hpp
+++ b/PSync/full-producer.hpp
@@ -42,21 +42,38 @@
{
public:
/**
- * @brief Constructor
- *
- * Registers syncPrefix in NFD and sends a sync interest.
- *
- * @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 callback to be invoked when there is new data
- * @param syncInterestLifetime Lifetime of the sync interest
- * @param syncReplyFreshness FreshnessPeriod of sync data
- * @param ibltCompression Compression scheme to use for IBF
- * @param contentCompression Compression scheme to use for Data content
+ * @brief Constructor options.
*/
+ struct Options
+ {
+ /// Callback to be invoked when there is new data.
+ UpdateCallback onUpdate = [] (const auto&) {};
+ /// Expected number of entries in IBF.
+ uint32_t ibfCount = 80;
+ /// Compression scheme to use for IBF.
+ CompressionScheme ibfCompression = CompressionScheme::DEFAULT;
+ /// Lifetime of sync Interest.
+ ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFETIME;
+ /// FreshnessPeriod of sync Data.
+ ndn::time::milliseconds syncDataFreshness = SYNC_REPLY_FRESHNESS;
+ /// Compression scheme to use for Data content.
+ CompressionScheme contentCompression = CompressionScheme::DEFAULT;
+ };
+
+ /**
+ * @brief Constructor.
+ *
+ * @param face Application face.
+ * @param keyChain KeyChain instance to use for signing.
+ * @param syncPrefix The prefix of the sync group.
+ * @param opts Options.
+ */
+ FullProducer(ndn::Face& face,
+ ndn::KeyChain& keyChain,
+ const ndn::Name& syncPrefix,
+ const Options& opts);
+
+ [[deprecated]]
FullProducer(ndn::Face& face,
ndn::KeyChain& keyChain,
size_t expectedNumEntries,
diff --git a/PSync/partial-producer.hpp b/PSync/partial-producer.hpp
index 78a7818..4980484 100644
--- a/PSync/partial-producer.hpp
+++ b/PSync/partial-producer.hpp
@@ -45,9 +45,9 @@
uint32_t ibfCount = 40;
/// Compression scheme to use for IBF.
CompressionScheme ibfCompression = CompressionScheme::NONE;
- /// FreshnessPeriod of hello data.
+ /// FreshnessPeriod of hello Data.
ndn::time::milliseconds helloDataFreshness = HELLO_REPLY_FRESHNESS;
- /// FreshnessPeriod of sync data.
+ /// FreshnessPeriod of sync Data.
ndn::time::milliseconds syncDataFreshness = SYNC_REPLY_FRESHNESS;
};
diff --git a/examples/full-sync.cpp b/examples/full-sync.cpp
index 12fd909..6248336 100644
--- a/examples/full-sync.cpp
+++ b/examples/full-sync.cpp
@@ -35,20 +35,25 @@
{
public:
/**
- * @brief Initialize producer and schedule updates
+ * @brief Initialize producer and schedule updates.
*
- * Set IBF size as 80 expecting 80 updates to IBF in a sync cycle
- * Set syncInterestLifetime and syncReplyFreshness to 1.6 seconds
- * userPrefix is the default user prefix, no updates are published on it in this example
+ * Set IBF size as 80 expecting 80 updates to IBF in a sync cycle.
+ * Set syncInterestLifetime and syncDataFreshness to 1.6 seconds.
+ * userPrefix is the prefix string of user node prefixes.
*/
Producer(const ndn::Name& syncPrefix, const std::string& userPrefix,
int numDataStreams, int maxNumPublish)
- : m_producer(m_face, m_keyChain, 80, syncPrefix, userPrefix,
- std::bind(&Producer::processSyncUpdate, this, _1),
- 1600_ms, 1600_ms)
+ : m_producer(m_face, m_keyChain, syncPrefix, [this] {
+ psync::FullProducer::Options opts;
+ opts.onUpdate = std::bind(&Producer::processSyncUpdate, this, _1);
+ opts.ibfCount = 80;
+ opts.syncInterestLifetime = 1600_ms;
+ opts.syncDataFreshness = 1600_ms;
+ return opts;
+ } ())
, m_maxNumPublish(maxNumPublish)
{
- // Add user prefixes and schedule updates for them in specified interval
+ // Add user prefixes and schedule updates for them in specified interval.
for (int i = 0; i < numDataStreams; i++) {
ndn::Name prefix(userPrefix + "-" + std::to_string(i));
m_producer.addUserNode(prefix);
diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp
index ba8260c..a03d799 100644
--- a/tests/test-full-producer.cpp
+++ b/tests/test-full-producer.cpp
@@ -41,8 +41,10 @@
BOOST_AUTO_TEST_CASE(OnInterest)
{
- Name syncPrefix("/psync"), userNode("/testUser");
- FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
+ Name syncPrefix("/psync");
+ FullProducer::Options opts;
+ opts.ibfCount = 40;
+ FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Name syncInterestName(syncPrefix);
syncInterestName.append("malicious-IBF");
@@ -52,8 +54,11 @@
BOOST_AUTO_TEST_CASE(ConstantTimeoutForFirstSegment)
{
- Name syncPrefix("/psync"), userNode("/testUser");
- FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr, 8_s);
+ Name syncPrefix("/psync");
+ FullProducer::Options opts;
+ opts.ibfCount = 40;
+ opts.syncInterestLifetime = 8_s;
+ FullProducer node(m_face, m_keyChain, syncPrefix, opts);
advanceClocks(10_ms);
m_face.sentInterests.clear();
@@ -65,8 +70,10 @@
BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
{
- Name syncPrefix("/psync"), userNode("/testUser");
- FullProducer node(m_face, m_keyChain, 40, syncPrefix, userNode, nullptr);
+ Name syncPrefix("/psync");
+ FullProducer::Options opts;
+ opts.ibfCount = 40;
+ FullProducer node(m_face, m_keyChain, syncPrefix, opts);
Name syncInterestName(syncPrefix);
node.m_iblt.appendToName(syncInterestName);
diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp
index 91f95db..874f6f7 100644
--- a/tests/test-full-sync.cpp
+++ b/tests/test-full-sync.cpp
@@ -44,8 +44,10 @@
userPrefixes[id] = "/userPrefix" + std::to_string(id);
faces[id] = std::make_unique<ndn::DummyClientFace>(m_io, m_keyChain,
ndn::DummyClientFace::Options{true, true});
- nodes[id] = std::make_unique<FullProducer>(*faces[id], m_keyChain, 40, syncPrefix, userPrefixes[id],
- [] (const auto&) {});
+ FullProducer::Options opts;
+ opts.ibfCount = 40;
+ nodes[id] = std::make_unique<FullProducer>(*faces[id], m_keyChain, syncPrefix, opts);
+ nodes[id]->addUserNode(userPrefixes[id]);
}
void