ndn::Interest Class Reference

Represents an Interest packet. More...

#include <ndn-cxx/interest.hpp>

+ Inheritance diagram for ndn::Interest:
+ Collaboration diagram for ndn::Interest:

Classes

class  Error
 

Public Member Functions

 Interest (const Name &name=Name(), time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
 Construct an Interest with given name and lifetime. More...
 
 Interest (const Block &wire)
 Construct an Interest by decoding from wire. More...
 
bool getCanBePrefix () const
 Check whether the CanBePrefix element is present. More...
 
int getChildSelector () const
 
uint64_t getCongestionMark () const
 get the value of the CongestionMark tag More...
 
const ExcludegetExclude () const
 
const DelegationListgetForwardingHint () const
 
time::milliseconds getInterestLifetime () const
 
int getMaxSuffixComponents () const
 
int getMinSuffixComponents () const
 
bool getMustBeFresh () const
 Check whether the MustBeFresh element is present. More...
 
const NamegetName () const
 
uint32_t getNonce () const
 Get nonce value. More...
 
const BlockgetParameters () const
 
const KeyLocatorgetPublisherPublicKeyLocator () const
 
const SelectorsgetSelectors () const
 
template<typename T >
shared_ptr< T > getTag () const
 get a tag item More...
 
bool hasNonce () const
 Check if the Nonce element is present. More...
 
bool hasParameters () const
 
bool hasSelectors () const
 Check if Interest has any selector present. More...
 
bool hasWire () const
 Check if this instance has cached wire encoding. More...
 
bool matchesData (const Data &data) const
 Check if Interest can be satisfied by data. More...
 
bool matchesInterest (const Interest &other) const
 Check if Interest matches other interest. More...
 
bool matchesName (const Name &name) const
 Check if Interest, including selectors, matches the given name. More...
 
template<typename Modifier >
InterestmodifyForwardingHint (const Modifier &modifier)
 Modify ForwardingHint in-place. More...
 
void refreshNonce ()
 Change nonce value. More...
 
template<typename T >
void removeTag () const
 remove tag item More...
 
InterestsetCanBePrefix (bool canBePrefix)
 Add or remove CanBePrefix element. More...
 
InterestsetChildSelector (int childSelector)
 
void setCongestionMark (uint64_t mark)
 set the CongestionMark tag to the specified value More...
 
InterestsetExclude (const Exclude &exclude)
 
InterestsetForwardingHint (const DelegationList &value)
 
InterestsetInterestLifetime (time::milliseconds lifetime)
 Set Interest's lifetime. More...
 
InterestsetMaxSuffixComponents (int maxSuffixComponents)
 
InterestsetMinSuffixComponents (int minSuffixComponents)
 
InterestsetMustBeFresh (bool mustBeFresh)
 Add or remove MustBeFresh element. More...
 
InterestsetName (const Name &name)
 
InterestsetNonce (uint32_t nonce)
 Set nonce value. More...
 
InterestsetParameters (const Block &parameters)
 Set parameters from a Block. More...
 
InterestsetParameters (const uint8_t *buffer, size_t bufferSize)
 Copy parameters from raw buffer. More...
 
InterestsetParameters (ConstBufferPtr buffer)
 Set parameters from a wire buffer. More...
 
InterestsetPublisherPublicKeyLocator (const KeyLocator &keyLocator)
 
InterestsetSelectors (const Selectors &selectors)
 
template<typename T >
void setTag (shared_ptr< T > tag) const
 set a tag item More...
 
std::string toUri () const
 Return a URI-like string that represents the Interest. More...
 
InterestunsetParameters ()
 Remove the Parameters element from this Interest. More...
 
void wireDecode (const Block &wire)
 Decode from wire in NDN Packet Format v0.2 or v0.3. More...
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder) const
 Prepend wire encoding to encoder. More...
 
const BlockwireEncode () const
 Encode to a Block. More...
 

Static Public Member Functions

static void setDefaultCanBePrefix (bool canBePrefix)
 Declare the default CanBePrefix setting of the application. More...
 

Friends

bool operator== (const Interest &lhs, const Interest &rhs)
 

Detailed Description

Represents an Interest packet.

Definition at line 44 of file interest.hpp.

Constructor & Destructor Documentation

ndn::Interest::Interest ( const Name name = Name(),
time::milliseconds  lifetime = DEFAULT_INTEREST_LIFETIME 
)
explicit

Construct an Interest with given name and lifetime.

Exceptions
std::invalid_argumentlifetime is negative
Warning
In certain contexts that use Interest::shared_from_this(), Interest must be created using make_shared. Otherwise, shared_from_this() will trigger undefined behavior.

Definition at line 46 of file interest.cpp.

ndn::Interest::Interest ( const Block wire)
explicit

Construct an Interest by decoding from wire.

Warning
In certain contexts that use Interest::shared_from_this(), Interest must be created using make_shared. Otherwise, shared_from_this() will trigger undefined behavior.

Definition at line 60 of file interest.cpp.

Member Function Documentation

bool ndn::Interest::getCanBePrefix ( ) const
inline

Check whether the CanBePrefix element is present.

This is a getter for the CanBePrefix element as defined in NDN Packet Format v0.3. In this implementation, it is mapped to the closest v0.2 semantics: MaxSuffixComponents=1 means CanBePrefix is absent.

Definition at line 174 of file interest.hpp.

int ndn::Interest::getChildSelector ( ) const
inline

Definition at line 427 of file interest.hpp.

uint64_t ndn::PacketBase::getCongestionMark ( ) const
inherited

get the value of the CongestionMark tag

Definition at line 28 of file packet-base.cpp.

const Exclude& ndn::Interest::getExclude ( ) const
inline

Definition at line 411 of file interest.hpp.

const DelegationList& ndn::Interest::getForwardingHint ( ) const
inline

Definition at line 223 of file interest.hpp.

time::milliseconds ndn::Interest::getInterestLifetime ( ) const
inline

Definition at line 279 of file interest.hpp.

int ndn::Interest::getMaxSuffixComponents ( ) const
inline

Definition at line 379 of file interest.hpp.

int ndn::Interest::getMinSuffixComponents ( ) const
inline

Definition at line 363 of file interest.hpp.

bool ndn::Interest::getMustBeFresh ( ) const
inline

Check whether the MustBeFresh element is present.

This is a getter for the MustBeFresh element as defined in NDN Packet Format v0.3. In this implementation, it is mapped to the closest v0.2 semantics and appears as MustBeFresh element under Selectors.

Definition at line 202 of file interest.hpp.

const Name& ndn::Interest::getName ( ) const
inline

Definition at line 134 of file interest.hpp.

uint32_t ndn::Interest::getNonce ( ) const

Get nonce value.

If nonce was not present, it is added and assigned a random value.

Definition at line 539 of file interest.cpp.

const Block& ndn::Interest::getParameters ( ) const
inline

Definition at line 297 of file interest.hpp.

const KeyLocator& ndn::Interest::getPublisherPublicKeyLocator ( ) const
inline

Definition at line 395 of file interest.hpp.

const Selectors& ndn::Interest::getSelectors ( ) const
inline

Definition at line 347 of file interest.hpp.

template<typename T >
shared_ptr< T > ndn::TagHost::getTag ( ) const
inherited

get a tag item

Template Parameters
Ttype of the tag, which must be a subclass of ndn::Tag
Return values
nullptrif no Tag of type T is stored

Definition at line 66 of file tag-host.hpp.

bool ndn::Interest::hasNonce ( ) const
inline

Check if the Nonce element is present.

Definition at line 253 of file interest.hpp.

bool ndn::Interest::hasParameters ( ) const
inline

Definition at line 291 of file interest.hpp.

bool ndn::Interest::hasSelectors ( ) const
inline

Check if Interest has any selector present.

Definition at line 340 of file interest.hpp.

bool ndn::Interest::hasWire ( ) const
inline

Check if this instance has cached wire encoding.

Definition at line 90 of file interest.hpp.

bool ndn::Interest::matchesData ( const Data data) const

Check if Interest can be satisfied by data.

This method considers Name, MinSuffixComponents, MaxSuffixComponents, PublisherPublicKeyLocator, and Exclude. This method does not consider ChildSelector and MustBeFresh.

Definition at line 445 of file interest.cpp.

bool ndn::Interest::matchesInterest ( const Interest other) const

Check if Interest matches other interest.

Interest matches other if both have the same name, selectors, and link. Other fields (e.g., Nonce) may be different.

Todo:
Implement distinguishing Interests by forwarding hint. The current implementation checks only name+selectors (Issue #3162).
Todo:
#3162 match ForwardingHint field

Definition at line 529 of file interest.cpp.

bool ndn::Interest::matchesName ( const Name name) const

Check if Interest, including selectors, matches the given name.

Parameters
nameThe name to be matched. If this is a Data name, it shall contain the implicit digest component

Definition at line 418 of file interest.cpp.

template<typename Modifier >
Interest& ndn::Interest::modifyForwardingHint ( const Modifier &  modifier)
inline

Modify ForwardingHint in-place.

Template Parameters
Modifiera unary function that accepts DelegationList&

This is equivalent to, but more efficient (avoids copying) than:

auto fh = interest.getForwardingHint();
modifier(fh);
interest.setForwardingHint(fh);

Definition at line 243 of file interest.hpp.

void ndn::Interest::refreshNonce ( )

Change nonce value.

If the Nonce element is present, the new nonce value will differ from the old value. If the Nonce element is not present, this method does nothing.

Definition at line 556 of file interest.cpp.

template<typename T >
void ndn::TagHost::removeTag ( ) const
inherited

remove tag item

Note
Tag can be removed even on a const tag host instance

Definition at line 93 of file tag-host.hpp.

Interest& ndn::Interest::setCanBePrefix ( bool  canBePrefix)
inline

Add or remove CanBePrefix element.

Parameters
canBePrefixwhether CanBePrefix element should be present.

This is a setter for the CanBePrefix element as defined in NDN Packet Format v0.3. In this implementation, it is mapped to the closest v0.2 semantics: MaxSuffixComponents=1 means CanBePrefix is absent.

Definition at line 187 of file interest.hpp.

Interest& ndn::Interest::setChildSelector ( int  childSelector)
inline

Definition at line 434 of file interest.hpp.

void ndn::PacketBase::setCongestionMark ( uint64_t  mark)
inherited

set the CongestionMark tag to the specified value

Definition at line 41 of file packet-base.cpp.

static void ndn::Interest::setDefaultCanBePrefix ( bool  canBePrefix)
inlinestatic

Declare the default CanBePrefix setting of the application.

As part of transitioning to NDN Packet Format v0.3, the default setting for CanBePrefix will be changed from "true" to "false". Application developers are advised to review all Interests expressed by their application and decide what CanBePrefix setting is appropriate for each Interest, to avoid breaking changes when the transition occurs. Application may either set CanBePrefix on a per-Interest basis, or declare a default CanBePrefix setting for all Interests expressed by the application using this function. If an application neither declares a default nor sets CanBePrefix on every Interest, Interest::wireEncode will print a one-time warning message.

Note
This function should not be used in libraries or in ndn-cxx unit tests.
See also
https://redmine.named-data.net/projects/nfd/wiki/Packet03Transition

Definition at line 162 of file interest.hpp.

Interest& ndn::Interest::setExclude ( const Exclude exclude)
inline

Definition at line 418 of file interest.hpp.

Interest & ndn::Interest::setForwardingHint ( const DelegationList value)

Definition at line 581 of file interest.cpp.

Interest & ndn::Interest::setInterestLifetime ( time::milliseconds  lifetime)

Set Interest's lifetime.

Exceptions
std::invalid_argumentlifetime is negative

Definition at line 570 of file interest.cpp.

Interest& ndn::Interest::setMaxSuffixComponents ( int  maxSuffixComponents)
inline

Definition at line 386 of file interest.hpp.

Interest& ndn::Interest::setMinSuffixComponents ( int  minSuffixComponents)
inline

Definition at line 370 of file interest.hpp.

Interest& ndn::Interest::setMustBeFresh ( bool  mustBeFresh)
inline

Add or remove MustBeFresh element.

Parameters
mustBeFreshwhether MustBeFresh element should be present.

This is a setter for the MustBeFresh element as defined in NDN Packet Format v0.3. In this implementation, it is mapped to the closest v0.2 semantics and appears as MustBeFresh element under Selectors.

Definition at line 215 of file interest.hpp.

Interest& ndn::Interest::setName ( const Name name)
inline

Definition at line 140 of file interest.hpp.

Interest & ndn::Interest::setNonce ( uint32_t  nonce)

Set nonce value.

Definition at line 548 of file interest.cpp.

Interest & ndn::Interest::setParameters ( const Block parameters)

Set parameters from a Block.

If the block's TLV-TYPE is Parameters, it will be used directly as this Interest's Parameters element. If the block's TLV-TYPE is not Parameters, it will be nested into a Parameters element.

Returns
a reference to this Interest

Definition at line 589 of file interest.cpp.

Interest & ndn::Interest::setParameters ( const uint8_t *  buffer,
size_t  bufferSize 
)

Copy parameters from raw buffer.

Parameters
bufferpointer to the first octet of parameters
bufferSizesize of the raw buffer
Returns
a reference to this Interest

Definition at line 602 of file interest.cpp.

Interest & ndn::Interest::setParameters ( ConstBufferPtr  buffer)

Set parameters from a wire buffer.

Parameters
buffercontaining the Interest parameters
Returns
a reference to this Interest

Definition at line 610 of file interest.cpp.

Interest& ndn::Interest::setPublisherPublicKeyLocator ( const KeyLocator keyLocator)
inline

Definition at line 402 of file interest.hpp.

Interest& ndn::Interest::setSelectors ( const Selectors selectors)
inline

Definition at line 354 of file interest.hpp.

template<typename T >
void ndn::TagHost::setTag ( shared_ptr< T >  tag) const
inherited

set a tag item

Template Parameters
Ttype of the tag, which must be a subclass of ndn::Tag
Note
Tag can be set even on a const tag host instance

Definition at line 79 of file tag-host.hpp.

std::string ndn::Interest::toUri ( ) const

Return a URI-like string that represents the Interest.

The string starts with getName().toUri(). If the Interest contains selectors, they are included as a query string. Example: "/test/name?ndn.MustBeFresh=1"

Definition at line 408 of file interest.cpp.

Interest & ndn::Interest::unsetParameters ( )

Remove the Parameters element from this Interest.

Postcondition
hasParameters() == false

Definition at line 618 of file interest.cpp.

void ndn::Interest::wireDecode ( const Block wire)

Decode from wire in NDN Packet Format v0.2 or v0.3.

Definition at line 218 of file interest.cpp.

template<encoding::Tag TAG>
size_t ndn::Interest::wireEncode ( EncodingImpl< TAG > &  encoder) const

Prepend wire encoding to encoder.

Definition at line 70 of file interest.cpp.

const Block & ndn::Interest::wireEncode ( ) const

Encode to a Block.

Encodes into NDN Packet Format v0.3 if Parameters element is present. In this case, Selectors are not encoded. Otherwise, encodes into NDN Packet Format v0.2.

Definition at line 202 of file interest.cpp.

Friends And Related Function Documentation

bool operator== ( const Interest lhs,
const Interest rhs 
)
friend

Definition at line 628 of file interest.cpp.