interest.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #include "ndn-cxx/interest.hpp"
23 #include "ndn-cxx/data.hpp"
24 #include "ndn-cxx/util/random.hpp"
25 
26 #include <boost/scope_exit.hpp>
27 
28 #ifdef NDN_CXX_HAVE_STACKTRACE
29 #include <boost/stacktrace/stacktrace.hpp>
30 #endif
31 
32 #include <cstring>
33 #include <iostream>
34 #include <sstream>
35 
36 namespace ndn {
37 
38 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>));
39 BOOST_CONCEPT_ASSERT((WireEncodable<Interest>));
40 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Interest>));
41 BOOST_CONCEPT_ASSERT((WireDecodable<Interest>));
42 static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
43  "Interest::Error must inherit from tlv::Error");
44 
45 #ifdef NDN_CXX_HAVE_TESTS
46 bool Interest::s_errorIfCanBePrefixUnset = true;
47 #endif // NDN_CXX_HAVE_TESTS
48 boost::logic::tribool Interest::s_defaultCanBePrefix = boost::logic::indeterminate;
49 
50 Interest::Interest(const Name& name, time::milliseconds lifetime)
51  : m_name(name)
52  , m_isCanBePrefixSet(false)
53  , m_interestLifetime(lifetime)
54 {
55  if (lifetime < 0_ms) {
56  NDN_THROW(std::invalid_argument("InterestLifetime must be >= 0"));
57  }
58 
59  if (!boost::logic::indeterminate(s_defaultCanBePrefix)) {
60  setCanBePrefix(bool(s_defaultCanBePrefix));
61  }
62 }
63 
65  : m_isCanBePrefixSet(true)
66 {
67  wireDecode(wire);
68 }
69 
70 // ---- encode and decode ----
71 
72 static void
74 {
75  static bool didWarn = false;
76  if (!didWarn) {
77  didWarn = true;
78  std::cerr << "WARNING: Interest.CanBePrefix will be set to false in the near future. "
79  << "Please declare a preferred setting via Interest::setDefaultCanBePrefix.\n";
80 #ifdef NDN_CXX_HAVE_STACKTRACE
81  if (std::getenv("NDN_CXX_VERBOSE_CANBEPREFIX_UNSET_WARNING") != nullptr) {
82  std::cerr << boost::stacktrace::stacktrace(2, 64);
83  }
84 #endif
85  }
86 }
87 
88 template<encoding::Tag TAG>
89 size_t
90 Interest::wireEncode(EncodingImpl<TAG>& encoder) const
91 {
92  if (!m_isCanBePrefixSet) {
94 #ifdef NDN_CXX_HAVE_TESTS
95  if (s_errorIfCanBePrefixUnset) {
96  NDN_THROW(std::logic_error("Interest.CanBePrefix is unset"));
97  }
98 #endif // NDN_CXX_HAVE_TESTS
99  }
100 
101  if (hasApplicationParameters()) {
102  return encode03(encoder);
103  }
104  else {
105  return encode02(encoder);
106  }
107 }
108 
109 template<encoding::Tag TAG>
110 size_t
111 Interest::encode02(EncodingImpl<TAG>& encoder) const
112 {
113  size_t totalLength = 0;
114 
115  // Encode as NDN Packet Format v0.2
116  // Interest ::= INTEREST-TYPE TLV-LENGTH
117  // Name
118  // Selectors?
119  // Nonce
120  // InterestLifetime?
121  // ForwardingHint?
122 
123  // (reverse encoding)
124 
125  // ForwardingHint
126  if (getForwardingHint().size() > 0) {
127  totalLength += getForwardingHint().wireEncode(encoder);
128  }
129 
130  // InterestLifetime
133  static_cast<uint64_t>(getInterestLifetime().count()));
134  }
135 
136  // Nonce
137  uint32_t nonce = getNonce(); // if nonce was unset, getNonce generates a random nonce
138  totalLength += encoder.prependByteArrayBlock(tlv::Nonce, reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce));
139 
140  // Selectors
141  if (hasSelectors()) {
142  totalLength += getSelectors().wireEncode(encoder);
143  }
144 
145  // Name
146  totalLength += getName().wireEncode(encoder);
147 
148  totalLength += encoder.prependVarNumber(totalLength);
149  totalLength += encoder.prependVarNumber(tlv::Interest);
150  return totalLength;
151 }
152 
153 template<encoding::Tag TAG>
154 size_t
155 Interest::encode03(EncodingImpl<TAG>& encoder) const
156 {
157  size_t totalLength = 0;
158 
159  // Encode as NDN Packet Format v0.3
160  // Interest ::= INTEREST-TYPE TLV-LENGTH
161  // Name
162  // CanBePrefix?
163  // MustBeFresh?
164  // ForwardingHint?
165  // Nonce?
166  // InterestLifetime?
167  // HopLimit?
168  // ApplicationParameters?
169 
170  // (reverse encoding)
171 
172  // ApplicationParameters
173  if (hasApplicationParameters()) {
174  totalLength += encoder.prependBlock(getApplicationParameters());
175  }
176 
177  // HopLimit: not yet supported
178 
179  // InterestLifetime
182  static_cast<uint64_t>(getInterestLifetime().count()));
183  }
184 
185  // Nonce
186  uint32_t nonce = getNonce(); // if nonce was unset, getNonce generates a random nonce
187  totalLength += encoder.prependByteArrayBlock(tlv::Nonce, reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce));
188 
189  // ForwardingHint
190  if (!getForwardingHint().empty()) {
191  totalLength += getForwardingHint().wireEncode(encoder);
192  }
193 
194  // MustBeFresh
195  if (getMustBeFresh()) {
196  totalLength += prependEmptyBlock(encoder, tlv::MustBeFresh);
197  }
198 
199  // CanBePrefix
200  if (getCanBePrefix()) {
201  totalLength += prependEmptyBlock(encoder, tlv::CanBePrefix);
202  }
203 
204  // Name
205  totalLength += getName().wireEncode(encoder);
206 
207  totalLength += encoder.prependVarNumber(totalLength);
208  totalLength += encoder.prependVarNumber(tlv::Interest);
209  return totalLength;
210 }
211 
213 
214 const Block&
216 {
217  if (m_wire.hasWire())
218  return m_wire;
219 
220  EncodingEstimator estimator;
221  size_t estimatedSize = wireEncode(estimator);
222 
223  EncodingBuffer buffer(estimatedSize, 0);
224  wireEncode(buffer);
225 
226  const_cast<Interest*>(this)->wireDecode(buffer.block());
227  return m_wire;
228 }
229 
230 void
232 {
233  m_wire = wire;
234  m_wire.parse();
235 
236  if (m_wire.type() != tlv::Interest) {
237  NDN_THROW(Error("Interest", m_wire.type()));
238  }
239 
240  if (!decode02()) {
241  decode03();
242  if (!hasNonce()) {
243  setNonce(getNonce());
244  }
245  }
246 
247  m_isCanBePrefixSet = true; // don't trigger warning from decoded packet
248 }
249 
250 bool
251 Interest::decode02()
252 {
253  auto element = m_wire.elements_begin();
254 
255  // Name
256  if (element != m_wire.elements_end() && element->type() == tlv::Name) {
257  m_name.wireDecode(*element);
258  ++element;
259  }
260  else {
261  return false;
262  }
263 
264  // Selectors?
265  if (element != m_wire.elements_end() && element->type() == tlv::Selectors) {
266  m_selectors.wireDecode(*element);
267  ++element;
268  }
269  else {
270  m_selectors = {};
271  }
272 
273  // Nonce
274  if (element != m_wire.elements_end() && element->type() == tlv::Nonce) {
275  uint32_t nonce = 0;
276  if (element->value_size() != sizeof(nonce)) {
277  NDN_THROW(Error("Nonce element is malformed"));
278  }
279  std::memcpy(&nonce, element->value(), sizeof(nonce));
280  m_nonce = nonce;
281  ++element;
282  }
283  else {
284  return false;
285  }
286 
287  // InterestLifetime?
288  if (element != m_wire.elements_end() && element->type() == tlv::InterestLifetime) {
289  m_interestLifetime = time::milliseconds(readNonNegativeInteger(*element));
290  ++element;
291  }
292  else {
293  m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
294  }
295 
296  // ForwardingHint?
297  if (element != m_wire.elements_end() && element->type() == tlv::ForwardingHint) {
298  m_forwardingHint.wireDecode(*element, false);
299  ++element;
300  }
301  else {
302  m_forwardingHint = {};
303  }
304 
305  return element == m_wire.elements_end();
306 }
307 
308 void
309 Interest::decode03()
310 {
311  // Interest ::= INTEREST-TYPE TLV-LENGTH
312  // Name
313  // CanBePrefix?
314  // MustBeFresh?
315  // ForwardingHint?
316  // Nonce?
317  // InterestLifetime?
318  // HopLimit?
319  // ApplicationParameters?
320 
321  auto element = m_wire.elements_begin();
322  if (element == m_wire.elements_end() || element->type() != tlv::Name) {
323  NDN_THROW(Error("Name element is missing or out of order"));
324  }
325  m_name.wireDecode(*element);
326  if (m_name.empty()) {
327  NDN_THROW(Error("Name has zero name components"));
328  }
329  int lastElement = 1; // last recognized element index, in spec order
330 
331  m_selectors = Selectors().setMaxSuffixComponents(1); // CanBePrefix=0
332  m_nonce.reset();
333  m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
334  m_forwardingHint = {};
335  m_parameters = {};
336 
337  for (++element; element != m_wire.elements_end(); ++element) {
338  switch (element->type()) {
339  case tlv::CanBePrefix: {
340  if (lastElement >= 2) {
341  NDN_THROW(Error("CanBePrefix element is out of order"));
342  }
343  if (element->value_size() != 0) {
344  NDN_THROW(Error("CanBePrefix element has non-zero TLV-LENGTH"));
345  }
346  m_selectors.setMaxSuffixComponents(-1);
347  lastElement = 2;
348  break;
349  }
350  case tlv::MustBeFresh: {
351  if (lastElement >= 3) {
352  NDN_THROW(Error("MustBeFresh element is out of order"));
353  }
354  if (element->value_size() != 0) {
355  NDN_THROW(Error("MustBeFresh element has non-zero TLV-LENGTH"));
356  }
357  m_selectors.setMustBeFresh(true);
358  lastElement = 3;
359  break;
360  }
361  case tlv::ForwardingHint: {
362  if (lastElement >= 4) {
363  NDN_THROW(Error("ForwardingHint element is out of order"));
364  }
365  m_forwardingHint.wireDecode(*element);
366  lastElement = 4;
367  break;
368  }
369  case tlv::Nonce: {
370  if (lastElement >= 5) {
371  NDN_THROW(Error("Nonce element is out of order"));
372  }
373  uint32_t nonce = 0;
374  if (element->value_size() != sizeof(nonce)) {
375  NDN_THROW(Error("Nonce element is malformed"));
376  }
377  std::memcpy(&nonce, element->value(), sizeof(nonce));
378  m_nonce = nonce;
379  lastElement = 5;
380  break;
381  }
382  case tlv::InterestLifetime: {
383  if (lastElement >= 6) {
384  NDN_THROW(Error("InterestLifetime element is out of order"));
385  }
386  m_interestLifetime = time::milliseconds(readNonNegativeInteger(*element));
387  lastElement = 6;
388  break;
389  }
390  case tlv::HopLimit: {
391  if (lastElement >= 7) {
392  break; // HopLimit is non-critical, ignore out-of-order appearance
393  }
394  if (element->value_size() != 1) {
395  NDN_THROW(Error("HopLimit element is malformed"));
396  }
397  // TLV-VALUE is ignored
398  lastElement = 7;
399  break;
400  }
402  if (lastElement >= 8) {
403  break; // ApplicationParameters is non-critical, ignore out-of-order appearance
404  }
405  m_parameters = *element;
406  lastElement = 8;
407  break;
408  }
409  default: {
410  if (tlv::isCriticalType(element->type())) {
411  NDN_THROW(Error("Unrecognized element of critical type " + to_string(element->type())));
412  }
413  break;
414  }
415  }
416  }
417 }
418 
419 std::string
421 {
422  std::ostringstream os;
423  os << *this;
424  return os.str();
425 }
426 
427 // ---- matching ----
428 
429 bool
430 Interest::matchesName(const Name& name) const
431 {
432  if (name.size() < m_name.size())
433  return false;
434 
435  if (!m_name.isPrefixOf(name))
436  return false;
437 
438  if (getMinSuffixComponents() >= 0 &&
439  // name must include implicit digest
440  !(name.size() - m_name.size() >= static_cast<size_t>(getMinSuffixComponents())))
441  return false;
442 
443  if (getMaxSuffixComponents() >= 0 &&
444  // name must include implicit digest
445  !(name.size() - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents())))
446  return false;
447 
448  if (!getExclude().empty() &&
449  name.size() > m_name.size() &&
450  getExclude().isExcluded(name[m_name.size()]))
451  return false;
452 
453  return true;
454 }
455 
456 bool
457 Interest::matchesData(const Data& data) const
458 {
459  size_t interestNameLength = m_name.size();
460  const Name& dataName = data.getName();
461  size_t fullNameLength = dataName.size() + 1;
462 
463  // check MinSuffixComponents
464  size_t minSuffixComponents = static_cast<size_t>(std::max(0, getMinSuffixComponents()));
465  if (!(interestNameLength + minSuffixComponents <= fullNameLength))
466  return false;
467 
468  // check MaxSuffixComponents
469  bool hasMaxSuffixComponents = getMaxSuffixComponents() >= 0;
470  if (hasMaxSuffixComponents &&
471  !(interestNameLength + getMaxSuffixComponents() >= fullNameLength))
472  return false;
473 
474  // check prefix
475  if (interestNameLength == fullNameLength) {
476  if (m_name.get(-1).isImplicitSha256Digest()) {
477  if (m_name != data.getFullName())
478  return false;
479  }
480  else {
481  // Interest Name is same length as Data full Name, but last component isn't digest
482  // so there's no possibility of matching
483  return false;
484  }
485  }
486  else {
487  // Interest Name is a strict prefix of Data full Name
488  if (!m_name.isPrefixOf(dataName))
489  return false;
490  }
491 
492  // check Exclude
493  // Exclude won't be violated if Interest Name is same as Data full Name
494  if (!getExclude().empty() && fullNameLength > interestNameLength) {
495  if (interestNameLength == fullNameLength - 1) {
496  // component to exclude is the digest
497  if (getExclude().isExcluded(data.getFullName().get(interestNameLength)))
498  return false;
499  // There's opportunity to inspect the Exclude filter and determine whether
500  // the digest would make a difference.
501  // eg. "<GenericNameComponent>AA</GenericNameComponent><Any/>" doesn't exclude
502  // any digest - fullName not needed;
503  // "<Any/><GenericNameComponent>AA</GenericNameComponent>" and
504  // "<Any/><ImplicitSha256DigestComponent>ffffffffffffffffffffffffffffffff
505  // </ImplicitSha256DigestComponent>"
506  // excludes all digests - fullName not needed;
507  // "<Any/><ImplicitSha256DigestComponent>80000000000000000000000000000000
508  // </ImplicitSha256DigestComponent>"
509  // excludes some digests - fullName required
510  // But Interests that contain the exact Data Name before digest and also
511  // contain Exclude filter is too rare to optimize for, so we request
512  // fullName no matter what's in the Exclude filter.
513  }
514  else {
515  // component to exclude is not the digest
516  if (getExclude().isExcluded(dataName.get(interestNameLength)))
517  return false;
518  }
519  }
520 
521  // check PublisherPublicKeyLocator
522  const KeyLocator& publisherPublicKeyLocator = getPublisherPublicKeyLocator();
523  if (!publisherPublicKeyLocator.empty()) {
524  const Signature& signature = data.getSignature();
525  const Block& signatureInfo = signature.getInfo();
527  if (it == signatureInfo.elements_end()) {
528  return false;
529  }
530  if (publisherPublicKeyLocator.wireEncode() != *it) {
531  return false;
532  }
533  }
534 
535  return true;
536 }
537 
538 bool
540 {
542  return this->getName() == other.getName() &&
543  this->getSelectors() == other.getSelectors();
544 }
545 
546 // ---- field accessors ----
547 
548 uint32_t
550 {
551  if (!m_nonce) {
552  m_nonce = random::generateWord32();
553  }
554  return *m_nonce;
555 }
556 
557 Interest&
558 Interest::setNonce(uint32_t nonce)
559 {
560  m_nonce = nonce;
561  m_wire.reset();
562  return *this;
563 }
564 
565 void
567 {
568  if (!hasNonce())
569  return;
570 
571  uint32_t oldNonce = getNonce();
572  uint32_t newNonce = oldNonce;
573  while (newNonce == oldNonce)
574  newNonce = random::generateWord32();
575 
576  setNonce(newNonce);
577 }
578 
579 Interest&
580 Interest::setInterestLifetime(time::milliseconds lifetime)
581 {
582  if (lifetime < 0_ms) {
583  NDN_THROW(std::invalid_argument("InterestLifetime must be >= 0"));
584  }
585  m_interestLifetime = lifetime;
586  m_wire.reset();
587  return *this;
588 }
589 
590 Interest&
592 {
593  m_forwardingHint = value;
594  m_wire.reset();
595  return *this;
596 }
597 
598 Interest&
600 {
601  if (parameters.empty()) {
602  m_parameters = Block(tlv::ApplicationParameters);
603  }
604  else if (parameters.type() == tlv::ApplicationParameters) {
605  m_parameters = parameters;
606  }
607  else {
608  m_parameters = Block(tlv::ApplicationParameters, parameters);
609  }
610  m_wire.reset();
611  return *this;
612 }
613 
614 Interest&
615 Interest::setApplicationParameters(const uint8_t* buffer, size_t bufferSize)
616 {
617  if (buffer == nullptr && bufferSize != 0) {
618  NDN_THROW(std::invalid_argument("ApplicationParameters buffer cannot be nullptr"));
619  }
620  m_parameters = makeBinaryBlock(tlv::ApplicationParameters, buffer, bufferSize);
621  m_wire.reset();
622  return *this;
623 }
624 
625 Interest&
627 {
628  if (buffer == nullptr) {
629  NDN_THROW(std::invalid_argument("ApplicationParameters buffer cannot be nullptr"));
630  }
631  m_parameters = Block(tlv::ApplicationParameters, std::move(buffer));
632  m_wire.reset();
633  return *this;
634 }
635 
636 Interest&
638 {
639  m_parameters = {};
640  m_wire.reset();
641  return *this;
642 }
643 
644 // ---- operators ----
645 
646 bool
647 operator==(const Interest& lhs, const Interest& rhs)
648 {
649  bool wasCanBePrefixSetOnLhs = lhs.m_isCanBePrefixSet;
650  bool wasCanBePrefixSetOnRhs = rhs.m_isCanBePrefixSet;
651  lhs.m_isCanBePrefixSet = true;
652  rhs.m_isCanBePrefixSet = true;
653  BOOST_SCOPE_EXIT_ALL(&) {
654  lhs.m_isCanBePrefixSet = wasCanBePrefixSetOnLhs;
655  rhs.m_isCanBePrefixSet = wasCanBePrefixSetOnRhs;
656  };
657 
658  return lhs.wireEncode() == rhs.wireEncode();
659 }
660 
661 std::ostream&
662 operator<<(std::ostream& os, const Interest& interest)
663 {
664  os << interest.getName();
665 
666  char delim = '?';
667 
668  if (interest.getMinSuffixComponents() >= 0) {
669  os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
670  delim = '&';
671  }
672  if (interest.getMaxSuffixComponents() >= 0) {
673  os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
674  delim = '&';
675  }
676  if (interest.getChildSelector() != DEFAULT_CHILD_SELECTOR) {
677  os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
678  delim = '&';
679  }
680  if (interest.getMustBeFresh()) {
681  os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
682  delim = '&';
683  }
685  os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime().count();
686  delim = '&';
687  }
688  if (interest.hasNonce()) {
689  os << delim << "ndn.Nonce=" << interest.getNonce();
690  delim = '&';
691  }
692  if (!interest.getExclude().empty()) {
693  os << delim << "ndn.Exclude=" << interest.getExclude();
694  delim = '&';
695  }
696 
697  return os;
698 }
699 
700 } // namespace ndn
void wireDecode(const Block &wire)
Decode the input from wire format.
Definition: selectors.cpp:131
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend wire encoding
Definition: key-locator.cpp:52
int getMinSuffixComponents() const
Definition: interest.hpp:366
int getMaxSuffixComponents() const
Definition: interest.hpp:382
const Name & getName() const
Definition: interest.hpp:134
Definition: data.cpp:26
bool matchesName(const Name &name) const
Check if Interest, including selectors, matches the given name.
Definition: interest.cpp:430
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)
Definition: selectors.cpp:225
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: selectors.cpp:61
const Block & getApplicationParameters() const
Definition: interest.hpp:297
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
Definition: tlv.hpp:174
element_const_iterator find(uint32_t type) const
Find the first sub-element of the specified TLV-TYPE.
Definition: block.cpp:425
void refreshNonce()
Change nonce value.
Definition: interest.cpp:566
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:321
Interest(const Name &name=Name(), time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
Construct an Interest with given name and lifetime.
Definition: interest.cpp:50
element_container::const_iterator element_const_iterator
Definition: block.hpp:47
bool hasSelectors() const
Check if Interest has any selector present.
Definition: interest.hpp:343
const Signature & getSignature() const
Get Signature.
Definition: data.hpp:185
const int DEFAULT_CHILD_SELECTOR
Definition: selectors.hpp:30
const Block & wireEncode() const
Encode to a Block.
Definition: interest.cpp:215
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:125
Interest & setApplicationParameters(const Block &parameters)
Set ApplicationParameters from a Block.
Definition: interest.cpp:599
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
Represents an Interest packet.
Definition: interest.hpp:44
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:230
bool empty() const noexcept
Check if the Block is empty.
Definition: block.hpp:201
std::string toUri() const
Return a URI-like string that represents the Interest.
Definition: interest.cpp:420
int getChildSelector() const
Definition: interest.hpp:430
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
uint32_t getNonce() const
Get nonce value.
Definition: interest.cpp:549
#define NDN_THROW(e)
Definition: exception.hpp:61
Selectors & setMaxSuffixComponents(int maxSuffixComponents)
Definition: selectors.cpp:190
bool getCanBePrefix() const
Check whether the CanBePrefix element is present.
Definition: interest.hpp:174
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in the range [0, 2^32)
Definition: random.cpp:66
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
Definition: exclude.cpp:231
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
const Selectors & getSelectors() const
Definition: interest.hpp:350
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:249
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Prepend an empty TLV element.
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
static void warnOnceCanBePrefixUnset()
Definition: interest.cpp:73
bool empty() const
Definition: key-locator.hpp:91
Interest & setNonce(uint32_t nonce)
Set nonce value.
Definition: interest.cpp:558
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
Definition: interest.cpp:90
const Exclude & getExclude() const
Definition: interest.hpp:414
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
friend bool operator==(const Interest &lhs, const Interest &rhs)
Definition: interest.cpp:647
size_t size() const
Get number of components.
Definition: name.hpp:147
Represents an absolute name.
Definition: name.hpp:43
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:251
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
Definition: interest.cpp:457
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:324
uint32_t type() const
Return the TLV-TYPE of the Block.
Definition: block.hpp:274
void wireDecode(const Block &wire)
Decode from wire in NDN Packet Format v0.2 or v0.3.
Definition: interest.cpp:231
bool matchesInterest(const Interest &other) const
Check if Interest matches other interest.
Definition: interest.cpp:539
const DelegationList & getForwardingHint() const
Definition: interest.hpp:223
const Name & getName() const
Get name.
Definition: data.hpp:124
bool empty() const
Definition: exclude.hpp:330
const Block & getInfo() const
Get SignatureInfo as wire format.
Definition: signature.hpp:73
bool empty() const
Check if name is empty.
Definition: name.hpp:139
represents a list of Delegations
Interest & setForwardingHint(const DelegationList &value)
Definition: interest.cpp:591
Interest & setInterestLifetime(time::milliseconds lifetime)
Set Interest&#39;s lifetime.
Definition: interest.cpp:580
const KeyLocator & getPublisherPublicKeyLocator() const
Definition: interest.hpp:398
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
Definition: interest.hpp:40
std::string to_string(const V &v)
Definition: backports.hpp:67
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:407
time::milliseconds getInterestLifetime() const
Definition: interest.hpp:279
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:195
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:399
void wireDecode(const Block &wire)
Decode name from wire encoding.
Definition: name.cpp:158
Interest & unsetApplicationParameters()
Remove the ApplicationParameters element from this Interest.
Definition: interest.cpp:637
Represents a Data packet.
Definition: data.hpp:35
bool getMustBeFresh() const
Check whether the MustBeFresh element is present.
Definition: interest.hpp:202
bool hasApplicationParameters() const
Definition: interest.hpp:291
const Component & get(ssize_t i) const
Get the component at the given index.
Definition: name.hpp:157
EncodingImpl< EncoderTag > EncodingBuffer
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
EncodingImpl< EstimatorTag > EncodingEstimator
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:37
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Definition: interest.hpp:187
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
bool hasNonce() const
Check if the Nonce element is present.
Definition: interest.hpp:253