blob: 05951be491846da47d7e934458f84c23dad6619f [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi899277a2017-07-07 22:12:12 +00002/*
Alexander Afanasyev1013fd02017-01-03 13:19:03 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Jeff Thompsonb7f95562013-07-03 18:36:42 -070020 */
21
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080022#include "interest.hpp"
Alexander Afanasyeve9fdb802014-02-05 17:36:51 -080023#include "util/random.hpp"
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070024#include "data.hpp"
Alexander Afanasyev840139f2013-12-28 15:02:50 -080025
Davide Pesaventoe1789892017-02-26 15:50:52 -050026#include <cstring>
27
Jeff Thompsonb7f95562013-07-03 18:36:42 -070028namespace ndn {
Alexander Afanasyev84681982014-01-03 13:26:09 -080029
Junxiao Shic2b8d242014-11-04 08:35:29 -070030BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>));
31BOOST_CONCEPT_ASSERT((WireEncodable<Interest>));
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070032BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Interest>));
Junxiao Shic2b8d242014-11-04 08:35:29 -070033BOOST_CONCEPT_ASSERT((WireDecodable<Interest>));
34static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
35 "Interest::Error must inherit from tlv::Error");
36
Junxiao Shi899277a2017-07-07 22:12:12 +000037Interest::Interest(const Name& name, time::milliseconds interestLifetime)
Junxiao Shi2af905b2014-11-27 13:10:54 -070038 : m_name(name)
Junxiao Shi2af905b2014-11-27 13:10:54 -070039 , m_interestLifetime(interestLifetime)
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -070040 , m_selectedDelegationIndex(INVALID_SELECTED_DELEGATION_INDEX)
Junxiao Shi2af905b2014-11-27 13:10:54 -070041{
Junxiao Shi899277a2017-07-07 22:12:12 +000042 if (interestLifetime < time::milliseconds::zero()) {
43 BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0"));
44 }
Junxiao Shi2af905b2014-11-27 13:10:54 -070045}
46
Junxiao Shi2af905b2014-11-27 13:10:54 -070047Interest::Interest(const Block& wire)
48{
49 wireDecode(wire);
50}
51
Junxiao Shi899277a2017-07-07 22:12:12 +000052// ---- encode and decode ----
Alexander Afanasyev840139f2013-12-28 15:02:50 -080053
Junxiao Shi899277a2017-07-07 22:12:12 +000054template<encoding::Tag TAG>
55size_t
56Interest::wireEncode(EncodingImpl<TAG>& encoder) const
57{
58 size_t totalLength = 0;
59
60 // Interest ::= INTEREST-TYPE TLV-LENGTH
61 // Name
62 // Selectors?
63 // Nonce
64 // InterestLifetime?
Junxiao Shi9c154cb2017-07-07 22:14:54 +000065 // ForwardingHint?
Junxiao Shi899277a2017-07-07 22:12:12 +000066 // Link?
67 // SelectedDelegation?
68
69 // (reverse encoding)
70
71 // Link and SelectedDelegation
72 if (hasLink()) {
73 if (hasSelectedDelegation()) {
74 totalLength += prependNonNegativeIntegerBlock(encoder,
75 tlv::SelectedDelegation,
76 m_selectedDelegationIndex);
77 }
78 totalLength += encoder.prependBlock(m_link);
Alexander Afanasyeve881e932014-06-08 14:47:03 +030079 }
Junxiao Shi899277a2017-07-07 22:12:12 +000080 else {
81 BOOST_ASSERT(!hasSelectedDelegation());
82 }
83
Junxiao Shi9c154cb2017-07-07 22:14:54 +000084 // ForwardingHint
85 if (m_forwardingHint.size() > 0) {
86 totalLength += m_forwardingHint.wireEncode(encoder);
87 }
88
Junxiao Shi899277a2017-07-07 22:12:12 +000089 // InterestLifetime
90 if (getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) {
91 totalLength += prependNonNegativeIntegerBlock(encoder,
92 tlv::InterestLifetime,
93 getInterestLifetime().count());
94 }
95
96 // Nonce
97 getNonce(); // to ensure that Nonce is properly set
98 totalLength += encoder.prependBlock(m_nonce);
99
100 // Selectors
101 if (hasSelectors()) {
102 totalLength += getSelectors().wireEncode(encoder);
103 }
104
105 // Name
106 totalLength += getName().wireEncode(encoder);
107
108 totalLength += encoder.prependVarNumber(totalLength);
109 totalLength += encoder.prependVarNumber(tlv::Interest);
110 return totalLength;
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800111}
112
Junxiao Shi899277a2017-07-07 22:12:12 +0000113template size_t
114Interest::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder) const;
115
116template size_t
117Interest::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder) const;
118
119const Block&
120Interest::wireEncode() const
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300121{
Junxiao Shi899277a2017-07-07 22:12:12 +0000122 if (m_wire.hasWire())
123 return m_wire;
124
125 EncodingEstimator estimator;
126 size_t estimatedSize = wireEncode(estimator);
127
128 EncodingBuffer buffer(estimatedSize, 0);
129 wireEncode(buffer);
130
131 // to ensure that Nonce block points to the right memory location
132 const_cast<Interest*>(this)->wireDecode(buffer.block());
133
134 return m_wire;
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300135}
Alexander Afanasyev840139f2013-12-28 15:02:50 -0800136
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700137void
Junxiao Shi899277a2017-07-07 22:12:12 +0000138Interest::wireDecode(const Block& wire)
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700139{
Junxiao Shi899277a2017-07-07 22:12:12 +0000140 m_wire = wire;
141 m_wire.parse();
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700142
Junxiao Shi899277a2017-07-07 22:12:12 +0000143 if (m_wire.type() != tlv::Interest)
144 BOOST_THROW_EXCEPTION(Error("Unexpected TLV number when decoding Interest"));
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700145
Junxiao Shi899277a2017-07-07 22:12:12 +0000146 // Name
147 m_name.wireDecode(m_wire.get(tlv::Name));
148
149 // Selectors
150 Block::element_const_iterator val = m_wire.find(tlv::Selectors);
151 if (val != m_wire.elements_end()) {
152 m_selectors.wireDecode(*val);
153 }
154 else
155 m_selectors = Selectors();
156
157 // Nonce
158 m_nonce = m_wire.get(tlv::Nonce);
159
160 // InterestLifetime
161 val = m_wire.find(tlv::InterestLifetime);
162 if (val != m_wire.elements_end()) {
163 m_interestLifetime = time::milliseconds(readNonNegativeInteger(*val));
164 }
165 else {
166 m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
167 }
168
Junxiao Shi9c154cb2017-07-07 22:14:54 +0000169 // ForwardingHint
170 val = m_wire.find(tlv::ForwardingHint);
171 if (val != m_wire.elements_end()) {
172 m_forwardingHint.wireDecode(*val, false);
173 }
174 else {
175 m_forwardingHint = DelegationList();
176 }
177
Junxiao Shi899277a2017-07-07 22:12:12 +0000178 // Link
179 m_linkCached.reset();
180 val = m_wire.find(tlv::Data);
181 if (val != m_wire.elements_end()) {
182 m_link = (*val);
183 }
184 else {
185 m_link = Block();
186 }
187
188 // SelectedDelegation
189 val = m_wire.find(tlv::SelectedDelegation);
190 if (val != m_wire.elements_end()) {
191 if (!this->hasLink()) {
192 BOOST_THROW_EXCEPTION(Error("Interest contains SelectedDelegation, but no LINK object"));
193 }
194 uint64_t selectedDelegation = readNonNegativeInteger(*val);
195 if (selectedDelegation < uint64_t(Link::countDelegationsFromWire(m_link))) {
196 m_selectedDelegationIndex = static_cast<size_t>(selectedDelegation);
197 }
198 else {
199 BOOST_THROW_EXCEPTION(Error("Invalid selected delegation index when decoding Interest"));
200 }
201 }
202 else {
203 m_selectedDelegationIndex = INVALID_SELECTED_DELEGATION_INDEX;
204 }
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700205}
206
Junxiao Shi899277a2017-07-07 22:12:12 +0000207// ---- matching ----
208
Alexander Afanasyev84681982014-01-03 13:26:09 -0800209bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700210Interest::matchesName(const Name& name) const
Jeff Thompson25b4e612013-10-10 16:03:24 -0700211{
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700212 if (name.size() < m_name.size())
213 return false;
214
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800215 if (!m_name.isPrefixOf(name))
Alexander Afanasyev84681982014-01-03 13:26:09 -0800216 return false;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700217
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800218 if (getMinSuffixComponents() >= 0 &&
Alexander Afanasyev3b703102014-06-13 17:01:14 -0700219 // name must include implicit digest
220 !(name.size() - m_name.size() >= static_cast<size_t>(getMinSuffixComponents())))
Alexander Afanasyev84681982014-01-03 13:26:09 -0800221 return false;
222
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800223 if (getMaxSuffixComponents() >= 0 &&
Alexander Afanasyev3b703102014-06-13 17:01:14 -0700224 // name must include implicit digest
225 !(name.size() - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents())))
Alexander Afanasyev84681982014-01-03 13:26:09 -0800226 return false;
227
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700228 if (!getExclude().empty() &&
229 name.size() > m_name.size() &&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800230 getExclude().isExcluded(name[m_name.size()]))
Alexander Afanasyev84681982014-01-03 13:26:09 -0800231 return false;
232
233 return true;
Jeff Thompson25b4e612013-10-10 16:03:24 -0700234}
235
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700236bool
237Interest::matchesData(const Data& data) const
238{
Junxiao Shi42c23622014-07-03 00:55:11 -0700239 size_t interestNameLength = m_name.size();
240 const Name& dataName = data.getName();
241 size_t fullNameLength = dataName.size() + 1;
242
243 // check MinSuffixComponents
244 bool hasMinSuffixComponents = getMinSuffixComponents() >= 0;
245 size_t minSuffixComponents = hasMinSuffixComponents ?
246 static_cast<size_t>(getMinSuffixComponents()) : 0;
247 if (!(interestNameLength + minSuffixComponents <= fullNameLength))
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700248 return false;
Junxiao Shi42c23622014-07-03 00:55:11 -0700249
250 // check MaxSuffixComponents
251 bool hasMaxSuffixComponents = getMaxSuffixComponents() >= 0;
252 if (hasMaxSuffixComponents &&
253 !(interestNameLength + getMaxSuffixComponents() >= fullNameLength))
254 return false;
255
256 // check prefix
257 if (interestNameLength == fullNameLength) {
Alexander Afanasyev56860f52014-11-07 11:51:17 -0800258 if (m_name.get(-1).isImplicitSha256Digest()) {
259 if (m_name != data.getFullName())
Junxiao Shi42c23622014-07-03 00:55:11 -0700260 return false;
261 }
262 else {
263 // Interest Name is same length as Data full Name, but last component isn't digest
264 // so there's no possibility of matching
265 return false;
266 }
267 }
268 else {
269 // Interest Name is a strict prefix of Data full Name
270 if (!m_name.isPrefixOf(dataName))
271 return false;
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700272 }
273
Junxiao Shi42c23622014-07-03 00:55:11 -0700274 // check Exclude
275 // Exclude won't be violated if Interest Name is same as Data full Name
276 if (!getExclude().empty() && fullNameLength > interestNameLength) {
277 if (interestNameLength == fullNameLength - 1) {
278 // component to exclude is the digest
279 if (getExclude().isExcluded(data.getFullName().get(interestNameLength)))
280 return false;
281 // There's opportunity to inspect the Exclude filter and determine whether
282 // the digest would make a difference.
Junxiao Shi08d07082014-12-03 11:31:44 -0700283 // eg. "<NameComponent>AA</NameComponent><Any/>" doesn't exclude any digest -
284 // fullName not needed;
285 // "<Any/><NameComponent>AA</NameComponent>" and
286 // "<Any/><ImplicitSha256DigestComponent>ffffffffffffffffffffffffffffffff
287 // </ImplicitSha256DigestComponent>"
288 // excludes all digests - fullName not needed;
289 // "<Any/><ImplicitSha256DigestComponent>80000000000000000000000000000000
290 // </ImplicitSha256DigestComponent>"
291 // excludes some digests - fullName required
Junxiao Shi42c23622014-07-03 00:55:11 -0700292 // But Interests that contain the exact Data Name before digest and also
293 // contain Exclude filter is too rare to optimize for, so we request
Junxiao Shi68247832017-07-03 22:06:49 +0000294 // fullName no matter what's in the Exclude filter.
Junxiao Shi42c23622014-07-03 00:55:11 -0700295 }
296 else {
297 // component to exclude is not the digest
298 if (getExclude().isExcluded(dataName.get(interestNameLength)))
299 return false;
300 }
301 }
302
303 // check PublisherPublicKeyLocator
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700304 const KeyLocator& publisherPublicKeyLocator = this->getPublisherPublicKeyLocator();
305 if (!publisherPublicKeyLocator.empty()) {
306 const Signature& signature = data.getSignature();
307 const Block& signatureInfo = signature.getInfo();
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600308 Block::element_const_iterator it = signatureInfo.find(tlv::KeyLocator);
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700309 if (it == signatureInfo.elements_end()) {
310 return false;
311 }
312 if (publisherPublicKeyLocator.wireEncode() != *it) {
313 return false;
314 }
315 }
316
317 return true;
318}
319
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800320bool
321Interest::matchesInterest(const Interest& other) const
322{
323 /// @todo #3162 match Link field
324 return (this->getName() == other.getName() &&
325 this->getSelectors() == other.getSelectors());
326}
327
Junxiao Shi899277a2017-07-07 22:12:12 +0000328// ---- field accessors ----
329
330uint32_t
331Interest::getNonce() const
332{
333 if (!m_nonce.hasWire())
334 const_cast<Interest*>(this)->setNonce(random::generateWord32());
335
Junxiao Shic2ac5d22017-07-17 22:18:31 +0000336 if (m_nonce.value_size() == sizeof(uint32_t)) {
337 uint32_t nonce = 0;
338 std::memcpy(&nonce, m_nonce.value(), sizeof(uint32_t));
339 return nonce;
340 }
Junxiao Shi899277a2017-07-07 22:12:12 +0000341 else {
342 // for compatibility reasons. Should be removed eventually
343 return readNonNegativeInteger(m_nonce);
344 }
345}
346
347Interest&
348Interest::setNonce(uint32_t nonce)
349{
350 if (m_wire.hasWire() && m_nonce.value_size() == sizeof(uint32_t)) {
351 std::memcpy(const_cast<uint8_t*>(m_nonce.value()), &nonce, sizeof(nonce));
352 }
353 else {
354 m_nonce = makeBinaryBlock(tlv::Nonce,
355 reinterpret_cast<const uint8_t*>(&nonce),
356 sizeof(nonce));
357 m_wire.reset();
358 }
359 return *this;
360}
361
362void
363Interest::refreshNonce()
364{
365 if (!hasNonce())
366 return;
367
368 uint32_t oldNonce = getNonce();
369 uint32_t newNonce = oldNonce;
370 while (newNonce == oldNonce)
371 newNonce = random::generateWord32();
372
373 setNonce(newNonce);
374}
375
Eric Newberryb555b002017-05-17 00:30:44 -0700376Interest&
377Interest::setInterestLifetime(time::milliseconds interestLifetime)
378{
379 if (interestLifetime < time::milliseconds::zero()) {
380 BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0"));
381 }
382 m_interestLifetime = interestLifetime;
383 m_wire.reset();
384 return *this;
385}
386
Junxiao Shi9c154cb2017-07-07 22:14:54 +0000387Interest&
388Interest::setForwardingHint(const DelegationList& value)
389{
390 m_forwardingHint = value;
391 m_wire.reset();
392 return *this;
393}
394
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700395bool
396Interest::hasLink() const
397{
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700398 return m_link.hasWire();
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700399}
400
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700401const Link&
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700402Interest::getLink() const
403{
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700404 if (hasLink()) {
405 if (!m_linkCached) {
406 m_linkCached = make_shared<Link>(m_link);
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700407 }
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700408 return *m_linkCached;
409 }
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700410 BOOST_THROW_EXCEPTION(Error("There is no encapsulated link object"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700411}
412
413void
414Interest::setLink(const Block& link)
415{
416 m_link = link;
417 if (!link.hasWire()) {
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700418 BOOST_THROW_EXCEPTION(Error("The given link does not have a wire format"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700419 }
420 m_wire.reset();
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700421 m_linkCached.reset();
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700422 this->unsetSelectedDelegation();
423}
424
425void
426Interest::unsetLink()
427{
428 m_link.reset();
429 m_wire.reset();
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700430 m_linkCached.reset();
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700431 this->unsetSelectedDelegation();
432}
433
434bool
435Interest::hasSelectedDelegation() const
436{
Alexander Afanasyevcac08382015-09-02 14:52:40 -0700437 return m_selectedDelegationIndex != INVALID_SELECTED_DELEGATION_INDEX;
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700438}
439
440Name
441Interest::getSelectedDelegation() const
442{
443 if (!hasSelectedDelegation()) {
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700444 BOOST_THROW_EXCEPTION(Error("There is no encapsulated selected delegation"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700445 }
446 return std::get<1>(Link::getDelegationFromWire(m_link, m_selectedDelegationIndex));
447}
448
449void
450Interest::setSelectedDelegation(const Name& delegationName)
451{
452 size_t delegationIndex = Link::findDelegationFromWire(m_link, delegationName);
453 if (delegationIndex != INVALID_SELECTED_DELEGATION_INDEX) {
454 m_selectedDelegationIndex = delegationIndex;
455 }
456 else {
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700457 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid selected delegation name"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700458 }
459 m_wire.reset();
460}
461
462void
463Interest::setSelectedDelegation(size_t delegationIndex)
464{
465 if (delegationIndex >= Link(m_link).getDelegations().size()) {
Spyridon Mastorakis0d2ed2e2015-07-27 19:09:12 -0700466 BOOST_THROW_EXCEPTION(Error("Invalid selected delegation index"));
Spyridon Mastorakisc8188b32015-04-18 18:33:38 -0700467 }
468 m_selectedDelegationIndex = delegationIndex;
469 m_wire.reset();
470}
471
472void
473Interest::unsetSelectedDelegation()
474{
475 m_selectedDelegationIndex = INVALID_SELECTED_DELEGATION_INDEX;
476 m_wire.reset();
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700477}
478
Junxiao Shi899277a2017-07-07 22:12:12 +0000479// ---- operators ----
480
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700481std::ostream&
482operator<<(std::ostream& os, const Interest& interest)
Jeff Thompsonfe556862013-07-09 13:52:55 -0700483{
Alexander Afanasyev84681982014-01-03 13:26:09 -0800484 os << interest.getName();
Jeff Thompsonfe556862013-07-09 13:52:55 -0700485
Alexander Afanasyev84681982014-01-03 13:26:09 -0800486 char delim = '?';
487
488 if (interest.getMinSuffixComponents() >= 0) {
489 os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
490 delim = '&';
Jeff Thompsonfe556862013-07-09 13:52:55 -0700491 }
Alexander Afanasyev84681982014-01-03 13:26:09 -0800492 if (interest.getMaxSuffixComponents() >= 0) {
493 os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
494 delim = '&';
Jeff Thompson37527d62013-08-21 11:15:54 -0700495 }
Eric Newberryb555b002017-05-17 00:30:44 -0700496 if (interest.getChildSelector() != DEFAULT_CHILD_SELECTOR) {
Alexander Afanasyev84681982014-01-03 13:26:09 -0800497 os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
498 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -0800499 }
Alexander Afanasyev84681982014-01-03 13:26:09 -0800500 if (interest.getMustBeFresh()) {
501 os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
502 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -0800503 }
Eric Newberryb555b002017-05-17 00:30:44 -0700504 if (interest.getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) {
Alexander Afanasyeva0c5f832014-06-19 13:27:56 -0700505 os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime().count();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800506 delim = '&';
507 }
508
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300509 if (interest.hasNonce()) {
Alexander Afanasyev84681982014-01-03 13:26:09 -0800510 os << delim << "ndn.Nonce=" << interest.getNonce();
511 delim = '&';
512 }
513 if (!interest.getExclude().empty()) {
514 os << delim << "ndn.Exclude=" << interest.getExclude();
515 delim = '&';
516 }
517
518 return os;
Jeff Thompson13e280b2013-12-03 13:12:23 -0800519}
520
Junxiao Shi08d07082014-12-03 11:31:44 -0700521} // namespace ndn