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 @@ 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; } 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 @@ IBLT::listEntries(std::set& positive, std::set& 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 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 @@ 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 -compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize) +compress(CompressionScheme scheme, ndn::span buffer) { ndn::OBufferStream out; bio::filtering_streambuf 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(buffer), bufferSize)); + in.push(bio::array_source(reinterpret_cast(buffer.data()), buffer.size())); bio::copy(in, out); return out.buf(); } std::shared_ptr -decompress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize) +decompress(CompressionScheme scheme, ndn::span buffer) { ndn::OBufferStream out; bio::filtering_streambuf 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(buffer), bufferSize)); + in.push(bio::array_source(reinterpret_cast(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 - -#include +#include namespace psync { namespace detail { @@ -45,10 +44,10 @@ murmurHash3(uint32_t seed, uint32_t value) } std::shared_ptr -compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize); +compress(CompressionScheme scheme, ndn::span buffer); std::shared_ptr -decompress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize); +decompress(CompressionScheme scheme, ndn::span 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 @@ 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{}(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; 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 @@ 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(block.wire(), block.size()); + auto buf = std::make_shared(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(segmentName); - data->setContent(segmentBegin, segmentEnd - segmentBegin); + data->setContent(ndn::span(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; 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_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)); } 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 @@ 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); 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 @@ 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); } 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 @@ 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); } }