Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support syncing arbitrary names in full sync mode #1

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The University of Memphis:

* Junxiao Shi <https://www.linkedin.com/in/shijunxiao>
* Davide Pesavento <https://www.linkedin.com/in/davidepesavento>
* Jeff Thompson <[email protected]>

## Technical advisor(s):

Expand Down
4 changes: 2 additions & 2 deletions PSync/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Consumer::onHelloData(const ndn::ConstBufferPtr& bufferPtr)

for (const auto& content : state.getContent()) {
const ndn::Name& prefix = content.getPrefix(-1);
uint64_t seq = content.get(content.size()-1).toNumber();
uint64_t seq = content.get(-1).toNumber();
// If consumer is subscribed then prefix must already be present in
// m_prefixes (see addSubscription). So [] operator is safe to use.
if (isSubscribed(prefix) && seq > m_prefixes[prefix]) {
Expand Down Expand Up @@ -225,7 +225,7 @@ Consumer::onSyncData(const ndn::ConstBufferPtr& bufferPtr)
for (const auto& content : state.getContent()) {
NDN_LOG_DEBUG(content);
const ndn::Name& prefix = content.getPrefix(-1);
uint64_t seq = content.get(content.size() - 1).toNumber();
uint64_t seq = content.get(-1).toNumber();
if (m_prefixes.find(prefix) == m_prefixes.end() || seq > m_prefixes[prefix]) {
// If this is just the next seq number then we had already informed the consumer about
// the previous sequence number and hence seq low and seq high should be equal to current seq
Expand Down
74 changes: 74 additions & 0 deletions PSync/detail/user-prefixes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, The University of Memphis
*
* This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors.
*
* PSync is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

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

namespace psync {

NDN_LOG_INIT(psync.UserPrefixes);

bool
UserPrefixes::addUserNode(const ndn::Name& prefix)
{
if (!isUserNode(prefix)) {
prefixes[prefix] = 0;
return true;
}
else {
return false;
}
}

void
UserPrefixes::removeUserNode(const ndn::Name& prefix)
{
auto it = prefixes.find(prefix);
if (it != prefixes.end()) {
prefixes.erase(it);
}
}

bool
UserPrefixes::updateSeqNo
(const ndn::Name& prefix, uint64_t seqNo, uint64_t& oldSeqNo)
{
oldSeqNo = 0;
NDN_LOG_DEBUG("UpdateSeq: " << prefix << " " << seqNo);

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

if (oldSeqNo >= seqNo) {
NDN_LOG_WARN("Update has lower/equal seq no for prefix, doing nothing!");
return false;
}

// Insert the new sequence number
it->second = seqNo;
return true;
}

} // namespace psync
113 changes: 113 additions & 0 deletions PSync/detail/user-prefixes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, The University of Memphis
*
* This file is part of PSync.
* See AUTHORS.md for complete list of PSync authors and contributors.
*
* PSync is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef PSYNC_USER_PREFIXES_HPP
#define PSYNC_USER_PREFIXES_HPP

#include <map>
#include <ndn-cxx/name.hpp>

namespace psync {

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

/**
* @brief Returns the current sequence number of the given prefix
*
* @param prefix prefix to get the sequence number of
*/
ndn::optional<uint64_t>
getSeqNo(const ndn::Name& prefix) const
{
auto it = prefixes.find(prefix);
if (it == prefixes.end()) {
return ndn::nullopt;
}
return it->second;
}

/**
* @brief Adds a user node for synchronization
*
* 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
* prefixes.
*/
bool
addUserNode(const ndn::Name& prefix);

/**
* @brief Remove the user node from synchronization. If the prefix is not in
* prefixes, then do nothing.
*
* The caller should first check isUserNode(prefix) and erase the prefix from
* the IBLT and other maps if needed.
*
* @param prefix the user node to be removed
*/
void
removeUserNode(const ndn::Name& prefix);

/**
* @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.
*
* @param prefix the prefix of the update
* @param seqNo the sequence number of the update
* @param oldSeqNo This sets oldSeqNo to the old sequence number for the
* 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 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> prefixes;
};

} // namespace psync

#endif // PSYNC_USER_PREFIXES_HPP
Loading