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