Convert to span and avoid deprecated ndn-cxx functions
Change-Id: I260639ef4c13e6a492b29d3b976cca0ae29876cb
This commit is contained in:
1 parent
85a73d2b75
commit
f6fd2fbd34
10 files changed
+34
-38
No files matched your search
@@ -127,7 +127,7 @@ private: // non-member operators
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 @@ IBLT::listEntries(std::set<uint32_t>& positive, std::set<uint32_t>& negative) co
|
||||
// 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 @@ IBLT::appendToName(ndn::Name& name) const
|
||||
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!"));
|
||||
|
||||
@@ -119,12 +119,12 @@ murmurHash3(const void* key, size_t len, uint32_t seed)
|
||||
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 @@ compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize)
|
||||
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 @@ decompress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize)
|
||||
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();
|
||||
|
||||
@@ -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 @@ murmurHash3(uint32_t seed, uint32_t value)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -184,7 +184,7 @@ FullProducer::onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& i
|
||||
// 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 @@ FullProducer::sendSyncData(const ndn::Name& name, const ndn::Block& block)
|
||||
// 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 @@ FullProducer::onSyncData(const ndn::Interest& interest, const ndn::ConstBufferPt
|
||||
|
||||
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 @@ FullProducer::satisfyPendingInterests()
|
||||
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;
|
||||
|
||||
@@ -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 @@ SegmentPublisher::publish(const ndn::Name& interestName, const ndn::Name& dataNa
|
||||
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 @@ SegmentPublisher::publish(const ndn::Name& interestName, const ndn::Name& dataNa
|
||||
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 @@ SegmentPublisher::publish(const ndn::Name& interestName, const ndn::Name& dataNa
|
||||
|
||||
// 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 @@ bool
|
||||
SegmentPublisher::replyFromStore(const ndn::Name& interestName)
|
||||
{
|
||||
auto it = m_ims.find(interestName);
|
||||
|
||||
if (it != nullptr) {
|
||||
m_face.put(*it);
|
||||
return true;
|
||||
|
||||
@@ -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_AUTO_TEST_CASE(OnSyncDataDecodeFailure)
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -476,7 +476,7 @@ BOOST_AUTO_TEST_CASE(DelayedSecondSegment)
|
||||
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);
|
||||
|
||||
+2
-3
@@ -97,9 +97,8 @@ BOOST_AUTO_TEST_CASE(NameAppendAndExtract)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
+6
-6
@@ -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 @@ BOOST_AUTO_TEST_CASE(Compression)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user