Minor code cleanups

Change-Id: I2b67216754ba30563a65a2697e6801e363986da1
This commit is contained in:
Davide Pesavento committed 2022-09-25 14:06:26 -04:00
1 parent c45a4eaef4
commit 03426efa2c
14 files changed
+106 -131

No files matched your search

+6 -7
View File
@@ -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.
@@ -19,7 +19,7 @@
#include <PSync/consumer.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/random.hpp>
@@ -44,7 +44,6 @@ public:
std::bind(&PSyncConsumer::afterReceiveHelloData, this, _1),
std::bind(&PSyncConsumer::processSyncUpdate, this, _1),
m_nSub, 0.001)
, m_rng(ndn::random::getRandomNumberEngine())
{
// This starts the consumer side by sending a hello interest to the producer
// When the producer responds with hello data, afterReceiveHelloData is called
@@ -96,18 +95,18 @@ private:
private:
ndn::Face m_face;
int m_nSub;
int m_nSub;
psync::Consumer m_consumer;
ndn::random::RandomNumberEngine& m_rng;
ndn::random::RandomNumberEngine& m_rng{ndn::random::getRandomNumberEngine()};
};
int
main(int argc, char* argv[])
{
if (argc != 3) {
std::cout << "usage: " << argv[0] << " "
<< "<sync-prefix> <number-of-subscriptions>" << std::endl;
std::cerr << "Usage: " << argv[0] << " <sync-prefix> <number-of-subscriptions>\n";
return 1;
}
+13 -16
View File
@@ -43,18 +43,16 @@ public:
*/
Producer(const ndn::Name& syncPrefix, const std::string& userPrefix,
int numDataStreams, int maxNumPublish)
: m_fullProducer(m_face, m_keyChain, 80, syncPrefix, userPrefix,
std::bind(&Producer::processSyncUpdate, this, _1),
1600_ms, 1600_ms)
: m_producer(m_face, m_keyChain, 80, syncPrefix, userPrefix,
std::bind(&Producer::processSyncUpdate, this, _1),
1600_ms, 1600_ms)
, 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 < numDataStreams; i++) {
ndn::Name prefix(userPrefix + "-" + std::to_string(i));
m_fullProducer.addUserNode(prefix);
m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)),
m_producer.addUserNode(prefix);
m_scheduler.schedule(ndn::time::milliseconds(m_uniformRand(m_rng)),
[this, prefix] { doUpdate(prefix); });
}
}
@@ -69,13 +67,13 @@ private:
void
doUpdate(const ndn::Name& prefix)
{
m_fullProducer.publishName(prefix);
m_producer.publishName(prefix);
uint64_t seqNo = m_fullProducer.getSeqNo(prefix).value();
uint64_t seqNo = m_producer.getSeqNo(prefix).value();
NDN_LOG_INFO("Publish: " << prefix << "/" << seqNo);
if (seqNo < m_maxNumPublish) {
m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)),
m_scheduler.schedule(ndn::time::milliseconds(m_uniformRand(m_rng)),
[this, prefix] { doUpdate(prefix); });
}
}
@@ -95,20 +93,19 @@ private:
ndn::KeyChain m_keyChain;
ndn::Scheduler m_scheduler{m_face.getIoService()};
psync::FullProducer m_fullProducer;
psync::FullProducer m_producer;
uint64_t m_maxNumPublish;
ndn::random::RandomNumberEngine& m_rng;
std::uniform_int_distribution<> m_rangeUniformRandom;
ndn::random::RandomNumberEngine& m_rng{ndn::random::getRandomNumberEngine()};
std::uniform_int_distribution<> m_uniformRand{0, 60000};
};
int
main(int argc, char* argv[])
{
if (argc != 5) {
std::cout << "usage: " << argv[0] << " <syncPrefix> <user-prefix> "
<< "<number-of-user-prefixes> <max-number-of-updates-per-user-prefix>"
<< std::endl;
std::cerr << "Usage: " << argv[0] << " <sync-prefix> <user-prefix> "
<< "<number-of-user-prefixes> <max-number-of-updates-per-user-prefix>\n";
return 1;
}
+8 -11
View File
@@ -41,8 +41,6 @@ public:
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 < numDataStreams; i++) {
@@ -52,8 +50,8 @@ public:
// Note that this does not add the already added userPrefix-0 in the constructor
m_producer.addUserNode(updateName);
// Each user prefix is updated at random interval between 0 and 60 second
m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)),
// Each user prefix is updated at a random interval between 0 and 60 seconds
m_scheduler.schedule(ndn::time::milliseconds(m_uniformRand(m_rng)),
[this, updateName] { doUpdate(updateName); });
}
}
@@ -75,8 +73,8 @@ private:
NDN_LOG_INFO("Publish: " << updateName << "/" << seqNo);
if (seqNo < m_maxNumPublish) {
// Schedule the next update for this user prefix b/w 0 and 60 seconds
m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)),
// Schedule the next update for this user prefix between 0 and 60 seconds
m_scheduler.schedule(ndn::time::milliseconds(m_uniformRand(m_rng)),
[this, updateName] { doUpdate(updateName); });
}
}
@@ -89,17 +87,16 @@ private:
psync::PartialProducer m_producer;
uint64_t m_maxNumPublish;
ndn::random::RandomNumberEngine& m_rng;
std::uniform_int_distribution<int> m_rangeUniformRandom;
ndn::random::RandomNumberEngine& m_rng{ndn::random::getRandomNumberEngine()};
std::uniform_int_distribution<> m_uniformRand{0, 60000};
};
int
main(int argc, char* argv[])
{
if (argc != 5) {
std::cout << "usage: " << argv[0] << " <sync-prefix> <user-prefix> "
<< "<number-of-user-prefixes> <max-number-of-updates-per-user-prefix>"
<< std::endl;
std::cerr << "Usage: " << argv[0] << " <sync-prefix> <user-prefix> "
<< "<number-of-user-prefixes> <max-number-of-updates-per-user-prefix>\n";
return 1;
}