table: Offload the implicit digest calculation to the library
Change-Id: I8577ec3ee194d639cce74b53fb5f02c7e718cbc3
Refs: #1678
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index f1bbb0f..2c1b657 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -22,14 +22,18 @@
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
- * \author Ilya Moiseenko <iliamo@ucla.edu>
+ * \author Ilya Moiseenko <http://ilyamoiseenko.com/>
+ * \author Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/>
+ * \author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
*/
#include "cs.hpp"
#include "core/logger.hpp"
#include "core/random.hpp"
+
#include <ndn-cxx/util/crypto.hpp>
#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
+
#include <boost/random/bernoulli_distribution.hpp>
/// max skip list layers
@@ -106,7 +110,7 @@
std::pair<cs::Entry*, bool>
Cs::insertToSkipList(const Data& data, bool isUnsolicited)
{
- NFD_LOG_TRACE("insertToSkipList() " << data.getName() << ", "
+ NFD_LOG_TRACE("insertToSkipList() " << data.getFullName() << ", "
<< "skipList size " << size());
BOOST_ASSERT(m_cleanupIndex.size() <= size());
@@ -139,7 +143,7 @@
if (head != (*rit)->end())
{
// it can happen when begin() contains the element in front of which we need to insert
- if (!isIterated && ((*head)->getName() >= entry->getName()))
+ if (!isIterated && ((*head)->getFullName() >= entry->getFullName()))
{
--updateTable[layer];
insertInFront = true;
@@ -148,7 +152,7 @@
{
SkipListLayer::iterator it = head;
- while ((*it)->getName() < entry->getName())
+ while ((*it)->getFullName() < entry->getFullName())
{
head = it;
updateTable[layer] = it;
@@ -180,7 +184,7 @@
bool isNameIdentical = false;
if (!isCsEmpty && isInBoundaries)
{
- isNameIdentical = (*head)->getName() == entry->getName();
+ isNameIdentical = (*head)->getFullName() == entry->getFullName();
}
//check if this is a duplicate packet
@@ -188,7 +192,7 @@
{
NFD_LOG_TRACE("Duplicate name (with digest)");
- (*head)->setData(data, isUnsolicited, entry->getDigest()); //updates stale time
+ (*head)->setData(data, isUnsolicited); //updates stale time
// new entry not needed, returning to the pool
entry->release();
@@ -246,7 +250,7 @@
bool
Cs::insert(const Data& data, bool isUnsolicited)
{
- NFD_LOG_TRACE("insert() " << data.getName());
+ NFD_LOG_TRACE("insert() " << data.getFullName());
if (isFull())
{
@@ -292,7 +296,7 @@
bool
Cs::eraseFromSkipList(cs::Entry* entry)
{
- NFD_LOG_TRACE("eraseFromSkipList() " << entry->getName());
+ NFD_LOG_TRACE("eraseFromSkipList() " << entry->getFullName());
NFD_LOG_TRACE("SkipList size " << size());
bool isErased = false;
@@ -399,7 +403,7 @@
if (head != (*rit)->end())
{
// it happens when begin() contains the element we want to find
- if (!isIterated && (interest.getName().isPrefixOf((*head)->getName())))
+ if (!isIterated && (interest.getName().isPrefixOf((*head)->getFullName())))
{
if (layer > 0)
{
@@ -415,9 +419,9 @@
{
SkipListLayer::iterator it = head;
- while ((*it)->getName() < interest.getName())
+ while ((*it)->getFullName() < interest.getName())
{
- NFD_LOG_TRACE((*it)->getName() << " < " << interest.getName());
+ NFD_LOG_TRACE((*it)->getFullName() << " < " << interest.getName());
head = it;
isIterated = true;
@@ -452,11 +456,11 @@
if (startingPoint != (*m_skipList.begin())->begin())
{
- BOOST_ASSERT((*startingPoint)->getName() < interest.getName());
+ BOOST_ASSERT((*startingPoint)->getFullName() < interest.getName());
}
NFD_LOG_TRACE("selectChild() " << interest.getChildSelector() << " "
- << (*startingPoint)->getName());
+ << (*startingPoint)->getFullName());
bool hasLeftmostSelector = (interest.getChildSelector() <= 0);
bool hasRightmostSelector = !hasLeftmostSelector;
@@ -468,11 +472,11 @@
if (doesInterestContainDigest)
{
- isInPrefix = interest.getName().getPrefix(-1).isPrefixOf((*startingPoint)->getName());
+ isInPrefix = interest.getName().getPrefix(-1).isPrefixOf((*startingPoint)->getFullName());
}
else
{
- isInPrefix = interest.getName().isPrefixOf((*startingPoint)->getName());
+ isInPrefix = interest.getName().isPrefixOf((*startingPoint)->getFullName());
}
if (isInPrefix)
@@ -506,11 +510,11 @@
if (doesInterestContainDigest)
{
isInPrefix = interest.getName().getPrefix(-1)
- .isPrefixOf((*rightmostCandidate)->getName());
+ .isPrefixOf((*rightmostCandidate)->getFullName());
}
else
{
- isInPrefix = interest.getName().isPrefixOf((*rightmostCandidate)->getName());
+ isInPrefix = interest.getName().isPrefixOf((*rightmostCandidate)->getFullName());
}
}
@@ -529,7 +533,7 @@
{
// get prefix which is one component longer than Interest name
// (without digest)
- const Name& childPrefix = (*rightmostCandidate)->getName()
+ const Name& childPrefix = (*rightmostCandidate)->getFullName()
.getPrefix(interest.getName().size());
NFD_LOG_TRACE("Child prefix" << childPrefix);
@@ -542,7 +546,7 @@
else
{
// get prefix which is one component longer than Interest name
- const Name& childPrefix = (*rightmostCandidate)->getName()
+ const Name& childPrefix = (*rightmostCandidate)->getFullName()
.getPrefix(interest.getName().size() + 1);
NFD_LOG_TRACE("Child prefix" << childPrefix);
@@ -572,11 +576,11 @@
if (doesInterestContainDigest)
{
- isInPrefix = interest.getName().getPrefix(-1).isPrefixOf((*startingPoint)->getName());
+ isInPrefix = interest.getName().getPrefix(-1).isPrefixOf((*startingPoint)->getFullName());
}
else
{
- isInPrefix = interest.getName().isPrefixOf((*startingPoint)->getName());
+ isInPrefix = interest.getName().isPrefixOf((*startingPoint)->getFullName());
}
if (isInPrefix)
@@ -599,19 +603,14 @@
NFD_LOG_TRACE("doesComplyWithSelectors()");
/// \todo The following detection is not correct
- /// 1. If data name ends with 32-octet component doesn't mean that this component is digest
+ /// 1. If Interest name ends with 32-octet component doesn't mean that this component is
+ /// digest
/// 2. Only min/max selectors (both 0) can be specified, all other selectors do not
/// make sense for interests with digest (though not sure if we need to enforce this)
if (doesInterestContainDigest)
{
- const ndn::name::Component& last = interest.getName().get(-1);
- const ndn::ConstBufferPtr& digest = entry->getDigest();
-
- BOOST_ASSERT(digest->size() == last.value_size());
- BOOST_ASSERT(digest->size() == ndn::crypto::SHA256_DIGEST_SIZE);
-
- if (std::memcmp(digest->buf(), last.value(), ndn::crypto::SHA256_DIGEST_SIZE) != 0)
+ if (interest.getName().get(-1) != entry->getFullName().get(-1))
{
NFD_LOG_TRACE("violates implicit digest");
return false;
@@ -624,7 +623,7 @@
{
size_t minDataNameLength = interest.getName().size() + interest.getMinSuffixComponents();
- bool isSatisfied = (minDataNameLength <= entry->getName().size());
+ bool isSatisfied = (minDataNameLength <= entry->getFullName().size());
if (!isSatisfied)
{
NFD_LOG_TRACE("violates minComponents");
@@ -636,7 +635,7 @@
{
size_t maxDataNameLength = interest.getName().size() + interest.getMaxSuffixComponents();
- bool isSatisfied = (maxDataNameLength >= entry->getName().size());
+ bool isSatisfied = (maxDataNameLength >= entry->getFullName().size());
if (!isSatisfied)
{
NFD_LOG_TRACE("violates maxComponents");
@@ -671,7 +670,7 @@
if (doesInterestContainDigest)
{
- const ndn::name::Component& lastComponent = entry->getName().get(-1);
+ const ndn::name::Component& lastComponent = entry->getFullName().get(-1);
if (!lastComponent.empty())
{
@@ -684,9 +683,9 @@
}
else
{
- if (entry->getName().size() >= interest.getName().size() + 1)
+ if (entry->getFullName().size() >= interest.getName().size() + 1)
{
- const ndn::name::Component& nextComponent = entry->getName()
+ const ndn::name::Component& nextComponent = entry->getFullName()
.get(interest.getName().size());
if (!nextComponent.empty())
{
@@ -709,7 +708,7 @@
// only when min selector is not specified or specified with value of 0
// and Interest's name length is exactly the length of the name of CS entry
if (interest.getMinSuffixComponents() <= 0 &&
- interest.getName().size() == (entry->getName().size()))
+ interest.getName().size() == (entry->getFullName().size()))
{
const ndn::name::Component& last = interest.getName().get(-1);
if (last.value_size() == ndn::crypto::SHA256_DIGEST_SIZE)
@@ -748,7 +747,7 @@
if (head != (*rit)->end())
{
// it can happen when begin() contains the element we want to remove
- if (!isIterated && ((*head)->getName() == exactName))
+ if (!isIterated && ((*head)->getFullName() == exactName))
{
eraseFromSkipList(*head);
return;
@@ -757,7 +756,7 @@
{
SkipListLayer::iterator it = head;
- while ((*it)->getName() < exactName)
+ while ((*it)->getFullName() < exactName)
{
head = it;
updateTable[layer] = it;
@@ -789,13 +788,13 @@
bool isNameIdentical = false;
if (!isCsEmpty && isInBoundaries)
{
- NFD_LOG_TRACE("Identical? " << (*head)->getName());
- isNameIdentical = (*head)->getName() == exactName;
+ NFD_LOG_TRACE("Identical? " << (*head)->getFullName());
+ isNameIdentical = (*head)->getFullName() == exactName;
}
if (isNameIdentical)
{
- NFD_LOG_TRACE("Found target " << (*head)->getName());
+ NFD_LOG_TRACE("Found target " << (*head)->getFullName());
eraseFromSkipList(*head);
}
}
@@ -810,7 +809,7 @@
{
for (SkipListLayer::iterator it = (*rit)->begin(); it != (*rit)->end(); ++it)
{
- NFD_LOG_TRACE("Layer " << layer << " " << (*it)->getName());
+ NFD_LOG_TRACE("Layer " << layer << " " << (*it)->getFullName());
}
layer--;
}