Skip to content

Commit

Permalink
full-producer*: fix compilation
Browse files Browse the repository at this point in the history
Fix some code style issues

Change-Id: I718241514bc05516ba18910e57fa6f49e0ad6602
  • Loading branch information
agawande committed Jul 13, 2019
1 parent a9e143d commit 8fa2a98
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 54 deletions.
16 changes: 8 additions & 8 deletions PSync/detail/user-prefixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

#include <ndn-cxx/util/logger.hpp>
#include "PSync/detail/user-prefixes.hpp"
#include <ndn-cxx/util/logger.hpp>

namespace psync {

Expand All @@ -28,7 +28,7 @@ bool
UserPrefixes::addUserNode(const ndn::Name& prefix)
{
if (!isUserNode(prefix)) {
m_prefixes[prefix] = 0;
prefixes[prefix] = 0;
return true;
}
else {
Expand All @@ -39,9 +39,9 @@ UserPrefixes::addUserNode(const ndn::Name& prefix)
void
UserPrefixes::removeUserNode(const ndn::Name& prefix)
{
auto it = m_prefixes.find(prefix);
if (it != m_prefixes.end()) {
m_prefixes.erase(it);
auto it = prefixes.find(prefix);
if (it != prefixes.end()) {
prefixes.erase(it);
}
}

Expand All @@ -52,12 +52,12 @@ UserPrefixes::updateSeqNo
oldSeqNo = 0;
NDN_LOG_DEBUG("UpdateSeq: " << prefix << " " << seqNo);

auto it = m_prefixes.find(prefix);
if (it != m_prefixes.end()) {
auto it = prefixes.find(prefix);
if (it != prefixes.end()) {
oldSeqNo = it->second;
}
else {
NDN_LOG_WARN("Prefix not found in m_prefixes");
NDN_LOG_WARN("Prefix not found in prefixes");
return false;
}

Expand Down
24 changes: 12 additions & 12 deletions PSync/detail/user-prefixes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace psync {

/**
* @brief UserPrefixes holds the m_prefixes map from prefix to sequence number,
* @brief UserPrefixes holds the prefixes map from prefix to sequence number,
* used by PartialProducer and FullProducer.
*
* Contains code common to both
Expand All @@ -35,15 +35,15 @@ class UserPrefixes
{
public:
/**
* @brief Check if the prefix is in m_prefixes.
* @brief Check if the prefix is in prefixes.
*
* @param prefix The prefix to check.
* @return True if the prefix is in m_prefixes.
* @return True if the prefix is in prefixes.
*/
bool
isUserNode(const ndn::Name& prefix) const
{
return m_prefixes.find(prefix) != m_prefixes.end();
return prefixes.find(prefix) != prefixes.end();
}

/**
Expand All @@ -54,8 +54,8 @@ class UserPrefixes
ndn::optional<uint64_t>
getSeqNo(const ndn::Name& prefix) const
{
auto it = m_prefixes.find(prefix);
if (it == m_prefixes.end()) {
auto it = prefixes.find(prefix);
if (it == prefixes.end()) {
return ndn::nullopt;
}
return it->second;
Expand All @@ -64,18 +64,18 @@ class UserPrefixes
/**
* @brief Adds a user node for synchronization
*
* Initializes m_prefixes[prefix] to zero
* Initializes prefixes[prefix] to zero
*
* @param prefix the user node to be added
* @return true if the prefix was added, false if the prefix was already in
* m_prefixes.
* prefixes.
*/
bool
addUserNode(const ndn::Name& prefix);

/**
* @brief Remove the user node from synchronization. If the prefix is not in
* m_prefixes, then do nothing.
* prefixes, then do nothing.
*
* The caller should first check isUserNode(prefix) and erase the prefix from
* the IBLT and other maps if needed.
Expand All @@ -86,7 +86,7 @@ class UserPrefixes
removeUserNode(const ndn::Name& prefix);

/**
* @brief Update m_prefixes with the given prefix and sequence number. This
* @brief Update prefixes with the given prefix and sequence number. This
* does not update the IBLT. This logs a message for the update.
*
* Whoever calls this needs to make sure that isUserNode(prefix) is true.
Expand All @@ -97,15 +97,15 @@ class UserPrefixes
* prefix. If this method returns true and oldSeqNo is not zero, the caller
* can remove the old prefix from the IBLT.
* @return True if the sequence number was updated, false if the prefix was
* not in m_prefixes, or if the seqNo is less than or equal to the old
* not in prefixes, or if the seqNo is less than or equal to the old
* sequence number. If this returns false, the caller should not update the
* IBLT.
*/
bool
updateSeqNo(const ndn::Name& prefix, uint64_t seqNo, uint64_t& oldSeqNo);

// prefix and sequence number
std::map <ndn::Name, uint64_t> m_prefixes;
std::map <ndn::Name, uint64_t> prefixes;
};

} // namespace psync
Expand Down
8 changes: 4 additions & 4 deletions PSync/full-producer-arbitrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ FullProducerArbitrary::sendSyncInterest()
m_outstandingInterestName = syncInterestName;

m_scheduledSyncInterestId =
m_scheduler.scheduleEvent(m_syncInterestLifetime / 2 + ndn::time::milliseconds(m_jitter(m_rng)),
[this] { sendSyncInterest(); });
m_scheduler.schedule(m_syncInterestLifetime / 2 + ndn::time::milliseconds(m_jitter(m_rng)),
[this] { sendSyncInterest(); });

ndn::Interest syncInterest(syncInterestName);

Expand Down Expand Up @@ -201,7 +201,7 @@ FullProducerArbitrary::onSyncInterest(const ndn::Name& prefixName, const ndn::In
if (m_name2hash.find(name) != m_name2hash.end()) {
if (!m_onShouldAddToSyncDataCallback ||
m_onShouldAddToSyncDataCallback(prefix.toUri(), negative)) {
state.addContent(name);
state.addContent(name);
}
}
}
Expand All @@ -216,7 +216,7 @@ FullProducerArbitrary::onSyncInterest(const ndn::Name& prefixName, const ndn::In
}

auto& entry = m_pendingEntries.emplace(interestName, PendingEntryInfoFull{iblt, {}}).first->second;
entry.expirationEvent = m_scheduler.scheduleEvent(interest.getInterestLifetime(),
entry.expirationEvent = m_scheduler.schedule(interest.getInterestLifetime(),
[this, interest] {
NDN_LOG_TRACE("Erase Pending Interest " << interest.getNonce());
m_pendingEntries.erase(interest.getName());
Expand Down
10 changes: 5 additions & 5 deletions PSync/full-producer-arbitrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace psync {
struct PendingEntryInfoFull
{
IBLT iblt;
ndn::util::scheduler::ScopedEventId expirationEvent;
ndn::scheduler::ScopedEventId expirationEvent;
};

typedef std::function<void(const std::vector<ndn::Name>&)> ArbitraryUpdateCallback;
Expand Down Expand Up @@ -116,7 +116,7 @@ class FullProducerArbitrary : public ProducerBase
void
sendSyncInterest();

PUBLIC_WITH_TESTS_ELSE_PRIVATE:
PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Process sync interest from other parties
*
Expand Down Expand Up @@ -177,7 +177,7 @@ class FullProducerArbitrary : public ProducerBase
void
satisfyPendingInterests();

PUBLIC_WITH_TESTS_ELSE_PRIVATE:
PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Delete pending sync interests that match given name
*/
Expand All @@ -189,15 +189,15 @@ class FullProducerArbitrary : public ProducerBase
ndn::KeyChain m_keyChain;
ndn::Scheduler m_scheduler;

PUBLIC_WITH_TESTS_ELSE_PROTECTED:
PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
SegmentPublisher m_segmentPublisher;

std::map<ndn::Name, PendingEntryInfoFull> m_pendingEntries;
ndn::time::milliseconds m_syncInterestLifetime;
ArbitraryUpdateCallback m_onArbitraryUpdateCallback;
ShouldAddToSyncDataCallback m_onShouldAddToSyncDataCallback;
CanAddName m_onCanAddName;
ndn::util::scheduler::ScopedEventId m_scheduledSyncInterestId;
ndn::scheduler::ScopedEventId m_scheduledSyncInterestId;
std::uniform_int_distribution<> m_jitter;
ndn::Name m_outstandingInterestName;
ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
Expand Down
14 changes: 7 additions & 7 deletions PSync/full-producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ FullProducer::FullProducer(const size_t expectedNumEntries,
ndn::Name prefix = name.getPrefix(-1);
uint64_t seq = name.get(-1).toNumber();

if (m_prefixes.m_prefixes.find(prefix) == m_prefixes.m_prefixes.end() ||
m_prefixes.m_prefixes[prefix] < seq) {
uint64_t oldSeq = m_prefixes.m_prefixes[prefix];
if (m_prefixes.prefixes.find(prefix) == m_prefixes.prefixes.end() ||
m_prefixes.prefixes[prefix] < seq) {
uint64_t oldSeq = m_prefixes.prefixes[prefix];
if (oldSeq != 0) {
m_producerArbitrary.removeName(ndn::Name(prefix).appendNumber(oldSeq));
}
Expand All @@ -72,7 +72,7 @@ FullProducer::publishName(const ndn::Name& prefix, ndn::optional<uint64_t> seq)
return;
}

uint64_t newSeq = seq.value_or(m_prefixes.m_prefixes[prefix] + 1);
uint64_t newSeq = seq.value_or(m_prefixes.prefixes[prefix] + 1);

NDN_LOG_INFO("Publish: " << prefix << "/" << newSeq);

Expand All @@ -99,7 +99,7 @@ bool
FullProducer::isNotFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative)
{
uint32_t nextHash = murmurHash3(N_HASHCHECK,
ndn::Name(prefix).appendNumber(m_prefixes.m_prefixes[prefix] + 1).toUri());
ndn::Name(prefix).appendNumber(m_prefixes.prefixes[prefix] + 1).toUri());
for (const auto& nHash : negative) {
if (nHash == nextHash) {
return false;
Expand All @@ -120,8 +120,8 @@ FullProducer::arbitraryUpdateCallBack(const std::vector<ndn::Name>& names)

NDN_LOG_INFO("Updates: " << prefix << " " << seq);

updates.push_back(MissingDataInfo{prefix, m_prefixes.m_prefixes[prefix] + 1, seq});
m_prefixes.m_prefixes[prefix] = seq;
updates.push_back(MissingDataInfo{prefix, m_prefixes.prefixes[prefix] + 1, seq});
m_prefixes.prefixes[prefix] = seq;
}

m_onUpdateCallback(updates);
Expand Down
6 changes: 3 additions & 3 deletions PSync/full-producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class FullProducer
removeUserNode(const ndn::Name& prefix)
{
if (m_prefixes.isUserNode(prefix)) {
uint64_t seqNo = m_prefixes.m_prefixes[prefix];
uint64_t seqNo = m_prefixes.prefixes[prefix];
m_prefixes.removeUserNode(prefix);
m_producerArbitrary.removeName(ndn::Name(prefix).appendNumber(seqNo));
}
Expand Down Expand Up @@ -142,15 +142,15 @@ class FullProducer
bool
isNotFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative);

PUBLIC_WITH_TESTS_ELSE_PROTECTED:
PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
void
updateSeqNo(const ndn::Name& prefix, uint64_t seq);

private:
void
arbitraryUpdateCallBack(const std::vector<ndn::Name>& names);

PUBLIC_WITH_TESTS_ELSE_PROTECTED:
PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
FullProducerArbitrary m_producerArbitrary;
UpdateCallback m_onUpdateCallback;

Expand Down
14 changes: 7 additions & 7 deletions PSync/partial-producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PartialProducer::publishName(const ndn::Name& prefix, ndn::optional<uint64_t> se
return;
}

uint64_t newSeq = seq.value_or(m_prefixes.m_prefixes[prefix] + 1);
uint64_t newSeq = seq.value_or(m_prefixes.prefixes[prefix] + 1);

NDN_LOG_INFO("Publish: " << prefix << "/" << newSeq);

Expand Down Expand Up @@ -102,7 +102,7 @@ PartialProducer::onHelloInterest(const ndn::Name& prefix, const ndn::Interest& i

State state;

for (const auto& prefix : m_prefixes.m_prefixes) {
for (const auto& prefix : m_prefixes.prefixes) {
state.addContent(ndn::Name(prefix.first).appendNumber(prefix.second));
}
NDN_LOG_DEBUG("sending content p: " << state);
Expand Down Expand Up @@ -174,7 +174,7 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in
std::set<uint32_t> positive;
std::set<uint32_t> negative;

NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.m_prefixes.size());
NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.prefixes.size());

bool peel = diff.listEntries(positive, negative);

Expand All @@ -197,7 +197,7 @@ PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& in
if (bf.contains(prefix.toUri())) {
// generate data
state.addContent(name);
NDN_LOG_DEBUG("Content: " << prefix << " " << std::to_string(m_prefixes.m_prefixes[prefix]));
NDN_LOG_DEBUG("Content: " << prefix << " " << std::to_string(m_prefixes.prefixes[prefix]));
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ PartialProducer::satisfyPendingSyncInterests(const ndn::Name& prefix) {

NDN_LOG_TRACE("Result of listEntries on the difference: " << peel);

NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.m_prefixes.size());
NDN_LOG_TRACE("Number elements in IBF: " << m_prefixes.prefixes.size());
NDN_LOG_TRACE("m_threshold: " << m_threshold << " Total: " << positive.size() + negative.size());

if (!peel) {
Expand All @@ -249,8 +249,8 @@ PartialProducer::satisfyPendingSyncInterests(const ndn::Name& prefix) {
State state;
if (entry.bf.contains(prefix.toUri()) || positive.size() + negative.size() >= m_threshold) {
if (entry.bf.contains(prefix.toUri())) {
state.addContent(ndn::Name(prefix).appendNumber(m_prefixes.m_prefixes[prefix]));
NDN_LOG_DEBUG("sending sync content " << prefix << " " << std::to_string(m_prefixes.m_prefixes[prefix]));
state.addContent(ndn::Name(prefix).appendNumber(m_prefixes.prefixes[prefix]));
NDN_LOG_DEBUG("sending sync content " << prefix << " " << std::to_string(m_prefixes.prefixes[prefix]));
}
else {
NDN_LOG_DEBUG("Sending with empty content to send latest IBF to consumer");
Expand Down
2 changes: 1 addition & 1 deletion PSync/partial-producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class PartialProducer : public ProducerBase
removeUserNode(const ndn::Name& prefix)
{
if (m_prefixes.isUserNode(prefix)) {
uint64_t seqNo = m_prefixes.m_prefixes[prefix];
uint64_t seqNo = m_prefixes.prefixes[prefix];
m_prefixes.removeUserNode(prefix);
removeFromIBF(ndn::Name(prefix).appendNumber(seqNo));
}
Expand Down
Loading

0 comments on commit 8fa2a98

Please sign in to comment.