State: reset wire after adding names; fix tests when zlib is disabled
refs: #5083, #5077 Change-Id: I48f24ad53d676036f6b03cc0472be9bb5026016e
This commit is contained in:
1 parent
1c7cd5224f
commit
e23b53bd1b
10 files changed
+55
-22
No files matched your search
@@ -95,7 +95,7 @@ public:
|
||||
* @param scheme compression scheme to be used for the IBLT
|
||||
*/
|
||||
explicit
|
||||
IBLT(size_t expectedNumEntries, CompressionScheme scheme = CompressionScheme::ZLIB);
|
||||
IBLT(size_t expectedNumEntries, CompressionScheme scheme);
|
||||
|
||||
/**
|
||||
* @brief Populate the hash table using the vector representation of IBLT
|
||||
|
||||
@@ -31,6 +31,7 @@ State::State(const ndn::Block& block)
|
||||
void
|
||||
State::addContent(const ndn::Name& prefix)
|
||||
{
|
||||
m_wire.reset();
|
||||
m_content.emplace_back(prefix);
|
||||
}
|
||||
|
||||
@@ -79,6 +80,8 @@ State::wireDecode(const ndn::Block& wire)
|
||||
ndn::to_string(blockType)));
|
||||
}
|
||||
|
||||
m_content.clear();
|
||||
|
||||
wire.parse();
|
||||
m_wire = wire;
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
**/
|
||||
|
||||
#include "PSync/detail/util.hpp"
|
||||
#include "PSync/detail/config.hpp"
|
||||
|
||||
#include <ndn-cxx/encoding/buffer-stream.hpp>
|
||||
#include <ndn-cxx/util/backports.hpp>
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#ifndef PSYNC_UTIL_HPP
|
||||
#define PSYNC_UTIL_HPP
|
||||
|
||||
#include "PSync/detail/config.hpp"
|
||||
|
||||
#include <ndn-cxx/name.hpp>
|
||||
|
||||
#include <inttypes.h>
|
||||
@@ -54,7 +56,12 @@ enum class CompressionScheme {
|
||||
GZIP,
|
||||
BZIP2,
|
||||
LZMA,
|
||||
ZSTD
|
||||
ZSTD,
|
||||
#ifdef PSYNC_HAVE_ZLIB
|
||||
DEFAULT = ZLIB
|
||||
#else
|
||||
DEFAULT = NONE
|
||||
#endif
|
||||
};
|
||||
|
||||
std::shared_ptr<ndn::Buffer>
|
||||
|
||||
@@ -158,7 +158,7 @@ FullProducer::onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& i
|
||||
NDN_LOG_DEBUG("Full Sync Interest Received, nonce: " << interest.getNonce() <<
|
||||
", hash: " << std::hash<ndn::Name>{}(interestName));
|
||||
|
||||
IBLT iblt(m_expectedNumEntries);
|
||||
IBLT iblt(m_expectedNumEntries, m_ibltCompression);
|
||||
try {
|
||||
iblt.initialize(ibltName);
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ public:
|
||||
const UpdateCallback& onUpdateCallBack,
|
||||
ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFTIME,
|
||||
ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
|
||||
CompressionScheme ibltCompression = CompressionScheme::ZLIB,
|
||||
CompressionScheme contentCompression = CompressionScheme::ZLIB);
|
||||
CompressionScheme ibltCompression = CompressionScheme::DEFAULT,
|
||||
CompressionScheme contentCompression = CompressionScheme::DEFAULT);
|
||||
|
||||
~FullProducer();
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
|
||||
const ndn::Name& syncPrefix,
|
||||
const ndn::Name& userPrefix,
|
||||
ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
|
||||
CompressionScheme ibltCompression = CompressionScheme::ZLIB,
|
||||
CompressionScheme contentCompression = CompressionScheme::ZLIB);
|
||||
CompressionScheme ibltCompression = CompressionScheme::NONE,
|
||||
CompressionScheme contentCompression = CompressionScheme::NONE);
|
||||
public:
|
||||
/**
|
||||
* @brief Returns the current sequence number of the given prefix
|
||||
|
||||
@@ -398,16 +398,26 @@ BOOST_AUTO_TEST_CASE(DelayedSecondSegment)
|
||||
{
|
||||
addNode(0);
|
||||
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
Name prefixToPublish("userNode0-" + to_string(i));
|
||||
int i = 0;
|
||||
State state;
|
||||
|
||||
std::shared_ptr<ndn::Buffer> compressed;
|
||||
do {
|
||||
Name prefixToPublish("userNode0-" + to_string(i++));
|
||||
nodes[0]->addUserNode(prefixToPublish);
|
||||
nodes[0]->publishName(prefixToPublish);
|
||||
}
|
||||
|
||||
state.addContent(ndn::Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish]));
|
||||
|
||||
auto block = state.wireEncode();
|
||||
compressed = compress(nodes[0]->m_contentCompression, block.wire(), block.size());
|
||||
|
||||
} while (compressed->size() < (ndn::MAX_NDN_PACKET_SIZE >> 1));
|
||||
|
||||
advanceClocks(ndn::time::milliseconds(10), 100);
|
||||
|
||||
Name syncInterestName(syncPrefix);
|
||||
IBLT iblt(40);
|
||||
IBLT iblt(40, nodes[0]->m_ibltCompression);
|
||||
iblt.appendToName(syncInterestName);
|
||||
|
||||
nodes[0]->onSyncInterest(syncPrefix, Interest(syncInterestName));
|
||||
|
||||
+10
-10
@@ -34,8 +34,8 @@ BOOST_AUTO_TEST_CASE(Equal)
|
||||
{
|
||||
int size = 10;
|
||||
|
||||
IBLT iblt1(size);
|
||||
IBLT iblt2(size);
|
||||
IBLT iblt1(size, CompressionScheme::DEFAULT);
|
||||
IBLT iblt2(size, CompressionScheme::DEFAULT);
|
||||
BOOST_CHECK_EQUAL(iblt1, iblt2);
|
||||
|
||||
std::string prefix = Name("/test/memphis").appendNumber(1).toUri();
|
||||
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(NameAppendAndExtract)
|
||||
{
|
||||
int size = 10;
|
||||
|
||||
IBLT iblt(size);
|
||||
IBLT iblt(size, CompressionScheme::DEFAULT);
|
||||
std::string prefix = Name("/test/memphis").appendNumber(1).toUri();
|
||||
uint32_t newHash = murmurHash3(11, prefix);
|
||||
iblt.insert(newHash);
|
||||
@@ -63,12 +63,12 @@ BOOST_AUTO_TEST_CASE(NameAppendAndExtract)
|
||||
Name ibltName("sync");
|
||||
iblt.appendToName(ibltName);
|
||||
|
||||
IBLT rcvd(size);
|
||||
IBLT rcvd(size, CompressionScheme::DEFAULT);
|
||||
rcvd.initialize(ibltName.get(-1));
|
||||
|
||||
BOOST_CHECK_EQUAL(iblt, rcvd);
|
||||
|
||||
IBLT rcvdDiffSize(20);
|
||||
IBLT rcvdDiffSize(20, CompressionScheme::DEFAULT);
|
||||
BOOST_CHECK_THROW(rcvdDiffSize.initialize(ibltName.get(-1)), std::runtime_error);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(CopyInsertErase)
|
||||
{
|
||||
int size = 10;
|
||||
|
||||
IBLT iblt1(size);
|
||||
IBLT iblt1(size, CompressionScheme::DEFAULT);
|
||||
|
||||
std::string prefix = Name("/test/memphis").appendNumber(1).toUri();
|
||||
uint32_t hash1 = murmurHash3(11, prefix);
|
||||
@@ -105,8 +105,8 @@ BOOST_AUTO_TEST_CASE(HigherSeqTest)
|
||||
// Relevant to full sync case
|
||||
int size = 10;
|
||||
|
||||
IBLT ownIBF(size);
|
||||
IBLT rcvdIBF(size);
|
||||
IBLT ownIBF(size, CompressionScheme::DEFAULT);
|
||||
IBLT rcvdIBF(size, CompressionScheme::DEFAULT);
|
||||
|
||||
std::string prefix = Name("/test/memphis").appendNumber(3).toUri();
|
||||
uint32_t hash1 = murmurHash3(11, prefix);
|
||||
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(Difference)
|
||||
{
|
||||
int size = 10;
|
||||
|
||||
IBLT ownIBF(size);
|
||||
IBLT ownIBF(size, CompressionScheme::DEFAULT);
|
||||
|
||||
IBLT rcvdIBF = ownIBF;
|
||||
|
||||
@@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(DifferenceBwOversizedIBFs)
|
||||
|
||||
int size = 10;
|
||||
|
||||
IBLT ownIBF(size);
|
||||
IBLT ownIBF(size, CompressionScheme::DEFAULT);
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
std::string prefix = Name("/test/memphis" + std::to_string(i)).appendNumber(1).toUri();
|
||||
|
||||
@@ -74,6 +74,20 @@ BOOST_AUTO_TEST_CASE(EmptyContent)
|
||||
BOOST_CHECK_EQUAL(state2.getContent().size(), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ReEncode)
|
||||
{
|
||||
State state;
|
||||
state.addContent(ndn::Name("test1"));
|
||||
state.addContent(ndn::Name("test2"));
|
||||
|
||||
state.wireEncode();
|
||||
|
||||
state.addContent(ndn::Name("test3"));
|
||||
|
||||
State state2(state.wireEncode());
|
||||
BOOST_CHECK_EQUAL(state2.getContent().size(), 3);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
} // namespace psync
|
||||
Reference in new issue
Block a user