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-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"
28 #include "ndn-cxx/util/random.hpp"
29 
30 #ifdef NDN_CXX_HAVE_STACKTRACE
31 #include <boost/stacktrace/stacktrace.hpp>
32 #endif
33 
34 #include <cstring>
35 #include <iostream>
36 #include <sstream>
37 
38 namespace ndn {
39 
40 BOOST_CONCEPT_ASSERT((WireEncodable<Interest>));
41 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Interest>));
42 BOOST_CONCEPT_ASSERT((WireDecodable<Interest>));
43 static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
44  "Interest::Error must inherit from tlv::Error");
45 
46 #ifdef NDN_CXX_HAVE_TESTS
47 bool Interest::s_errorIfCanBePrefixUnset = true;
48 #endif // NDN_CXX_HAVE_TESTS
49 boost::logic::tribool Interest::s_defaultCanBePrefix = boost::logic::indeterminate;
50 bool Interest::s_autoCheckParametersDigest = true;
51 
52 Interest::Interest(const Name& name, time::milliseconds lifetime)
53 {
54  setName(name);
55  setInterestLifetime(lifetime);
56 
57  if (!boost::logic::indeterminate(s_defaultCanBePrefix)) {
58  setCanBePrefix(bool(s_defaultCanBePrefix));
59  }
60 }
61 
63 {
64  wireDecode(wire);
65 }
66 
67 // ---- encode and decode ----
68 
69 static void
71 {
72  static bool didWarn = false;
73  if (!didWarn) {
74  didWarn = true;
75  std::cerr << "WARNING: Interest.CanBePrefix will be set to false in the near future. "
76  << "Please declare a preferred setting via Interest::setDefaultCanBePrefix.\n";
77 #ifdef NDN_CXX_HAVE_STACKTRACE
78  if (std::getenv("NDN_CXX_VERBOSE_CANBEPREFIX_UNSET_WARNING") != nullptr) {
79  std::cerr << boost::stacktrace::stacktrace(2, 64);
80  }
81 #endif
82  }
83 }
84 
85 template<encoding::Tag TAG>
86 size_t
88 {
89  if (!m_isCanBePrefixSet) {
91 #ifdef NDN_CXX_HAVE_TESTS
92  if (s_errorIfCanBePrefixUnset) {
93  NDN_THROW(std::logic_error("Interest.CanBePrefix is unset"));
94  }
95 #endif // NDN_CXX_HAVE_TESTS
96  }
97 
98  // Encode as NDN Packet Format v0.3
99  // Interest = INTEREST-TYPE TLV-LENGTH
100  // Name
101  // [CanBePrefix]
102  // [MustBeFresh]
103  // [ForwardingHint]
104  // [Nonce]
105  // [InterestLifetime]
106  // [HopLimit]
107  // [ApplicationParameters [InterestSignature]]
108  // (elements are encoded in reverse order)
109 
110  // sanity check of ApplicationParameters and ParametersSha256DigestComponent
111  ssize_t digestIndex = findParametersDigestComponent(getName());
112  BOOST_ASSERT(digestIndex != -2); // guaranteed by the checks in setName() and wireDecode()
113  if (digestIndex == -1) {
115  NDN_THROW(Error("Interest with parameters must have a ParametersSha256DigestComponent"));
116  }
117  else if (!hasApplicationParameters()) {
118  NDN_THROW(Error("Interest without parameters must not have a ParametersSha256DigestComponent"));
119  }
120 
121  size_t totalLength = 0;
122 
123  // ApplicationParameters and following elements (in reverse order)
124  std::for_each(m_parameters.rbegin(), m_parameters.rend(), [&] (const Block& b) {
125  totalLength += encoder.prependBlock(b);
126  });
127 
128  // HopLimit
129  if (getHopLimit()) {
130  uint8_t hopLimit = *getHopLimit();
131  totalLength += encoder.prependByteArrayBlock(tlv::HopLimit, &hopLimit, sizeof(hopLimit));
132  }
133 
134  // InterestLifetime
137  static_cast<uint64_t>(getInterestLifetime().count()));
138  }
139 
140  // Nonce
141  uint32_t nonce = getNonce(); // if nonce was unset, this generates a fresh nonce
142  totalLength += encoder.prependByteArrayBlock(tlv::Nonce, reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce));
143 
144  // ForwardingHint
145  if (!getForwardingHint().empty()) {
146  totalLength += getForwardingHint().wireEncode(encoder);
147  }
148 
149  // MustBeFresh
150  if (getMustBeFresh()) {
151  totalLength += prependEmptyBlock(encoder, tlv::MustBeFresh);
152  }
153 
154  // CanBePrefix
155  if (getCanBePrefix()) {
156  totalLength += prependEmptyBlock(encoder, tlv::CanBePrefix);
157  }
158 
159  // Name
160  totalLength += getName().wireEncode(encoder);
161 
162  totalLength += encoder.prependVarNumber(totalLength);
163  totalLength += encoder.prependVarNumber(tlv::Interest);
164  return totalLength;
165 }
166 
168 
169 const Block&
171 {
172  if (m_wire.hasWire())
173  return m_wire;
174 
175  EncodingEstimator estimator;
176  size_t estimatedSize = wireEncode(estimator);
177 
178  EncodingBuffer encoder(estimatedSize, 0);
179  wireEncode(encoder);
180 
181  const_cast<Interest*>(this)->wireDecode(encoder.block());
182  return m_wire;
183 }
184 
185 void
187 {
188  if (wire.type() != tlv::Interest) {
189  NDN_THROW(Error("Interest", wire.type()));
190  }
191  m_wire = wire;
192  m_wire.parse();
193 
194  // Interest = INTEREST-TYPE TLV-LENGTH
195  // Name
196  // [CanBePrefix]
197  // [MustBeFresh]
198  // [ForwardingHint]
199  // [Nonce]
200  // [InterestLifetime]
201  // [HopLimit]
202  // [ApplicationParameters [InterestSignature]]
203 
204  auto element = m_wire.elements_begin();
205  if (element == m_wire.elements_end() || element->type() != tlv::Name) {
206  NDN_THROW(Error("Name element is missing or out of order"));
207  }
208  // decode into a temporary object until we determine that the name is valid, in order
209  // to maintain class invariants and thus provide a basic form of exception safety
210  Name tempName(*element);
211  if (tempName.empty()) {
212  NDN_THROW(Error("Name has zero name components"));
213  }
214  ssize_t digestIndex = findParametersDigestComponent(tempName);
215  if (digestIndex == -2) {
216  NDN_THROW(Error("Name has more than one ParametersSha256DigestComponent"));
217  }
218  m_name = std::move(tempName);
219 
220  m_isCanBePrefixSet = true; // don't trigger warning from decoded packet
221  m_canBePrefix = m_mustBeFresh = false;
222  m_forwardingHint = {};
223  m_nonce.reset();
224  m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
225  m_hopLimit.reset();
226  m_parameters.clear();
227 
228  int lastElement = 1; // last recognized element index, in spec order
229  for (++element; element != m_wire.elements_end(); ++element) {
230  switch (element->type()) {
231  case tlv::CanBePrefix: {
232  if (lastElement >= 2) {
233  NDN_THROW(Error("CanBePrefix element is out of order"));
234  }
235  if (element->value_size() != 0) {
236  NDN_THROW(Error("CanBePrefix element has non-zero TLV-LENGTH"));
237  }
238  m_canBePrefix = true;
239  lastElement = 2;
240  break;
241  }
242  case tlv::MustBeFresh: {
243  if (lastElement >= 3) {
244  NDN_THROW(Error("MustBeFresh element is out of order"));
245  }
246  if (element->value_size() != 0) {
247  NDN_THROW(Error("MustBeFresh element has non-zero TLV-LENGTH"));
248  }
249  m_mustBeFresh = true;
250  lastElement = 3;
251  break;
252  }
253  case tlv::ForwardingHint: {
254  if (lastElement >= 4) {
255  NDN_THROW(Error("ForwardingHint element is out of order"));
256  }
257  m_forwardingHint.wireDecode(*element);
258  lastElement = 4;
259  break;
260  }
261  case tlv::Nonce: {
262  if (lastElement >= 5) {
263  NDN_THROW(Error("Nonce element is out of order"));
264  }
265  uint32_t nonce = 0;
266  if (element->value_size() != sizeof(nonce)) {
267  NDN_THROW(Error("Nonce element is malformed"));
268  }
269  std::memcpy(&nonce, element->value(), sizeof(nonce));
270  m_nonce = nonce;
271  lastElement = 5;
272  break;
273  }
274  case tlv::InterestLifetime: {
275  if (lastElement >= 6) {
276  NDN_THROW(Error("InterestLifetime element is out of order"));
277  }
278  m_interestLifetime = time::milliseconds(readNonNegativeInteger(*element));
279  lastElement = 6;
280  break;
281  }
282  case tlv::HopLimit: {
283  if (lastElement >= 7) {
284  break; // HopLimit is non-critical, ignore out-of-order appearance
285  }
286  if (element->value_size() != 1) {
287  NDN_THROW(Error("HopLimit element is malformed"));
288  }
289  m_hopLimit = *element->value();
290  lastElement = 7;
291  break;
292  }
294  if (lastElement >= 8) {
295  break; // ApplicationParameters is non-critical, ignore out-of-order appearance
296  }
297  BOOST_ASSERT(!hasApplicationParameters());
298  m_parameters.push_back(*element);
299  lastElement = 8;
300  break;
301  }
302  default: { // unrecognized element
303  // if the TLV-TYPE is critical, abort decoding
304  if (tlv::isCriticalType(element->type())) {
305  NDN_THROW(Error("Unrecognized element of critical type " + to_string(element->type())));
306  }
307  // if we already encountered ApplicationParameters, store this element as parameter
308  if (hasApplicationParameters()) {
309  m_parameters.push_back(*element);
310  }
311  // otherwise, ignore it
312  break;
313  }
314  }
315  }
316 
317  if (s_autoCheckParametersDigest && !isParametersDigestValid()) {
318  NDN_THROW(Error("ParametersSha256DigestComponent does not match the SHA-256 of Interest parameters"));
319  }
320 }
321 
322 std::string
324 {
325  std::ostringstream os;
326  os << *this;
327  return os.str();
328 }
329 
330 // ---- matching ----
331 
332 bool
333 Interest::matchesData(const Data& data) const
334 {
335  size_t interestNameLength = m_name.size();
336  const Name& dataName = data.getName();
337  size_t fullNameLength = dataName.size() + 1;
338 
339  // check Name and CanBePrefix
340  if (interestNameLength == fullNameLength) {
341  if (m_name.get(-1).isImplicitSha256Digest()) {
342  if (m_name != data.getFullName()) {
343  return false;
344  }
345  }
346  else {
347  // Interest Name is same length as Data full Name, but last component isn't digest
348  // so there's no possibility of matching
349  return false;
350  }
351  }
352  else if (getCanBePrefix() ? !m_name.isPrefixOf(dataName) : (m_name != dataName)) {
353  return false;
354  }
355 
356  // check MustBeFresh
357  if (getMustBeFresh() && data.getFreshnessPeriod() <= 0_ms) {
358  return false;
359  }
360 
361  return true;
362 }
363 
364 bool
366 {
367  return getName() == other.getName() &&
368  getCanBePrefix() == other.getCanBePrefix() &&
369  getMustBeFresh() == other.getMustBeFresh();
370 }
371 
372 // ---- field accessors and modifiers ----
373 
374 Interest&
376 {
377  ssize_t digestIndex = findParametersDigestComponent(name);
378  if (digestIndex == -2) {
379  NDN_THROW(std::invalid_argument("Name cannot have more than one ParametersSha256DigestComponent"));
380  }
381  if (name != m_name) {
382  m_name = name;
383  if (hasApplicationParameters()) {
384  addOrReplaceParametersDigestComponent();
385  }
386  m_wire.reset();
387  }
388  return *this;
389 }
390 
391 Interest&
393 {
394  m_forwardingHint = value;
395  m_wire.reset();
396  return *this;
397 }
398 
399 uint32_t
401 {
402  if (!hasNonce()) {
403  m_nonce = random::generateWord32();
404  m_wire.reset();
405  }
406  return *m_nonce;
407 }
408 
409 Interest&
410 Interest::setNonce(uint32_t nonce)
411 {
412  if (nonce != m_nonce) {
413  m_nonce = nonce;
414  m_wire.reset();
415  }
416  return *this;
417 }
418 
419 void
421 {
422  if (!hasNonce())
423  return;
424 
425  uint32_t oldNonce = *m_nonce;
426  while (m_nonce == oldNonce)
427  m_nonce = random::generateWord32();
428 
429  m_wire.reset();
430 }
431 
432 Interest&
433 Interest::setInterestLifetime(time::milliseconds lifetime)
434 {
435  if (lifetime < 0_ms) {
436  NDN_THROW(std::invalid_argument("InterestLifetime must be >= 0"));
437  }
438  if (lifetime != m_interestLifetime) {
439  m_interestLifetime = lifetime;
440  m_wire.reset();
441  }
442  return *this;
443 }
444 
445 Interest&
446 Interest::setHopLimit(optional<uint8_t> hopLimit)
447 {
448  if (hopLimit != m_hopLimit) {
449  m_hopLimit = hopLimit;
450  m_wire.reset();
451  }
452  return *this;
453 }
454 
455 void
456 Interest::setApplicationParametersInternal(Block parameters)
457 {
458  parameters.encode(); // ensure we have wire encoding needed by computeParametersDigest()
459  if (m_parameters.empty()) {
460  m_parameters.push_back(std::move(parameters));
461  }
462  else {
463  BOOST_ASSERT(m_parameters[0].type() == tlv::ApplicationParameters);
464  m_parameters[0] = std::move(parameters);
465  }
466 }
467 
468 Interest&
470 {
471  if (!parameters.isValid()) {
472  setApplicationParametersInternal(Block(tlv::ApplicationParameters));
473  }
474  else if (parameters.type() == tlv::ApplicationParameters) {
475  setApplicationParametersInternal(parameters);
476  }
477  else {
478  setApplicationParametersInternal(Block(tlv::ApplicationParameters, parameters));
479  }
480  addOrReplaceParametersDigestComponent();
481  m_wire.reset();
482  return *this;
483 }
484 
485 Interest&
486 Interest::setApplicationParameters(const uint8_t* value, size_t length)
487 {
488  if (value == nullptr && length != 0) {
489  NDN_THROW(std::invalid_argument("ApplicationParameters buffer cannot be nullptr"));
490  }
491  setApplicationParametersInternal(makeBinaryBlock(tlv::ApplicationParameters, value, length));
492  addOrReplaceParametersDigestComponent();
493  m_wire.reset();
494  return *this;
495 }
496 
497 Interest&
499 {
500  if (value == nullptr) {
501  NDN_THROW(std::invalid_argument("ApplicationParameters buffer cannot be nullptr"));
502  }
503  setApplicationParametersInternal(Block(tlv::ApplicationParameters, std::move(value)));
504  addOrReplaceParametersDigestComponent();
505  m_wire.reset();
506  return *this;
507 }
508 
509 Interest&
511 {
512  m_parameters.clear();
513  ssize_t digestIndex = findParametersDigestComponent(getName());
514  if (digestIndex >= 0) {
515  m_name.erase(digestIndex);
516  }
517  m_wire.reset();
518  return *this;
519 }
520 
521 // ---- ParametersSha256DigestComponent support ----
522 
523 bool
525 {
526  ssize_t digestIndex = findParametersDigestComponent(getName());
527  if (digestIndex == -1) {
528  return !hasApplicationParameters();
529  }
530  // cannot be -2 because of the checks in setName() and wireDecode()
531  BOOST_ASSERT(digestIndex >= 0);
532 
533  if (!hasApplicationParameters()) {
534  return false;
535  }
536 
537  const auto& digestComponent = getName()[digestIndex];
538  auto digest = computeParametersDigest();
539 
540  return std::equal(digestComponent.value_begin(), digestComponent.value_end(),
541  digest->begin(), digest->end());
542 }
543 
544 shared_ptr<Buffer>
545 Interest::computeParametersDigest() const
546 {
547  using namespace security::transform;
548 
549  StepSource in;
550  OBufferStream out;
552 
553  std::for_each(m_parameters.begin(), m_parameters.end(), [&] (const Block& b) {
554  in.write(b.wire(), b.size());
555  });
556  in.end();
557 
558  return out.buf();
559 }
560 
561 void
562 Interest::addOrReplaceParametersDigestComponent()
563 {
564  BOOST_ASSERT(hasApplicationParameters());
565 
566  ssize_t digestIndex = findParametersDigestComponent(getName());
567  auto digestComponent = name::Component::fromParametersSha256Digest(computeParametersDigest());
568 
569  if (digestIndex == -1) {
570  // no existing digest components, append one
571  m_name.append(std::move(digestComponent));
572  }
573  else {
574  // cannot be -2 because of the checks in setName() and wireDecode()
575  BOOST_ASSERT(digestIndex >= 0);
576  // replace the existing digest component
577  m_name.set(digestIndex, std::move(digestComponent));
578  }
579 }
580 
581 ssize_t
582 Interest::findParametersDigestComponent(const Name& name)
583 {
584  ssize_t pos = -1;
585  for (ssize_t i = 0; i < static_cast<ssize_t>(name.size()); i++) {
586  if (name[i].isParametersSha256Digest()) {
587  if (pos != -1)
588  return -2;
589  pos = i;
590  }
591  }
592  return pos;
593 }
594 
595 // ---- operators ----
596 
597 std::ostream&
598 operator<<(std::ostream& os, const Interest& interest)
599 {
600  os << interest.getName();
601 
602  char delim = '?';
603  auto printOne = [&] (const auto&... args) {
604  os << delim;
605  delim = '&';
606  using expand = int[];
607  (void)expand{(os << args, 0)...}; // use a fold expression when we switch to C++17
608  };
609 
610  if (interest.getCanBePrefix()) {
611  printOne("CanBePrefix");
612  }
613  if (interest.getMustBeFresh()) {
614  printOne("MustBeFresh");
615  }
616  if (interest.hasNonce()) {
617  printOne("Nonce=", interest.getNonce());
618  }
620  printOne("Lifetime=", interest.getInterestLifetime().count());
621  }
622  if (interest.getHopLimit()) {
623  printOne("HopLimit=", static_cast<unsigned>(*interest.getHopLimit()));
624  }
625 
626  return os;
627 }
628 
629 } // namespace ndn
ndn::Interest::getNonce
uint32_t getNonce() const
Get nonce value.
Definition: interest.cpp:400
ndn::tlv::CanBePrefix
@ CanBePrefix
Definition: tlv.hpp:71
ndn::Interest::getCanBePrefix
bool getCanBePrefix() const noexcept
Check whether the CanBePrefix element is present.
Definition: interest.hpp:155
ndn::Interest::toUri
std::string toUri() const
Return a URI-like string that represents the Interest.
Definition: interest.cpp:323
ndn::DelegationList::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
Definition: delegation-list.cpp:63
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
ndn::tlv::Nonce
@ Nonce
Definition: tlv.hpp:74
ndn::tlv::Interest
@ Interest
Definition: tlv.hpp:65
ndn::Name::erase
void erase(ssize_t i)
Erase the component at the specified index.
Definition: name.cpp:270
ndn::Name::isPrefixOf
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:299
step-source.hpp
ndn::Name::size
size_t size() const
Returns the number of components.
Definition: name.hpp:153
ndn::DigestAlgorithm::SHA256
@ SHA256
ndn::tlv::InterestLifetime
@ InterestLifetime
Definition: tlv.hpp:75
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:399
ndn::Interest::setInterestLifetime
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
Definition: interest.cpp:433
ndn::tlv::ForwardingHint
@ ForwardingHint
Definition: tlv.hpp:73
random.hpp
ndn::Name::empty
NDN_CXX_NODISCARD bool empty() const
Checks if the name is empty, i.e.
Definition: name.hpp:145
ndn::Interest::unsetApplicationParameters
Interest & unsetApplicationParameters()
Remove the ApplicationParameters element from this Interest.
Definition: interest.cpp:510
ndn::Data::getName
const Name & getName() const
Get name.
Definition: data.hpp:124
ndn::Interest::wireEncode
const Block & wireEncode() const
Encode into a Block according to NDN Packet Format v0.3.
Definition: interest.cpp:170
ndn::Block::reset
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:250
ndn::Interest::getMustBeFresh
bool getMustBeFresh() const noexcept
Check whether the MustBeFresh element is present.
Definition: interest.hpp:175
ndn::Interest::setApplicationParameters
Interest & setApplicationParameters(const Block &parameters)
Set ApplicationParameters from a Block.
Definition: interest.cpp:469
ndn::Interest::refreshNonce
void refreshNonce()
Change nonce value.
Definition: interest.cpp:420
ndn::Block::isValid
bool isValid() const noexcept
Check if the Block is valid.
Definition: block.hpp:188
ndn::Interest::setHopLimit
Interest & setHopLimit(optional< uint8_t > hopLimit)
Set the Interest's hop limit.
Definition: interest.cpp:446
ndn::name::Component::fromParametersSha256Digest
static Component fromParametersSha256Digest(ConstBufferPtr digest)
Create ParametersSha256DigestComponent component.
Definition: name-component.cpp:440
ndn::WireDecodable
a concept check for TLV abstraction with .wireDecode method and constructible from Block
Definition: concepts.hpp:81
ndn::Data::getFreshnessPeriod
time::milliseconds getFreshnessPeriod() const
Definition: data.hpp:213
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition: encoding-buffer-fwd.hpp:39
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
Definition: block-helpers.cpp:64
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
digest-filter.hpp
ns3::ndn::Name
Name
Definition: ndn-common.cpp:25
ndn::Block::type
uint32_t type() const
Return the TLV-TYPE of the Block.
Definition: block.hpp:274
ndn::WireEncodable
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:45
ndn::tlv::HopLimit
@ HopLimit
Definition: tlv.hpp:76
ndn::tlv::MustBeFresh
@ MustBeFresh
Definition: tlv.hpp:72
ndn::Name::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: name.cpp:117
ndn::Interest::Error
Definition: interest.hpp:47
ndn::Name::set
Name & set(ssize_t i, const Component &component)
Replace the component at the specified index.
Definition: name.cpp:206
ndn::Interest::setCanBePrefix
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Definition: interest.hpp:164
ndn::Interest::Interest
Interest(const Name &name=Name(), time::milliseconds lifetime=DEFAULT_INTEREST_LIFETIME)
Construct an Interest with given name and lifetime.
Definition: interest.cpp:52
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
ndn::Name::append
Name & append(const Component &component)
Append a component.
Definition: name.hpp:277
ndn::name::Component::isImplicitSha256Digest
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
Definition: name-component.cpp:416
stream-sink.hpp
ndn::Interest::getForwardingHint
const DelegationList & getForwardingHint() const noexcept
Definition: interest.hpp:192
ndn::random::generateWord32
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in the range [0, 2^32)
Definition: random.cpp:66
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
ndn::tlv::Name
@ Name
Definition: tlv.hpp:67
ndn::DEFAULT_INTEREST_LIFETIME
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
Definition: interest.hpp:39
ndn::DelegationList
represents a list of Delegations
Definition: delegation-list.hpp:38
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:325
ndn::Data
Represents a Data packet.
Definition: data.hpp:36
ndn::warnOnceCanBePrefixUnset
static void warnOnceCanBePrefixUnset()
Definition: interest.cpp:70
ndn::Interest::matchesData
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
Definition: interest.cpp:333
ndn::Interest::getInterestLifetime
time::milliseconds getInterestLifetime() const noexcept
Definition: interest.hpp:248
ndn::OBufferStream
implements an output stream that constructs ndn::Buffer
Definition: buffer-stream.hpp:71
ndn::encoding::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Definition: block-helpers.cpp:35
interest.hpp
ndn::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Interest)
ndn::Interest::setForwardingHint
Interest & setForwardingHint(const DelegationList &value)
Definition: interest.cpp:392
ndn::security::transform::digestFilter
unique_ptr< Transform > digestFilter(DigestAlgorithm algo)
Definition: digest-filter.cpp:76
ndn::encoding::EncodingImpl
Definition: encoding-buffer-fwd.hpp:36
ndn::Interest::hasApplicationParameters
bool hasApplicationParameters() const noexcept
Definition: interest.hpp:273
data.hpp
ndn::Interest::hasNonce
bool hasNonce() const noexcept
Check if the Nonce element is present.
Definition: interest.hpp:222
ndn::Interest::setName
Interest & setName(const Name &name)
Set the Interest's name.
Definition: interest.cpp:375
ndn::tlv::isCriticalType
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
Definition: tlv.hpp:174
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::security::transform::streamSink
unique_ptr< Sink > streamSink(std::ostream &os)
Definition: stream-sink.cpp:53
ndn::to_string
std::string to_string(const T &val)
Definition: backports.hpp:102
ndn::Interest::getHopLimit
optional< uint8_t > getHopLimit() const noexcept
Definition: interest.hpp:260
ndn::Block::elements_end
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:407
ndn::operator<<
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
ndn::name
Definition: name-component-types.hpp:33
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:230
ndn::Interest::getName
const Name & getName() const noexcept
Definition: interest.hpp:121
buffer-stream.hpp
ndn::encoding::prependEmptyBlock
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Prepend an empty TLV element.
Definition: block-helpers.cpp:74
ndn::OBufferStream::buf
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Definition: buffer-stream.cpp:54
ndn::Data::getFullName
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:195
ndn::Block::encode
void encode()
Encode sub-elements into TLV-VALUE.
Definition: block.cpp:353
ndn::Name::get
const Component & get(ssize_t i) const
Returns an immutable reference to the component at the specified index.
Definition: name.hpp:164
ndn::Interest::setNonce
Interest & setNonce(uint32_t nonce)
Set nonce value.
Definition: interest.cpp:410
ndn::DelegationList::wireDecode
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
Definition: delegation-list.cpp:105
ndn::Interest::isParametersDigestValid
bool isParametersDigestValid() const
Check if the ParametersSha256DigestComponent in the name is valid.
Definition: interest.cpp:524
ndn::encoding::makeBinaryBlock
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
Definition: block-helpers.cpp:181
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
ndn::WireEncodableWithEncodingBuffer
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:61
ndn::Interest::matchesInterest
bool matchesInterest(const Interest &other) const
Check if this Interest matches other.
Definition: interest.cpp:365
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition: encoding-buffer-fwd.hpp:38
ndn::tlv::ApplicationParameters
@ ApplicationParameters
Definition: tlv.hpp:77
ndn::Interest::wireDecode
void wireDecode(const Block &wire)
Decode from wire according to NDN Packet Format v0.3.
Definition: interest.cpp:186