|
ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
|
#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 Name & | name () const |
| Get the Name (const reference) | |
| Name & | name () |
| Get the Name (reference) | |
| Interest & | setName (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. | |
| Interest & | setNonce (uint32_t nonce) |
| Set the Nonce. | |
| Interest & | generateNonce () |
| Generate and set a random Nonce. | |
InterestLifetime field | |
| uint32_t | lifetime () const |
| Get the InterestLifetime. | |
| Interest & | setLifetime (uint32_t lifetimeMs) |
| Set the InterestLifetime. | |
HopLimit field | |
| std::optional< uint8_t > | hopLimit () const |
| Get the HopLimit. | |
| Interest & | setHopLimit (uint8_t limit) |
| Set the HopLimit. | |
| Interest & | decrementHopLimit () |
| Decrement the HopLimit by 1. | |
CanBePrefix field | |
| bool | canBePrefix () const |
| Get the CanBePrefix flag. | |
| Interest & | setCanBePrefix (bool canBePrefix) |
| Set the CanBePrefix flag. | |
MustBeFresh field | |
| bool | mustBeFresh () const |
| Get the MustBeFresh flag. | |
| Interest & | setMustBeFresh (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 Name * | forwardingHint (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. | |
| Interest & | setApplicationParameters (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. | |
| Interest & | setSignatureSeqNum (uint64_t seqNum) |
| Set the signature sequence number. | |
| const Name * | keyLocator () const |
| Get the KeyLocator. | |
| bool | hasKeyLocator () const |
| Check if KeyLocator is set. | |
| Interest & | setKeyLocator (const Name &name) |
| Set the KeyLocator. | |
| Interest & | clearKeyLocator () |
| 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< Interest > | fromWire (const uint8_t *buf, size_t len) |
| Decode an Interest from TLV wire format. | |
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.
Definition at line 50 of file interest.hpp.
|
default |
|
explicit |
Create an Interest with a specified Name.
| name | The Interest name |
Definition at line 11 of file interest.cpp.
Add a ForwardingHint.
ForwardingHint is a list of Names indicating routes to the producer. Delegations obtained from a Link Object can be set here.
| name | Name to add |
Definition at line 64 of file interest.cpp.
References name().
Referenced by addForwardingHint().
| Error ndn::Interest::addForwardingHint | ( | std::string_view | uri | ) |
Add a ForwardingHint from a URI string.
| uri | URI string |
Definition at line 72 of file interest.cpp.
References addForwardingHint(), and ndn::Name::fromUri().
|
inline |
Get the ApplicationParameters.
Definition at line 307 of file interest.hpp.
|
inline |
Get the size of ApplicationParameters.
Definition at line 315 of file interest.hpp.
|
inline |
Get the CanBePrefix flag.
When true, this Interest also accepts Data whose Name matches as a prefix.
Definition at line 220 of file interest.hpp.
Referenced by setCanBePrefix().
| void ndn::Interest::clearForwardingHints | ( | ) |
Clear all ForwardingHints.
Definition at line 87 of file interest.cpp.
| Interest & ndn::Interest::clearKeyLocator | ( | ) |
Clear the KeyLocator.
Definition at line 109 of file interest.cpp.
| 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.
Definition at line 47 of file interest.cpp.
| Error ndn::Interest::encode | ( | uint8_t * | buf, |
| size_t | bufSize, | ||
| size_t & | encodedLen | ||
| ) | const |
Encode the Interest to TLV wire format.
| buf | Output buffer |
| bufSize | Buffer size |
| encodedLen | Stores the number of encoded bytes |
Definition at line 350 of file interest.cpp.
References ndn::tlv::ApplicationParameters, ndn::tlv::CanBePrefix, ndn::TlvEncoder::current(), ndn::Name::encode(), ndn::tlv::ForwardingHint, ndn::tlv::HopLimit, ndn::tlv::Interest, ndn::INTEREST_DEFAULT_LIFETIME_MS, ndn::tlv::InterestLifetime, ndn::tlv::InterestSignatureValue, ndn::tlv::MustBeFresh, ndn::tlv::Nonce, ndn::PACKET_MAX_SIZE, ndn::TlvEncoder::position(), ndn::TlvEncoder::remaining(), ndn::TlvEncoder::setPosition(), ndn::TlvEncoder::size(), ndn::varNumberSize(), ndn::TlvEncoder::writeBytes(), ndn::TlvEncoder::writeLength(), ndn::TlvEncoder::writeTlv(), ndn::TlvEncoder::writeTlvNonNegativeInteger(), and ndn::TlvEncoder::writeType().
| const Name * ndn::Interest::forwardingHint | ( | size_t | index | ) | const |
Get a ForwardingHint by index.
| index | Index (starting from 0) |
Definition at line 80 of file interest.cpp.
|
inline |
Get the number of ForwardingHints.
Definition at line 278 of file interest.hpp.
Decode an Interest from TLV wire format.
| buf | Input buffer |
| len | Buffer length |
Definition at line 580 of file interest.cpp.
References ndn::tlv::ApplicationParameters, ndn::tlv::CanBePrefix, ndn::TlvDecoder::current(), ndn::tlv::ForwardingHint, ndn::Name::fromWire(), ndn::tlv::HopLimit, ndn::tlv::Interest, ndn::tlv::InterestLifetime, ndn::tlv::InterestSignatureInfo, ndn::tlv::InterestSignatureValue, ndn::tlv::MustBeFresh, ndn::tlv::Name, ndn::tlv::Nonce, ndn::TlvDecoder::position(), ndn::TlvDecoder::readBytes(), ndn::TlvDecoder::readNonNegativeInteger(), ndn::TlvDecoder::readTlvHeader(), ndn::TlvDecoder::remaining(), ndn::TlvDecoder::setPosition(), ndn::SIGNATURE_MAX_SIZE, and ndn::TlvDecoder::skip().
| Interest & ndn::Interest::generateNonce | ( | ) |
Generate and set a random Nonce.
Definition at line 32 of file interest.cpp.
References ndn::generateRandomNonce().
|
inline |
Check if ForwardingHints are set.
Definition at line 296 of file interest.hpp.
|
inline |
Check if KeyLocator is set.
Definition at line 391 of file interest.hpp.
|
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.
Definition at line 189 of file interest.hpp.
|
inline |
Check if the Interest is signed.
Definition at line 337 of file interest.hpp.
|
inline |
Get the KeyLocator.
Returns the reference information (Name) of the key used for signing.
Definition at line 385 of file interest.hpp.
|
inline |
Get the InterestLifetime.
Returns the Interest's lifetime in milliseconds. Default value is 4000ms (INTEREST_DEFAULT_LIFETIME_MS).
Definition at line 167 of file interest.hpp.
Referenced by ndn::Pit::insert().
|
inline |
Get the MustBeFresh flag.
When true, Data returned from the Content Store must be fresh (within its FreshnessPeriod).
Definition at line 242 of file interest.hpp.
Referenced by setMustBeFresh().
|
inline |
|
inline |
Get the Name (const reference)
Definition at line 105 of file interest.hpp.
Referenced by addForwardingHint(), ndn::Pit::insert(), setKeyLocator(), and setName().
|
inline |
Get the Nonce.
The Nonce is a 32-bit random value used for loop detection.
Definition at line 139 of file interest.hpp.
Referenced by ndn::Pit::insert(), and setNonce().
| Interest & ndn::Interest::setApplicationParameters | ( | const uint8_t * | params, |
| size_t | len | ||
| ) |
Set ApplicationParameters.
Data is copied to an internal buffer.
| params | Pointer to the parameter data |
| len | Size of the parameters in bytes |
Definition at line 91 of file interest.cpp.
| Interest & ndn::Interest::setCanBePrefix | ( | bool | canBePrefix | ) |
Set the CanBePrefix flag.
| canBePrefix | true to allow prefix matching |
Definition at line 54 of file interest.cpp.
References canBePrefix().
| Interest & ndn::Interest::setHopLimit | ( | uint8_t | limit | ) |
Set the HopLimit.
| limit | HopLimit value (0-255) |
Definition at line 42 of file interest.cpp.
Set the KeyLocator.
| name | Name identifying the key |
Definition at line 103 of file interest.cpp.
References name().
| Interest & ndn::Interest::setLifetime | ( | uint32_t | lifetimeMs | ) |
Set the InterestLifetime.
| lifetimeMs | Lifetime (milliseconds) |
Definition at line 37 of file interest.cpp.
| Interest & ndn::Interest::setMustBeFresh | ( | bool | mustBeFresh | ) |
Set the MustBeFresh flag.
| mustBeFresh | true to accept only fresh Data |
Definition at line 59 of file interest.cpp.
References mustBeFresh().
| Error ndn::Interest::setName | ( | std::string_view | uri | ) |
Set the Name from a URI string.
| uri | URI string (e.g., "/sensor/temperature") |
Definition at line 18 of file interest.cpp.
References ndn::Name::fromUri().
| Interest & ndn::Interest::setNonce | ( | uint32_t | nonce | ) |
Set the Nonce.
| nonce | Nonce value to set |
Definition at line 27 of file interest.cpp.
References nonce().
| Interest & ndn::Interest::setSignatureSeqNum | ( | uint64_t | seqNum | ) |
Set the signature sequence number.
| seqNum | Sequence number |
Definition at line 98 of file interest.cpp.
|
inline |
Get the signature nonce.
A random value for replay attack prevention.
Definition at line 352 of file interest.hpp.
|
inline |
Get the signature sequence number.
A sequence number for replay attack prevention. Can be used in combination with SignatureNonce and SignatureTime.
Definition at line 369 of file interest.hpp.
|
inline |
Get the signature time.
Definition at line 359 of file interest.hpp.
|
inline |
|
inline |
Get a pointer to the signature value.
Definition at line 410 of file interest.hpp.
|
inline |
Get the size of the signature value.
Definition at line 416 of file interest.hpp.
| Error ndn::Interest::signWithDigestSha256 | ( | ) |
Sign with DigestSha256.
Computes a SHA-256 digest from the TLV starting at ApplicationParameters, and stores it in InterestSignatureValue.
Definition at line 196 of file interest.cpp.
References ndn::currentTimeMs(), ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.
| 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.
| privKey | Private key (32 bytes) |
Definition at line 303 of file interest.cpp.
References ndn::currentTimeMs(), and ndn::PACKET_MAX_SIZE.
| 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.
| key | Pointer to the key data |
| keyLen | Key length (bytes) |
Definition at line 219 of file interest.cpp.
References ndn::currentTimeMs(), ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.
| bool ndn::Interest::verifyDigestSha256 | ( | ) | const |
Verify a DigestSha256 signature.
Definition at line 246 of file interest.cpp.
References ndn::PACKET_MAX_SIZE, and ndn::SHA256_DIGEST_SIZE.
| bool ndn::Interest::verifyEcdsa | ( | const uint8_t * | pubKey | ) | const |
Verify an ECDSA P-256 signature.
| pubKey | Public key (65 bytes, uncompressed form) |
Definition at line 326 of file interest.cpp.
References ndn::ECDSA_P256_SIG_MAX_SIZE, and ndn::PACKET_MAX_SIZE.
| bool ndn::Interest::verifyHmac | ( | const uint8_t * | key, |
| size_t | keyLen | ||
| ) | const |
Verify an HMAC-SHA256 signature.
| key | Pointer to the key data |
| keyLen | Key length (bytes) |
Definition at line 273 of file interest.cpp.
References ndn::HMAC_SHA256_SIZE, and ndn::PACKET_MAX_SIZE.