**breaking** use Name TLV-VALUE as input to murmurHash3

Previously the library was using Name URI string, which is not guaranteed
to be stable and unique.

refs #4838

Change-Id: Ic5e29f11f1320f95a754fb5def03faeb4d89cc01
This commit is contained in:
Junxiao Shi committed 2022-01-09 21:26:22 +00:00
1 parent e51936f8c6
commit 32ccfc4d1d
10 files changed
+67 -57

No files matched your search

+4 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -60,7 +60,7 @@ Consumer::addSubscription(const ndn::Name& prefix, uint64_t seqNo, bool callSync
} }
m_subscriptionList.emplace(prefix); m_subscriptionList.emplace(prefix);
m_bloomFilter.insert(prefix.toUri()); m_bloomFilter.insert(prefix);
if (callSyncDataCb && seqNo != 0) { if (callSyncDataCb && seqNo != 0) {
m_onUpdate({{prefix, seqNo, seqNo}}); m_onUpdate({{prefix, seqNo, seqNo}});
@@ -130,7 +130,7 @@ Consumer::onHelloData(const ndn::ConstBufferPtr& bufferPtr)
// Extract IBF from name which is the last element in hello data's name // Extract IBF from name which is the last element in hello data's name
m_iblt = m_helloDataName.getSubName(m_helloDataName.size() - 1, 1); m_iblt = m_helloDataName.getSubName(m_helloDataName.size() - 1, 1);
NDN_LOG_TRACE("m_iblt: " << std::hash<std::string>{}(m_iblt.toUri())); NDN_LOG_TRACE("m_iblt: " << std::hash<ndn::Name>{}(m_iblt));
detail::State state{ndn::Block(bufferPtr)}; detail::State state{ndn::Block(bufferPtr)};
std::vector<MissingDataInfo> updates; std::vector<MissingDataInfo> updates;
@@ -175,7 +175,7 @@ Consumer::sendSyncInterest()
ndn::Interest syncInterest(syncInterestName); ndn::Interest syncInterest(syncInterestName);
NDN_LOG_DEBUG("sendSyncInterest, nonce: " << syncInterest.getNonce() << NDN_LOG_DEBUG("sendSyncInterest, nonce: " << syncInterest.getNonce() <<
" hash: " << std::hash<std::string>{}(syncInterest.getName().toUri())); " hash: " << std::hash<ndn::Name>{}(syncInterest.getName()));
if (m_syncFetcher) { if (m_syncFetcher) {
m_syncFetcher->stop(); m_syncFetcher->stop();
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -250,7 +250,7 @@ BloomFilter::clear()
} }
void void
BloomFilter::insert(const std::string& key) BloomFilter::insert(const ndn::Name& key)
{ {
std::size_t bit_index = 0; std::size_t bit_index = 0;
std::size_t bit = 0; std::size_t bit = 0;
@@ -266,7 +266,7 @@ BloomFilter::insert(const std::string& key)
} }
bool bool
BloomFilter::contains(const std::string& key) const BloomFilter::contains(const ndn::Name& key) const
{ {
std::size_t bit_index = 0; std::size_t bit_index = 0;
std::size_t bit = 0; std::size_t bit = 0;
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -90,10 +90,10 @@ public:
clear(); clear();
void void
insert(const std::string& key); insert(const ndn::Name& key);
bool bool
contains(const std::string& key) const; contains(const ndn::Name& key) const;
private: private:
typedef uint32_t bloom_type; typedef uint32_t bloom_type;
+8 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -116,6 +116,13 @@ murmurHash3(const void* key, size_t len, uint32_t seed)
return h1; return h1;
} }
uint32_t
murmurHash3(uint32_t seed, const ndn::Name& name)
{
auto wire = name.wireEncode();
return murmurHash3(wire.value(), wire.value_size(), seed);
}
std::shared_ptr<ndn::Buffer> std::shared_ptr<ndn::Buffer>
compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize) compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize)
{ {
+6 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -32,11 +32,11 @@ namespace detail {
uint32_t uint32_t
murmurHash3(const void* key, size_t len, uint32_t seed); murmurHash3(const void* key, size_t len, uint32_t seed);
inline uint32_t /**
murmurHash3(uint32_t seed, const std::string& str) * @brief Compute 32-bit MurmurHash3 of Name TLV-VALUE.
{ */
return murmurHash3(str.data(), str.size(), seed); uint32_t
} murmurHash3(uint32_t seed, const ndn::Name& name);
inline uint32_t inline uint32_t
murmurHash3(uint32_t seed, uint32_t value) murmurHash3(uint32_t seed, uint32_t value)
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -207,7 +207,7 @@ FullProducer::onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& i
ndn::Name nameWithoutSeq = nameIt->second.getPrefix(-1); ndn::Name nameWithoutSeq = nameIt->second.getPrefix(-1);
// Don't sync up sequence number zero // Don't sync up sequence number zero
if (m_prefixes[nameWithoutSeq] != 0 && if (m_prefixes[nameWithoutSeq] != 0 &&
!isFutureHash(nameWithoutSeq.toUri(), negative)) { !isFutureHash(nameWithoutSeq, negative)) {
state.addContent(nameIt->second); state.addContent(nameIt->second);
} }
} }
@@ -355,7 +355,7 @@ bool
FullProducer::isFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative) FullProducer::isFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative)
{ {
auto nextHash = detail::murmurHash3(detail::N_HASHCHECK, auto nextHash = detail::murmurHash3(detail::N_HASHCHECK,
ndn::Name(prefix).appendNumber(m_prefixes[prefix] + 1).toUri()); ndn::Name(prefix).appendNumber(m_prefixes[prefix] + 1));
return negative.find(nextHash) != negative.end(); return negative.find(nextHash) != negative.end();
} }
+13 -10
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -29,6 +29,9 @@ namespace psync {
NDN_LOG_INIT(psync.PartialProducer); NDN_LOG_INIT(psync.PartialProducer);
const ndn::name::Component HELLO("hello");
const ndn::name::Component SYNC("sync");
PartialProducer::PartialProducer(size_t expectedNumEntries, PartialProducer::PartialProducer(size_t expectedNumEntries,
ndn::Face& face, ndn::Face& face,
const ndn::Name& syncPrefix, const ndn::Name& syncPrefix,
@@ -42,9 +45,9 @@ PartialProducer::PartialProducer(size_t expectedNumEntries,
{ {
m_registeredPrefix = m_face.registerPrefix(m_syncPrefix, m_registeredPrefix = m_face.registerPrefix(m_syncPrefix,
[this] (const ndn::Name& syncPrefix) { [this] (const ndn::Name& syncPrefix) {
m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("hello"), m_face.setInterestFilter(ndn::Name(m_syncPrefix).append(HELLO),
std::bind(&PartialProducer::onHelloInterest, this, _1, _2)); std::bind(&PartialProducer::onHelloInterest, this, _1, _2));
m_face.setInterestFilter(ndn::Name(m_syncPrefix).append("sync"), m_face.setInterestFilter(ndn::Name(m_syncPrefix).append(SYNC),
std::bind(&PartialProducer::onSyncInterest, this, _1, _2)); std::bind(&PartialProducer::onSyncInterest, this, _1, _2));
}, },
std::bind(&PartialProducer::onRegisterFailed, this, _1, _2)); std::bind(&PartialProducer::onRegisterFailed, this, _1, _2));
@@ -69,14 +72,14 @@ PartialProducer::publishName(const ndn::Name& prefix, ndn::optional<uint64_t> se
void void
PartialProducer::onHelloInterest(const ndn::Name& prefix, const ndn::Interest& interest) PartialProducer::onHelloInterest(const ndn::Name& prefix, const ndn::Interest& interest)
{ {
if (m_segmentPublisher.replyFromStore(interest.getName())) { const auto& name = interest.getName();
if (m_segmentPublisher.replyFromStore(name)) {
return; return;
} }
// Last component or fourth last component (in case of interest with version and segment) // Last component or fourth last component (in case of interest with version and segment)
// needs to be hello // needs to be hello
if (interest.getName().get(interest.getName().size()-1).toUri() != "hello" && if (name.get(name.size() - 1) != HELLO && name.get(name.size() - 4) != HELLO) {
interest.getName().get(interest.getName().size()-4).toUri() != "hello") {
return; return;
} }
@@ -103,7 +106,7 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in
} }
NDN_LOG_DEBUG("Sync Interest Received, nonce: " << interest.getNonce() << NDN_LOG_DEBUG("Sync Interest Received, nonce: " << interest.getNonce() <<
" hash: " << std::hash<std::string>{}(interest.getName().toUri())); " hash: " << std::hash<ndn::Name>{}(interest.getName()));
ndn::Name nameWithoutSyncPrefix = interest.getName().getSubName(prefix.size()); ndn::Name nameWithoutSyncPrefix = interest.getName().getSubName(prefix.size());
ndn::Name interestName; ndn::Name interestName;
@@ -173,7 +176,7 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in
for (const auto& hash : positive) { for (const auto& hash : positive) {
auto nameIt = m_biMap.left.find(hash); auto nameIt = m_biMap.left.find(hash);
if (nameIt != m_biMap.left.end()) { if (nameIt != m_biMap.left.end()) {
if (bf.contains(nameIt->second.getPrefix(-1).toUri())) { if (bf.contains(nameIt->second.getPrefix(-1))) {
// generate data // generate data
state.addContent(nameIt->second); state.addContent(nameIt->second);
NDN_LOG_DEBUG("Content: " << nameIt->second << " " << nameIt->first); NDN_LOG_DEBUG("Content: " << nameIt->second << " " << nameIt->first);
@@ -227,8 +230,8 @@ PartialProducer::satisfyPendingSyncInterests(const ndn::Name& prefix) {
} }
detail::State state; detail::State state;
if (entry.bf.contains(prefix.toUri()) || positive.size() + negative.size() >= m_threshold) { if (entry.bf.contains(prefix) || positive.size() + negative.size() >= m_threshold) {
if (entry.bf.contains(prefix.toUri())) { if (entry.bf.contains(prefix)) {
state.addContent(ndn::Name(prefix).appendNumber(m_prefixes[prefix])); state.addContent(ndn::Name(prefix).appendNumber(m_prefixes[prefix]));
NDN_LOG_DEBUG("sending sync content " << prefix << " " << std::to_string(m_prefixes[prefix])); NDN_LOG_DEBUG("sending sync content " << prefix << " " << std::to_string(m_prefixes[prefix]));
} }
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -116,7 +116,7 @@ ProducerBase::updateSeqNo(const ndn::Name& prefix, uint64_t seq)
// Insert the new seq no in m_prefixes, m_biMap, and m_iblt // Insert the new seq no in m_prefixes, m_biMap, and m_iblt
it->second = seq; it->second = seq;
ndn::Name prefixWithSeq = ndn::Name(prefix).appendNumber(seq); ndn::Name prefixWithSeq = ndn::Name(prefix).appendNumber(seq);
auto newHash = detail::murmurHash3(detail::N_HASHCHECK, prefixWithSeq.toUri()); auto newHash = detail::murmurHash3(detail::N_HASHCHECK, prefixWithSeq);
m_biMap.insert({newHash, prefixWithSeq}); m_biMap.insert({newHash, prefixWithSeq});
m_iblt.insert(newHash); m_iblt.insert(newHash);
} }
+20 -20
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(Equal)
IBLT iblt2(size, CompressionScheme::DEFAULT); IBLT iblt2(size, CompressionScheme::DEFAULT);
BOOST_CHECK_EQUAL(iblt1, iblt2); BOOST_CHECK_EQUAL(iblt1, iblt2);
std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); auto prefix = Name("/test/memphis").appendNumber(1);
uint32_t newHash = murmurHash3(11, prefix); uint32_t newHash = murmurHash3(11, prefix);
iblt1.insert(newHash); iblt1.insert(newHash);
iblt2.insert(newHash); iblt2.insert(newHash);
@@ -54,17 +54,17 @@ static const uint8_t IBF[] = {
// Header // Header
0x08, 0xB4, 0x08, 0xB4,
// Uncompressed IBF // Uncompressed IBF
0x00, 0x00, 0x00, 0x01, 0xF6, 0xA7, 0x7A, 0xBA, 0x6B, 0xA3, 0x4D, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5C, 0x5B, 0xF2, 0x67,
0x42, 0x24, 0xEE, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5C, 0x5B, 0xF2, 0x67,
0x42, 0x24, 0xEE, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF6, 0xA7, 0x7A, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x6B, 0xA3, 0x4D, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x5B, 0xF2, 0x67, 0x42, 0x24, 0xEE, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xF6, 0xA7, 0x7A, 0xBA, 0x6B, 0xA3, 0x4D, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
}; };
@@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(NameAppendAndExtract)
const int size = 10; const int size = 10;
IBLT iblt(size, CompressionScheme::DEFAULT); IBLT iblt(size, CompressionScheme::DEFAULT);
auto prefix = Name("/test/memphis").appendNumber(1).toUri(); auto prefix = Name("/test/memphis").appendNumber(1);
auto hash = murmurHash3(11, prefix); auto hash = murmurHash3(11, prefix);
iblt.insert(hash); iblt.insert(hash);
@@ -110,18 +110,18 @@ BOOST_AUTO_TEST_CASE(CopyInsertErase)
IBLT iblt1(size, CompressionScheme::DEFAULT); IBLT iblt1(size, CompressionScheme::DEFAULT);
std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); auto prefix = Name("/test/memphis").appendNumber(1);
uint32_t hash1 = murmurHash3(11, prefix); uint32_t hash1 = murmurHash3(11, prefix);
iblt1.insert(hash1); iblt1.insert(hash1);
IBLT iblt2(iblt1); IBLT iblt2(iblt1);
iblt2.erase(hash1); iblt2.erase(hash1);
prefix = Name("/test/memphis").appendNumber(2).toUri(); prefix = Name("/test/memphis").appendNumber(2);
uint32_t hash3 = murmurHash3(11, prefix); uint32_t hash3 = murmurHash3(11, prefix);
iblt2.insert(hash3); iblt2.insert(hash3);
iblt1.erase(hash1); iblt1.erase(hash1);
prefix = Name("/test/memphis").appendNumber(5).toUri(); prefix = Name("/test/memphis").appendNumber(5);
uint32_t hash5 = murmurHash3(11, prefix); uint32_t hash5 = murmurHash3(11, prefix);
iblt1.insert(hash5); iblt1.insert(hash5);
@@ -141,11 +141,11 @@ BOOST_AUTO_TEST_CASE(HigherSeqTest)
IBLT ownIBF(size, CompressionScheme::DEFAULT); IBLT ownIBF(size, CompressionScheme::DEFAULT);
IBLT rcvdIBF(size, CompressionScheme::DEFAULT); IBLT rcvdIBF(size, CompressionScheme::DEFAULT);
std::string prefix = Name("/test/memphis").appendNumber(3).toUri(); auto prefix = Name("/test/memphis").appendNumber(3);
uint32_t hash1 = murmurHash3(11, prefix); uint32_t hash1 = murmurHash3(11, prefix);
ownIBF.insert(hash1); ownIBF.insert(hash1);
std::string prefix2 = Name("/test/memphis").appendNumber(4).toUri(); auto prefix2 = Name("/test/memphis").appendNumber(4);
uint32_t hash2 = murmurHash3(11, prefix2); uint32_t hash2 = murmurHash3(11, prefix2);
rcvdIBF.insert(hash2); rcvdIBF.insert(hash2);
@@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(Difference)
BOOST_CHECK_EQUAL(positive.size(), 0); BOOST_CHECK_EQUAL(positive.size(), 0);
BOOST_CHECK_EQUAL(negative.size(), 0); BOOST_CHECK_EQUAL(negative.size(), 0);
std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); auto prefix = Name("/test/memphis").appendNumber(1);
uint32_t newHash = murmurHash3(11, prefix); uint32_t newHash = murmurHash3(11, prefix);
ownIBF.insert(newHash); ownIBF.insert(newHash);
@@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(Difference)
BOOST_CHECK_EQUAL(positive.size(), 1); BOOST_CHECK_EQUAL(positive.size(), 1);
BOOST_CHECK_EQUAL(negative.size(), 0); BOOST_CHECK_EQUAL(negative.size(), 0);
prefix = Name("/test/csu").appendNumber(1).toUri(); prefix = Name("/test/csu").appendNumber(1);
newHash = murmurHash3(11, prefix); newHash = murmurHash3(11, prefix);
rcvdIBF.insert(newHash); rcvdIBF.insert(newHash);
@@ -204,14 +204,14 @@ BOOST_AUTO_TEST_CASE(DifferenceBwOversizedIBFs)
IBLT ownIBF(size, CompressionScheme::DEFAULT); IBLT ownIBF(size, CompressionScheme::DEFAULT);
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
std::string prefix = Name("/test/memphis" + std::to_string(i)).appendNumber(1).toUri(); auto prefix = Name("/test/memphis" + std::to_string(i)).appendNumber(1);
uint32_t newHash = murmurHash3(11, prefix); uint32_t newHash = murmurHash3(11, prefix);
ownIBF.insert(newHash); ownIBF.insert(newHash);
} }
IBLT rcvdIBF = ownIBF; IBLT rcvdIBF = ownIBF;
std::string prefix = Name("/test/ucla").appendNumber(1).toUri(); auto prefix = Name("/test/ucla").appendNumber(1);
uint32_t newHash = murmurHash3(11, prefix); uint32_t newHash = murmurHash3(11, prefix);
ownIBF.insert(newHash); ownIBF.insert(newHash);
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* -*- 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. * This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors. * See AUTHORS.md for complete list of PSync authors and contributors.
@@ -47,21 +47,21 @@ BOOST_AUTO_TEST_CASE(Basic)
BOOST_CHECK_EQUAL(producerBase.getSeqNo(userNode).value(), 0); BOOST_CHECK_EQUAL(producerBase.getSeqNo(userNode).value(), 0);
producerBase.updateSeqNo(userNode, 1); producerBase.updateSeqNo(userNode, 1);
BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()).value() == 1); BOOST_CHECK(producerBase.getSeqNo(userNode).value() == 1);
std::string prefixWithSeq = Name(userNode).appendNumber(1).toUri(); auto prefixWithSeq = Name(userNode).appendNumber(1);
uint32_t hash = producerBase.m_biMap.right.find(prefixWithSeq)->second; uint32_t hash = producerBase.m_biMap.right.find(prefixWithSeq)->second;
Name prefix(producerBase.m_biMap.left.find(hash)->second); Name prefix(producerBase.m_biMap.left.find(hash)->second);
BOOST_CHECK_EQUAL(prefix.getPrefix(-1), userNode); BOOST_CHECK_EQUAL(prefix.getPrefix(-1), userNode);
producerBase.removeUserNode(userNode); producerBase.removeUserNode(userNode);
BOOST_CHECK(producerBase.getSeqNo(userNode.toUri()) == nullopt); BOOST_CHECK(producerBase.getSeqNo(userNode) == nullopt);
BOOST_CHECK(producerBase.m_biMap.right.find(prefixWithSeq) == producerBase.m_biMap.right.end()); BOOST_CHECK(producerBase.m_biMap.right.find(prefixWithSeq) == producerBase.m_biMap.right.end());
BOOST_CHECK(producerBase.m_biMap.left.find(hash) == producerBase.m_biMap.left.end()); BOOST_CHECK(producerBase.m_biMap.left.find(hash) == producerBase.m_biMap.left.end());
Name nonExistentUserNode("/notAUser"); Name nonExistentUserNode("/notAUser");
producerBase.updateSeqNo(nonExistentUserNode, 1); producerBase.updateSeqNo(nonExistentUserNode, 1);
BOOST_CHECK(producerBase.m_biMap.right.find(Name(nonExistentUserNode).appendNumber(1).toUri()) == BOOST_CHECK(producerBase.m_biMap.right.find(Name(nonExistentUserNode).appendNumber(1)) ==
producerBase.m_biMap.right.end()); producerBase.m_biMap.right.end());
} }