22 #ifndef NDN_CXX_INTEREST_HPP 23 #define NDN_CXX_INTEREST_HPP 35 #include <boost/endian/conversion.hpp> 36 #include <boost/logic/tribool.hpp> 59 class Nonce final :
public std::array<uint8_t, 4>
61 using Base = std::array<uint8_t, 4>;
69 boost::endian::native_to_big_inplace(n);
70 std::memcpy(data(), &n,
sizeof(n));
73 Nonce(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t n4) noexcept
88 return static_cast<const Base&
>(lhs) == static_cast<const Base&>(rhs);
94 return static_cast<const Base&
>(lhs) != static_cast<const Base&>(rhs);
100 printHex(os, nonce.data(), nonce.size(),
false);
112 Interest(
const Name& name =
Name(), time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME);
124 template<encoding::Tag TAG>
143 return m_wire.hasWire();
202 s_defaultCanBePrefix = canBePrefix;
210 return m_canBePrefix;
219 m_canBePrefix = canBePrefix;
221 m_isCanBePrefixSet =
true;
230 return m_mustBeFresh;
239 m_mustBeFresh = mustBeFresh;
247 return m_forwardingHint;
263 template<
typename Modifier>
267 modifier(m_forwardingHint);
277 return m_nonce.has_value();
305 return m_interestLifetime;
333 return !m_parameters.empty();
346 if (m_parameters.empty())
349 return m_parameters.front();
415 optional<SignatureInfo>
450 return s_autoCheckParametersDigest;
456 s_autoCheckParametersDigest = b;
471 setApplicationParametersInternal(
Block parameters);
474 computeParametersDigest()
const;
484 addOrReplaceParametersDigestComponent();
493 findParametersDigestComponent(
const Name& name);
495 std::vector<Block>::const_iterator
496 findFirstParameter(uint32_t type)
const;
498 #ifdef NDN_CXX_HAVE_TESTS 501 static bool s_errorIfCanBePrefixUnset;
502 #endif // NDN_CXX_HAVE_TESTS 505 static boost::logic::tribool s_defaultCanBePrefix;
506 static bool s_autoCheckParametersDigest;
510 mutable optional<Nonce> m_nonce;
511 time::milliseconds m_interestLifetime;
512 optional<uint8_t> m_hopLimit;
513 mutable bool m_isCanBePrefixSet =
false;
514 bool m_canBePrefix =
true;
515 bool m_mustBeFresh =
false;
523 std::vector<Block> m_parameters;
525 mutable Block m_wire;
535 #endif // NDN_CXX_INTEREST_HPP bool isParametersDigestValid() const
Check if the ParametersSha256DigestComponent in the name is valid.
bool getMustBeFresh() const noexcept
Check whether the MustBeFresh element is present.
const Block & wireEncode() const
Encode into a Block.
static bool getAutoCheckParametersDigest()
Represents a SignatureInfo or InterestSignatureInfo TLV element.
Interest & modifyForwardingHint(const Modifier &modifier)
Modify ForwardingHint in-place.
Interest & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
std::string toUri() const
Return a URI-like string that represents the Interest.
void refreshNonce()
Change nonce value.
bool getCanBePrefix() const noexcept
Check whether the CanBePrefix element is present.
std::ostream & operator<<(std::ostream &os, const Data &data)
Interest(const Name &name=Name(), time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
Construct an Interest with given name and lifetime.
bool hasApplicationParameters() const noexcept
Return whether this Interest has any ApplicationParameters.
bool matchesInterest(const Interest &other) const
Check if this Interest matches other.
InputBuffers extractSignedRanges() const
Extract ranges of Interest covered by the signature in Packet Specification v0.3. ...
Represents a TLV element of the NDN packet format.
Represents an Interest packet.
Nonce(uint32_t n) noexcept
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
Interest & setNonce(optional< Nonce > nonce)
Set the Interest's nonce.
optional< SignatureInfo > getSignatureInfo() const
Get the InterestSignatureInfo.
Interest & setSignatureValue(ConstBufferPtr value)
Set the InterestSignatureValue.
const DelegationList & getForwardingHint() const noexcept
#define NDN_CXX_NODISCARD
base class to allow simple management of packet tags
Nonce getNonce() const
Get nonce value.
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
bool hasNonce() const noexcept
Check if the Nonce element is present.
optional< uint8_t > getHopLimit() const noexcept
static void setDefaultCanBePrefix(bool canBePrefix)
Declare the default CanBePrefix setting of the application.
Represents an absolute name.
static void setAutoCheckParametersDigest(bool b)
void wireDecode(const Block &wire)
Decode from wire.
Interest & setHopLimit(optional< uint8_t > hopLimit)
Set the Interest's hop limit.
Block getSignatureValue() const
Get the InterestSignatureValue.
Interest & setSignatureInfo(const SignatureInfo &info)
Set the InterestSignatureInfo.
bool hasWire() const noexcept
Check if this instance has cached wire encoding.
const Name & getName() const noexcept
represents a list of Delegations
Interest & setForwardingHint(const DelegationList &value)
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
time::milliseconds getInterestLifetime() const noexcept
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
friend bool operator!=(const Nonce &lhs, const Nonce &rhs) noexcept
Interest & unsetApplicationParameters()
Remove the ApplicationParameters element from this Interest.
Represents a Data packet.
Interest & setApplicationParameters(const Block &block)
Set ApplicationParameters from a Block.
Error(const char *expectedType, uint32_t actualType)
represents an error in TLV encoding or decoding
friend bool operator==(const Nonce &lhs, const Nonce &rhs) noexcept
bool isSigned() const noexcept
Return whether the Interest is signed.
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Nonce(uint8_t n1, uint8_t n2, uint8_t n3, uint8_t n4) noexcept
shared_ptr< const Buffer > ConstBufferPtr
Interest & setName(const Name &name)
Set the Interest's name.
Block getApplicationParameters() const
Get the ApplicationParameters.