diff --git a/.jenkins.d/10-build.sh b/.jenkins.d/10-build.sh index 1528655..5fd152d 100755 --- a/.jenkins.d/10-build.sh +++ b/.jenkins.d/10-build.sh @@ -18,16 +18,16 @@ if [[ $JOB_NAME != *"code-coverage" && $JOB_NAME != *"limited-build" ]]; then # Cleanup ./waf --color=yes distclean - # Build in release mode without tests - ./waf --color=yes configure + # Build in release mode with examples + ./waf --color=yes configure --with-examples --with-compression ./waf --color=yes build # Cleanup ./waf --color=yes distclean fi -# Build in debug mode with tests and examples -./waf --color=yes configure --debug --with-tests --with-examples $ASAN $COVERAGE +# Build in debug mode with tests +./waf --color=yes configure --debug --with-tests $ASAN $COVERAGE ./waf --color=yes build # (tests will be run against the debug version) diff --git a/examples/chat-pubsub.cpp b/examples/chat-pubsub.cpp index fd4c1de..1bfad0d 100644 --- a/examples/chat-pubsub.cpp +++ b/examples/chat-pubsub.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2022 University of California, Los Angeles + * Copyright (c) 2012-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -14,12 +14,13 @@ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ +#include +#include #include #include #include #include -#include -#include + #include using namespace ndn::svs; @@ -33,7 +34,7 @@ struct Options class Program { public: - Program(const Options &options) + Program(const Options& options) : m_options(options) { // Use HMAC signing for Sync Interests @@ -46,8 +47,8 @@ class Program // Do not fetch publications older than 10 seconds SVSPubSubOptions opts; - opts.UseTimestamp = true; - opts.MaxPubAge = ndn::time::milliseconds(10000); + opts.useTimestamp = true; + opts.maxPubAge = ndn::time::seconds(10); // Create the Pub/Sub instance m_svsps = std::make_shared( @@ -58,7 +59,7 @@ class Program opts, secOpts); - std::cout << "SVS client starting:" << m_options.m_id << std::endl; + std::cout << "SVS client starting: " << m_options.m_id << std::endl; // Subscribe to all data packets with prefix /chat (the "topic") m_svsps->subscribe(ndn::Name("/chat"), [] (const auto& subData) @@ -79,23 +80,22 @@ class Program void run() { - // Begin processing face events in a separate thread - std::thread thread_svs([this] { face.processEvents(); }); + // Begin processing face events in a separate thread. + std::thread svsThread([this] { face.processEvents(); }); // Announce our presence. - // Note that the SVS-PS instance is thread-safe - std::string init_msg = "User " + m_options.m_id + " has joined the groupchat"; - publishMsg(init_msg); + // Note that the SVS-PS instance is thread-safe. + publishMsg("User " + m_options.m_id + " has joined the groupchat"); - // Read from stdin and publish messages - std::string userInput = ""; + // Read from stdin and publish messages. + std::string userInput; while (true) { std::getline(std::cin, userInput); publishMsg(userInput); } - // Wait for the SVS-PS thread to finish - thread_svs.join(); + // Wait for the SVS-PS thread to finish. + svsThread.join(); } protected: @@ -148,11 +148,12 @@ class Program ndn::KeyChain m_keyChain; }; -int main(int argc, char **argv) +int +main(int argc, char** argv) { if (argc != 2) { - std::cout << "Usage: client " << std::endl; - exit(1); + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return 1; } Options opt; @@ -161,5 +162,6 @@ int main(int argc, char **argv) Program program(opt); program.run(); + return 0; } diff --git a/examples/chat.cpp b/examples/chat.cpp index 906efb8..9904690 100644 --- a/examples/chat.cpp +++ b/examples/chat.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-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -30,7 +31,8 @@ struct Options class Program { public: - Program(const Options &options) : m_options(options) + Program(const Options& options) + : m_options(options) { // Use HMAC signing for Sync Interests // Note: this is not generally recommended, but is used here for simplicity @@ -39,35 +41,34 @@ class Program // Create the SVSync instance m_svs = std::make_shared( - ndn::Name(m_options.prefix), // Sync prefix, common for all nodes in the group - ndn::Name(m_options.m_id), // Unique data prefix for this node - face, // Shared NDN face - std::bind(&Program::onMissingData, this, _1), // Callback on learning new sequence numbers from SVS - securityOptions); // Security configuration + ndn::Name(m_options.prefix), // Sync prefix, common for all nodes in the group + ndn::Name(m_options.m_id), // Unique data prefix for this node + face, // Shared NDN face + std::bind(&Program::onMissingData, this, _1), // Callback on learning new sequence numbers from SVS + securityOptions); // Security configuration - std::cout << "SVS client starting:" << m_options.m_id << std::endl; + std::cout << "SVS client starting: " << m_options.m_id << std::endl; } void run() { - // Begin processing face events in a separate thread - std::thread thread_svs([this] { face.processEvents(); }); + // Begin processing face events in a separate thread. + std::thread svsThread([this] { face.processEvents(); }); // Announce our presence. - // Note that the SVSync instance is thread-safe - std::string init_msg = "User " + m_options.m_id + " has joined the groupchat"; - publishMsg(init_msg); + // Note that the SVSync instance is thread-safe. + publishMsg("User " + m_options.m_id + " has joined the groupchat"); - // Read from stdin and publish messages - std::string userInput = ""; + // Read from stdin and publish messages. + std::string userInput; while (true) { std::getline(std::cin, userInput); publishMsg(userInput); } - // Wait for the SVSync thread to finish on exit - thread_svs.join(); + // Wait for the SVSync thread to finish on exit. + svsThread.join(); } protected: @@ -85,12 +86,12 @@ class Program { // Request a single data packet using the SVSync API ndn::svs::NodeID nid = v[i].nodeId; - m_svs->fetchData(nid, s, [nid] (const ndn::Data& data) - { - const std::string content(reinterpret_cast(data.getContent().value()), - data.getContent().value_size()); - std::cout << data.getName() << " : " << content << std::endl; - }); + m_svs->fetchData(nid, s, [nid] (const auto& data) + { + std::string content(reinterpret_cast(data.getContent().value()), + data.getContent().value_size()); + std::cout << data.getName() << " : " << content << std::endl; + }); } } } @@ -99,11 +100,11 @@ class Program * Publish a string message to the SVSync group */ void - publishMsg(const std::string& msg) + publishMsg(std::string_view msg) { // Encode the message into a Content TLV block, which is what the SVSync API expects auto block = ndn::encoding::makeStringBlock(ndn::tlv::Content, msg); - m_svs->publishData(block, ndn::time::milliseconds(1000)); + m_svs->publishData(block, ndn::time::seconds(1)); } public: @@ -114,11 +115,11 @@ class Program }; int -main(int argc, char **argv) +main(int argc, char** argv) { if (argc != 2) { - std::cout << "Usage: client " << std::endl; - exit(1); + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return 1; } Options opt; @@ -127,5 +128,6 @@ main(int argc, char **argv) Program program(opt); program.run(); + return 0; } diff --git a/ndn-svs/core.cpp b/ndn-svs/core.cpp index 4b65543..92e09ae 100644 --- a/ndn-svs/core.cpp +++ b/ndn-svs/core.cpp @@ -17,16 +17,18 @@ #include "core.hpp" #include "tlv.hpp" -#include -#include #include #include +#include +#include + +#include #ifdef NDN_SVS_COMPRESSION -#include #include #include #include +#include #endif namespace ndn::svs { @@ -45,7 +47,8 @@ SVSyncCore::SVSyncCore(ndn::Face& face, , m_periodicSyncTime(30_s) , m_periodicSyncJitter(0.1) , m_rng(ndn::random::getRandomNumberEngine()) - , m_retxDist(m_periodicSyncTime.count() * (1.0 - m_periodicSyncJitter), m_periodicSyncTime.count() * (1.0 + m_periodicSyncJitter)) + , m_retxDist(m_periodicSyncTime.count() * (1.0 - m_periodicSyncJitter), + m_periodicSyncTime.count() * (1.0 + m_periodicSyncJitter)) , m_intrReplyDist(0, m_maxSuppressionTime.count()) , m_keyChainMem("pib-memory:", "tpm-memory:") , m_scheduler(m_face.getIoContext()) @@ -55,27 +58,23 @@ SVSyncCore::SVSyncCore(ndn::Face& face, m_face.setInterestFilter(syncPrefix, std::bind(&SVSyncCore::onSyncInterest, this, _2), std::bind(&SVSyncCore::sendInitialInterest, this), - [] (auto&&...) { - NDN_THROW(Error("Failed to register sync prefix")); - }); + [] (auto&&...) { NDN_THROW(Error("Failed to register sync prefix")); }); } -inline int +static inline int suppressionCurve(int constFactor, int value) { - /** - * This curve increases the probability that only one or a few - * nodes pick lower values for timers compared to other nodes. - * This leads to better suppression results. - * Increasing the curve factor makes the curve steeper => - * better for more nodes, but worse for fewer nodes. - */ + // This curve increases the probability that only one or a few + // nodes pick lower values for timers compared to other nodes. + // This leads to better suppression results. + // Increasing the curve factor makes the curve steeper => + // better for more nodes, but worse for fewer nodes. double c = constFactor; double v = value; double f = 10.0; // curve factor - return (int) (c * (1.0 - std::exp((v - c) / (c / f)))); + return static_cast(c * (1.0 - std::exp((v - c) / (c / f)))); } void @@ -83,14 +82,14 @@ SVSyncCore::sendInitialInterest() { // Wait for 100ms before sending the first sync interest // This is necessary to give other things time to initialize - m_scheduler.schedule(time::milliseconds(100), [this] { + m_scheduler.schedule(100_ms, [this] { m_initialized = true; retxSyncInterest(true, 0); }); } void -SVSyncCore::onSyncInterest(const Interest &interest) +SVSyncCore::onSyncInterest(const Interest& interest) { switch (m_securityOptions.interestSigner->signingInfo.getSignerType()) { @@ -106,7 +105,7 @@ SVSyncCore::onSyncInterest(const Interest &interest) return; default: - if (static_cast(m_securityOptions.validator)) + if (m_securityOptions.validator) m_securityOptions.validator->validate(interest, std::bind(&SVSyncCore::onSyncInterestValidated, this, _1), nullptr); @@ -117,9 +116,9 @@ SVSyncCore::onSyncInterest(const Interest &interest) } void -SVSyncCore::onSyncInterestValidated(const Interest &interest) +SVSyncCore::onSyncInterestValidated(const Interest& interest) { - const auto &n = interest.getName(); + const auto& n = interest.getName(); // Get incoming face uint64_t incomingFace = 0; @@ -137,22 +136,20 @@ SVSyncCore::onSyncInterestValidated(const Interest &interest) ndn::Block vvBlock = n.get(-2); // Decompress if necessary - if (vvBlock.type() == 211) { + if (vvBlock.type() == tlv::StateVectorLzma) { #ifdef NDN_SVS_COMPRESSION boost::iostreams::filtering_istreambuf in; in.push(boost::iostreams::lzma_decompressor()); in.push(boost::iostreams::array_source(reinterpret_cast(vvBlock.value()), vvBlock.value_size())); ndn::OBufferStream decompressed; boost::iostreams::copy(in, decompressed); - auto inner = ndn::Block::fromBuffer(decompressed.buf()); if (!std::get<0>(inner)) { - throw ndn::tlv::Error("Failed to decode inner block"); + NDN_THROW(ndn::tlv::Error("Failed to decode inner block")); } - vvBlock = std::get<1>(inner); #else - throw ndn::tlv::Error("SVS was compiled without compression support"); + NDN_THROW(ndn::tlv::Error("SVS was compiled without compression support")); #endif } @@ -181,7 +178,7 @@ SVSyncCore::onSyncInterestValidated(const Interest &interest) // Callback if missing data found if (!missingData.empty()) { - for (auto &e : missingData) + for (auto& e : missingData) e.incomingFace = incomingFace; m_onUpdate(missingData); } @@ -273,13 +270,12 @@ SVSyncCore::sendSyncInterest() in.push(boost::iostreams::array_source(reinterpret_cast(vvWire.data()), vvWire.size())); ndn::OBufferStream compressed; boost::iostreams::copy(in, compressed); - vvWire = ndn::Block(svs::tlv::StateVectorLzma, compressed.buf()); + vvWire = ndn::Block(tlv::StateVectorLzma, compressed.buf()); #endif syncName.append(Name::Component(vvWire)); - interest.setName(syncName); - interest.setInterestLifetime(time::milliseconds(1)); + interest.setInterestLifetime(1_ms); switch (m_securityOptions.interestSigner->signingInfo.getSignerType()) { @@ -299,7 +295,7 @@ SVSyncCore::sendSyncInterest() } std::tuple> -SVSyncCore::mergeStateVector(const VersionVector &vvOther) +SVSyncCore::mergeStateVector(const VersionVector& vvOther) { std::lock_guard lock(m_vvMutex); @@ -389,15 +385,16 @@ long SVSyncCore::getCurrentTime() const { return std::chrono::duration_cast( - m_steadyClock.now().time_since_epoch()).count(); + std::chrono::steady_clock::now().time_since_epoch()).count(); } bool -SVSyncCore::recordVector(const VersionVector &vvOther) +SVSyncCore::recordVector(const VersionVector& vvOther) { std::lock_guard lock(m_recordedVvMutex); - if (!m_recordedVv) return false; + if (!m_recordedVv) + return false; std::lock_guard lock1(m_vvMutex); @@ -417,7 +414,7 @@ SVSyncCore::recordVector(const VersionVector &vvOther) } void -SVSyncCore::enterSuppressionState(const VersionVector &vvOther) +SVSyncCore::enterSuppressionState(const VersionVector& vvOther) { std::lock_guard lock(m_recordedVvMutex); diff --git a/ndn-svs/core.hpp b/ndn-svs/core.hpp index f3b4a03..43b88bd 100644 --- a/ndn-svs/core.hpp +++ b/ndn-svs/core.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2022 University of California, Los Angeles + * Copyright (c) 2012-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -25,7 +25,6 @@ #include #include -#include #include namespace ndn::svs { @@ -128,11 +127,13 @@ class SVSyncCore : noncopyable using RecvExtraBlockCallback = std::function; /** - * @brief Callback to get extra data block for sync interest - * The version vector will be locked during the duration of this callback, - * so it must return FAST - */ - void setGetExtraBlockCallback(const GetExtraBlockCallback& callback) + * @brief Callback to get extra data block for sync interest. + * + * The version vector will be locked during the duration of this callback, + * so it must return FAST! + */ + void + setGetExtraBlockCallback(const GetExtraBlockCallback& callback) { m_getExtraBlock = callback; } @@ -141,7 +142,8 @@ class SVSyncCore : noncopyable * @brief Callback on receiving extra data in a sync interest. * Will be called BEFORE the interest is processed. */ - void setRecvExtraBlockCallback(const RecvExtraBlockCallback& callback) + void + setRecvExtraBlockCallback(const RecvExtraBlockCallback& callback) { m_recvExtraBlock = callback; } @@ -162,10 +164,10 @@ class SVSyncCore : noncopyable NDN_SVS_PUBLIC_WITH_TESTS_ELSE_PRIVATE: void - onSyncInterest(const Interest &interest); + onSyncInterest(const Interest& interest); void - onSyncInterestValidated(const Interest &interest); + onSyncInterestValidated(const Interest& interest); /** * @brief Mark the instance as initialized and send the first interest @@ -211,7 +213,7 @@ class SVSyncCore : noncopyable * @returns if recorded successfully */ bool - recordVector(const VersionVector &vvOther); + recordVector(const VersionVector& vvOther); /** * @brief Enter suppression state by setting @@ -222,7 +224,7 @@ class SVSyncCore : noncopyable * @param vvOther first vector to record */ void - enterSuppressionState(const VersionVector &vvOther); + enterSuppressionState(const VersionVector& vvOther); /// @brief Reference to scheduler ndn::Scheduler& @@ -284,8 +286,6 @@ class SVSyncCore : noncopyable scheduler::ScopedEventId m_retxEvent; scheduler::ScopedEventId m_packetEvent; - std::chrono::steady_clock m_steadyClock; - // Time at which the next sync interest will be sent std::atomic_long m_nextSyncInterest; diff --git a/ndn-svs/mapping-provider.cpp b/ndn-svs/mapping-provider.cpp index 2bd6d56..6895967 100644 --- a/ndn-svs/mapping-provider.cpp +++ b/ndn-svs/mapping-provider.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2022 University of California, Los Angeles + * Copyright (c) 2012-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -141,7 +141,7 @@ MappingProvider::onMappingQuery(const Interest& interest) Data data(interest.getName()); data.setContent(queryResponse.encode()); - data.setFreshnessPeriod(ndn::time::milliseconds(1000)); + data.setFreshnessPeriod(1_s); m_securityOptions.dataSigner->sign(data); m_face.put(data); } @@ -163,9 +163,9 @@ MappingProvider::fetchNameMapping(const MissingDataInfo& info, { Name queryName = getMappingQueryDataName(info); Interest interest(queryName); - interest.setMustBeFresh(false); interest.setCanBePrefix(false); - interest.setInterestLifetime(ndn::time::milliseconds(2000)); + interest.setMustBeFresh(false); + interest.setInterestLifetime(2_s); auto onDataValidated = [this, onValidated, info] (const Data& data) { @@ -195,7 +195,10 @@ MappingProvider::fetchNameMapping(const MissingDataInfo& info, Name MappingProvider::getMappingQueryDataName(const MissingDataInfo& info) { - return Name(info.nodeId).append(m_syncPrefix).append("MAPPING").appendNumber(info.low).appendNumber(info.high); + return Name(info.nodeId).append(m_syncPrefix) + .append("MAPPING") + .appendNumber(info.low) + .appendNumber(info.high); } MissingDataInfo diff --git a/ndn-svs/svspubsub.cpp b/ndn-svs/svspubsub.cpp index 2fcb8ca..30c0e4e 100644 --- a/ndn-svs/svspubsub.cpp +++ b/ndn-svs/svspubsub.cpp @@ -18,6 +18,8 @@ #include +#include + namespace ndn::svs { SVSPubSub::SVSPubSub(const Name& syncPrefix, @@ -106,7 +108,7 @@ SVSPubSub::insertMapping(const NodeID& nid, SeqNo seqNo, const Name& name, // this way we can add well-known mappings to the list // add timestamp block - if (m_opts.UseTimestamp) { + if (m_opts.useTimestamp) { unsigned long now = std::chrono::duration_cast (std::chrono::system_clock::now().time_since_epoch()).count(); @@ -150,7 +152,7 @@ SVSPubSub::subscribeToProducer(const Name& nodePrefix, const SubscriptionCallbac void SVSPubSub::unsubscribe(uint32_t handle) { - auto unsub = [](uint32_t handle, std::vector subs) + auto unsub = [handle](std::vector subs) { for (size_t i = 0; i < subs.size(); i++) { @@ -162,12 +164,12 @@ SVSPubSub::unsubscribe(uint32_t handle) } }; - unsub(handle, m_producerSubscriptions); - unsub(handle, m_prefixSubscriptions); + unsub(m_producerSubscriptions); + unsub(m_prefixSubscriptions); } void -SVSPubSub::updateCallbackInternal(const std::vector& info) +SVSPubSub::updateCallbackInternal(const std::vector& info) { for (const auto& stream : info) { @@ -248,7 +250,7 @@ SVSPubSub::processMapping(const NodeID& nodeId, SeqNo seqNo) auto mapping = m_mappingProvider.getMapping(nodeId, seqNo); // check if timestamp is too old - if (m_opts.MaxPubAge > time::milliseconds::zero()) + if (m_opts.maxPubAge > 0_ms) { // look for the additional timestamp block // if no timestamp block is present, we just skip this step @@ -262,7 +264,7 @@ SVSPubSub::processMapping(const NodeID& nodeId, SeqNo seqNo) (std::chrono::system_clock::now().time_since_epoch()).count(); unsigned long pubTime = Name::Component(block).toNumber(); - unsigned long maxAge = time::microseconds(m_opts.MaxPubAge).count(); + unsigned long maxAge = time::microseconds(m_opts.maxPubAge).count(); if (now - pubTime > maxAge) return false; @@ -368,7 +370,7 @@ SVSPubSub::onSyncData(const Data& firstData, const std::pair& publi auto innerName = Data(block.elements()[0]).getName().getPrefix(-2); // Function to send final buffer to subscriptions if possible - auto sendFinalBuffer = [this, innerName, publication, finalBuffer, bufSize, numFailed, numValidated, numElem] () + auto sendFinalBuffer = [this, innerName, publication, finalBuffer, bufSize, numFailed, numValidated, numElem] { if (*numValidated + *numFailed != numElem) return; diff --git a/ndn-svs/svspubsub.hpp b/ndn-svs/svspubsub.hpp index df84da6..941d4da 100644 --- a/ndn-svs/svspubsub.hpp +++ b/ndn-svs/svspubsub.hpp @@ -37,16 +37,18 @@ struct SVSPubSubOptions /** * @brief Send publication timestamp in mapping blocks. + * * This option should be enabled in all instances for - * correct usage of the MaxPubAge option. + * correct usage of the maxPubAge option. */ - bool UseTimestamp = true; + bool useTimestamp = true; /** * @brief Maximum age of publications to be fetched. - * The UseTimestamp option should be enabled for this to work. + * + * The useTimestamp option should be enabled for this to work. */ - time::milliseconds MaxPubAge = time::milliseconds::zero(); + time::milliseconds maxPubAge = 0_ms; }; /** @@ -72,7 +74,7 @@ class SVSPubSub : noncopyable const Name& nodePrefix, ndn::Face& face, UpdateCallback updateCallback, - const SVSPubSubOptions& options = SVSPubSubOptions(), + const SVSPubSubOptions& options = {}, const SecurityOptions& securityOptions = SecurityOptions::DEFAULT); virtual @@ -185,7 +187,7 @@ class SVSPubSub : noncopyable onSyncData(const Data& syncData, const std::pair& publication); void - updateCallbackInternal(const std::vector& info); + updateCallbackInternal(const std::vector& info); Block onGetExtraData(const VersionVector& vv); diff --git a/ndn-svs/svsync-base.cpp b/ndn-svs/svsync-base.cpp index c86fffb..c5dda36 100644 --- a/ndn-svs/svsync-base.cpp +++ b/ndn-svs/svsync-base.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2022 University of California, Los Angeles + * Copyright (c) 2012-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -16,7 +16,6 @@ #include "svsync-base.hpp" #include "store-memory.hpp" -#include "tlv.hpp" #include @@ -95,7 +94,7 @@ SVSyncBase::insertDataSegment(const Block& content, const ndn::time::millisecond } void -SVSyncBase::onDataInterest(const Interest &interest) +SVSyncBase::onDataInterest(const Interest& interest) { auto data = m_dataStore->find(interest); if (data != nullptr) @@ -122,7 +121,7 @@ SVSyncBase::fetchData(const NodeID& nid, const SeqNo& seqNo, Name interestName = getDataName(nid, seqNo); Interest interest(interestName); interest.setCanBePrefix(true); - interest.setInterestLifetime(ndn::time::milliseconds(2000)); + interest.setInterestLifetime(2_s); m_fetcher.expressInterest(interest, std::bind(&SVSyncBase::onDataValidated, this, _2, onValidated), diff --git a/ndn-svs/svsync-base.hpp b/ndn-svs/svsync-base.hpp index bc7644a..5e22a25 100644 --- a/ndn-svs/svsync-base.hpp +++ b/ndn-svs/svsync-base.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2022 University of California, Los Angeles + * Copyright (c) 2012-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -19,8 +19,8 @@ #include "core.hpp" #include "fetcher.hpp" -#include "store.hpp" #include "security-options.hpp" +#include "store.hpp" namespace ndn::svs { @@ -171,7 +171,7 @@ class SVSyncBase : noncopyable private: void - onDataInterest(const Interest &interest); + onDataInterest(const Interest& interest); void onDataValidated(const Data& data, diff --git a/ndn-svs/tlv.hpp b/ndn-svs/tlv.hpp index bf6f049..64eb9d1 100644 --- a/ndn-svs/tlv.hpp +++ b/ndn-svs/tlv.hpp @@ -1,15 +1,17 @@ #ifndef NDN_SVS_TLV_HPP #define NDN_SVS_TLV_HPP +#include + namespace ndn::svs::tlv { -enum { - StateVector = 201, - StateVectorEntry = 202, - SeqNo = 204, - MappingData = 205, - MappingEntry = 206, - StateVectorLzma = 211, +enum : uint32_t { + StateVector = 201, + StateVectorEntry = 202, + SeqNo = 204, + MappingData = 205, + MappingEntry = 206, + StateVectorLzma = 211, }; } // namespace ndn::svs::tlv diff --git a/tests/unit-tests/core.t.cpp b/tests/unit-tests/core.t.cpp index 83383fd..ec576db 100644 --- a/tests/unit-tests/core.t.cpp +++ b/tests/unit-tests/core.t.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-2023 University of California, Los Angeles * * This file is part of ndn-svs, synchronization library for distributed realtime * applications for NDN. @@ -18,31 +18,28 @@ #include "tests/boost-test.hpp" -namespace ndn { -namespace svs { -namespace test { +namespace ndn::tests { -struct TestCoreFixture +using namespace ndn::svs; + +class CoreFixture { - TestCoreFixture() +protected: + CoreFixture() : m_syncPrefix("/ndn/test") - , m_core(m_face, m_syncPrefix, std::bind(&TestCoreFixture::update, this, _1)) + , m_core(m_face, m_syncPrefix, [] (auto&&...) {}) { } +protected: Face m_face; Name m_syncPrefix; SVSyncCore m_core; - - void - update(const std::vector& v) - { - } }; -BOOST_FIXTURE_TEST_SUITE(TestCore, TestCoreFixture) +BOOST_FIXTURE_TEST_SUITE(TestCore, CoreFixture) -BOOST_AUTO_TEST_CASE(mergeStateVector) +BOOST_AUTO_TEST_CASE(MergeStateVector) { std::vector missingData; @@ -74,7 +71,7 @@ BOOST_AUTO_TEST_CASE(mergeStateVector) BOOST_CHECK_EQUAL(v.get("two"), 2); BOOST_CHECK_EQUAL(v.get("three"), 3); - BOOST_CHECK_EQUAL(missingData.size(), 1); + BOOST_REQUIRE_EQUAL(missingData.size(), 1); BOOST_CHECK_EQUAL(missingData[0].nodeId, "three"); BOOST_CHECK_EQUAL(missingData[0].low, 1); BOOST_CHECK_EQUAL(missingData[0].high, 3); @@ -82,6 +79,4 @@ BOOST_AUTO_TEST_CASE(mergeStateVector) BOOST_AUTO_TEST_SUITE_END() -} // namespace ndn -} // namespace ndn -} // namespace ndn +} // namespace ndn::tests diff --git a/tests/unit-tests/version-vector.t.cpp b/tests/unit-tests/version-vector.t.cpp index 326a525..f4fd111 100644 --- a/tests/unit-tests/version-vector.t.cpp +++ b/tests/unit-tests/version-vector.t.cpp @@ -19,23 +19,24 @@ #include "tests/boost-test.hpp" -namespace ndn { -namespace svs { -namespace test { +namespace ndn::tests { -class TestVersionVectorFixture +using namespace ndn::svs; + +class VersionVectorFixture { protected: - TestVersionVectorFixture() + VersionVectorFixture() { v.set("one", 1); v.set("two", 2); } +protected: VersionVector v; }; -BOOST_FIXTURE_TEST_SUITE(TestVersionVector, TestVersionVectorFixture) +BOOST_FIXTURE_TEST_SUITE(TestVersionVector, VersionVectorFixture) BOOST_AUTO_TEST_CASE(Get) { @@ -78,7 +79,7 @@ BOOST_AUTO_TEST_CASE(DecodeStatic) // Hex: CA0A070508036F6E65CC0101CA0A0705080374776FCC0102 constexpr std::string_view encoded{"\xCA\x0A\x07\x05\x08\x03\x6F\x6E\x65\xCC\x01\x01" "\xCA\x0A\x07\x05\x08\x03\x74\x77\x6F\xCC\x01\x02"}; - VersionVector dv(ndn::encoding::makeStringBlock(tlv::StateVector, encoded)); + VersionVector dv(ndn::encoding::makeStringBlock(svs::tlv::StateVector, encoded)); BOOST_CHECK_EQUAL(dv.get("one"), 1); BOOST_CHECK_EQUAL(dv.get("two"), 2); } @@ -103,6 +104,4 @@ BOOST_AUTO_TEST_CASE(Ordering) BOOST_AUTO_TEST_SUITE_END() -} // namespace ndn -} // namespace ndn -} // namespace ndn +} // namespace ndn::tests