blob: fc851e7bb267c6cd6df58fdf38a85cfb9c31a043 [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
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070017class Data;
18
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070019const time::seconds DEFAULT_INTEREST_LIFETIME = time::seconds(4);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080020
Jeff Thompson8238d002013-07-10 11:56:49 -070021/**
Jeff Thompson8238d002013-07-10 11:56:49 -070022 * An Interest holds a Name and other fields for an interest.
23 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -080024class Interest : public enable_shared_from_this<Interest>
25{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070026public:
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080027 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -080028 * @brief Create a new Interest with an empty name and "none" for all values.
29 */
30 Interest()
31 : m_nonce(0)
32 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070033 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080034 {
35 }
36
37 /**
38 * @brief Create a new Interest with the given name and "none" for other values.
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070039 *
Alexander Afanasyevc348f832014-02-17 16:35:17 -080040 * @param name The name for the interest.
41 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070042 Interest(const Name& name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080043 : m_name(name)
44 , m_nonce(0)
45 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070046 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080047 {
48 }
49
50 /**
51 * Create a new Interest with the given name and interest lifetime and "none" for other values.
52 * @param name The name for the interest.
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070053 * @param interestLifetimeMilliseconds The interest lifetime in time::milliseconds, or -1 for none.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080054 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070055 Interest(const Name& name, const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080056 : m_name(name)
57 , m_nonce(0)
58 , m_scope(-1)
59 , m_interestLifetime(interestLifetime)
60 {
61 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070062
Alexander Afanasyevc348f832014-02-17 16:35:17 -080063 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070064 const Selectors& selectors,
Alexander Afanasyevc348f832014-02-17 16:35:17 -080065 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070066 const time::milliseconds& interestLifetime,
67 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080068 : m_name(name)
69 , m_selectors(selectors)
70 , m_nonce(nonce)
71 , m_scope(scope)
72 , m_interestLifetime(interestLifetime)
73 {
74 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070075
Alexander Afanasyevc348f832014-02-17 16:35:17 -080076 /**
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080077 * Create a new Interest for the given name and values.
78 * @param name
79 * @param minSuffixComponents
80 * @param maxSuffixComponents
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080081 * @param exclude
82 * @param childSelector
Alexander Afanasyev84681982014-01-03 13:26:09 -080083 * @param mustBeFresh
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080084 * @param scope
Alexander Afanasyev84681982014-01-03 13:26:09 -080085 * @param interestLifetime
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080086 * @param nonce
Junxiao Shib332e782014-03-31 14:23:46 -070087 *
88 * @deprecated Interest().setX(...).setY(...)
89 * or use the overload taking Selectors
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080090 */
Alexander Afanasyev84681982014-01-03 13:26:09 -080091 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070092 int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyev84681982014-01-03 13:26:09 -080093 const Exclude& exclude,
94 int childSelector,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070095 bool mustBeFresh,
Alexander Afanasyev84681982014-01-03 13:26:09 -080096 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070097 const time::milliseconds& interestLifetime,
98 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080099 : m_name(name)
100 , m_selectors(minSuffixComponents, maxSuffixComponents, exclude, childSelector, mustBeFresh)
101 , m_nonce(nonce)
102 , m_scope(scope)
103 , m_interestLifetime(interestLifetime)
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700104 {
105 }
106
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800107 explicit
108 Interest(const Block& wire)
109 {
110 wireDecode(wire);
111 }
112
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800113 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800114 * @brief Fast encoding or block size estimation
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800115 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800116 template<bool T>
117 inline size_t
118 wireEncode(EncodingImpl<T> &block) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800119
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800120 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800121 * @brief Encode to a wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800122 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800123 inline const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800124 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800125
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800126 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800127 * @brief Decode from the wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800128 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700129 inline void
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800130 wireDecode(const Block &wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800131
132 /**
133 * @brief Check if already has wire
134 */
135 inline bool
136 hasWire() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700137
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700138 /**
Jeff Thompson13e280b2013-12-03 13:12:23 -0800139 * Encode the name according to the "NDN URI Scheme". If there are interest selectors, append "?" and
140 * added the selectors as a query string. For example "/test/name?ndn.ChildSelector=1".
141 * @return The URI string.
142 */
Alexander Afanasyev84681982014-01-03 13:26:09 -0800143 inline std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800144 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700145
Alexander Afanasyev84681982014-01-03 13:26:09 -0800146 inline bool
147 hasSelectors() const;
148
149 inline bool
150 hasGuiders() const;
151
152 /**
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700153 * @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 -0800154 * interest selectors.
155 * @param self A pointer to the ndn_Interest struct.
156 * @param name A pointer to the name to check.
157 * @return 1 if the name and interest selectors match, 0 otherwise.
158 */
159 bool
160 matchesName(const Name &name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800161
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700162 /** @brief Determines whether this Interest can be satisfied by @p data.
163 *
164 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
165 * PublisherPublicKeyLocator, and Exclude.
166 * This method does not consider ChildSelector and MustBeFresh.
167 *
168 * @todo recognize implicit digest component
169 */
170 bool
171 matchesData(const Data& data) const;
172
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800173 ///////////////////////////////////////////////////////////////////////////////
174 ///////////////////////////////////////////////////////////////////////////////
175 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800176 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700177
178 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800179 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700180 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800181 return m_name;
182 }
183
184 Interest&
185 setName(const Name& name)
186 {
187 m_name = name;
188 m_wire.reset();
189 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700190 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700191
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800192 //
Alexander Afanasyev84681982014-01-03 13:26:09 -0800193
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800194 const Selectors&
195 getSelectors() const
196 {
197 return m_selectors;
198 }
199
200 Interest&
201 setSelectors(const Selectors& selectors)
202 {
203 m_selectors = selectors;
204 m_wire.reset();
205 return *this;
206 }
207
208 //
209
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700210 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800211 getScope() const
212 {
213 return m_scope;
214 }
215
216 Interest&
217 setScope(int scope)
218 {
219 m_scope = scope;
220 m_wire.reset();
221 return *this;
222 }
223
224 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700225
226 const time::milliseconds&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800227 getInterestLifetime() const
228 {
229 return m_interestLifetime;
230 }
231
232 Interest&
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700233 setInterestLifetime(const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800234 {
235 m_interestLifetime = interestLifetime;
236 m_wire.reset();
237 return *this;
238 }
239
240 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700241
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800242 /**
243 * @brief Get Interest's nonce
244 *
245 * If nonce was not set before this call, it will be automatically assigned to a random value
246 *
247 * Const reference needed for C decoding
248 */
249 const uint32_t&
250 getNonce() const;
251
252 Interest&
253 setNonce(uint32_t nonce)
254 {
255 m_nonce = nonce;
256 m_wire.reset();
257 return *this;
258 }
259
260 //
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800261
262 nfd::LocalControlHeader&
263 getLocalControlHeader()
264 {
265 return m_localControlHeader;
266 }
267
268 const nfd::LocalControlHeader&
269 getLocalControlHeader() const
270 {
271 return m_localControlHeader;
272 }
273
274 // helper methods for LocalControlHeader
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700275
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800276 uint64_t
277 getIncomingFaceId() const
278 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800279 return getLocalControlHeader().getIncomingFaceId();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800280 }
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800281
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800282 Interest&
283 setIncomingFaceId(uint64_t incomingFaceId)
284 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800285 getLocalControlHeader().setIncomingFaceId(incomingFaceId);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800286 // ! do not reset Interest's wire !
287 return *this;
288 }
289
290 //
291
292 // NextHopFaceId helpers make sense only for Interests
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700293
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800294 uint64_t
295 getNextHopFaceId() const
296 {
297 return getLocalControlHeader().getNextHopFaceId();
298 }
299
300 Interest&
301 setNextHopFaceId(uint64_t nextHopFaceId)
302 {
303 getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
304 // ! do not reset Interest's wire !
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800305 return *this;
306 }
307
308 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700309
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800310 ///////////////////////////////////////////////////////////////////////////////
311 ///////////////////////////////////////////////////////////////////////////////
312 ///////////////////////////////////////////////////////////////////////////////
313 // Wrappers for Selectors
314 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700315
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800316 int
317 getMinSuffixComponents() const
318 {
319 return m_selectors.getMinSuffixComponents();
320 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700321
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800322 Interest&
323 setMinSuffixComponents(int minSuffixComponents)
324 {
325 m_selectors.setMinSuffixComponents(minSuffixComponents);
326 m_wire.reset();
327 return *this;
328 }
329
330 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700331
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800332 int
333 getMaxSuffixComponents() const
334 {
335 return m_selectors.getMaxSuffixComponents();
336 }
337
338 Interest&
339 setMaxSuffixComponents(int maxSuffixComponents)
340 {
341 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
342 m_wire.reset();
343 return *this;
344 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700345
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800346 //
347
Junxiao Shib332e782014-03-31 14:23:46 -0700348 const KeyLocator&
349 getPublisherPublicKeyLocator() const
350 {
351 return m_selectors.getPublisherPublicKeyLocator();
352 }
353
354 Interest&
355 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
356 {
357 m_selectors.setPublisherPublicKeyLocator(keyLocator);
358 m_wire.reset();
359 return *this;
360 }
361
362 //
363
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800364 const Exclude&
365 getExclude() const
366 {
367 return m_selectors.getExclude();
368 }
369
370 Interest&
371 setExclude(const Exclude& exclude)
372 {
373 m_selectors.setExclude(exclude);
374 m_wire.reset();
375 return *this;
376 }
377
378 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700379
380 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800381 getChildSelector() const
382 {
383 return m_selectors.getChildSelector();
384 }
385
386 Interest&
387 setChildSelector(int childSelector)
388 {
389 m_selectors.setChildSelector(childSelector);
390 m_wire.reset();
391 return *this;
392 }
393
394 //
395
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700396 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800397 getMustBeFresh() const
398 {
399 return m_selectors.getMustBeFresh();
400 }
401
402 Interest&
403 setMustBeFresh(bool mustBeFresh)
404 {
405 m_selectors.setMustBeFresh(mustBeFresh);
406 m_wire.reset();
407 return *this;
408 }
409
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800410private:
411 Name m_name;
412 Selectors m_selectors;
413 mutable uint32_t m_nonce;
414 int m_scope;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700415 time::milliseconds m_interestLifetime;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800416
417 mutable Block m_wire;
Yingdi Yua4e57672014-02-06 11:16:17 -0800418
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800419 nfd::LocalControlHeader m_localControlHeader;
420 friend class nfd::LocalControlHeader;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700421};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800422
423std::ostream &
424operator << (std::ostream &os, const Interest &interest);
425
426inline std::string
427Interest::toUri() const
428{
429 std::ostringstream os;
430 os << *this;
431 return os.str();
432}
433
434inline bool
435Interest::hasSelectors() const
436{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800437 return !m_selectors.empty();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800438}
439
440inline bool
441Interest::hasGuiders() const
442{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800443 return m_scope >= 0 ||
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700444 m_interestLifetime >= time::milliseconds::zero() ||
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800445 m_nonce > 0;
Alexander Afanasyev84681982014-01-03 13:26:09 -0800446}
447
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800448template<bool T>
449inline size_t
450Interest::wireEncode(EncodingImpl<T> &block) const
451{
452 size_t total_len = 0;
453
454 // Interest ::= INTEREST-TYPE TLV-LENGTH
455 // Name
456 // Selectors?
457 // Nonce
458 // Scope?
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700459 // InterestLifetime?
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800460
461 // (reverse encoding)
462
463 // InterestLifetime
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700464 if (getInterestLifetime() >= time::milliseconds::zero()
465 && getInterestLifetime() != DEFAULT_INTEREST_LIFETIME)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800466 {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700467 total_len += prependNonNegativeIntegerBlock(block, Tlv::InterestLifetime, getInterestLifetime().count());
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800468 }
469
470 // Scope
471 if (getScope() >= 0)
472 {
473 total_len += prependNonNegativeIntegerBlock(block, Tlv::Scope, getScope());
474 }
475
476 // Nonce
477 total_len += prependNonNegativeIntegerBlock(block, Tlv::Nonce, getNonce());
478
479 // Selectors
480 if (!getSelectors().empty())
481 {
482 total_len += getSelectors().wireEncode(block);
483 }
484
485 // Name
486 total_len += getName().wireEncode(block);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700487
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800488 total_len += block.prependVarNumber (total_len);
489 total_len += block.prependVarNumber (Tlv::Interest);
490 return total_len;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700491}
492
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800493inline const Block&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800494Interest::wireEncode() const
495{
496 if (m_wire.hasWire())
497 return m_wire;
498
499 EncodingEstimator estimator;
500 size_t estimatedSize = wireEncode(estimator);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700501
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800502 EncodingBuffer buffer(estimatedSize, 0);
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800503 wireEncode(buffer);
504
505 m_wire = buffer.block();
506 return m_wire;
507}
508
509inline void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700510Interest::wireDecode(const Block &wire)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800511{
512 m_wire = wire;
513 m_wire.parse();
514
515 // Interest ::= INTEREST-TYPE TLV-LENGTH
516 // Name
517 // Selectors?
518 // Nonce
519 // Scope?
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700520 // InterestLifetime?
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800521
522 if (m_wire.type() != Tlv::Interest)
523 throw Tlv::Error("Unexpected TLV number when decoding Interest");
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700524
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800525 // Name
526 m_name.wireDecode(m_wire.get(Tlv::Name));
527
528 // Selectors
529 Block::element_const_iterator val = m_wire.find(Tlv::Selectors);
530 if (val != m_wire.elements_end())
531 {
532 m_selectors.wireDecode(*val);
533 }
534 else
535 m_selectors = Selectors();
536
537 // Nonce
538 val = m_wire.find(Tlv::Nonce);
539 if (val != m_wire.elements_end())
540 {
541 m_nonce = readNonNegativeInteger(*val);
542 }
543 else
544 m_nonce = 0;
545
546 // Scope
547 val = m_wire.find(Tlv::Scope);
548 if (val != m_wire.elements_end())
549 {
550 m_scope = readNonNegativeInteger(*val);
551 }
552 else
553 m_scope = -1;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700554
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800555 // InterestLifetime
556 val = m_wire.find(Tlv::InterestLifetime);
557 if (val != m_wire.elements_end())
558 {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700559 m_interestLifetime = time::milliseconds(readNonNegativeInteger(*val));
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800560 }
561 else
562 {
563 m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
564 }
565}
566
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800567inline bool
568Interest::hasWire() const
569{
570 return m_wire.hasWire();
571}
572
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800573
574} // namespace ndn
575
576#endif // NDN_INTEREST_HPP