blob: 5aa541c2ae9af537be8375d6d2def2ea835b119a [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07005 */
6
7#ifndef NDN_INTEREST_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_INTEREST_HPP
Jeff Thompsonb7f95562013-07-03 18:36:42 -07009
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080010#include "common.hpp"
Jeff Thompson53412192013-08-06 13:35:50 -070011#include "name.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080012#include "selectors.hpp"
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080013#include "management/nfd-local-control-header.hpp"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070014
15namespace ndn {
Alexander Afanasyevc348f832014-02-17 16:35:17 -080016
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070017const time::seconds DEFAULT_INTEREST_LIFETIME = time::seconds(4);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080018
Jeff Thompson8238d002013-07-10 11:56:49 -070019/**
Jeff Thompson8238d002013-07-10 11:56:49 -070020 * An Interest holds a Name and other fields for an interest.
21 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -080022class Interest : public enable_shared_from_this<Interest>
23{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070024public:
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080025 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -080026 * @brief Create a new Interest with an empty name and "none" for all values.
27 */
28 Interest()
29 : m_nonce(0)
30 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070031 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080032 {
33 }
34
35 /**
36 * @brief Create a new Interest with the given name and "none" for other values.
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070037 *
Alexander Afanasyevc348f832014-02-17 16:35:17 -080038 * @param name The name for the interest.
39 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070040 Interest(const Name& name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080041 : m_name(name)
42 , m_nonce(0)
43 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070044 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080045 {
46 }
47
48 /**
49 * Create a new Interest with the given name and interest lifetime and "none" for other values.
50 * @param name The name for the interest.
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070051 * @param interestLifetimeMilliseconds The interest lifetime in time::milliseconds, or -1 for none.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080052 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070053 Interest(const Name& name, const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080054 : m_name(name)
55 , m_nonce(0)
56 , m_scope(-1)
57 , m_interestLifetime(interestLifetime)
58 {
59 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070060
Alexander Afanasyevc348f832014-02-17 16:35:17 -080061 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070062 const Selectors& selectors,
Alexander Afanasyevc348f832014-02-17 16:35:17 -080063 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070064 const time::milliseconds& interestLifetime,
65 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080066 : m_name(name)
67 , m_selectors(selectors)
68 , m_nonce(nonce)
69 , m_scope(scope)
70 , m_interestLifetime(interestLifetime)
71 {
72 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070073
Alexander Afanasyevc348f832014-02-17 16:35:17 -080074 /**
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080075 * Create a new Interest for the given name and values.
76 * @param name
77 * @param minSuffixComponents
78 * @param maxSuffixComponents
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080079 * @param exclude
80 * @param childSelector
Alexander Afanasyev84681982014-01-03 13:26:09 -080081 * @param mustBeFresh
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080082 * @param scope
Alexander Afanasyev84681982014-01-03 13:26:09 -080083 * @param interestLifetime
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080084 * @param nonce
Junxiao Shib332e782014-03-31 14:23:46 -070085 *
86 * @deprecated Interest().setX(...).setY(...)
87 * or use the overload taking Selectors
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080088 */
Alexander Afanasyev84681982014-01-03 13:26:09 -080089 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070090 int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyev84681982014-01-03 13:26:09 -080091 const Exclude& exclude,
92 int childSelector,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070093 bool mustBeFresh,
Alexander Afanasyev84681982014-01-03 13:26:09 -080094 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070095 const time::milliseconds& interestLifetime,
96 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080097 : m_name(name)
98 , m_selectors(minSuffixComponents, maxSuffixComponents, exclude, childSelector, mustBeFresh)
99 , m_nonce(nonce)
100 , m_scope(scope)
101 , m_interestLifetime(interestLifetime)
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700102 {
103 }
104
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800105 explicit
106 Interest(const Block& wire)
107 {
108 wireDecode(wire);
109 }
110
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800111 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800112 * @brief Fast encoding or block size estimation
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800113 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800114 template<bool T>
115 inline size_t
116 wireEncode(EncodingImpl<T> &block) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800117
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800118 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800119 * @brief Encode to a wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800120 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800121 inline const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800122 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800123
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800124 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800125 * @brief Decode from the wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800126 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700127 inline void
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800128 wireDecode(const Block &wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800129
130 /**
131 * @brief Check if already has wire
132 */
133 inline bool
134 hasWire() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700135
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700136 /**
Jeff Thompson13e280b2013-12-03 13:12:23 -0800137 * Encode the name according to the "NDN URI Scheme". If there are interest selectors, append "?" and
138 * added the selectors as a query string. For example "/test/name?ndn.ChildSelector=1".
139 * @return The URI string.
140 */
Alexander Afanasyev84681982014-01-03 13:26:09 -0800141 inline std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800142 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700143
Alexander Afanasyev84681982014-01-03 13:26:09 -0800144 inline bool
145 hasSelectors() const;
146
147 inline bool
148 hasGuiders() const;
149
150 /**
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700151 * @brief Check if Interest name matches the given name (using ndn_Name_match) and the given name also conforms to the
Alexander Afanasyev84681982014-01-03 13:26:09 -0800152 * interest selectors.
153 * @param self A pointer to the ndn_Interest struct.
154 * @param name A pointer to the name to check.
155 * @return 1 if the name and interest selectors match, 0 otherwise.
156 */
157 bool
158 matchesName(const Name &name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800159
160 ///////////////////////////////////////////////////////////////////////////////
161 ///////////////////////////////////////////////////////////////////////////////
162 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800163 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700164
165 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800166 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700167 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800168 return m_name;
169 }
170
171 Interest&
172 setName(const Name& name)
173 {
174 m_name = name;
175 m_wire.reset();
176 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700177 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700178
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800179 //
Alexander Afanasyev84681982014-01-03 13:26:09 -0800180
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800181 const Selectors&
182 getSelectors() const
183 {
184 return m_selectors;
185 }
186
187 Interest&
188 setSelectors(const Selectors& selectors)
189 {
190 m_selectors = selectors;
191 m_wire.reset();
192 return *this;
193 }
194
195 //
196
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700197 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800198 getScope() const
199 {
200 return m_scope;
201 }
202
203 Interest&
204 setScope(int scope)
205 {
206 m_scope = scope;
207 m_wire.reset();
208 return *this;
209 }
210
211 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700212
213 const time::milliseconds&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800214 getInterestLifetime() const
215 {
216 return m_interestLifetime;
217 }
218
219 Interest&
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700220 setInterestLifetime(const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800221 {
222 m_interestLifetime = interestLifetime;
223 m_wire.reset();
224 return *this;
225 }
226
227 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700228
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800229 /**
230 * @brief Get Interest's nonce
231 *
232 * If nonce was not set before this call, it will be automatically assigned to a random value
233 *
234 * Const reference needed for C decoding
235 */
236 const uint32_t&
237 getNonce() const;
238
239 Interest&
240 setNonce(uint32_t nonce)
241 {
242 m_nonce = nonce;
243 m_wire.reset();
244 return *this;
245 }
246
247 //
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800248
249 nfd::LocalControlHeader&
250 getLocalControlHeader()
251 {
252 return m_localControlHeader;
253 }
254
255 const nfd::LocalControlHeader&
256 getLocalControlHeader() const
257 {
258 return m_localControlHeader;
259 }
260
261 // helper methods for LocalControlHeader
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700262
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800263 uint64_t
264 getIncomingFaceId() const
265 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800266 return getLocalControlHeader().getIncomingFaceId();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800267 }
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800268
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800269 Interest&
270 setIncomingFaceId(uint64_t incomingFaceId)
271 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800272 getLocalControlHeader().setIncomingFaceId(incomingFaceId);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800273 // ! do not reset Interest's wire !
274 return *this;
275 }
276
277 //
278
279 // NextHopFaceId helpers make sense only for Interests
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700280
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800281 uint64_t
282 getNextHopFaceId() const
283 {
284 return getLocalControlHeader().getNextHopFaceId();
285 }
286
287 Interest&
288 setNextHopFaceId(uint64_t nextHopFaceId)
289 {
290 getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
291 // ! do not reset Interest's wire !
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800292 return *this;
293 }
294
295 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700296
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800297 ///////////////////////////////////////////////////////////////////////////////
298 ///////////////////////////////////////////////////////////////////////////////
299 ///////////////////////////////////////////////////////////////////////////////
300 // Wrappers for Selectors
301 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700302
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800303 int
304 getMinSuffixComponents() const
305 {
306 return m_selectors.getMinSuffixComponents();
307 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700308
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800309 Interest&
310 setMinSuffixComponents(int minSuffixComponents)
311 {
312 m_selectors.setMinSuffixComponents(minSuffixComponents);
313 m_wire.reset();
314 return *this;
315 }
316
317 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700318
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800319 int
320 getMaxSuffixComponents() const
321 {
322 return m_selectors.getMaxSuffixComponents();
323 }
324
325 Interest&
326 setMaxSuffixComponents(int maxSuffixComponents)
327 {
328 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
329 m_wire.reset();
330 return *this;
331 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700332
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800333 //
334
Junxiao Shib332e782014-03-31 14:23:46 -0700335 const KeyLocator&
336 getPublisherPublicKeyLocator() const
337 {
338 return m_selectors.getPublisherPublicKeyLocator();
339 }
340
341 Interest&
342 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
343 {
344 m_selectors.setPublisherPublicKeyLocator(keyLocator);
345 m_wire.reset();
346 return *this;
347 }
348
349 //
350
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800351 const Exclude&
352 getExclude() const
353 {
354 return m_selectors.getExclude();
355 }
356
357 Interest&
358 setExclude(const Exclude& exclude)
359 {
360 m_selectors.setExclude(exclude);
361 m_wire.reset();
362 return *this;
363 }
364
365 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700366
367 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800368 getChildSelector() const
369 {
370 return m_selectors.getChildSelector();
371 }
372
373 Interest&
374 setChildSelector(int childSelector)
375 {
376 m_selectors.setChildSelector(childSelector);
377 m_wire.reset();
378 return *this;
379 }
380
381 //
382
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700383 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800384 getMustBeFresh() const
385 {
386 return m_selectors.getMustBeFresh();
387 }
388
389 Interest&
390 setMustBeFresh(bool mustBeFresh)
391 {
392 m_selectors.setMustBeFresh(mustBeFresh);
393 m_wire.reset();
394 return *this;
395 }
396
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800397private:
398 Name m_name;
399 Selectors m_selectors;
400 mutable uint32_t m_nonce;
401 int m_scope;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700402 time::milliseconds m_interestLifetime;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800403
404 mutable Block m_wire;
Yingdi Yua4e57672014-02-06 11:16:17 -0800405
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800406 nfd::LocalControlHeader m_localControlHeader;
407 friend class nfd::LocalControlHeader;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700408};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800409
410std::ostream &
411operator << (std::ostream &os, const Interest &interest);
412
413inline std::string
414Interest::toUri() const
415{
416 std::ostringstream os;
417 os << *this;
418 return os.str();
419}
420
421inline bool
422Interest::hasSelectors() const
423{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800424 return !m_selectors.empty();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800425}
426
427inline bool
428Interest::hasGuiders() const
429{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800430 return m_scope >= 0 ||
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700431 m_interestLifetime >= time::milliseconds::zero() ||
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800432 m_nonce > 0;
Alexander Afanasyev84681982014-01-03 13:26:09 -0800433}
434
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800435template<bool T>
436inline size_t
437Interest::wireEncode(EncodingImpl<T> &block) const
438{
439 size_t total_len = 0;
440
441 // Interest ::= INTEREST-TYPE TLV-LENGTH
442 // Name
443 // Selectors?
444 // Nonce
445 // Scope?
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700446 // InterestLifetime?
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800447
448 // (reverse encoding)
449
450 // InterestLifetime
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700451 if (getInterestLifetime() >= time::milliseconds::zero()
452 && getInterestLifetime() != DEFAULT_INTEREST_LIFETIME)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800453 {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700454 total_len += prependNonNegativeIntegerBlock(block, Tlv::InterestLifetime, getInterestLifetime().count());
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800455 }
456
457 // Scope
458 if (getScope() >= 0)
459 {
460 total_len += prependNonNegativeIntegerBlock(block, Tlv::Scope, getScope());
461 }
462
463 // Nonce
464 total_len += prependNonNegativeIntegerBlock(block, Tlv::Nonce, getNonce());
465
466 // Selectors
467 if (!getSelectors().empty())
468 {
469 total_len += getSelectors().wireEncode(block);
470 }
471
472 // Name
473 total_len += getName().wireEncode(block);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700474
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800475 total_len += block.prependVarNumber (total_len);
476 total_len += block.prependVarNumber (Tlv::Interest);
477 return total_len;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700478}
479
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800480inline const Block&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800481Interest::wireEncode() const
482{
483 if (m_wire.hasWire())
484 return m_wire;
485
486 EncodingEstimator estimator;
487 size_t estimatedSize = wireEncode(estimator);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700488
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800489 EncodingBuffer buffer(estimatedSize, 0);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800490 wireEncode(buffer);
491
492 m_wire = buffer.block();
493 return m_wire;
494}
495
496inline void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700497Interest::wireDecode(const Block &wire)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800498{
499 m_wire = wire;
500 m_wire.parse();
501
502 // Interest ::= INTEREST-TYPE TLV-LENGTH
503 // Name
504 // Selectors?
505 // Nonce
506 // Scope?
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700507 // InterestLifetime?
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800508
509 if (m_wire.type() != Tlv::Interest)
510 throw Tlv::Error("Unexpected TLV number when decoding Interest");
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700511
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800512 // Name
513 m_name.wireDecode(m_wire.get(Tlv::Name));
514
515 // Selectors
516 Block::element_const_iterator val = m_wire.find(Tlv::Selectors);
517 if (val != m_wire.elements_end())
518 {
519 m_selectors.wireDecode(*val);
520 }
521 else
522 m_selectors = Selectors();
523
524 // Nonce
525 val = m_wire.find(Tlv::Nonce);
526 if (val != m_wire.elements_end())
527 {
528 m_nonce = readNonNegativeInteger(*val);
529 }
530 else
531 m_nonce = 0;
532
533 // Scope
534 val = m_wire.find(Tlv::Scope);
535 if (val != m_wire.elements_end())
536 {
537 m_scope = readNonNegativeInteger(*val);
538 }
539 else
540 m_scope = -1;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700541
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800542 // InterestLifetime
543 val = m_wire.find(Tlv::InterestLifetime);
544 if (val != m_wire.elements_end())
545 {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700546 m_interestLifetime = time::milliseconds(readNonNegativeInteger(*val));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800547 }
548 else
549 {
550 m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
551 }
552}
553
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800554inline bool
555Interest::hasWire() const
556{
557 return m_wire.hasWire();
558}
559
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800560
561} // namespace ndn
562
563#endif // NDN_INTEREST_HPP