Move config.hpp and a few more private headers to a 'detail' subdir
Also upgrade waf to version 2.0.21
Change-Id: Id290b8336c607fb3939f2ab96dd066dae9810c1e
diff --git a/src/logic.cpp b/src/logic.cpp
index 6d52def..db6bc02 100644
--- a/src/logic.cpp
+++ b/src/logic.cpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2020 University of California, Los Angeles
+ * Copyright (c) 2012-2021 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -24,16 +24,16 @@
*/
#include "logic.hpp"
-#include "logger.hpp"
-#include "bzip2-helper.hpp"
+#include "detail/bzip2-helper.hpp"
#include <ndn-cxx/util/backports.hpp>
#include <ndn-cxx/util/exception.hpp>
+#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/string-helper.hpp>
-INIT_LOGGER(Logic);
+NDN_LOG_INIT(sync.Logic);
-#define _LOG_DEBUG_ID(v) _LOG_DEBUG("Instance" << m_instanceId << ": " << v)
+#define CHRONO_LOG_DBG(v) NDN_LOG_DEBUG("Instance" << m_instanceId << ": " << v)
namespace chronosync {
@@ -69,18 +69,18 @@
* The returned value can be customized using the environment variable `CHRONOSYNC_MAX_PACKET_SIZE`,
* but the returned value will be at least 500 and no more than `ndn::MAX_NDN_PACKET_SIZE`.
*/
-#ifndef CHRONOSYNC_HAVE_TESTS
+#ifndef CHRONOSYNC_WITH_TESTS
static
-#endif // CHRONOSYNC_HAVE_TESTS
+#endif // CHRONOSYNC_WITH_TESTS
size_t
getMaxPacketLimit()
{
static size_t limit = 0;
-#ifndef CHRONOSYNC_HAVE_TESTS
+#ifndef CHRONOSYNC_WITH_TESTS
if (limit != 0) {
return limit;
}
-#endif // CHRONOSYNC_HAVE_TESTS
+#endif // CHRONOSYNC_WITH_TESTS
if (getenv("CHRONOSYNC_MAX_PACKET_SIZE") != nullptr) {
try {
@@ -132,25 +132,25 @@
, m_validator(validator)
, m_instanceId(s_instanceCounter++)
{
- _LOG_DEBUG_ID(">> Logic::Logic");
+ CHRONO_LOG_DBG(">> Logic::Logic");
addUserNode(m_defaultUserPrefix, defaultSigningId, session, false);
- _LOG_DEBUG_ID("Listen to: " << m_syncPrefix);
+ CHRONO_LOG_DBG("Listen to: " << m_syncPrefix);
m_syncRegisteredPrefix = m_face.setInterestFilter(
ndn::InterestFilter(m_syncPrefix).allowLoopback(false),
bind(&Logic::onSyncInterest, this, _1, _2),
bind(&Logic::onSyncRegisterFailed, this, _1, _2));
sendSyncInterest();
- _LOG_DEBUG_ID("<< Logic::Logic");
+ CHRONO_LOG_DBG("<< Logic::Logic");
}
Logic::~Logic()
{
- _LOG_DEBUG_ID(">> Logic::~Logic");
+ CHRONO_LOG_DBG(">> Logic::~Logic");
m_interestTable.clear();
m_scheduler.cancelAllEvents();
- _LOG_DEBUG_ID("<< Logic::~Logic");
+ CHRONO_LOG_DBG("<< Logic::~Logic");
}
void
@@ -262,20 +262,20 @@
auto it = m_nodeList.find(prefix);
if (it != m_nodeList.end()) {
NodeInfo& node = it->second;
- _LOG_DEBUG_ID(">> Logic::updateSeqNo");
- _LOG_DEBUG_ID("seqNo: " << seqNo << " m_seqNo: " << node.seqNo);
+ CHRONO_LOG_DBG(">> Logic::updateSeqNo");
+ CHRONO_LOG_DBG("seqNo: " << seqNo << " m_seqNo: " << node.seqNo);
if (seqNo < node.seqNo || seqNo == 0)
return;
node.seqNo = seqNo;
- _LOG_DEBUG_ID("updateSeqNo: m_seqNo " << node.seqNo);
+ CHRONO_LOG_DBG("updateSeqNo: m_seqNo " << node.seqNo);
if (!m_isInReset) {
- _LOG_DEBUG_ID("updateSeqNo: not in Reset ");
+ CHRONO_LOG_DBG("updateSeqNo: not in Reset");
ConstBufferPtr previousRoot = m_state.getRootDigest();
{
std::string hash = ndn::toHex(previousRoot->data(), previousRoot->size(), false);
- _LOG_DEBUG_ID("Hash: " << hash);
+ CHRONO_LOG_DBG("Hash: " << hash);
}
bool isInserted = false;
@@ -283,8 +283,8 @@
SeqNo oldSeq;
std::tie(isInserted, isUpdated, oldSeq) = m_state.update(node.sessionName, node.seqNo);
- _LOG_DEBUG_ID("Insert: " << std::boolalpha << isInserted);
- _LOG_DEBUG_ID("Updated: " << std::boolalpha << isUpdated);
+ CHRONO_LOG_DBG("Insert: " << std::boolalpha << isInserted);
+ CHRONO_LOG_DBG("Updated: " << std::boolalpha << isUpdated);
if (isInserted || isUpdated) {
DiffStatePtr commit = make_shared<DiffState>();
commit->update(node.sessionName, node.seqNo);
@@ -322,12 +322,12 @@
}
void
-Logic::onSyncInterest(const Name& prefix, const Interest& interest)
+Logic::onSyncInterest(const Name&, const Interest& interest)
{
- _LOG_DEBUG_ID(">> Logic::onSyncInterest");
+ CHRONO_LOG_DBG(">> Logic::onSyncInterest");
Name name = interest.getName();
- _LOG_DEBUG_ID("InterestName: " << name);
+ CHRONO_LOG_DBG("InterestName: " << name);
if (name.size() >= 1 && RESET_COMPONENT == name.get(-1)) {
processResetInterest(interest);
@@ -339,20 +339,19 @@
processSyncInterest(interest);
}
- _LOG_DEBUG_ID("<< Logic::onSyncInterest");
+ CHRONO_LOG_DBG("<< Logic::onSyncInterest");
}
void
Logic::onSyncRegisterFailed(const Name& prefix, const std::string& msg)
{
- //Sync prefix registration failed
- _LOG_DEBUG_ID(">> Logic::onSyncRegisterFailed");
+ CHRONO_LOG_DBG(">> Logic::onSyncRegisterFailed");
}
void
-Logic::onSyncData(const Interest& interest, const Data& data)
+Logic::onSyncData(const Interest&, const Data& data)
{
- _LOG_DEBUG_ID(">> Logic::onSyncData");
+ CHRONO_LOG_DBG(">> Logic::onSyncData");
if (m_validator != nullptr)
m_validator->validate(data,
bind(&Logic::onSyncDataValidated, this, _1),
@@ -360,38 +359,38 @@
else
onSyncDataValidated(data);
- _LOG_DEBUG_ID("<< Logic::onSyncData");
+ CHRONO_LOG_DBG("<< Logic::onSyncData");
}
void
-Logic::onResetData(const Interest& interest, const Data& data)
+Logic::onResetData(const Interest&, const Data&)
{
// This should not happened, drop the received data.
}
void
-Logic::onSyncNack(const Interest& interest, const ndn::lp::Nack& nack)
+Logic::onSyncNack(const Interest&, const ndn::lp::Nack& nack)
{
- _LOG_DEBUG_ID(">> Logic::onSyncNack");
+ CHRONO_LOG_DBG(">> Logic::onSyncNack");
if (nack.getReason() == ndn::lp::NackReason::NO_ROUTE) {
auto after = ndn::time::milliseconds(m_reexpressionJitter(m_rng));
- _LOG_DEBUG_ID("Schedule sync interest after: " << after);
+ CHRONO_LOG_DBG("Schedule sync interest after: " << after);
m_scheduler.schedule(after, [this] { sendSyncInterest(); });
}
- _LOG_DEBUG_ID("<< Logic::onSyncNack");
+ CHRONO_LOG_DBG("<< Logic::onSyncNack");
}
void
Logic::onSyncTimeout(const Interest& interest)
{
// It is OK. Others will handle the time out situation.
- _LOG_DEBUG_ID(">> Logic::onSyncTimeout");
- _LOG_DEBUG_ID("Interest: " << interest.getName());
- _LOG_DEBUG_ID("<< Logic::onSyncTimeout");
+ CHRONO_LOG_DBG(">> Logic::onSyncTimeout");
+ CHRONO_LOG_DBG("Interest: " << interest.getName());
+ CHRONO_LOG_DBG("<< Logic::onSyncTimeout");
}
void
-Logic::onSyncDataValidationFailed(const Data& data)
+Logic::onSyncDataValidationFailed(const Data&)
{
// SyncReply cannot be validated.
}
@@ -408,14 +407,14 @@
processSyncData(name, digest, Block(std::move(contentBuffer)));
}
catch (const std::ios_base::failure& error) {
- _LOG_WARN("Error decompressing content of " << data.getName() << " (" << error.what() << ")");
+ NDN_LOG_WARN("Error decompressing content of " << data.getName() << " (" << error.what() << ")");
}
}
void
Logic::processSyncInterest(const Interest& interest, bool isTimedProcessing/*=false*/)
{
- _LOG_DEBUG_ID(">> Logic::processSyncInterest");
+ CHRONO_LOG_DBG(">> Logic::processSyncInterest");
Name name = interest.getName();
ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
@@ -425,23 +424,23 @@
// If the digest of the incoming interest is the same as root digest
// Put the interest into InterestTable
if (*rootDigest == *digest) {
- _LOG_DEBUG_ID("Oh, we are in the same state");
+ CHRONO_LOG_DBG("Oh, we are in the same state");
m_interestTable.insert(interest, digest, false);
if (!m_isInReset)
return;
if (!isTimedProcessing) {
- _LOG_DEBUG_ID("Non timed processing in reset");
+ CHRONO_LOG_DBG("Non timed processing in reset");
// Still in reset, our own seq has not been put into state yet
// Do not hurry, some others may be also resetting and may send their reply
time::milliseconds after(m_rangeUniformRandom(m_rng));
- _LOG_DEBUG_ID("After: " << after);
+ CHRONO_LOG_DBG("After: " << after);
m_delayedInterestProcessingId = m_scheduler.schedule(after,
[=] { processSyncInterest(interest, true); });
}
else {
- _LOG_DEBUG_ID("Timed processing in reset");
+ CHRONO_LOG_DBG("Timed processing in reset");
// Now we can get out of reset state by putting our own stuff into m_state.
cancelReset();
}
@@ -451,7 +450,7 @@
// If the digest of incoming interest is an "empty" digest
if (*digest == *EMPTY_DIGEST) {
- _LOG_DEBUG_ID("Poor guy, he knows nothing");
+ CHRONO_LOG_DBG("Poor guy, he knows nothing");
sendSyncData(m_defaultUserPrefix, name, m_state);
return;
}
@@ -459,13 +458,13 @@
auto stateIter = m_log.find(digest);
// If the digest of incoming interest can be found from the log
if (stateIter != m_log.end()) {
- _LOG_DEBUG_ID("It is ok, you are so close");
+ CHRONO_LOG_DBG("It is ok, you are so close");
sendSyncData(m_defaultUserPrefix, name, *(*stateIter)->diff());
return;
}
if (!isTimedProcessing) {
- _LOG_DEBUG_ID("Let's wait, just wait for a while");
+ CHRONO_LOG_DBG("Let's wait, just wait for a while");
// Do not hurry, some incoming SyncReplies may help us to recognize the digest
m_interestTable.insert(interest, digest, true);
@@ -475,25 +474,25 @@
}
else {
// OK, nobody is helping us, just tell the truth.
- _LOG_DEBUG_ID("OK, nobody is helping us, let us try to recover");
+ CHRONO_LOG_DBG("OK, nobody is helping us, let us try to recover");
m_interestTable.erase(digest);
sendRecoveryInterest(digest);
}
- _LOG_DEBUG_ID("<< Logic::processSyncInterest");
+ CHRONO_LOG_DBG("<< Logic::processSyncInterest");
}
void
Logic::processResetInterest(const Interest&)
{
- _LOG_DEBUG_ID(">> Logic::processResetInterest");
+ CHRONO_LOG_DBG(">> Logic::processResetInterest");
reset(true);
}
void
Logic::processSyncData(const Name&, ConstBufferPtr digest, const Block& syncReply)
{
- _LOG_DEBUG_ID(">> Logic::processSyncData");
+ CHRONO_LOG_DBG(">> Logic::processSyncData");
DiffStatePtr commit = make_shared<DiffState>();
ConstBufferPtr previousRoot = m_state.getRootDigest();
@@ -528,12 +527,11 @@
insertToDiffLog(commit, previousRoot);
}
else {
- _LOG_DEBUG_ID("What? nothing new");
+ CHRONO_LOG_DBG("What? nothing new");
}
}
catch (const State::Error&) {
- _LOG_DEBUG_ID("Something really fishy happened during state decoding");
- // Something really fishy happened during state decoding;
+ CHRONO_LOG_DBG("Something really fishy happened during state decoding");
commit.reset();
return;
}
@@ -541,7 +539,7 @@
if (static_cast<bool>(commit) && !commit->getLeaves().empty()) {
// state changed and it is safe to express a new interest
auto after = time::milliseconds(m_reexpressionJitter(m_rng));
- _LOG_DEBUG_ID("Reschedule sync interest after: " << after);
+ CHRONO_LOG_DBG("Reschedule sync interest after: " << after);
m_reexpressingInterestId = m_scheduler.schedule(after, [this] { sendSyncInterest(); });
}
}
@@ -549,9 +547,9 @@
void
Logic::satisfyPendingSyncInterests(const Name& updatedPrefix, ConstDiffStatePtr commit)
{
- _LOG_DEBUG_ID(">> Logic::satisfyPendingSyncInterests");
+ CHRONO_LOG_DBG(">> Logic::satisfyPendingSyncInterests");
try {
- _LOG_DEBUG_ID("InterestTable size: " << m_interestTable.size());
+ CHRONO_LOG_DBG("InterestTable size: " << m_interestTable.size());
auto it = m_interestTable.begin();
while (it != m_interestTable.end()) {
ConstUnsatisfiedInterestPtr request = *it;
@@ -566,13 +564,13 @@
catch (const InterestTable::Error&) {
// ok. not really an error
}
- _LOG_DEBUG_ID("<< Logic::satisfyPendingSyncInterests");
+ CHRONO_LOG_DBG("<< Logic::satisfyPendingSyncInterests");
}
void
Logic::insertToDiffLog(DiffStatePtr commit, ConstBufferPtr previousRoot)
{
- _LOG_DEBUG_ID(">> Logic::insertToDiffLog");
+ CHRONO_LOG_DBG(">> Logic::insertToDiffLog");
// Connect to the history
if (!m_log.empty())
(*m_log.find(previousRoot))->setNext(commit);
@@ -580,17 +578,17 @@
// Insert the commit
m_log.erase(commit->getRootDigest());
m_log.insert(commit);
- _LOG_DEBUG_ID("<< Logic::insertToDiffLog");
+ CHRONO_LOG_DBG("<< Logic::insertToDiffLog");
}
void
Logic::sendResetInterest()
{
- _LOG_DEBUG_ID(">> Logic::sendResetInterest");
+ CHRONO_LOG_DBG(">> Logic::sendResetInterest");
if (m_needPeriodReset) {
- _LOG_DEBUG_ID("Need Period Reset");
- _LOG_DEBUG_ID("ResetTimer: " << m_resetTimer);
+ CHRONO_LOG_DBG("Need Period Reset");
+ CHRONO_LOG_DBG("ResetTimer: " << m_resetTimer);
m_resetInterestId = m_scheduler.schedule(m_resetTimer + time::milliseconds(m_reexpressionJitter(m_rng)),
[this] { sendResetInterest(); });
@@ -607,13 +605,13 @@
bind(&Logic::onResetData, this, _1, _2),
bind(&Logic::onSyncTimeout, this, _1), // Nack
bind(&Logic::onSyncTimeout, this, _1));
- _LOG_DEBUG_ID("<< Logic::sendResetInterest");
+ CHRONO_LOG_DBG("<< Logic::sendResetInterest");
}
void
Logic::sendSyncInterest()
{
- _LOG_DEBUG_ID(">> Logic::sendSyncInterest");
+ CHRONO_LOG_DBG(">> Logic::sendSyncInterest");
Name interestName;
interestName.append(m_syncPrefix)
@@ -639,8 +637,8 @@
bind(&Logic::onSyncNack, this, _1, _2),
bind(&Logic::onSyncTimeout, this, _1));
- _LOG_DEBUG_ID("Send interest: " << interest.getName());
- _LOG_DEBUG_ID("<< Logic::sendSyncInterest");
+ CHRONO_LOG_DBG("Send interest: " << interest.getName());
+ CHRONO_LOG_DBG("<< Logic::sendSyncInterest");
}
void
@@ -688,7 +686,8 @@
while (syncReply.wireEncode().size() > getMaxPacketLimit() - NDNLP_EXPECTED_OVERHEAD) {
if (nExcludedStates == 1) {
// To show this debug message only once
- _LOG_DEBUG("Sync reply size exceeded maximum packet limit (" << (getMaxPacketLimit() - NDNLP_EXPECTED_OVERHEAD) << ")");
+ NDN_LOG_DEBUG("Sync reply size exceeded maximum packet limit ("
+ << (getMaxPacketLimit() - NDNLP_EXPECTED_OVERHEAD) << ")");
}
State partialState;
trimState(partialState, state, nExcludedStates);
@@ -704,7 +703,7 @@
void
Logic::sendSyncData(const Name& nodePrefix, const Name& name, const State& state)
{
- _LOG_DEBUG_ID(">> Logic::sendSyncData");
+ CHRONO_LOG_DBG(">> Logic::sendSyncData");
if (m_nodeList.find(nodePrefix) == m_nodeList.end())
return;
@@ -717,17 +716,17 @@
// re-schedule sending Sync interest
time::milliseconds after(m_reexpressionJitter(m_rng));
- _LOG_DEBUG_ID("Satisfy our own interest");
- _LOG_DEBUG_ID("Reschedule sync interest after " << after);
+ CHRONO_LOG_DBG("Satisfy our own interest");
+ CHRONO_LOG_DBG("Reschedule sync interest after " << after);
m_reexpressingInterestId = m_scheduler.schedule(after, [this] { sendSyncInterest(); });
}
- _LOG_DEBUG_ID("<< Logic::sendSyncData");
+ CHRONO_LOG_DBG("<< Logic::sendSyncData");
}
void
Logic::cancelReset()
{
- _LOG_DEBUG_ID(">> Logic::cancelReset");
+ CHRONO_LOG_DBG(">> Logic::cancelReset");
if (!m_isInReset)
return;
@@ -735,20 +734,20 @@
for (const auto& node : m_nodeList) {
updateSeqNo(node.second.seqNo, node.first);
}
- _LOG_DEBUG_ID("<< Logic::cancelReset");
+ CHRONO_LOG_DBG("<< Logic::cancelReset");
}
void
Logic::printDigest(ConstBufferPtr digest)
{
std::string hash = ndn::toHex(digest->data(), digest->size(), false);
- _LOG_DEBUG_ID("Hash: " << hash);
+ CHRONO_LOG_DBG("Hash: " << hash);
}
void
Logic::sendRecoveryInterest(ConstBufferPtr digest)
{
- _LOG_DEBUG_ID(">> Logic::sendRecoveryInterest");
+ CHRONO_LOG_DBG(">> Logic::sendRecoveryInterest");
Name interestName;
interestName.append(m_syncPrefix)
@@ -764,14 +763,14 @@
bind(&Logic::onRecoveryData, this, _1, _2),
bind(&Logic::onRecoveryTimeout, this, _1), // Nack
bind(&Logic::onRecoveryTimeout, this, _1));
- _LOG_DEBUG_ID("interest: " << interest.getName());
- _LOG_DEBUG_ID("<< Logic::sendRecoveryInterest");
+ CHRONO_LOG_DBG("interest: " << interest.getName());
+ CHRONO_LOG_DBG("<< Logic::sendRecoveryInterest");
}
void
Logic::processRecoveryInterest(const Interest& interest)
{
- _LOG_DEBUG_ID(">> Logic::processRecoveryInterest");
+ CHRONO_LOG_DBG(">> Logic::processRecoveryInterest");
Name name = interest.getName();
ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
@@ -779,30 +778,30 @@
auto stateIter = m_log.find(digest);
if (stateIter != m_log.end() || *digest == *EMPTY_DIGEST || *rootDigest == *digest) {
- _LOG_DEBUG_ID("I can help you recover");
+ CHRONO_LOG_DBG("I can help you recover");
sendSyncData(m_defaultUserPrefix, name, m_state);
return;
}
- _LOG_DEBUG_ID("<< Logic::processRecoveryInterest");
+ CHRONO_LOG_DBG("<< Logic::processRecoveryInterest");
}
void
Logic::onRecoveryData(const Interest& interest, const Data& data)
{
- _LOG_DEBUG_ID(">> Logic::onRecoveryData");
+ CHRONO_LOG_DBG(">> Logic::onRecoveryData");
m_pendingRecoveryInterests.erase(interest.getName()[-1].toUri());
onSyncDataValidated(data);
- _LOG_DEBUG_ID("<< Logic::onRecoveryData");
+ CHRONO_LOG_DBG("<< Logic::onRecoveryData");
}
void
Logic::onRecoveryTimeout(const Interest& interest)
{
- _LOG_DEBUG_ID(">> Logic::onRecoveryTimeout");
+ CHRONO_LOG_DBG(">> Logic::onRecoveryTimeout");
m_pendingRecoveryInterests.erase(interest.getName()[-1].toUri());
- _LOG_DEBUG_ID("Interest: " << interest.getName());
- _LOG_DEBUG_ID("<< Logic::onRecoveryTimeout");
+ CHRONO_LOG_DBG("Interest: " << interest.getName());
+ CHRONO_LOG_DBG("<< Logic::onRecoveryTimeout");
}
} // namespace chronosync