ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::Interest Class Reference

NDN Interest packet. More...

#include <ndn/interest.hpp>

Public Member Functions

 Interest ()=default
 Default constructor.
 
 Interest (const Name &name)
 Create an Interest with a specified Name.
 
Encoding
Error encode (uint8_t *buf, size_t bufSize, size_t &encodedLen) const
 Encode the Interest to TLV wire format.
 
Name field
const Namename () const
 Get the Name (const reference)
 
Namename ()
 Get the Name (reference)
 
InterestsetName (const Name &name)
 Set the Name (supports method chaining)
 
Error setName (std::string_view uri)
 Set the Name from a URI string.
 
Nonce field
std::optional< uint32_t > nonce () const
 Get the Nonce.
 
InterestsetNonce (uint32_t nonce)
 Set the Nonce.
 
InterestgenerateNonce ()
 Generate and set a random Nonce.
 
InterestLifetime field
uint32_t lifetime () const
 Get the InterestLifetime.
 
InterestsetLifetime (uint32_t lifetimeMs)
 Set the InterestLifetime.
 
HopLimit field
std::optional< uint8_t > hopLimit () const
 Get the HopLimit.
 
InterestsetHopLimit (uint8_t limit)
 Set the HopLimit.
 
InterestdecrementHopLimit ()
 Decrement the HopLimit by 1.
 
CanBePrefix field
bool canBePrefix () const
 Get the CanBePrefix flag.
 
InterestsetCanBePrefix (bool canBePrefix)
 Set the CanBePrefix flag.
 
MustBeFresh field
bool mustBeFresh () const
 Get the MustBeFresh flag.
 
InterestsetMustBeFresh (bool mustBeFresh)
 Set the MustBeFresh flag.
 
ForwardingHint field
Error addForwardingHint (const Name &name)
 Add a ForwardingHint.
 
Error addForwardingHint (std::string_view uri)
 Add a ForwardingHint from a URI string.
 
size_t forwardingHintCount () const
 Get the number of ForwardingHints.
 
const NameforwardingHint (size_t index) const
 Get a ForwardingHint by index.
 
void clearForwardingHints ()
 Clear all ForwardingHints.
 
bool hasForwardingHint () const
 Check if ForwardingHints are set.
 
ApplicationParameters field
const uint8_t * applicationParameters () const
 Get the ApplicationParameters.
 
size_t applicationParametersSize () const
 Get the size of ApplicationParameters.
 
InterestsetApplicationParameters (const uint8_t *params, size_t len)
 Set ApplicationParameters.
 
Signature fields
bool isSigned () const
 Check if the Interest is signed.
 
SignatureType signatureType () const
 Get the signature type.
 
const uint8_t * signatureNonce () const
 Get the signature nonce.
 
std::optional< uint64_t > signatureTime () const
 Get the signature time.
 
std::optional< uint64_t > signatureSeqNum () const
 Get the signature sequence number.
 
InterestsetSignatureSeqNum (uint64_t seqNum)
 Set the signature sequence number.
 
const NamekeyLocator () const
 Get the KeyLocator.
 
bool hasKeyLocator () const
 Check if KeyLocator is set.
 
InterestsetKeyLocator (const Name &name)
 Set the KeyLocator.
 
InterestclearKeyLocator ()
 Clear the KeyLocator.
 
const uint8_t * signatureValue () const
 Get a pointer to the signature value.
 
size_t signatureValueSize () const
 Get the size of the signature value.
 
Error signWithDigestSha256 ()
 Sign with DigestSha256.
 
Error signWithHmac (const uint8_t *key, size_t keyLen)
 Sign with HMAC-SHA256.
 
bool verifyDigestSha256 () const
 Verify a DigestSha256 signature.
 
bool verifyHmac (const uint8_t *key, size_t keyLen) const
 Verify an HMAC-SHA256 signature.
 
Error signWithEcdsa (const uint8_t *privKey)
 Sign with ECDSA P-256.
 
bool verifyEcdsa (const uint8_t *pubKey) const
 Verify an ECDSA P-256 signature.
 

Static Public Member Functions

Decoding
static Result< InterestfromWire (const uint8_t *buf, size_t len)
 Decode an Interest from TLV wire format.
 

Detailed Description

NDN Interest packet.

An Interest packet is sent by a consumer to request data. Only the Name field is required; all other fields are optional.

// Create and configure an Interest
ndn::Interest interest;
interest.setName("/sensor/temperature");
interest.setLifetime(5000);
interest.generateNonce();
// Encode
uint8_t buf[128];
size_t len = 0;
if (interest.encode(buf, sizeof(buf), len) == ndn::Error::Success) {
// Send buf over the network
}
// Decode
auto result = ndn::Interest::fromWire(buf, len);
if (result.ok()) {
printf("Interest for: %s\n", result.value.name().toUri(...));
}
NDN Interest packet.
Definition interest.hpp:50
Interest & setLifetime(uint32_t lifetimeMs)
Set the InterestLifetime.
Definition interest.cpp:37
static Result< Interest > fromWire(const uint8_t *buf, size_t len)
Decode an Interest from TLV wire format.
Definition interest.cpp:580
Error encode(uint8_t *buf, size_t bufSize, size_t &encodedLen) const
Encode the Interest to TLV wire format.
Definition interest.cpp:350
Interest & generateNonce()
Generate and set a random Nonce.
Definition interest.cpp:32
Interest & setName(const Name &name)
Set the Name (supports method chaining)
Definition interest.cpp:13

Definition at line 50 of file interest.hpp.

Constructor & Destructor Documentation

◆ Interest() [1/2]

ndn::Interest::Interest ( )
default

Default constructor.

Creates an empty Interest. Name is empty, Nonce is unset, and lifetime is set to the default value (4000ms).

◆ Interest() [2/2]

ndn::Interest::Interest ( const Name name)
explicit

Create an Interest with a specified Name.

Parameters
nameThe Interest name

Definition at line 11 of file interest.cpp.

Member Function Documentation

◆ addForwardingHint() [1/2]

Error ndn::Interest::addForwardingHint ( const Name name)

Add a ForwardingHint.

ForwardingHint is a list of Names indicating routes to the producer. Delegations obtained from a Link Object can be set here.

Parameters
nameName to add
Returns
Error::Success on success, Error::Full when at capacity

Definition at line 64 of file interest.cpp.

References name().

Referenced by addForwardingHint().

◆ addForwardingHint() [2/2]

Error ndn::Interest::addForwardingHint ( std::string_view  uri)

Add a ForwardingHint from a URI string.

Parameters
uriURI string
Returns
Error::Success on success

Definition at line 72 of file interest.cpp.

References addForwardingHint(), and ndn::Name::fromUri().

◆ applicationParameters()

const uint8_t * ndn::Interest::applicationParameters ( ) const
inline

Get the ApplicationParameters.

Returns
Pointer to the parameter data, nullptr if unset

Definition at line 307 of file interest.hpp.

◆ applicationParametersSize()

size_t ndn::Interest::applicationParametersSize ( ) const
inline

Get the size of ApplicationParameters.

Returns
Size of the parameters in bytes

Definition at line 315 of file interest.hpp.

◆ canBePrefix()

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

Get the CanBePrefix flag.

When true, this Interest also accepts Data whose Name matches as a prefix.

Returns
CanBePrefix flag (default is false)

Definition at line 220 of file interest.hpp.

Referenced by setCanBePrefix().

◆ clearForwardingHints()

void ndn::Interest::clearForwardingHints ( )

Clear all ForwardingHints.

Definition at line 87 of file interest.cpp.

◆ clearKeyLocator()

Interest & ndn::Interest::clearKeyLocator ( )

Clear the KeyLocator.

Returns
Reference to this Interest

Definition at line 109 of file interest.cpp.

◆ decrementHopLimit()

Interest & ndn::Interest::decrementHopLimit ( )

Decrement the HopLimit by 1.

If HopLimit is set, decrements it by 1. If it is already 0, it remains 0.

Returns
Reference to this Interest

Definition at line 47 of file interest.cpp.

◆ encode()

◆ forwardingHint()

const Name * ndn::Interest::forwardingHint ( size_t  index) const

Get a ForwardingHint by index.

Parameters
indexIndex (starting from 0)
Returns
Pointer to the Name at the given index, nullptr if out of range

Definition at line 80 of file interest.cpp.

◆ forwardingHintCount()

size_t ndn::Interest::forwardingHintCount ( ) const
inline

Get the number of ForwardingHints.

Returns
Number of ForwardingHints

Definition at line 278 of file interest.hpp.

◆ fromWire()

◆ generateNonce()

Interest & ndn::Interest::generateNonce ( )

Generate and set a random Nonce.

Returns
Reference to this Interest

Definition at line 32 of file interest.cpp.

References ndn::generateRandomNonce().

◆ hasForwardingHint()

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

Check if ForwardingHints are set.

Returns
true if ForwardingHints are present

Definition at line 296 of file interest.hpp.

◆ hasKeyLocator()

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

Check if KeyLocator is set.

Returns
true if KeyLocator is present

Definition at line 391 of file interest.hpp.

◆ hopLimit()

std::optional< uint8_t > ndn::Interest::hopLimit ( ) const
inline

Get the HopLimit.

HopLimit is the maximum number of hops an Interest can traverse. It decreases by 1 at each hop and is not forwarded when it reaches 0.

Returns
HopLimit value (0-255) if set, nullopt if unset

Definition at line 189 of file interest.hpp.

◆ isSigned()

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

Check if the Interest is signed.

Returns
true if a signature is present

Definition at line 337 of file interest.hpp.

◆ keyLocator()

const Name * ndn::Interest::keyLocator ( ) const
inline

Get the KeyLocator.

Returns the reference information (Name) of the key used for signing.

Returns
KeyLocator Name if set, nullptr if unset

Definition at line 385 of file interest.hpp.

◆ lifetime()

uint32_t ndn::Interest::lifetime ( ) const
inline

Get the InterestLifetime.

Returns the Interest's lifetime in milliseconds. Default value is 4000ms (INTEREST_DEFAULT_LIFETIME_MS).

Returns
InterestLifetime (milliseconds)

Definition at line 167 of file interest.hpp.

Referenced by ndn::Pit::insert().

◆ mustBeFresh()

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

Get the MustBeFresh flag.

When true, Data returned from the Content Store must be fresh (within its FreshnessPeriod).

Returns
MustBeFresh flag (default is false)

Definition at line 242 of file interest.hpp.

Referenced by setMustBeFresh().

◆ name() [1/2]

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

Get the Name (reference)

Returns
Reference to the Name

Definition at line 111 of file interest.hpp.

◆ name() [2/2]

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

Get the Name (const reference)

Returns
Const reference to the Name

Definition at line 105 of file interest.hpp.

Referenced by addForwardingHint(), ndn::Pit::insert(), setKeyLocator(), and setName().

◆ nonce()

std::optional< uint32_t > ndn::Interest::nonce ( ) const
inline

Get the Nonce.

The Nonce is a 32-bit random value used for loop detection.

Returns
Nonce value if set, nullopt if unset

Definition at line 139 of file interest.hpp.

Referenced by ndn::Pit::insert(), and setNonce().

◆ setApplicationParameters()

Interest & ndn::Interest::setApplicationParameters ( const uint8_t *  params,
size_t  len 
)

Set ApplicationParameters.

Data is copied to an internal buffer.

Parameters
paramsPointer to the parameter data
lenSize of the parameters in bytes
Returns
Reference to this Interest

Definition at line 91 of file interest.cpp.

◆ setCanBePrefix()

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

Set the CanBePrefix flag.

Parameters
canBePrefixtrue to allow prefix matching
Returns
Reference to this Interest

Definition at line 54 of file interest.cpp.

References canBePrefix().

◆ setHopLimit()

Interest & ndn::Interest::setHopLimit ( uint8_t  limit)

Set the HopLimit.

Parameters
limitHopLimit value (0-255)
Returns
Reference to this Interest

Definition at line 42 of file interest.cpp.

◆ setKeyLocator()

Interest & ndn::Interest::setKeyLocator ( const Name name)

Set the KeyLocator.

Parameters
nameName identifying the key
Returns
Reference to this Interest

Definition at line 103 of file interest.cpp.

References name().

◆ setLifetime()

Interest & ndn::Interest::setLifetime ( uint32_t  lifetimeMs)

Set the InterestLifetime.

Parameters
lifetimeMsLifetime (milliseconds)
Returns
Reference to this Interest

Definition at line 37 of file interest.cpp.

◆ setMustBeFresh()

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

Set the MustBeFresh flag.

Parameters
mustBeFreshtrue to accept only fresh Data
Returns
Reference to this Interest

Definition at line 59 of file interest.cpp.

References mustBeFresh().

◆ setName() [1/2]

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

Set the Name (supports method chaining)

Parameters
nameName to set
Returns
Reference to this Interest

Definition at line 13 of file interest.cpp.

References name().

◆ setName() [2/2]

Error ndn::Interest::setName ( std::string_view  uri)

Set the Name from a URI string.

Parameters
uriURI string (e.g., "/sensor/temperature")
Returns
Error::Success on success, error code on parse failure

Definition at line 18 of file interest.cpp.

References ndn::Name::fromUri().

◆ setNonce()

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

Set the Nonce.

Parameters
nonceNonce value to set
Returns
Reference to this Interest

Definition at line 27 of file interest.cpp.

References nonce().

◆ setSignatureSeqNum()

Interest & ndn::Interest::setSignatureSeqNum ( uint64_t  seqNum)

Set the signature sequence number.

Parameters
seqNumSequence number
Returns
Reference to this Interest

Definition at line 98 of file interest.cpp.

◆ signatureNonce()

const uint8_t * ndn::Interest::signatureNonce ( ) const
inline

Get the signature nonce.

A random value for replay attack prevention.

Returns
Pointer to the signature nonce (8 bytes), nullptr if unset

Definition at line 352 of file interest.hpp.

◆ signatureSeqNum()

std::optional< uint64_t > ndn::Interest::signatureSeqNum ( ) const
inline

Get the signature sequence number.

A sequence number for replay attack prevention. Can be used in combination with SignatureNonce and SignatureTime.

Returns
Sequence number if set, nullopt if unset

Definition at line 369 of file interest.hpp.

◆ signatureTime()

std::optional< uint64_t > ndn::Interest::signatureTime ( ) const
inline

Get the signature time.

Returns
Signature time (milliseconds Unix epoch) if set, nullopt if unset

Definition at line 359 of file interest.hpp.

◆ signatureType()

SignatureType ndn::Interest::signatureType ( ) const
inline

Get the signature type.

Returns
Signature type

Definition at line 343 of file interest.hpp.

◆ signatureValue()

const uint8_t * ndn::Interest::signatureValue ( ) const
inline

Get a pointer to the signature value.

Returns
Pointer to the signature value buffer

Definition at line 410 of file interest.hpp.

◆ signatureValueSize()

size_t ndn::Interest::signatureValueSize ( ) const
inline

Get the size of the signature value.

Returns
Size of the signature value in bytes

Definition at line 416 of file interest.hpp.

◆ signWithDigestSha256()

Error ndn::Interest::signWithDigestSha256 ( )

Sign with DigestSha256.

Computes a SHA-256 digest from the TLV starting at ApplicationParameters, and stores it in InterestSignatureValue.

Returns
Error::Success on success

Definition at line 196 of file interest.cpp.

References ndn::currentTimeMs(), ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.

◆ signWithEcdsa()

Error ndn::Interest::signWithEcdsa ( const uint8_t *  privKey)

Sign with ECDSA P-256.

Computes an ECDSA signature using the specified private key and stores it in InterestSignatureValue. It is recommended to set the KeyLocator beforehand.

Parameters
privKeyPrivate key (32 bytes)
Returns
Error::Success on success

Definition at line 303 of file interest.cpp.

References ndn::currentTimeMs(), and ndn::PACKET_MAX_SIZE.

◆ signWithHmac()

Error ndn::Interest::signWithHmac ( const uint8_t *  key,
size_t  keyLen 
)

Sign with HMAC-SHA256.

Computes HMAC-SHA256 using the specified key and stores it in InterestSignatureValue.

Parameters
keyPointer to the key data
keyLenKey length (bytes)
Returns
Error::Success on success

Definition at line 219 of file interest.cpp.

References ndn::currentTimeMs(), ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.

◆ verifyDigestSha256()

bool ndn::Interest::verifyDigestSha256 ( ) const

Verify a DigestSha256 signature.

Returns
true if the signature is valid

Definition at line 246 of file interest.cpp.

References ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.

◆ verifyEcdsa()

bool ndn::Interest::verifyEcdsa ( const uint8_t *  pubKey) const

Verify an ECDSA P-256 signature.

Parameters
pubKeyPublic key (65 bytes, uncompressed form)
Returns
true if the signature is valid

Definition at line 326 of file interest.cpp.

References ndn::ECDSA_P256_SIG_MAX_SIZE, and ndn::PACKET_MAX_SIZE.

◆ verifyHmac()

bool ndn::Interest::verifyHmac ( const uint8_t *  key,
size_t  keyLen 
) const

Verify an HMAC-SHA256 signature.

Parameters
keyPointer to the key data
keyLenKey length (bytes)
Returns
true if the signature is valid

Definition at line 273 of file interest.cpp.

References ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.


The documentation for this class was generated from the following files: