Convert to span and avoid deprecated ndn-cxx functions
Change-Id: I260639ef4c13e6a492b29d3b976cca0ae29876cb
diff --git a/PSync/detail/bloom-filter.hpp b/PSync/detail/bloom-filter.hpp
index 9aa4e6f..8ed7028 100644
--- a/PSync/detail/bloom-filter.hpp
+++ b/PSync/detail/bloom-filter.hpp
@@ -127,7 +127,7 @@
friend std::ostream&
operator<<(std::ostream& os, const BloomFilter& bf)
{
- ndn::printHex(os, bf.bit_table_.data(), bf.bit_table_.size(), false);
+ ndn::printHex(os, bf.bit_table_, false);
return os;
}
diff --git a/PSync/detail/iblt.cpp b/PSync/detail/iblt.cpp
index 28cae11..b62b893 100644
--- a/PSync/detail/iblt.cpp
+++ b/PSync/detail/iblt.cpp
@@ -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.
@@ -158,7 +158,7 @@
// If any buckets for one of the hash functions is not empty,
// then we didn't peel them all:
for (const auto& entry : peeled.m_hashTable) {
- if (entry.isEmpty() != true) {
+ if (!entry.isEmpty()) {
return false;
}
}
@@ -203,14 +203,14 @@
std::memcpy(&table[(i * unitSize) + 8], &keyCheck, sizeof(keyCheck));
}
- auto compressed = compress(m_compressionScheme, table.data(), table.size());
+ auto compressed = compress(m_compressionScheme, table);
name.append(ndn::name::Component(std::move(compressed)));
}
std::vector<uint32_t>
IBLT::extractValueFromName(const ndn::name::Component& ibltName) const
{
- auto decompressedBuf = decompress(m_compressionScheme, ibltName.value(), ibltName.value_size());
+ auto decompressedBuf = decompress(m_compressionScheme, ibltName.value_bytes());
if (decompressedBuf->size() % 4 != 0) {
NDN_THROW(Error("Received IBF cannot be decompressed correctly!"));
diff --git a/PSync/detail/util.cpp b/PSync/detail/util.cpp
index 3e58d77..9a3e5cf 100644
--- a/PSync/detail/util.cpp
+++ b/PSync/detail/util.cpp
@@ -119,12 +119,12 @@
uint32_t
murmurHash3(uint32_t seed, const ndn::Name& name)
{
- auto wire = name.wireEncode();
+ const auto& wire = name.wireEncode();
return murmurHash3(wire.value(), wire.value_size(), seed);
}
std::shared_ptr<ndn::Buffer>
-compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize)
+compress(CompressionScheme scheme, ndn::span<const uint8_t> buffer)
{
ndn::OBufferStream out;
bio::filtering_streambuf<bio::input> in;
@@ -173,14 +173,14 @@
case CompressionScheme::NONE:
break;
}
- in.push(bio::array_source(reinterpret_cast<const char*>(buffer), bufferSize));
+ in.push(bio::array_source(reinterpret_cast<const char*>(buffer.data()), buffer.size()));
bio::copy(in, out);
return out.buf();
}
std::shared_ptr<ndn::Buffer>
-decompress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize)
+decompress(CompressionScheme scheme, ndn::span<const uint8_t> buffer)
{
ndn::OBufferStream out;
bio::filtering_streambuf<bio::input> in;
@@ -229,7 +229,7 @@
case CompressionScheme::NONE:
break;
}
- in.push(bio::array_source(reinterpret_cast<const char*>(buffer), bufferSize));
+ in.push(bio::array_source(reinterpret_cast<const char*>(buffer.data()), buffer.size()));
bio::copy(in, out);
return out.buf();
diff --git a/PSync/detail/util.hpp b/PSync/detail/util.hpp
index 9f6676d..cf405f8 100644
--- a/PSync/detail/util.hpp
+++ b/PSync/detail/util.hpp
@@ -23,8 +23,7 @@
#include "PSync/common.hpp"
#include <ndn-cxx/encoding/buffer.hpp>
-
-#include <string>
+#include <ndn-cxx/util/span.hpp>
namespace psync {
namespace detail {
@@ -45,10 +44,10 @@
}
std::shared_ptr<ndn::Buffer>
-compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize);
+compress(CompressionScheme scheme, ndn::span<const uint8_t> buffer);
std::shared_ptr<ndn::Buffer>
-decompress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize);
+decompress(CompressionScheme scheme, ndn::span<const uint8_t> buffer);
} // namespace detail
} // namespace psync
diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp
index ca2ee5a..8e62a22 100644
--- a/PSync/full-producer.cpp
+++ b/PSync/full-producer.cpp
@@ -184,7 +184,7 @@
// Send all data if greater then threshold, else send positive below as usual
// Or send if we can't get neither positive nor negative differences
if (positive.size() + negative.size() >= m_threshold ||
- (positive.size() == 0 && negative.size() == 0)) {
+ (positive.empty() && negative.empty())) {
detail::State state;
for (const auto& content : m_prefixes) {
if (content.second != 0) {
@@ -245,7 +245,7 @@
// TODO: Remove appending of hash - serves no purpose to the receiver
ndn::Name dataName(ndn::Name(name).appendNumber(std::hash<ndn::Name>{}(nameWithIblt)));
- auto content = detail::compress(m_contentCompression, block.wire(), block.size());
+ auto content = detail::compress(m_contentCompression, block);
// checking if our own interest got satisfied
if (m_outstandingInterestName == name) {
@@ -278,7 +278,7 @@
detail::State state;
try {
- auto decompressed = detail::decompress(m_contentCompression, bufferPtr->data(), bufferPtr->size());
+ auto decompressed = detail::decompress(m_contentCompression, *bufferPtr);
state.wireDecode(ndn::Block(std::move(decompressed)));
}
catch (const std::exception& e) {
@@ -330,7 +330,7 @@
if (!diff.listEntries(positive, negative)) {
NDN_LOG_TRACE("Decode failed for pending interest");
if (positive.size() + negative.size() >= m_threshold ||
- (positive.size() == 0 && negative.size() == 0)) {
+ (positive.empty() && negative.empty())) {
NDN_LOG_TRACE("pos + neg > threshold or no diff can be found, erase pending interest");
it = m_pendingEntries.erase(it);
continue;
diff --git a/PSync/segment-publisher.cpp b/PSync/segment-publisher.cpp
index 1bdc981..5d42b88 100644
--- a/PSync/segment-publisher.cpp
+++ b/PSync/segment-publisher.cpp
@@ -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.
@@ -36,7 +36,7 @@
const ndn::Block& block, ndn::time::milliseconds freshness,
const ndn::security::SigningInfo& signingInfo)
{
- auto buf = std::make_shared<const ndn::Buffer>(block.wire(), block.size());
+ auto buf = std::make_shared<const ndn::Buffer>(block.begin(), block.end());
publish(interestName, dataName, buf, freshness, signingInfo);
}
@@ -55,8 +55,7 @@
const uint8_t* segmentBegin = rawBuffer;
const uint8_t* end = rawBuffer + buffer->size();
- size_t maxPacketSize = (ndn::MAX_NDN_PACKET_SIZE >> 1);
-
+ const size_t maxPacketSize = ndn::MAX_NDN_PACKET_SIZE >> 1;
uint64_t totalSegments = buffer->size() / maxPacketSize;
ndn::Name segmentPrefix(dataName);
@@ -74,14 +73,14 @@
// We get a std::exception: bad_weak_ptr from m_ims if we don't use shared_ptr for data
auto data = std::make_shared<ndn::Data>(segmentName);
- data->setContent(segmentBegin, segmentEnd - segmentBegin);
+ data->setContent(ndn::span<const uint8_t>(segmentBegin, segmentEnd));
data->setFreshnessPeriod(freshness);
data->setFinalBlock(ndn::name::Component::fromSegment(totalSegments));
- segmentBegin = segmentEnd;
-
m_keyChain.sign(*data, signingInfo);
+ segmentBegin = segmentEnd;
+
// Put on face only the segment which has a pending interest
// otherwise the segment is unsolicited
if (interestSegment == segmentNo) {
@@ -99,7 +98,6 @@
SegmentPublisher::replyFromStore(const ndn::Name& interestName)
{
auto it = m_ims.find(interestName);
-
if (it != nullptr) {
m_face.put(*it);
return true;
diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp
index f2c4a13..1ea3119 100644
--- a/tests/test-full-producer.cpp
+++ b/tests/test-full-producer.cpp
@@ -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.
@@ -80,7 +80,7 @@
BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, badCompress));
const uint8_t test[] = {'t', 'e', 's', 't'};
- auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test, sizeof(test));
+ auto goodCompressBadBlock = detail::compress(node.m_contentCompression, test);
BOOST_CHECK_NO_THROW(node.onSyncData(syncInterest, goodCompressBadBlock));
}
diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp
index 8aa9c8e..d3d9e03 100644
--- a/tests/test-full-sync.cpp
+++ b/tests/test-full-sync.cpp
@@ -476,7 +476,7 @@
state.addContent(Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish]));
auto block = state.wireEncode();
- compressed = detail::compress(nodes[0]->m_contentCompression, block.wire(), block.size());
+ compressed = detail::compress(nodes[0]->m_contentCompression, block);
} while (compressed->size() < (ndn::MAX_NDN_PACKET_SIZE >> 1));
advanceClocks(10_ms, 100);
diff --git a/tests/test-iblt.cpp b/tests/test-iblt.cpp
index b2f4d3e..1f00564 100644
--- a/tests/test-iblt.cpp
+++ b/tests/test-iblt.cpp
@@ -97,9 +97,8 @@
Name malformedName("/test");
auto compressed = compress(CompressionScheme::DEFAULT,
- malformedName.wireEncode().value(),
- malformedName.wireEncode().value_size());
- malformedName.append(compressed->data(), compressed->size());
+ malformedName.wireEncode().value_bytes());
+ malformedName.append(name::Component(std::move(compressed)));
IBLT rcvd2(size, CompressionScheme::DEFAULT);
BOOST_CHECK_THROW(rcvd2.initialize(malformedName.at(-1)), IBLT::Error);
}
diff --git a/tests/test-util.cpp b/tests/test-util.cpp
index e37957a..8020fe4 100644
--- a/tests/test-util.cpp
+++ b/tests/test-util.cpp
@@ -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.
@@ -56,14 +56,14 @@
const uint8_t uncompressed[] = {'t', 'e', 's', 't'};
for (const auto& s : supported) {
- BOOST_CHECK_NO_THROW(compress(s, uncompressed, sizeof(uncompressed)));
- auto compressed = compress(s, uncompressed, sizeof(uncompressed));
- BOOST_CHECK_NO_THROW(decompress(s, compressed->data(), compressed->size()));
+ BOOST_CHECK_NO_THROW(compress(s, uncompressed));
+ auto compressed = compress(s, uncompressed);
+ BOOST_CHECK_NO_THROW(decompress(s, *compressed));
}
for (const auto& s : notSupported) {
- BOOST_CHECK_THROW(compress(s, uncompressed, sizeof(uncompressed)), CompressionError);
- BOOST_CHECK_THROW(decompress(s, uncompressed, sizeof(uncompressed)), CompressionError);
+ BOOST_CHECK_THROW(compress(s, uncompressed), CompressionError);
+ BOOST_CHECK_THROW(decompress(s, uncompressed), CompressionError);
}
}