22 #ifndef NDN_CXX_INTEREST_HPP
23 #define NDN_CXX_INTEREST_HPP
34 #include <boost/endian/conversion.hpp>
58 class Nonce final :
public std::array<uint8_t, 4>
60 using Base = std::array<uint8_t, 4>;
68 boost::endian::native_to_big_inplace(n);
69 std::memcpy(data(), &n,
sizeof(n));
72 Nonce(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t n4) noexcept
87 return static_cast<const Base&
>(lhs) ==
static_cast<const Base&
>(rhs);
93 return static_cast<const Base&
>(lhs) !=
static_cast<const Base&
>(rhs);
123 template<encoding::Tag TAG>
191 return m_canBePrefix;
201 m_canBePrefix = canBePrefix;
212 return m_mustBeFresh;
222 m_mustBeFresh = mustBeFresh;
230 return m_forwardingHint;
242 return m_nonce.has_value();
276 return m_interestLifetime;
309 return !m_parameters.empty();
322 if (m_parameters.empty())
325 return m_parameters.front();
441 return s_autoCheckParametersDigest;
447 s_autoCheckParametersDigest = b;
462 setApplicationParametersInternal(
Block parameters);
465 setSignatureValueInternal(
Block sigValue);
468 computeParametersDigest()
const;
478 addOrReplaceParametersDigestComponent();
487 findParametersDigestComponent(
const Name& name);
489 std::vector<Block>::const_iterator
490 findFirstParameter(uint32_t type)
const;
493 static bool s_autoCheckParametersDigest;
496 std::vector<Name> m_forwardingHint;
497 mutable optional<Nonce> m_nonce;
499 optional<uint8_t> m_hopLimit;
500 bool m_canBePrefix =
false;
501 bool m_mustBeFresh =
false;
509 std::vector<Block> m_parameters;
511 mutable Block m_wire;
#define NDN_CXX_NODISCARD
Represents a TLV element of the NDN packet format.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
void reset() noexcept
Reset the Block to a default-constructed state.
Represents a Data packet.
Nonce(uint32_t n) noexcept
friend bool operator!=(const Nonce &lhs, const Nonce &rhs) noexcept
Nonce(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t n4) noexcept
friend std::ostream & operator<<(std::ostream &os, const Nonce &nonce)
friend bool operator==(const Nonce &lhs, const Nonce &rhs) noexcept
Represents an Interest packet.
Interest & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
static void setAutoCheckParametersDigest(bool b)
void wireDecode(const Block &wire)
Decode from wire.
const Name & getName() const noexcept
Block getApplicationParameters() const
Get the ApplicationParameters element.
Interest & setHopLimit(optional< uint8_t > hopLimit)
Set the Interest's hop limit.
Nonce getNonce() const
Get nonce value.
Interest & setSignatureValue(span< const uint8_t > value)
Set InterestSignatureValue by copying from a contiguous sequence of bytes.
span< const Name > getForwardingHint() const noexcept
bool matchesInterest(const Interest &other) const
Check if this Interest matches other.
bool hasApplicationParameters() const noexcept
Return whether this Interest has any ApplicationParameters element.
time::milliseconds getInterestLifetime() const noexcept
Get the Interest's lifetime.
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
bool getMustBeFresh() const noexcept
Check whether the MustBeFresh element is present.
Block getSignatureValue() const
Get the InterestSignatureValue element.
InputBuffers extractSignedRanges() const
Extract ranges of Interest covered by the signature in Packet Specification v0.3.
bool hasNonce() const noexcept
Check if the Nonce element is present.
bool getCanBePrefix() const noexcept
Check whether the CanBePrefix element is present.
void refreshNonce()
Change nonce value.
optional< uint8_t > getHopLimit() const noexcept
Get the Interest's hop limit.
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
bool isSigned() const noexcept
Return whether the Interest is signed.
optional< SignatureInfo > getSignatureInfo() const
Get the InterestSignatureInfo element.
Interest & unsetApplicationParameters()
Remove the ApplicationParameters element from this Interest.
bool isParametersDigestValid() const
Check if the ParametersSha256DigestComponent in the name is valid.
Interest & setName(const Name &name)
Set the Interest's name.
Interest & setSignatureInfo(const SignatureInfo &info)
Set the InterestSignatureInfo element.
Interest & setApplicationParameters(const Block &block)
Set ApplicationParameters from a Block.
Interest & setForwardingHint(std::vector< Name > value)
std::string toUri() const
Return a URI-like string that represents the Interest.
static bool getAutoCheckParametersDigest()
Interest & setNonce(optional< Nonce > nonce)
Set the Interest's nonce.
const Block & wireEncode() const
Encode into a Block.
Interest(const Name &name={}, time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
Construct an Interest with given name and lifetime.
bool hasWire() const noexcept
Check if this instance has cached wire encoding.
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
Represents an absolute name.
Base class to allow simple management of packet tags.
Represents a SignatureInfo or InterestSignatureInfo TLV element.
Represents an error in TLV encoding or decoding.
Error(const char *expectedType, uint32_t actualType)
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
boost::chrono::milliseconds milliseconds
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
shared_ptr< const Buffer > ConstBufferPtr
std::ostream & operator<<(std::ostream &os, const Data &data)
const time::milliseconds DEFAULT_INTEREST_LIFETIME
Default value of InterestLifetime.