31 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>));
35 static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
36 "Interest::Error must inherit from tlv::Error");
40 , m_interestLifetime(lifetime)
42 if (lifetime < time::milliseconds::zero()) {
43 BOOST_THROW_EXCEPTION(std::invalid_argument(
"InterestLifetime must be >= 0"));
54 template<encoding::Tag TAG>
58 size_t totalLength = 0;
70 if (m_forwardingHint.
size() > 0) {
71 totalLength += m_forwardingHint.
wireEncode(encoder);
83 totalLength += encoder.prependByteArray(reinterpret_cast<uint8_t*>(&nonce),
sizeof(nonce));
84 totalLength += encoder.prependVarNumber(
sizeof(nonce));
85 totalLength += encoder.prependVarNumber(
tlv::Nonce);
95 totalLength += encoder.prependVarNumber(totalLength);
125 BOOST_THROW_EXCEPTION(
Error(
"expecting Interest element, got " +
to_string(m_wire.
type())));
162 if (ele->value_size() !=
sizeof(nonce)) {
163 BOOST_THROW_EXCEPTION(Error(
"Nonce element is malformed"));
165 std::memcpy(&nonce, ele->value(),
sizeof(nonce));
188 m_forwardingHint = DelegationList();
207 bool hasName =
false;
208 m_selectors =
Selectors().setMaxSuffixComponents(1);
211 m_forwardingHint = DelegationList();
214 for (
const Block& ele : m_wire.
elements()) {
215 switch (ele.type()) {
218 BOOST_THROW_EXCEPTION(Error(
"Name element is out of order"));
222 if (m_name.
empty()) {
223 BOOST_THROW_EXCEPTION(Error(
"Name has zero name components"));
230 BOOST_THROW_EXCEPTION(Error(
"CanBePrefix element is out of order"));
232 if (ele.value_size() != 0) {
233 BOOST_THROW_EXCEPTION(Error(
"CanBePrefix element has non-zero TLV-LENGTH"));
241 BOOST_THROW_EXCEPTION(Error(
"MustBeFresh element is out of order"));
243 if (ele.value_size() != 0) {
244 BOOST_THROW_EXCEPTION(Error(
"MustBeFresh element has non-zero TLV-LENGTH"));
252 BOOST_THROW_EXCEPTION(Error(
"ForwardingHint element is out of order"));
260 BOOST_THROW_EXCEPTION(Error(
"Nonce element is out of order"));
263 if (ele.value_size() !=
sizeof(nonce)) {
264 BOOST_THROW_EXCEPTION(Error(
"Nonce element is malformed"));
266 std::memcpy(&nonce, ele.value(),
sizeof(nonce));
273 BOOST_THROW_EXCEPTION(Error(
"InterestLifetime element is out of order"));
283 if (ele.value_size() != 1) {
284 BOOST_THROW_EXCEPTION(Error(
"HopLimit element is malformed"));
292 BOOST_THROW_EXCEPTION(Error(
"Parameters element is out of order"));
300 BOOST_THROW_EXCEPTION(Error(
"unrecognized element of critical type " +
309 BOOST_THROW_EXCEPTION(Error(
"Name element is missing"));
316 std::ostringstream os;
353 size_t interestNameLength = m_name.
size();
355 size_t fullNameLength = dataName.
size() + 1;
359 size_t minSuffixComponents = hasMinSuffixComponents ?
361 if (!(interestNameLength + minSuffixComponents <= fullNameLength))
366 if (hasMaxSuffixComponents &&
371 if (interestNameLength == fullNameLength) {
391 if (interestNameLength == fullNameLength - 1) {
419 if (!publisherPublicKeyLocator.
empty()) {
426 if (publisherPublicKeyLocator.
wireEncode() != *it) {
468 uint32_t newNonce = oldNonce;
469 while (newNonce == oldNonce)
478 if (lifetime < time::milliseconds::zero()) {
479 BOOST_THROW_EXCEPTION(std::invalid_argument(
"InterestLifetime must be >= 0"));
481 m_interestLifetime = lifetime;
489 m_forwardingHint = value;
525 os << delim <<
"ndn.Nonce=" << interest.
getNonce();
529 os << delim <<
"ndn.Exclude=" << interest.
getExclude();
void wireDecode(const Block &wire)
Decode the input from wire format.
const Block & wireEncode() const
Encode to a Block.
bool hasWire() const
Check if the Block has fully encoded wire.
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getName() const
Get name.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Selectors & setMustBeFresh(bool mustBeFresh)
std::string toUri() const
Return a URI-like string that represents the Interest.
const Component & get(ssize_t i) const
Get the component at the given index.
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
void refreshNonce()
Change nonce value.
std::ostream & operator<<(std::ostream &os, const Data &data)
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Interest(const Name &name=Name(), time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
Construct an Interest with given name and lifetime.
bool matchesInterest(const Interest &other) const
Check if Interest matches other interest.
element_container::const_iterator element_const_iterator
bool matchesName(const Name &name) const
Check if Interest, including selectors, matches the given name.
const int DEFAULT_CHILD_SELECTOR
void parse() const
Parse TLV-VALUE into sub elements.
Represents a TLV element of NDN packet format.
Represents an Interest packet.
element_const_iterator elements_begin() const
Equivalent to elements().begin()
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
const element_container & elements() const
Get container of sub elements.
Selectors & setMaxSuffixComponents(int maxSuffixComponents)
bool hasNonce() const
Check if the Nonce element is present.
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in the range [0, 2^32)
a concept check for TLV abstraction with .wireEncode method
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
element_const_iterator elements_end() const
Equivalent to elements().end()
const Signature & getSignature() const
Get Signature.
NDN_CXX_DEPRECATED int getMinSuffixComponents() const
element_const_iterator find(uint32_t type) const
Find the first sub element of specified TLV-TYPE.
uint32_t getNonce() const
Get nonce value.
NDN_CXX_DEPRECATED const Selectors & getSelectors() const
const Block & getInfo() const
Get SignatureInfo as wire format.
Interest & setNonce(uint32_t nonce)
Set nonce value.
NDN_CXX_DEPRECATED const Exclude & getExclude() const
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
size_t size() const noexcept
void reset()
Reset wire buffer of the element.
Represents an absolute name.
const Name & getFullName() const
Get full name including implicit digest.
size_t size() const
Get number of components.
void wireDecode(const Block &wire)
Decode from wire in NDN Packet Format v0.2 or v0.3.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend wire encoding
NDN_CXX_DEPRECATED int getChildSelector() const
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
time::milliseconds getInterestLifetime() const
NDN_CXX_DEPRECATED bool hasSelectors() const
Check if Interest has any selector present.
represents a list of Delegations
bool empty() const
Check if name is empty.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Interest & setForwardingHint(const DelegationList &value)
bool getMustBeFresh() const
Check whether the MustBeFresh element is present.
Interest & setInterestLifetime(time::milliseconds lifetime)
Set Interest's lifetime.
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
std::string to_string(const V &v)
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
NDN_CXX_DEPRECATED const KeyLocator & getPublisherPublicKeyLocator() const
void wireDecode(const Block &wire)
Decode name from wire encoding.
a concept check for TLV abstraction with .wireEncode method
Represents a Data packet.
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
EncodingImpl< EstimatorTag > EncodingEstimator
const Name & getName() const
Holds SignatureInfo and SignatureValue in a Data packet.
NDN_CXX_DEPRECATED int getMaxSuffixComponents() const