NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 "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 #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>));
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
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  auto element = m_wire.elements_begin();
309  if (element == m_wire.elements_end() || element->type() != tlv::Name) {
310  BOOST_THROW_EXCEPTION(Error("Name element is missing or out of order"));
311  }
312  m_name.wireDecode(*element);
313  if (m_name.empty()) {
314  BOOST_THROW_EXCEPTION(Error("Name has zero name components"));
315  }
316  int lastElement = 1; // last recognized element index, in spec order
317 
318  m_selectors = Selectors().setMaxSuffixComponents(1); // CanBePrefix=0
319  m_nonce.reset();
320  m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
321  m_forwardingHint = DelegationList();
322  m_parameters = Block();
323 
324  for (++element; element != m_wire.elements_end(); ++element) {
325  switch (element->type()) {
326  case tlv::CanBePrefix: {
327  if (lastElement >= 2) {
328  BOOST_THROW_EXCEPTION(Error("CanBePrefix element is out of order"));
329  }
330  if (element->value_size() != 0) {
331  BOOST_THROW_EXCEPTION(Error("CanBePrefix element has non-zero TLV-LENGTH"));
332  }
333  m_selectors.setMaxSuffixComponents(-1);
334  lastElement = 2;
335  break;
336  }
337  case tlv::MustBeFresh: {
338  if (lastElement >= 3) {
339  BOOST_THROW_EXCEPTION(Error("MustBeFresh element is out of order"));
340  }
341  if (element->value_size() != 0) {
342  BOOST_THROW_EXCEPTION(Error("MustBeFresh element has non-zero TLV-LENGTH"));
343  }
344  m_selectors.setMustBeFresh(true);
345  lastElement = 3;
346  break;
347  }
348  case tlv::ForwardingHint: {
349  if (lastElement >= 4) {
350  BOOST_THROW_EXCEPTION(Error("ForwardingHint element is out of order"));
351  }
352  m_forwardingHint.wireDecode(*element);
353  lastElement = 4;
354  break;
355  }
356  case tlv::Nonce: {
357  if (lastElement >= 5) {
358  BOOST_THROW_EXCEPTION(Error("Nonce element is out of order"));
359  }
360  uint32_t nonce = 0;
361  if (element->value_size() != sizeof(nonce)) {
362  BOOST_THROW_EXCEPTION(Error("Nonce element is malformed"));
363  }
364  std::memcpy(&nonce, element->value(), sizeof(nonce));
365  m_nonce = nonce;
366  lastElement = 5;
367  break;
368  }
369  case tlv::InterestLifetime: {
370  if (lastElement >= 6) {
371  BOOST_THROW_EXCEPTION(Error("InterestLifetime element is out of order"));
372  }
373  m_interestLifetime = time::milliseconds(readNonNegativeInteger(*element));
374  lastElement = 6;
375  break;
376  }
377  case tlv::HopLimit: {
378  if (lastElement >= 7) {
379  break; // HopLimit is non-critical, ignore out-of-order appearance
380  }
381  if (element->value_size() != 1) {
382  BOOST_THROW_EXCEPTION(Error("HopLimit element is malformed"));
383  }
384  // TLV-VALUE is ignored
385  lastElement = 7;
386  break;
387  }
388  case tlv::Parameters: {
389  if (lastElement >= 8) {
390  BOOST_THROW_EXCEPTION(Error("Parameters element is out of order"));
391  }
392  m_parameters = *element;
393  lastElement = 8;
394  break;
395  }
396  default: {
397  if (tlv::isCriticalType(element->type())) {
398  BOOST_THROW_EXCEPTION(Error("unrecognized element of critical type " +
399  to_string(element->type())));
400  }
401  break;
402  }
403  }
404  }
405 }
406 
407 std::string
409 {
410  std::ostringstream os;
411  os << *this;
412  return os.str();
413 }
414 
415 // ---- matching ----
416 
417 bool
419 {
420  if (name.size() < m_name.size())
421  return false;
422 
423  if (!m_name.isPrefixOf(name))
424  return false;
425 
426  if (getMinSuffixComponents() >= 0 &&
427  // name must include implicit digest
428  !(name.size() - m_name.size() >= static_cast<size_t>(getMinSuffixComponents())))
429  return false;
430 
431  if (getMaxSuffixComponents() >= 0 &&
432  // name must include implicit digest
433  !(name.size() - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents())))
434  return false;
435 
436  if (!getExclude().empty() &&
437  name.size() > m_name.size() &&
438  getExclude().isExcluded(name[m_name.size()]))
439  return false;
440 
441  return true;
442 }
443 
444 bool
445 Interest::matchesData(const Data& data) const
446 {
447  size_t interestNameLength = m_name.size();
448  const Name& dataName = data.getName();
449  size_t fullNameLength = dataName.size() + 1;
450 
451  // check MinSuffixComponents
452  bool hasMinSuffixComponents = getMinSuffixComponents() >= 0;
453  size_t minSuffixComponents = hasMinSuffixComponents ?
454  static_cast<size_t>(getMinSuffixComponents()) : 0;
455  if (!(interestNameLength + minSuffixComponents <= fullNameLength))
456  return false;
457 
458  // check MaxSuffixComponents
459  bool hasMaxSuffixComponents = getMaxSuffixComponents() >= 0;
460  if (hasMaxSuffixComponents &&
461  !(interestNameLength + getMaxSuffixComponents() >= fullNameLength))
462  return false;
463 
464  // check prefix
465  if (interestNameLength == fullNameLength) {
466  if (m_name.get(-1).isImplicitSha256Digest()) {
467  if (m_name != data.getFullName())
468  return false;
469  }
470  else {
471  // Interest Name is same length as Data full Name, but last component isn't digest
472  // so there's no possibility of matching
473  return false;
474  }
475  }
476  else {
477  // Interest Name is a strict prefix of Data full Name
478  if (!m_name.isPrefixOf(dataName))
479  return false;
480  }
481 
482  // check Exclude
483  // Exclude won't be violated if Interest Name is same as Data full Name
484  if (!getExclude().empty() && fullNameLength > interestNameLength) {
485  if (interestNameLength == fullNameLength - 1) {
486  // component to exclude is the digest
487  if (getExclude().isExcluded(data.getFullName().get(interestNameLength)))
488  return false;
489  // There's opportunity to inspect the Exclude filter and determine whether
490  // the digest would make a difference.
491  // eg. "<GenericNameComponent>AA</GenericNameComponent><Any/>" doesn't exclude
492  // any digest - fullName not needed;
493  // "<Any/><GenericNameComponent>AA</GenericNameComponent>" and
494  // "<Any/><ImplicitSha256DigestComponent>ffffffffffffffffffffffffffffffff
495  // </ImplicitSha256DigestComponent>"
496  // excludes all digests - fullName not needed;
497  // "<Any/><ImplicitSha256DigestComponent>80000000000000000000000000000000
498  // </ImplicitSha256DigestComponent>"
499  // excludes some digests - fullName required
500  // But Interests that contain the exact Data Name before digest and also
501  // contain Exclude filter is too rare to optimize for, so we request
502  // fullName no matter what's in the Exclude filter.
503  }
504  else {
505  // component to exclude is not the digest
506  if (getExclude().isExcluded(dataName.get(interestNameLength)))
507  return false;
508  }
509  }
510 
511  // check PublisherPublicKeyLocator
512  const KeyLocator& publisherPublicKeyLocator = this->getPublisherPublicKeyLocator();
513  if (!publisherPublicKeyLocator.empty()) {
514  const Signature& signature = data.getSignature();
515  const Block& signatureInfo = signature.getInfo();
517  if (it == signatureInfo.elements_end()) {
518  return false;
519  }
520  if (publisherPublicKeyLocator.wireEncode() != *it) {
521  return false;
522  }
523  }
524 
525  return true;
526 }
527 
528 bool
530 {
532  return (this->getName() == other.getName() &&
533  this->getSelectors() == other.getSelectors());
534 }
535 
536 // ---- field accessors ----
537 
538 uint32_t
540 {
541  if (!m_nonce) {
542  m_nonce = random::generateWord32();
543  }
544  return *m_nonce;
545 }
546 
547 Interest&
548 Interest::setNonce(uint32_t nonce)
549 {
550  m_nonce = nonce;
551  m_wire.reset();
552  return *this;
553 }
554 
555 void
557 {
558  if (!hasNonce())
559  return;
560 
561  uint32_t oldNonce = getNonce();
562  uint32_t newNonce = oldNonce;
563  while (newNonce == oldNonce)
564  newNonce = random::generateWord32();
565 
566  setNonce(newNonce);
567 }
568 
569 Interest&
570 Interest::setInterestLifetime(time::milliseconds lifetime)
571 {
572  if (lifetime < time::milliseconds::zero()) {
573  BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0"));
574  }
575  m_interestLifetime = lifetime;
576  m_wire.reset();
577  return *this;
578 }
579 
580 Interest&
582 {
583  m_forwardingHint = value;
584  m_wire.reset();
585  return *this;
586 }
587 
588 Interest&
589 Interest::setParameters(const Block& parameters)
590 {
591  if (parameters.type() == tlv::Parameters) {
592  m_parameters = parameters;
593  }
594  else {
595  m_parameters = Block(tlv::Parameters, parameters);
596  }
597  m_wire.reset();
598  return *this;
599 }
600 
601 Interest&
602 Interest::setParameters(const uint8_t* buffer, size_t bufferSize)
603 {
604  m_parameters = makeBinaryBlock(tlv::Parameters, buffer, bufferSize);
605  m_wire.reset();
606  return *this;
607 }
608 
609 Interest&
611 {
612  m_parameters = Block(tlv::Parameters, std::move(buffer));
613  m_wire.reset();
614  return *this;
615 }
616 
617 Interest&
619 {
620  m_parameters = Block();
621  m_wire.reset();
622  return *this;
623 }
624 
625 // ---- operators ----
626 
627 bool
628 operator==(const Interest& lhs, const Interest& rhs)
629 {
630  bool wasCanBePrefixSetOnLhs = lhs.m_isCanBePrefixSet;
631  bool wasCanBePrefixSetOnRhs = rhs.m_isCanBePrefixSet;
632  lhs.m_isCanBePrefixSet = true;
633  rhs.m_isCanBePrefixSet = true;
634  BOOST_SCOPE_EXIT_ALL(&) {
635  lhs.m_isCanBePrefixSet = wasCanBePrefixSetOnLhs;
636  rhs.m_isCanBePrefixSet = wasCanBePrefixSetOnRhs;
637  };
638 
639  return lhs.wireEncode() == rhs.wireEncode();
640 }
641 
642 std::ostream&
643 operator<<(std::ostream& os, const Interest& interest)
644 {
645  os << interest.getName();
646 
647  char delim = '?';
648 
649  if (interest.getMinSuffixComponents() >= 0) {
650  os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
651  delim = '&';
652  }
653  if (interest.getMaxSuffixComponents() >= 0) {
654  os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
655  delim = '&';
656  }
657  if (interest.getChildSelector() != DEFAULT_CHILD_SELECTOR) {
658  os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
659  delim = '&';
660  }
661  if (interest.getMustBeFresh()) {
662  os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
663  delim = '&';
664  }
666  os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime().count();
667  delim = '&';
668  }
669 
670  if (interest.hasNonce()) {
671  os << delim << "ndn.Nonce=" << interest.getNonce();
672  delim = '&';
673  }
674  if (!interest.getExclude().empty()) {
675  os << delim << "ndn.Exclude=" << interest.getExclude();
676  delim = '&';
677  }
678 
679  return os;
680 }
681 
682 } // namespace ndn
void wireDecode(const Block &wire)
Decode the input from wire format.
Definition: selectors.cpp:131
const Block & wireEncode() const
Encode to a Block.
Definition: interest.cpp:202
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:249
Copyright (c) 2011-2015 Regents of the University of California.
const Name & getName() const
Get name.
Definition: data.hpp:124
int getChildSelector() const
Definition: interest.hpp:427
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
const Selectors & getSelectors() const
Definition: interest.hpp:347
Selectors & setMustBeFresh(bool mustBeFresh)
Definition: selectors.cpp:225
std::string toUri() const
Return a URI-like string that represents the Interest.
Definition: interest.cpp:408
const Component & get(ssize_t i) const
Get the component at the given index.
Definition: name.hpp:157
bool empty() const
Definition: exclude.hpp:330
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
Definition: tlv.hpp:171
void refreshNonce()
Change nonce value.
Definition: interest.cpp:556
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:251
Interest(const Name &name=Name(), time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
Construct an Interest with given name and lifetime.
Definition: interest.cpp:46
bool matchesInterest(const Interest &other) const
Check if Interest matches other interest.
Definition: interest.cpp:529
element_container::const_iterator element_const_iterator
Definition: block.hpp:47
bool matchesName(const Name &name) const
Check if Interest, including selectors, matches the given name.
Definition: interest.cpp:418
const int DEFAULT_CHILD_SELECTOR
Definition: selectors.hpp:30
void parse() const
Parse TLV-VALUE into sub elements.
Definition: block.cpp:333
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
Represents an Interest packet.
Definition: interest.hpp:44
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:369
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
Selectors & setMaxSuffixComponents(int maxSuffixComponents)
Definition: selectors.cpp:190
bool hasNonce() const
Check if the Nonce element is present.
Definition: interest.hpp:253
int getMaxSuffixComponents() const
Definition: interest.hpp:379
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in the range [0, 2^32)
Definition: random.cpp:66
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:60
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:377
const Signature & getSignature() const
Get Signature.
Definition: data.hpp:185
const KeyLocator & getPublisherPublicKeyLocator() const
Definition: interest.hpp:395
element_const_iterator find(uint32_t type) const
Find the first sub element of specified TLV-TYPE.
Definition: block.cpp:434
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
uint32_t getNonce() const
Get nonce value.
Definition: interest.cpp:539
const Block & getInfo() const
Get SignatureInfo as wire format.
Definition: signature.hpp:73
const Block & getParameters() const
Definition: interest.hpp:297
Interest & setNonce(uint32_t nonce)
Set nonce value.
Definition: interest.cpp:548
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
Definition: interest.cpp:445
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.
void reset()
Reset wire buffer of the element.
Definition: block.cpp:255
Represents an absolute name.
Definition: name.hpp:43
bool getCanBePrefix() const
Check whether the CanBePrefix element is present.
Definition: interest.hpp:174
bool hasParameters() const
Definition: interest.hpp:291
const Exclude & getExclude() const
Definition: interest.hpp:411
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:196
size_t size() const
Get number of components.
Definition: name.hpp:147
void wireDecode(const Block &wire)
Decode from wire in NDN Packet Format v0.2 or v0.3.
Definition: interest.cpp:218
size_t wireEncode(EncodingImpl< TAG > &encoder) const
prepend wire encoding
Definition: key-locator.cpp:52
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
Definition: interest.cpp:70
int getMinSuffixComponents() const
Definition: interest.hpp:363
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: selectors.cpp:61
time::milliseconds getInterestLifetime() const
Definition: interest.hpp:279
const DelegationList & getForwardingHint() const
Definition: interest.hpp:223
represents a list of Delegations
bool empty() const
Check if name is empty.
Definition: name.hpp:139
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:313
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:125
Interest & setForwardingHint(const DelegationList &value)
Definition: interest.cpp:581
bool getMustBeFresh() const
Check whether the MustBeFresh element is present.
Definition: interest.hpp:202
Interest & setInterestLifetime(time::milliseconds lifetime)
Set Interest's lifetime.
Definition: interest.cpp:570
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
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
Definition: exclude.cpp:231
void wireDecode(const Block &wire)
Decode name from wire encoding.
Definition: name.cpp:158
Interest & unsetParameters()
Remove the Parameters element from this Interest.
Definition: interest.cpp:618
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:44
Represents a Data packet.
Definition: data.hpp:35
a concept check for TLV abstraction with .wireDecode method and constructible from Block
Definition: concepts.hpp:80
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
Definition: block.hpp:249
EncodingImpl< EstimatorTag > EncodingEstimator
bool hasSelectors() const
Check if Interest has any selector present.
Definition: interest.hpp:340
const Name & getName() const
Definition: interest.hpp:134
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
Interest & setParameters(const Block &parameters)
Set parameters from a Block.
Definition: interest.cpp:589
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126