build: migrate to C++17
Change-Id: Ic5c01274f62556764ea96fc232cf3d835c4ab659
diff --git a/src/detail/bzip2-helper.cpp b/src/detail/bzip2-helper.cpp
index 4c5617e..a774b50 100644
--- a/src/detail/bzip2-helper.cpp
+++ b/src/detail/bzip2-helper.cpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2021 University of California, Los Angeles
+ * Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -27,8 +27,7 @@
#include <ndn-cxx/encoding/buffer-stream.hpp>
-namespace chronosync {
-namespace bzip2 {
+namespace chronosync::bzip2 {
namespace bio = boost::iostreams;
@@ -56,5 +55,4 @@
return os.buf();
}
-} // namespace bzip2
-} // namespace chronosync
+} // namespace chronosync::bzip2
diff --git a/src/detail/bzip2-helper.hpp b/src/detail/bzip2-helper.hpp
index 47ff5ac..9eb966d 100644
--- a/src/detail/bzip2-helper.hpp
+++ b/src/detail/bzip2-helper.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2021 University of California, Los Angeles
+ * Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -22,8 +22,7 @@
#include <ndn-cxx/encoding/buffer.hpp>
-namespace chronosync {
-namespace bzip2 {
+namespace chronosync::bzip2 {
/**
* @brief Compress @p buffer of size @p bufferSize with bzip2
@@ -37,7 +36,6 @@
std::shared_ptr<ndn::Buffer>
decompress(const char* buffer, size_t bufferSize);
-} // namespace bzip2
-} // namespace chronosync
+} // namespace chronosync::bzip2
#endif // CHRONOSYNC_DETAIL_BZIP2_HELPER_HPP
diff --git a/src/detail/common.hpp b/src/detail/common.hpp
index dffd218..cb75626 100644
--- a/src/detail/common.hpp
+++ b/src/detail/common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2021 University of California, Los Angeles
+ * Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -65,9 +65,7 @@
using std::size_t;
using std::bind;
-using std::function;
using std::make_shared;
-using std::ref;
using std::shared_ptr;
using ndn::Block;
@@ -79,8 +77,9 @@
using ndn::security::ValidationError;
namespace name = ndn::name;
-namespace time = ndn::time;
namespace security = ndn::security;
+namespace time = ndn::time;
+using namespace ndn::time_literals;
} // namespace chronosync
diff --git a/src/detail/tlv.hpp b/src/detail/tlv.hpp
index 5f9bd31..2a4b9b1 100644
--- a/src/detail/tlv.hpp
+++ b/src/detail/tlv.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2021 University of California, Los Angeles
+ * Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -22,8 +22,7 @@
#ifndef CHRONOSYNC_DETAIL_TLV_HPP
#define CHRONOSYNC_DETAIL_TLV_HPP
-namespace chronosync {
-namespace tlv {
+namespace chronosync::tlv {
/**
* @brief Type value of sync reply related TLVs
@@ -35,7 +34,6 @@
SeqNo = 130, // 0x82
};
-} // namespace tlv
-} // namespace chronosync
+} // namespace chronosync::tlv
#endif // CHRONOSYNC_DETAIL_TLV_HPP
diff --git a/src/logic.cpp b/src/logic.cpp
index 05defbd..387690d 100644
--- a/src/logic.cpp
+++ b/src/logic.cpp
@@ -37,29 +37,15 @@
namespace chronosync {
-const uint8_t EMPTY_DIGEST_VALUE[] = {
+const std::vector<uint8_t> EMPTY_DIGEST{
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
};
-int Logic::s_instanceCounter = 0;
-
-const ndn::Name Logic::DEFAULT_NAME;
-const ndn::Name Logic::EMPTY_NAME;
-const std::shared_ptr<Validator> Logic::DEFAULT_VALIDATOR;
-const time::steady_clock::Duration Logic::DEFAULT_RESET_TIMER = time::seconds(0);
-const time::steady_clock::Duration Logic::DEFAULT_CANCEL_RESET_TIMER = time::milliseconds(500);
-const time::milliseconds Logic::DEFAULT_RESET_INTEREST_LIFETIME(1000);
-const time::milliseconds Logic::DEFAULT_SYNC_INTEREST_LIFETIME(1000);
-const time::milliseconds Logic::DEFAULT_SYNC_REPLY_FRESHNESS(1000);
-const time::milliseconds Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME(1000);
-
-const ConstBufferPtr Logic::EMPTY_DIGEST(new ndn::Buffer(EMPTY_DIGEST_VALUE, 32));
-const ndn::name::Component Logic::RESET_COMPONENT("reset");
-const ndn::name::Component Logic::RECOVERY_COMPONENT("recovery");
-
+const name::Component RESET_COMPONENT("reset");
+const name::Component RECOVERY_COMPONENT("recovery");
const size_t NDNLP_EXPECTED_OVERHEAD = 20;
/**
@@ -84,7 +70,7 @@
if (getenv("CHRONOSYNC_MAX_PACKET_SIZE") != nullptr) {
try {
- limit = ndn::clamp<size_t>(boost::lexical_cast<size_t>(getenv("CHRONOSYNC_MAX_PACKET_SIZE")),
+ limit = std::clamp<size_t>(boost::lexical_cast<size_t>(getenv("CHRONOSYNC_MAX_PACKET_SIZE")),
500, ndn::MAX_NDN_PACKET_SIZE);
}
catch (const boost::bad_lexical_cast&) {
@@ -104,8 +90,8 @@
const UpdateCallback& onUpdate,
const Name& defaultSigningId,
std::shared_ptr<Validator> validator,
- const time::steady_clock::Duration& resetTimer,
- const time::steady_clock::Duration& cancelResetTimer,
+ const time::steady_clock::duration& resetTimer,
+ const time::steady_clock::duration& cancelResetTimer,
const time::milliseconds& resetInterestLifetime,
const time::milliseconds& syncInterestLifetime,
const time::milliseconds& syncReplyFreshness,
@@ -129,7 +115,7 @@
, m_syncInterestLifetime(syncInterestLifetime)
, m_syncReplyFreshness(syncReplyFreshness)
, m_recoveryInterestLifetime(recoveryInterestLifetime)
- , m_validator(validator)
+ , m_validator(std::move(validator))
, m_instanceId(s_instanceCounter++)
{
CHRONO_LOG_DBG(">> Logic::Logic");
@@ -275,19 +261,16 @@
ConstBufferPtr previousRoot = m_state.getRootDigest();
printDigest(previousRoot);
- bool isInserted = false;
- bool isUpdated = false;
- SeqNo oldSeq;
- std::tie(isInserted, isUpdated, oldSeq) = m_state.update(node.sessionName, node.seqNo);
-
+ auto [isInserted, isUpdated, oldSeq] = m_state.update(node.sessionName, node.seqNo);
CHRONO_LOG_DBG("Insert: " << std::boolalpha << isInserted);
CHRONO_LOG_DBG("Updated: " << std::boolalpha << isUpdated);
+ (void)oldSeq; // silence "unused variable" warning with gcc 7
+
if (isInserted || isUpdated) {
DiffStatePtr commit = make_shared<DiffState>();
commit->update(node.sessionName, node.seqNo);
commit->setRootDigest(m_state.getRootDigest());
insertToDiffLog(commit, previousRoot);
-
satisfyPendingSyncInterests(prefix, commit);
}
}
@@ -445,7 +428,7 @@
}
// If the digest of incoming interest is an "empty" digest
- if (*digest == *EMPTY_DIGEST) {
+ if (*digest == EMPTY_DIGEST) {
CHRONO_LOG_DBG("Poor guy, he knows nothing");
sendSyncData(m_defaultUserPrefix, name, m_state);
return;
@@ -505,10 +488,7 @@
const Name& info = leaf->getSessionName();
SeqNo seq = leaf->getSeq();
- bool isInserted = false;
- bool isUpdated = false;
- SeqNo oldSeq;
- std::tie(isInserted, isUpdated, oldSeq) = m_state.update(info, seq);
+ auto [isInserted, isUpdated, oldSeq] = m_state.update(info, seq);
if (isInserted || isUpdated) {
commit->update(info, seq);
oldSeq++;
@@ -610,7 +590,7 @@
Name interestName;
interestName.append(m_syncPrefix)
- .append(ndn::name::Component(*m_state.getRootDigest()));
+ .append(name::Component(*m_state.getRootDigest()));
m_pendingSyncInterestName = interestName;
@@ -688,7 +668,7 @@
trimState(partialState, state, nExcludedStates);
finalizeReply(partialState);
- BOOST_ASSERT(state.getLeaves().size() != 0);
+ BOOST_ASSERT(!state.getLeaves().empty());
nExcludedStates *= 2;
}
@@ -746,7 +726,7 @@
Name interestName;
interestName.append(m_syncPrefix)
.append(RECOVERY_COMPONENT)
- .append(ndn::name::Component(*digest));
+ .append(name::Component(*digest));
Interest interest(interestName);
interest.setMustBeFresh(true);
@@ -771,7 +751,7 @@
ConstBufferPtr rootDigest = m_state.getRootDigest();
auto stateIter = m_log.find(digest);
- if (stateIter != m_log.end() || *digest == *EMPTY_DIGEST || *rootDigest == *digest) {
+ if (stateIter != m_log.end() || *digest == EMPTY_DIGEST || *rootDigest == *digest) {
CHRONO_LOG_DBG("I can help you recover");
sendSyncData(m_defaultUserPrefix, name, m_state);
return;
diff --git a/src/logic.hpp b/src/logic.hpp
index 1383ef2..b180ca0 100644
--- a/src/logic.hpp
+++ b/src/logic.hpp
@@ -70,7 +70,7 @@
* The parameter is a set of MissingDataInfo, of which each corresponds to
* a session that has changed its state.
*/
-using UpdateCallback = function<void(const std::vector<MissingDataInfo>&)>;
+using UpdateCallback = std::function<void(const std::vector<MissingDataInfo>&)>;
/**
* @brief Logic of ChronoSync
@@ -84,12 +84,15 @@
using std::runtime_error::runtime_error;
};
- static const time::steady_clock::Duration DEFAULT_RESET_TIMER;
- static const time::steady_clock::Duration DEFAULT_CANCEL_RESET_TIMER;
- static const time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME;
- static const time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME;
- static const time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS;
- static const time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME;
+ static inline const Name EMPTY_NAME;
+ static inline const Name DEFAULT_NAME;
+ static inline const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
+ static constexpr time::steady_clock::duration DEFAULT_RESET_TIMER = 0_ms;
+ static constexpr time::steady_clock::duration DEFAULT_CANCEL_RESET_TIMER = 500_ms;
+ static constexpr time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME = 1_s;
+ static constexpr time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME = 1_s;
+ static constexpr time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS = 1_s;
+ static constexpr time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME = 1_s;
/**
* @brief Constructor
@@ -114,8 +117,8 @@
const UpdateCallback& onUpdate,
const Name& defaultSigningId = DEFAULT_NAME,
std::shared_ptr<Validator> validator = DEFAULT_VALIDATOR,
- const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER,
- const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER,
+ const time::steady_clock::duration& resetTimer = DEFAULT_RESET_TIMER,
+ const time::steady_clock::duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER,
const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME,
const time::milliseconds& syncInterestLifetime = DEFAULT_SYNC_INTEREST_LIFETIME,
const time::milliseconds& syncReplyFreshness = DEFAULT_SYNC_REPLY_FRESHNESS,
@@ -442,17 +445,8 @@
void
onRecoveryTimeout(const Interest& interest);
-public:
- static const ndn::Name DEFAULT_NAME;
- static const ndn::Name EMPTY_NAME;
- static const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
-
private:
- using NodeList = std::unordered_map<ndn::Name, NodeInfo>;
-
- static const ConstBufferPtr EMPTY_DIGEST;
- static const ndn::name::Component RESET_COMPONENT;
- static const ndn::name::Component RECOVERY_COMPONENT;
+ using NodeList = std::unordered_map<Name, NodeInfo>;
// Communication
ndn::Face& m_face;
@@ -487,9 +481,9 @@
std::uniform_int_distribution<> m_rangeUniformRandom;
std::uniform_int_distribution<> m_reexpressionJitter;
/// @brief Timer to send next reset 0 for no reset
- time::steady_clock::Duration m_resetTimer;
+ time::steady_clock::duration m_resetTimer;
/// @brief Timer to cancel reset state
- time::steady_clock::Duration m_cancelResetTimer;
+ time::steady_clock::duration m_cancelResetTimer;
/// @brief Lifetime of reset interest
time::milliseconds m_resetInterestLifetime;
/// @brief Lifetime of sync interest
@@ -503,8 +497,8 @@
ndn::KeyChain m_keyChain;
std::shared_ptr<Validator> m_validator;
- int m_instanceId;
- static int s_instanceCounter;
+ const int m_instanceId;
+ static inline int s_instanceCounter = 0;
};
#ifdef CHRONOSYNC_WITH_TESTS
diff --git a/src/socket.cpp b/src/socket.cpp
index e2c8b66..820b0a0 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -30,10 +30,6 @@
namespace chronosync {
-const ndn::Name Socket::DEFAULT_NAME;
-const ndn::Name Socket::DEFAULT_PREFIX;
-const std::shared_ptr<Validator> Socket::DEFAULT_VALIDATOR;
-
Socket::Socket(const Name& syncPrefix,
const Name& userPrefix,
ndn::Face& face,
@@ -49,14 +45,16 @@
syncInterestLifetime, Logic::DEFAULT_SYNC_REPLY_FRESHNESS, Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME,
session)
, m_signingId(signingId)
- , m_validator(validator)
+ , m_validator(std::move(validator))
{
NDN_LOG_DEBUG(">> Socket::Socket");
+
if (m_userPrefix != DEFAULT_NAME)
m_registeredPrefixList[m_userPrefix] =
m_face.setInterestFilter(m_userPrefix,
[this] (auto&&... args) { onInterest(std::forward<decltype(args)>(args)...); },
[] (auto&&...) {});
+
NDN_LOG_DEBUG("<< Socket::Socket");
}
diff --git a/src/socket.hpp b/src/socket.hpp
index e7fb4ef..78e67d2 100644
--- a/src/socket.hpp
+++ b/src/socket.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2019 University of California, Los Angeles
+ * Copyright (c) 2012-2022 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -52,11 +52,7 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what)
- : std::runtime_error(what)
- {
- }
+ using std::runtime_error::runtime_error;
};
Socket(const Name& syncPrefix,
@@ -70,9 +66,8 @@
~Socket();
- using DataValidatedCallback = function<void(const Data&)>;
-
- using DataValidationErrorCallback = function<void(const Data&, const ValidationError& error)> ;
+ using DataValidatedCallback = std::function<void(const Data&)>;
+ using DataValidationErrorCallback = std::function<void(const Data&, const ValidationError& error)> ;
/**
* @brief Add a sync node under same logic
@@ -232,12 +227,12 @@
const ValidationError& error);
public:
- static const ndn::Name DEFAULT_NAME;
- static const ndn::Name DEFAULT_PREFIX;
- static const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
+ static inline const Name DEFAULT_NAME;
+ static inline const Name DEFAULT_PREFIX;
+ static inline const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
private:
- using RegisteredPrefixList = std::unordered_map<ndn::Name, ndn::RegisteredPrefixHandle>;
+ using RegisteredPrefixList = std::unordered_map<Name, ndn::RegisteredPrefixHandle>;
Name m_userPrefix;
ndn::Face& m_face;
diff --git a/src/state.cpp b/src/state.cpp
index 00df7b9..260d493 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -40,16 +40,16 @@
auto leaf = m_leaves.find(info);
if (leaf == m_leaves.end()) {
m_leaves.insert(make_shared<Leaf>(info, seq));
- return std::make_tuple(true, false, 0);
+ return {true, false, 0};
}
else {
if ((*leaf)->getSeq() == seq || seq < (*leaf)->getSeq()) {
- return std::make_tuple(false, false, 0);
+ return {false, false, 0};
}
SeqNo old = (*leaf)->getSeq();
m_leaves.modify(leaf, [seq] (LeafPtr& leaf) { leaf->setSeq(seq); } );
- return std::make_tuple(false, true, old);
+ return {false, true, old};
}
}
@@ -128,7 +128,7 @@
NDN_THROW(Error("The supplied block does not contain wire format"));
if (wire.type() != tlv::SyncReply)
- NDN_THROW(Error("Unexpected TLV type when decoding SyncReply: " + ndn::to_string(wire.type())));
+ NDN_THROW(Error("Unexpected TLV type when decoding SyncReply: " + std::to_string(wire.type())));
wire.parse();
m_wire = wire;