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>,
private boost::equality_comparable<Nonce>
66 boost::endian::native_to_big_inplace(n);
67 std::memcpy(data(), &n,
sizeof(n));
70 Nonce(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t n4) noexcept
86 return std::equal(lhs.begin(), lhs.end(), rhs.begin());
119 template<encoding::Tag TAG>
197 return m_canBePrefix;
213 return m_mustBeFresh;
229 return m_forwardingHint;
246 return m_nonce.has_value();
263 setNonce(std::optional<Nonce> nonce);
294 std::optional<uint8_t>
314 return !m_parameters.empty();
327 if (m_parameters.empty())
330 return m_parameters.front();
457 [[nodiscard]] InputBuffers
464 return s_autoCheckParametersDigest;
470 s_autoCheckParametersDigest = b;
486 setApplicationParametersInternal(
Block parameters);
489 setSignatureValueInternal(
Block sigValue);
491 [[nodiscard]] shared_ptr<Buffer>
492 computeParametersDigest()
const;
502 addOrReplaceParametersDigestComponent();
511 findParametersDigestComponent(
const Name& name);
513 std::vector<Block>::const_iterator
514 findFirstParameter(uint32_t type)
const;
518 std::vector<Name> m_forwardingHint;
519 mutable std::optional<Nonce> m_nonce;
521 std::optional<uint8_t> m_hopLimit;
522 bool m_canBePrefix =
false;
523 bool m_mustBeFresh =
false;
531 std::vector<Block> m_parameters;
533 mutable Block m_wire;
535 static inline bool s_autoCheckParametersDigest =
true;
Represents a TLV element of the NDN packet format.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Represents a Data packet.
Nonce(uint32_t n) 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.
static void setAutoCheckParametersDigest(bool b)
void wireDecode(const Block &wire)
Decode from wire.
Interest & setHopLimit(std::optional< uint8_t > hopLimit)
Set the Interest's hop limit.
std::optional< SignatureInfo > getSignatureInfo() const
Get the InterestSignatureInfo element.
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Interest & setNonce(std::optional< Nonce > nonce)
Set the Interest's nonce.
const Name & getName() const noexcept
Get the Interest name.
Block getApplicationParameters() const
Get the ApplicationParameters element.
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
Get the delegations (names) in the ForwardingHint.
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 this Interest can be satisfied by data.
Interest & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
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.
bool hasNonce() const noexcept
Check if the Nonce element is present.
std::optional< uint8_t > getHopLimit() const noexcept
Get the Interest's hop limit.
bool getCanBePrefix() const noexcept
Check whether the CanBePrefix element is present.
void refreshNonce()
Change nonce value.
bool isSigned() const noexcept
Return whether the Interest is signed.
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 name.
Interest & setApplicationParameters(std::nullptr_t)=delete
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)
Set the ForwardingHint delegations (names).
std::string toUri() const
Return a URI-like string that represents the Interest.
static bool getAutoCheckParametersDigest()
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.
std::ostream & operator<<(std::ostream &os, const Data &data)
constexpr time::milliseconds DEFAULT_INTEREST_LIFETIME
Default value of InterestLifetime.
std::shared_ptr< const Buffer > ConstBufferPtr