diff --git a/PSync/common.hpp b/PSync/common.hpp
new file mode 100644
index 0000000..d72198d
--- /dev/null
+++ b/PSync/common.hpp
@@ -0,0 +1,66 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2020, The University of Memphis
+ *
+ * This file is part of PSync.
+ * See AUTHORS.md for complete list of PSync authors and contributors.
+ *
+ * PSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * PSync, e.g., in COPYING.md file. If not, see .
+ */
+
+#ifndef PSYNC_COMMON_HPP
+#define PSYNC_COMMON_HPP
+
+#include "PSync/detail/config.hpp"
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+namespace psync {
+
+enum class CompressionScheme {
+ NONE,
+ ZLIB,
+ GZIP,
+ BZIP2,
+ LZMA,
+ ZSTD,
+#ifdef PSYNC_HAVE_ZLIB
+ DEFAULT = ZLIB
+#else
+ DEFAULT = NONE
+#endif
+};
+
+class CompressionError : public std::runtime_error
+{
+public:
+ using std::runtime_error::runtime_error;
+};
+
+struct MissingDataInfo
+{
+ ndn::Name prefix;
+ uint64_t lowSeq;
+ uint64_t highSeq;
+};
+
+using UpdateCallback = std::function&)>;
+
+} // namespace psync
+
+#endif // PSYNC_COMMON_HPP
diff --git a/PSync/consumer.cpp b/PSync/consumer.cpp
index 95e3f89..1b100cb 100644
--- a/PSync/consumer.cpp
+++ b/PSync/consumer.cpp
@@ -20,10 +20,8 @@
#include "PSync/consumer.hpp"
#include "PSync/detail/state.hpp"
-#include
#include
-
-#include
+#include
namespace psync {
@@ -37,19 +35,19 @@ Consumer::Consumer(const ndn::Name& syncPrefix,
double false_positive = 0.001,
ndn::time::milliseconds helloInterestLifetime,
ndn::time::milliseconds syncInterestLifetime)
- : m_face(face)
- , m_scheduler(m_face.getIoService())
- , m_syncPrefix(syncPrefix)
- , m_helloInterestPrefix(ndn::Name(m_syncPrefix).append("hello"))
- , m_syncInterestPrefix(ndn::Name(m_syncPrefix).append("sync"))
- , m_syncDataContentType(ndn::tlv::ContentType_Blob)
- , m_onReceiveHelloData(onReceiveHelloData)
- , m_onUpdate(onUpdate)
- , m_bloomFilter(count, false_positive)
- , m_helloInterestLifetime(helloInterestLifetime)
- , m_syncInterestLifetime(syncInterestLifetime)
- , m_rng(ndn::random::getRandomNumberEngine())
- , m_rangeUniformRandom(100, 500)
+ : m_face(face)
+ , m_scheduler(m_face.getIoService())
+ , m_syncPrefix(syncPrefix)
+ , m_helloInterestPrefix(ndn::Name(m_syncPrefix).append("hello"))
+ , m_syncInterestPrefix(ndn::Name(m_syncPrefix).append("sync"))
+ , m_syncDataContentType(ndn::tlv::ContentType_Blob)
+ , m_onReceiveHelloData(onReceiveHelloData)
+ , m_onUpdate(onUpdate)
+ , m_bloomFilter(count, false_positive)
+ , m_helloInterestLifetime(helloInterestLifetime)
+ , m_syncInterestLifetime(syncInterestLifetime)
+ , m_rng(ndn::random::getRandomNumberEngine())
+ , m_rangeUniformRandom(100, 500)
{
}
@@ -65,7 +63,7 @@ Consumer::addSubscription(const ndn::Name& prefix, uint64_t seqNo, bool callSync
m_bloomFilter.insert(prefix.toUri());
if (callSyncDataCb && seqNo != 0) {
- m_onUpdate({MissingDataInfo(prefix, seqNo, seqNo)});
+ m_onUpdate({{prefix, seqNo, seqNo}});
}
return true;
@@ -134,8 +132,7 @@ Consumer::onHelloData(const ndn::ConstBufferPtr& bufferPtr)
NDN_LOG_TRACE("m_iblt: " << std::hash{}(m_iblt.toUri()));
- State state{ndn::Block{bufferPtr}};
-
+ detail::State state{ndn::Block(bufferPtr)};
std::vector updates;
std::map availableSubscriptions;
@@ -148,7 +145,7 @@ Consumer::onHelloData(const ndn::ConstBufferPtr& bufferPtr)
// m_prefixes (see addSubscription). So [] operator is safe to use.
if (isSubscribed(prefix) && seq > m_prefixes[prefix]) {
// In case we are behind on this prefix and consumer is subscribed to it
- updates.emplace_back(prefix, m_prefixes[prefix] + 1, seq);
+ updates.push_back({prefix, m_prefixes[prefix] + 1, seq});
m_prefixes[prefix] = seq;
}
availableSubscriptions.emplace(prefix, seq);
@@ -233,8 +230,7 @@ Consumer::onSyncData(const ndn::ConstBufferPtr& bufferPtr)
// Extract IBF from sync data name which is the last component
m_iblt = m_syncDataName.getSubName(m_syncDataName.size() - 1, 1);
- State state{ndn::Block{bufferPtr}};
-
+ detail::State state{ndn::Block(bufferPtr)};
std::vector updates;
for (const auto& content : state) {
@@ -244,7 +240,7 @@ Consumer::onSyncData(const ndn::ConstBufferPtr& bufferPtr)
if (m_prefixes.find(prefix) == m_prefixes.end() || seq > m_prefixes[prefix]) {
// If this is just the next seq number then we had already informed the consumer about
// the previous sequence number and hence seq low and seq high should be equal to current seq
- updates.emplace_back(prefix, m_prefixes[prefix] + 1, seq);
+ updates.push_back({prefix, m_prefixes[prefix] + 1, seq});
m_prefixes[prefix] = seq;
}
// Else updates will be empty and consumer will not be notified.
diff --git a/PSync/consumer.hpp b/PSync/consumer.hpp
index 5f80d8e..3a695cb 100644
--- a/PSync/consumer.hpp
+++ b/PSync/consumer.hpp
@@ -20,9 +20,9 @@
#ifndef PSYNC_CONSUMER_HPP
#define PSYNC_CONSUMER_HPP
+#include "PSync/common.hpp"
#include "PSync/detail/access-specifiers.hpp"
#include "PSync/detail/bloom-filter.hpp"
-#include "PSync/detail/util.hpp"
#include
#include
@@ -31,14 +31,12 @@
#include
#include