interest: delete Link and SelectedDelegation fields
They have been replaced by ForwardingHint. refs #4055 Change-Id: I1d5b5c0f4530af3d8ba2d9a624bb62cf341ccf39
This commit is contained in:
1 parent
4f92d873c0
commit
d701e5bebc
6 files changed
+10
-685
No files matched your search
@@ -37,7 +37,6 @@ static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
|
||||
Interest::Interest(const Name& name, time::milliseconds interestLifetime)
|
||||
: m_name(name)
|
||||
, m_interestLifetime(interestLifetime)
|
||||
, m_selectedDelegationIndex(INVALID_SELECTED_DELEGATION_INDEX)
|
||||
{
|
||||
if (interestLifetime < time::milliseconds::zero()) {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0"));
|
||||
@@ -63,24 +62,9 @@ Interest::wireEncode(EncodingImpl<TAG>& encoder) const
|
||||
// Nonce
|
||||
// InterestLifetime?
|
||||
// ForwardingHint?
|
||||
// Link?
|
||||
// SelectedDelegation?
|
||||
|
||||
// (reverse encoding)
|
||||
|
||||
// Link and SelectedDelegation
|
||||
if (hasLink()) {
|
||||
if (hasSelectedDelegation()) {
|
||||
totalLength += prependNonNegativeIntegerBlock(encoder,
|
||||
tlv::SelectedDelegation,
|
||||
m_selectedDelegationIndex);
|
||||
}
|
||||
totalLength += encoder.prependBlock(m_link);
|
||||
}
|
||||
else {
|
||||
BOOST_ASSERT(!hasSelectedDelegation());
|
||||
}
|
||||
|
||||
// ForwardingHint
|
||||
if (m_forwardingHint.size() > 0) {
|
||||
totalLength += m_forwardingHint.wireEncode(encoder);
|
||||
@@ -130,9 +114,7 @@ Interest::wireEncode() const
|
||||
EncodingBuffer buffer(estimatedSize, 0);
|
||||
wireEncode(buffer);
|
||||
|
||||
// to ensure that Link block points to the right memory location
|
||||
const_cast<Interest*>(this)->wireDecode(buffer.block());
|
||||
|
||||
return m_wire;
|
||||
}
|
||||
|
||||
@@ -185,34 +167,6 @@ Interest::wireDecode(const Block& wire)
|
||||
else {
|
||||
m_forwardingHint = DelegationList();
|
||||
}
|
||||
|
||||
// Link
|
||||
m_linkCached.reset();
|
||||
val = m_wire.find(tlv::Data);
|
||||
if (val != m_wire.elements_end()) {
|
||||
m_link = (*val);
|
||||
}
|
||||
else {
|
||||
m_link = Block();
|
||||
}
|
||||
|
||||
// SelectedDelegation
|
||||
val = m_wire.find(tlv::SelectedDelegation);
|
||||
if (val != m_wire.elements_end()) {
|
||||
if (!this->hasLink()) {
|
||||
BOOST_THROW_EXCEPTION(Error("Interest contains SelectedDelegation, but no LINK object"));
|
||||
}
|
||||
uint64_t selectedDelegation = readNonNegativeInteger(*val);
|
||||
if (selectedDelegation < uint64_t(Link::countDelegationsFromWire(m_link))) {
|
||||
m_selectedDelegationIndex = static_cast<size_t>(selectedDelegation);
|
||||
}
|
||||
else {
|
||||
BOOST_THROW_EXCEPTION(Error("Invalid selected delegation index when decoding Interest"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_selectedDelegationIndex = INVALID_SELECTED_DELEGATION_INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- matching ----
|
||||
@@ -388,90 +342,6 @@ Interest::setForwardingHint(const DelegationList& value)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool
|
||||
Interest::hasLink() const
|
||||
{
|
||||
return m_link.hasWire();
|
||||
}
|
||||
|
||||
const Link&
|
||||
Interest::getLink() const
|
||||
{
|
||||
if (hasLink()) {
|
||||
if (!m_linkCached) {
|
||||
m_linkCached = make_shared<Link>(m_link);
|
||||
}
|
||||
return *m_linkCached;
|
||||
}
|
||||
BOOST_THROW_EXCEPTION(Error("There is no encapsulated link object"));
|
||||
}
|
||||
|
||||
void
|
||||
Interest::setLink(const Block& link)
|
||||
{
|
||||
m_link = link;
|
||||
if (!link.hasWire()) {
|
||||
BOOST_THROW_EXCEPTION(Error("The given link does not have a wire format"));
|
||||
}
|
||||
m_wire.reset();
|
||||
m_linkCached.reset();
|
||||
this->unsetSelectedDelegation();
|
||||
}
|
||||
|
||||
void
|
||||
Interest::unsetLink()
|
||||
{
|
||||
m_link.reset();
|
||||
m_wire.reset();
|
||||
m_linkCached.reset();
|
||||
this->unsetSelectedDelegation();
|
||||
}
|
||||
|
||||
bool
|
||||
Interest::hasSelectedDelegation() const
|
||||
{
|
||||
return m_selectedDelegationIndex != INVALID_SELECTED_DELEGATION_INDEX;
|
||||
}
|
||||
|
||||
Name
|
||||
Interest::getSelectedDelegation() const
|
||||
{
|
||||
if (!hasSelectedDelegation()) {
|
||||
BOOST_THROW_EXCEPTION(Error("There is no encapsulated selected delegation"));
|
||||
}
|
||||
return std::get<1>(Link::getDelegationFromWire(m_link, m_selectedDelegationIndex));
|
||||
}
|
||||
|
||||
void
|
||||
Interest::setSelectedDelegation(const Name& delegationName)
|
||||
{
|
||||
size_t delegationIndex = Link::findDelegationFromWire(m_link, delegationName);
|
||||
if (delegationIndex != INVALID_SELECTED_DELEGATION_INDEX) {
|
||||
m_selectedDelegationIndex = delegationIndex;
|
||||
}
|
||||
else {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid selected delegation name"));
|
||||
}
|
||||
m_wire.reset();
|
||||
}
|
||||
|
||||
void
|
||||
Interest::setSelectedDelegation(size_t delegationIndex)
|
||||
{
|
||||
if (delegationIndex >= Link(m_link).getDelegations().size()) {
|
||||
BOOST_THROW_EXCEPTION(Error("Invalid selected delegation index"));
|
||||
}
|
||||
m_selectedDelegationIndex = delegationIndex;
|
||||
m_wire.reset();
|
||||
}
|
||||
|
||||
void
|
||||
Interest::unsetSelectedDelegation()
|
||||
{
|
||||
m_selectedDelegationIndex = INVALID_SELECTED_DELEGATION_INDEX;
|
||||
m_wire.reset();
|
||||
}
|
||||
|
||||
// ---- operators ----
|
||||
|
||||
std::ostream&
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#define NDN_INTEREST_HPP
|
||||
|
||||
#include "delegation-list.hpp"
|
||||
#include "link.hpp"
|
||||
#include "name.hpp"
|
||||
#include "selectors.hpp"
|
||||
#include "tag-host.hpp"
|
||||
@@ -329,77 +328,6 @@ public: // Selectors
|
||||
return *this;
|
||||
}
|
||||
|
||||
public: // Link and SelectedDelegation
|
||||
/**
|
||||
* @brief Check whether the Interest contains a Link object
|
||||
* @return True if there is a link object, otherwise false
|
||||
*/
|
||||
bool
|
||||
hasLink() const;
|
||||
|
||||
/**
|
||||
* @brief Get the link object for this interest
|
||||
* @return The link object if there is one contained in this interest
|
||||
* @throws Interest::Error if there is no link object contained in the interest
|
||||
* @throws tlv::Error if the incorporated link object is malformed
|
||||
*/
|
||||
const Link&
|
||||
getLink() const;
|
||||
|
||||
/**
|
||||
* @brief Set the link object for this interest
|
||||
* @param link The link object that will be included in this interest (in wire format)
|
||||
* @post !hasSelectedDelegation()
|
||||
*/
|
||||
void
|
||||
setLink(const Block& link);
|
||||
|
||||
/**
|
||||
* @brief Delete the link object for this interest
|
||||
* @post !hasLink()
|
||||
*/
|
||||
void
|
||||
unsetLink();
|
||||
|
||||
/**
|
||||
* @brief Check whether the Interest includes a selected delegation
|
||||
* @return True if there is a selected delegation, otherwise false
|
||||
*/
|
||||
bool
|
||||
hasSelectedDelegation() const;
|
||||
|
||||
/**
|
||||
* @brief Get the name of the selected delegation
|
||||
* @return The name of the selected delegation
|
||||
* @throw Error SelectedDelegation is not set.
|
||||
*/
|
||||
Name
|
||||
getSelectedDelegation() const;
|
||||
|
||||
/**
|
||||
* @brief Set the selected delegation
|
||||
* @param delegationName The name of the selected delegation
|
||||
* @throw Error Link is not set.
|
||||
* @throw std::invalid_argument @p delegationName does not exist in Link.
|
||||
*/
|
||||
void
|
||||
setSelectedDelegation(const Name& delegationName);
|
||||
|
||||
/**
|
||||
* @brief Set the selected delegation
|
||||
* @param delegationIndex The index of the selected delegation
|
||||
* @throw Error Link is not set.
|
||||
* @throw std::out_of_range @p delegationIndex is out of bound in Link.
|
||||
*/
|
||||
void
|
||||
setSelectedDelegation(size_t delegationIndex);
|
||||
|
||||
/**
|
||||
* @brief Unset the selected delegation
|
||||
*/
|
||||
void
|
||||
unsetSelectedDelegation();
|
||||
|
||||
private:
|
||||
Name m_name;
|
||||
Selectors m_selectors;
|
||||
@@ -407,9 +335,6 @@ private:
|
||||
time::milliseconds m_interestLifetime;
|
||||
DelegationList m_forwardingHint;
|
||||
|
||||
mutable Block m_link;
|
||||
mutable shared_ptr<Link> m_linkCached;
|
||||
size_t m_selectedDelegationIndex;
|
||||
mutable Block m_wire;
|
||||
};
|
||||
|
||||
|
||||
+1
-3
@@ -1,5 +1,5 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
/*
|
||||
* Copyright (c) 2013-2017 Regents of the University of California.
|
||||
*
|
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
|
||||
@@ -28,8 +28,6 @@
|
||||
|
||||
namespace ndn {
|
||||
|
||||
const size_t INVALID_SELECTED_DELEGATION_INDEX = std::numeric_limits<size_t>::max();
|
||||
|
||||
/** @brief represents a Link object
|
||||
*/
|
||||
class Link : public Data
|
||||
|
||||
@@ -41,8 +41,6 @@ BOOST_AUTO_TEST_CASE(DefaultConstructor)
|
||||
BOOST_CHECK(i.getSelectors().empty());
|
||||
BOOST_CHECK_EQUAL(i.hasNonce(), false);
|
||||
BOOST_CHECK_EQUAL(i.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
|
||||
BOOST_CHECK_EQUAL(i.hasLink(), false);
|
||||
BOOST_CHECK(!i.hasSelectedDelegation());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EncodeDecodeBasic)
|
||||
@@ -110,57 +108,6 @@ BOOST_AUTO_TEST_CASE(EncodeDecodeFull)
|
||||
BOOST_CHECK_EQUAL(i1, i2);
|
||||
}
|
||||
|
||||
const uint8_t LINK[] = {
|
||||
0x06, 0xda, // Data
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x06,
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x14, 0x07, // MetaInfo
|
||||
0x18, 0x01, // ContentType
|
||||
0x01,
|
||||
0x19, 0x02, // FreshnessPeriod
|
||||
0x27, 0x10,
|
||||
0x15, 0x1a, // Content
|
||||
0x1f, 0x0c, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x0a,
|
||||
0x07, 0x07, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x1f, 0x0a, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x14,
|
||||
0x07, 0x05, // Name
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x16, 0x1b, // SignatureInfo
|
||||
0x1b, 0x01, // SignatureType
|
||||
0x01,
|
||||
0x1c, 0x16, // KeyLocator
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x04,
|
||||
0x74, 0x65, 0x73, 0x74,
|
||||
0x08, 0x03,
|
||||
0x6b, 0x65, 0x79,
|
||||
0x08, 0x07,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
|
||||
0x17, 0x80, // SignatureValue
|
||||
0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
|
||||
0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
|
||||
0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
|
||||
0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
|
||||
0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
|
||||
0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
|
||||
0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
|
||||
0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
|
||||
0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
|
||||
0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(WireDecodeReset) // checks wireDecode resets all fields
|
||||
{
|
||||
Interest i1;
|
||||
@@ -168,24 +115,18 @@ BOOST_AUTO_TEST_CASE(WireDecodeReset) // checks wireDecode resets all fields
|
||||
i1.setMinSuffixComponents(100);
|
||||
i1.setNonce(10);
|
||||
i1.setInterestLifetime(time::seconds(10));
|
||||
i1.setLink(Block(LINK, sizeof(LINK)));
|
||||
i1.setSelectedDelegation(0);
|
||||
|
||||
Interest i2(i1.wireEncode());
|
||||
BOOST_CHECK_EQUAL(i2.getName().toUri(), "/test");
|
||||
BOOST_CHECK_EQUAL(i2.getInterestLifetime(), time::seconds(10));
|
||||
BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), 100);
|
||||
BOOST_CHECK_EQUAL(i2.getNonce(), 10);
|
||||
BOOST_CHECK_EQUAL(i2.hasLink(), true);
|
||||
BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), true);
|
||||
|
||||
i2.wireDecode(Interest().wireEncode());
|
||||
BOOST_CHECK_EQUAL(i2.getName().toUri(), "/");
|
||||
BOOST_CHECK_EQUAL(i2.getInterestLifetime(), DEFAULT_INTEREST_LIFETIME);
|
||||
BOOST_CHECK_EQUAL(i2.getMinSuffixComponents(), -1);
|
||||
BOOST_WARN_NE(i2.getNonce(), 10);
|
||||
BOOST_CHECK_EQUAL(i2.hasLink(), false);
|
||||
BOOST_CHECK_EQUAL(i2.hasSelectedDelegation(), false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DecodeNoName)
|
||||
@@ -314,7 +255,7 @@ BOOST_AUTO_TEST_CASE(MatchesInterest)
|
||||
.setExclude(Exclude().excludeAfter(name::Component("J")))
|
||||
.setNonce(10)
|
||||
.setInterestLifetime(time::seconds(5))
|
||||
.setLink(Block(LINK, sizeof(LINK)));
|
||||
.setForwardingHint({{1, "/H"}});
|
||||
|
||||
Interest other;
|
||||
BOOST_CHECK_EQUAL(interest.matchesInterest(other), false);
|
||||
@@ -325,7 +266,7 @@ BOOST_AUTO_TEST_CASE(MatchesInterest)
|
||||
other.setSelectors(interest.getSelectors());
|
||||
BOOST_CHECK_EQUAL(interest.matchesInterest(other), false); // will match until #3162 implemented
|
||||
|
||||
other.setLink(interest.getLink().wireEncode());
|
||||
other.setForwardingHint({{1, "/H"}});
|
||||
BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
|
||||
|
||||
other.setNonce(200);
|
||||
@@ -333,9 +274,6 @@ BOOST_AUTO_TEST_CASE(MatchesInterest)
|
||||
|
||||
other.setInterestLifetime(time::hours(5));
|
||||
BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
|
||||
|
||||
other.setSelectedDelegation(0);
|
||||
BOOST_CHECK_EQUAL(interest.matchesInterest(other), true);
|
||||
}
|
||||
|
||||
// ---- field accessors ----
|
||||
@@ -475,407 +413,16 @@ BOOST_AUTO_TEST_CASE(Equality)
|
||||
BOOST_CHECK_EQUAL(a == b, true);
|
||||
BOOST_CHECK_EQUAL(a != b, false);
|
||||
|
||||
///\todo #4055 compare ForwardingHint
|
||||
|
||||
// compare Link
|
||||
a.setLink(Block(LINK, sizeof(LINK)));
|
||||
// compare ForwardingHint
|
||||
a.setForwardingHint({{1, "/H"}});
|
||||
BOOST_CHECK_EQUAL(a == b, false);
|
||||
BOOST_CHECK_EQUAL(a != b, true);
|
||||
|
||||
b.setLink(Block(LINK, sizeof(LINK)));
|
||||
BOOST_CHECK_EQUAL(a == b, true);
|
||||
BOOST_CHECK_EQUAL(a != b, false);
|
||||
|
||||
// compare SelectedDelegation
|
||||
BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
|
||||
BOOST_CHECK_EQUAL(b.hasSelectedDelegation(), false);
|
||||
|
||||
a.setSelectedDelegation(Name("/local"));
|
||||
BOOST_CHECK_EQUAL(a == b, false);
|
||||
BOOST_CHECK_EQUAL(a != b, true);
|
||||
|
||||
b.setSelectedDelegation(Name("/local"));
|
||||
b.setForwardingHint({{1, "/H"}});
|
||||
BOOST_CHECK_EQUAL(a == b, true);
|
||||
BOOST_CHECK_EQUAL(a != b, false);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(LinkSelectedDelegation, IdentityManagementFixture)
|
||||
|
||||
const uint8_t InterestWithLink[] = {
|
||||
0x05, 0xfb, // Interest
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x5, // NameComponent
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x3, // NameComponent
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x6, // NameComponent
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x0a, 0x4, // Nonce
|
||||
0x1, 0x0, 0x0, 0x00,
|
||||
0x06, 0xda, // Data
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x06,
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x14, 0x07, // MetaInfo
|
||||
0x18, 0x01, // ContentType
|
||||
0x01,
|
||||
0x19, 0x02, // FreshnessPeriod
|
||||
0x27, 0x10,
|
||||
0x15, 0x1a, // Content
|
||||
0x1f, 0x0c, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x0a,
|
||||
0x07, 0x07, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x1f, 0x0a, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x14,
|
||||
0x07, 0x05, // Name
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x16, 0x1b, // SignatureInfo
|
||||
0x1b, 0x01, // SignatureType
|
||||
0x01,
|
||||
0x1c, 0x16, // KeyLocator
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x04,
|
||||
0x74, 0x65, 0x73, 0x74,
|
||||
0x08, 0x03,
|
||||
0x6b, 0x65, 0x79,
|
||||
0x08, 0x07,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
|
||||
0x17, 0x80, // SignatureValue
|
||||
0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
|
||||
0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
|
||||
0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
|
||||
0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
|
||||
0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
|
||||
0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
|
||||
0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
|
||||
0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
|
||||
0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
|
||||
0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
|
||||
0x20, 0x01, // SelectedDelegation
|
||||
0x00
|
||||
};
|
||||
|
||||
const uint8_t InterestWithSelectedDelegationButNoLink[] = {
|
||||
0x05, 0x1f, // Interest
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x5, // NameComponent
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x3, // NameComponent
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x6, // NameComponent
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x0a, 0x4, // Nonce
|
||||
0x1, 0x0, 0x0, 0x00,
|
||||
0x20, 0x01, // SelectedDelegation
|
||||
0x00
|
||||
};
|
||||
|
||||
const uint8_t InterestWithLinkNotNonIntegerSelectedDelegation[] = {
|
||||
0x05, 0xfb, // Interest
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x5, // NameComponent
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x3, // NameComponent
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x6, // NameComponent
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x0a, 0x4, // Nonce
|
||||
0x1, 0x0, 0x0, 0x00,
|
||||
0x06, 0xda, // Data
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x06,
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x14, 0x07, // MetaInfo
|
||||
0x18, 0x01, // ContentType
|
||||
0x01,
|
||||
0x19, 0x02, // FreshnessPeriod
|
||||
0x27, 0x10,
|
||||
0x15, 0x1a, // Content
|
||||
0x1f, 0x0c, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x0a,
|
||||
0x07, 0x07, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x1f, 0x0a, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x14,
|
||||
0x07, 0x05, // Name
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x16, 0x1b, // SignatureInfo
|
||||
0x1b, 0x01, // SignatureType
|
||||
0x01,
|
||||
0x1c, 0x16, // KeyLocator
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x04,
|
||||
0x74, 0x65, 0x73, 0x74,
|
||||
0x08, 0x03,
|
||||
0x6b, 0x65, 0x79,
|
||||
0x08, 0x07,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
|
||||
0x17, 0x78, // SignatureValue
|
||||
0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
|
||||
0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
|
||||
0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
|
||||
0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
|
||||
0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
|
||||
0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
|
||||
0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
|
||||
0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
|
||||
0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
|
||||
0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7,
|
||||
0x20, 0x03, // SelectedDelegation
|
||||
0xAA, 0xAA, 0xAA
|
||||
};
|
||||
|
||||
const uint8_t InterestWithLinkNonDecreasingOrder[] = {
|
||||
0x05, 0xfb, // Interest
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x5, // NameComponent
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x3, // NameComponent
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x6, // NameComponent
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x0a, 0x4, // Nonce
|
||||
0x1, 0x0, 0x0, 0x00,
|
||||
0x06, 0xda, // Data
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x08, 0x06,
|
||||
0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
|
||||
0x14, 0x07, // MetaInfo
|
||||
0x18, 0x01, // ContentType
|
||||
0x01,
|
||||
0x19, 0x02, // FreshnessPeriod
|
||||
0x27, 0x10,
|
||||
0x15, 0x1a, // Content
|
||||
0x1f, 0x0c, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x14,
|
||||
0x07, 0x07, // Name
|
||||
0x08, 0x05,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x6c,
|
||||
0x1f, 0x0a, // LinkDelegation
|
||||
0x1e, 0x01, // LinkPreference
|
||||
0x0a,
|
||||
0x07, 0x05, // Name
|
||||
0x08, 0x03,
|
||||
0x6e, 0x64, 0x6e,
|
||||
0x16, 0x1b, // SignatureInfo
|
||||
0x1b, 0x01, // SignatureType
|
||||
0x01,
|
||||
0x1c, 0x16, // KeyLocator
|
||||
0x07, 0x14, // Name
|
||||
0x08, 0x04,
|
||||
0x74, 0x65, 0x73, 0x74,
|
||||
0x08, 0x03,
|
||||
0x6b, 0x65, 0x79,
|
||||
0x08, 0x07,
|
||||
0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72,
|
||||
0x17, 0x80, // SignatureValue
|
||||
0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
|
||||
0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
|
||||
0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
|
||||
0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
|
||||
0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
|
||||
0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
|
||||
0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
|
||||
0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
|
||||
0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
|
||||
0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1,
|
||||
0x20, 0x01, // SelectedDelegation
|
||||
0x01
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(LinkObject)
|
||||
{
|
||||
Link link1("test", {{100, "/test3"}, {20, "/test2"}, {10, "/test1"}});
|
||||
m_keyChain.sign(link1);
|
||||
Block wire = link1.wireEncode();
|
||||
|
||||
Interest a;
|
||||
BOOST_REQUIRE_NO_THROW(a.setLink(wire));
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(a.getLink());
|
||||
|
||||
Link link2 = a.getLink();
|
||||
Name name = link2.getName();
|
||||
BOOST_CHECK_EQUAL(Name("test"), name);
|
||||
BOOST_CHECK_EQUAL(a.hasLink(), true);
|
||||
Link::DelegationSet delegations;
|
||||
delegations = link2.getDelegations();
|
||||
|
||||
auto i = delegations.begin();
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
|
||||
++i;
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
|
||||
++i;
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
|
||||
|
||||
a.setLink(Block(LINK, sizeof(LINK)));
|
||||
BOOST_CHECK_EQUAL(a.getLink().getDelegations().size(), 2);
|
||||
|
||||
a.unsetLink();
|
||||
BOOST_CHECK_EQUAL(a.hasLink(), false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SelectedDelegationChecks)
|
||||
{
|
||||
Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
|
||||
m_keyChain.sign(link);
|
||||
Block wire = link.wireEncode();
|
||||
|
||||
Interest a;
|
||||
a.setLink(wire);
|
||||
BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(Name("test2")));
|
||||
BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test2"));
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(a.setSelectedDelegation(uint32_t(2)));
|
||||
BOOST_CHECK_EQUAL(a.getSelectedDelegation(), Name("test3"));
|
||||
|
||||
a.unsetSelectedDelegation();
|
||||
BOOST_CHECK_EQUAL(a.hasSelectedDelegation(), false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EncodeDecodeWithLink)
|
||||
{
|
||||
Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
|
||||
m_keyChain.sign(link1);
|
||||
Block wire = link1.wireEncode();
|
||||
|
||||
Interest a;
|
||||
a.setName("/Test/Encode/Decode/With/Link");
|
||||
a.setChildSelector(1);
|
||||
a.setNonce(100);
|
||||
a.setInterestLifetime(time::seconds(10));
|
||||
a.setLink(wire);
|
||||
|
||||
Block interestBlock = a.wireEncode();
|
||||
Interest b(interestBlock);
|
||||
|
||||
BOOST_CHECK_EQUAL(a == b, true);
|
||||
|
||||
Link link2 = b.getLink();
|
||||
Link::DelegationSet delegations;
|
||||
delegations = link2.getDelegations();
|
||||
|
||||
auto i = delegations.begin();
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*i), 10);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test1"));
|
||||
++i;
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*i), 20);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test2"));
|
||||
++i;
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*i), 100);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*i), Name("test3"));
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DecodeInterestWithLink)
|
||||
{
|
||||
Block interestBlock(InterestWithLink, sizeof(InterestWithLink));
|
||||
|
||||
ndn::Interest i;
|
||||
BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
|
||||
Link link = i.getLink();
|
||||
BOOST_CHECK_EQUAL(link.getName(), Name("/local/ndn/prefix"));
|
||||
Link::DelegationSet delegations = link.getDelegations();
|
||||
|
||||
auto it = delegations.begin();
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*it), 10);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*it), Name("local"));
|
||||
++it;
|
||||
BOOST_CHECK_EQUAL(std::get<0>(*it), 20);
|
||||
BOOST_CHECK_EQUAL(std::get<1>(*it), Name("ndn"));
|
||||
|
||||
BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
|
||||
BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("local"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DecodeInterestWithLinkNonDecreasingOrder)
|
||||
{
|
||||
Block interestBlock(InterestWithLinkNonDecreasingOrder,
|
||||
sizeof(InterestWithLinkNonDecreasingOrder));
|
||||
|
||||
ndn::Interest i;
|
||||
BOOST_REQUIRE_NO_THROW(i.wireDecode(interestBlock));
|
||||
BOOST_REQUIRE_NO_THROW(i.getSelectedDelegation());
|
||||
BOOST_CHECK_EQUAL(i.getSelectedDelegation(), Name("ndn"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(InterestContainingSelectedDelegationButNoLink)
|
||||
{
|
||||
Block interestBlock(InterestWithSelectedDelegationButNoLink,
|
||||
sizeof(InterestWithSelectedDelegationButNoLink));
|
||||
|
||||
ndn::Interest i;
|
||||
BOOST_CHECK_THROW(i.wireDecode(interestBlock), Interest::Error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SelectedDelegationIsNotNonNegativeInteger)
|
||||
{
|
||||
Block interestBlock(InterestWithLinkNotNonIntegerSelectedDelegation,
|
||||
sizeof(InterestWithLinkNotNonIntegerSelectedDelegation));
|
||||
|
||||
ndn::Interest i;
|
||||
BOOST_CHECK_THROW(i.wireDecode(interestBlock), tlv::Error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SelectedDelegationEqualToDelegationCount)
|
||||
{
|
||||
Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
|
||||
m_keyChain.sign(link1);
|
||||
Block wire = link1.wireEncode();
|
||||
|
||||
Interest a;
|
||||
a.setName("/Test/Encode/Decode/With/Link");
|
||||
a.setChildSelector(1);
|
||||
a.setNonce(100);
|
||||
a.setInterestLifetime(time::seconds(10));
|
||||
a.setLink(wire);
|
||||
BOOST_CHECK_THROW(a.setSelectedDelegation(3), Interest::Error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(SelectedDelegationGreaterThanDelegationCount)
|
||||
{
|
||||
Link link1("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
|
||||
m_keyChain.sign(link1);
|
||||
Block wire = link1.wireEncode();
|
||||
|
||||
Interest a;
|
||||
a.setName("/Test/Encode/Decode/With/Link");
|
||||
a.setChildSelector(1);
|
||||
a.setNonce(100);
|
||||
a.setInterestLifetime(time::seconds(10));
|
||||
a.setLink(wire);
|
||||
BOOST_CHECK_THROW(a.setSelectedDelegation(4), Interest::Error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // LinkSelectedDelegation
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END() // TestInterest
|
||||
|
||||
} // namespace tests
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2013-2016 Regents of the University of California.
|
||||
/*
|
||||
* Copyright (c) 2013-2017 Regents of the University of California.
|
||||
*
|
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
|
||||
*
|
||||
@@ -52,14 +52,6 @@ signData(Data& data)
|
||||
return data;
|
||||
}
|
||||
|
||||
shared_ptr<Link>
|
||||
makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations)
|
||||
{
|
||||
auto link = make_shared<Link>(name, delegations);
|
||||
signData(link);
|
||||
return link;
|
||||
}
|
||||
|
||||
lp::Nack
|
||||
makeNack(const Interest& interest, lp::NackReason reason)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2013-2016 Regents of the University of California.
|
||||
/*
|
||||
* Copyright (c) 2013-2017 Regents of the University of California.
|
||||
*
|
||||
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
|
||||
*
|
||||
@@ -59,13 +59,6 @@ signData(shared_ptr<Data> data)
|
||||
return data;
|
||||
}
|
||||
|
||||
/** \brief create a Link object with fake signature
|
||||
* \note Link may be modified afterwards without losing the fake signature.
|
||||
* If a real signature is desired, sign again with KeyChain.
|
||||
*/
|
||||
shared_ptr<Link>
|
||||
makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations);
|
||||
|
||||
/** \brief create a Nack
|
||||
* \param interest Interest
|
||||
* \param reason Nack reason
|
||||
|
||||
Reference in new issue
Block a user