blob: 02e7ba97946189d99ddb6b980bf0c357401b926b [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * Based on code originally written by Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonb7f95562013-07-03 18:36:42 -070022 */
23
24#ifndef NDN_INTEREST_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070025#define NDN_INTEREST_HPP
Jeff Thompsonb7f95562013-07-03 18:36:42 -070026
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080027#include "common.hpp"
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070028
Jeff Thompson53412192013-08-06 13:35:50 -070029#include "name.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080030#include "selectors.hpp"
Alexander Afanasyev90164962014-03-06 08:29:59 +000031#include "interest-filter.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070032#include "util/time.hpp"
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080033#include "management/nfd-local-control-header.hpp"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070034
35namespace ndn {
Alexander Afanasyevc348f832014-02-17 16:35:17 -080036
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070037class Data;
38
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070039const time::seconds DEFAULT_INTEREST_LIFETIME = time::seconds(4);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080040
Junxiao Shic2b8d242014-11-04 08:35:29 -070041/** @brief represents an Interest packet
Jeff Thompson8238d002013-07-10 11:56:49 -070042 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -080043class Interest : public enable_shared_from_this<Interest>
44{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070045public:
Junxiao Shic2b8d242014-11-04 08:35:29 -070046 class Error : public tlv::Error
47 {
48 public:
49 explicit
50 Error(const std::string& what)
51 : tlv::Error(what)
52 {
53 }
54 };
55
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080056 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070057 * @brief Create a new Interest with an empty name (`ndn:/`)
58 *
59 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
60 * created using `make_shared`:
61 *
62 * shared_ptr<Interest> interest = make_shared<Interest>();
63 *
64 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080065 */
66 Interest()
Alexander Afanasyeve881e932014-06-08 14:47:03 +030067 : m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070068 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080069 {
70 }
71
72 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070073 * @brief Create a new Interest with the given name
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070074 *
Alexander Afanasyevc348f832014-02-17 16:35:17 -080075 * @param name The name for the interest.
Alexander Afanasyev770827c2014-05-13 17:42:55 -070076 *
77 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
78 * created using `make_shared`:
79 *
80 * shared_ptr<Interest> interest = make_shared<Interest>(name);
81 *
82 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080083 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070084 Interest(const Name& name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080085 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080086 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070087 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080088 {
89 }
90
91 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070092 * @brief Create a new Interest with the given name and interest lifetime
93 *
94 * @param name The name for the interest.
95 * @param interestLifetime The interest lifetime in time::milliseconds, or -1 for none.
96 *
97 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
98 * created using `make_shared`:
99 *
100 * shared_ptr<Interest> interest = make_shared<Interest>(name, time::seconds(1));
101 *
102 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800103 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700104 Interest(const Name& name, const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800105 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800106 , m_scope(-1)
107 , m_interestLifetime(interestLifetime)
108 {
109 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700110
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700111 /**
112 * @brief Create a new Interest for the given name, selectors, and guiders
113 *
114 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
115 * created using `make_shared`:
116 *
117 * shared_ptr<Interest> interest = make_shared<Interest>(...);
118 *
119 * Otherwise, Interest::shared_from_this() will throw an exception.
120 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800121 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700122 const Selectors& selectors,
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800123 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700124 const time::milliseconds& interestLifetime,
125 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800126 : m_name(name)
127 , m_selectors(selectors)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800128 , m_scope(scope)
129 , m_interestLifetime(interestLifetime)
130 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300131 if (nonce > 0) {
132 setNonce(nonce);
133 }
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800134 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700135
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800136 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700137 * @brief Create a new Interest for the given name and parameters
Junxiao Shib332e782014-03-31 14:23:46 -0700138 *
139 * @deprecated Interest().setX(...).setY(...)
140 * or use the overload taking Selectors
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700141 *
142 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
143 * created using `make_shared`:
144 *
145 * shared_ptr<Interest> interest = make_shared<Interest>(...);
146 *
147 * Otherwise, Interest::shared_from_this() will throw an exception.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800148 */
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700149 DEPRECATED(
Alexander Afanasyev84681982014-01-03 13:26:09 -0800150 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700151 int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800152 const Exclude& exclude,
153 int childSelector,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700154 bool mustBeFresh,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800155 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700156 const time::milliseconds& interestLifetime,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700157 uint32_t nonce = 0))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800158 : m_name(name)
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700159 , m_selectors(Selectors()
160 .setMinSuffixComponents(minSuffixComponents)
161 .setMaxSuffixComponents(maxSuffixComponents)
162 .setExclude(exclude)
163 .setChildSelector(childSelector)
164 .setMustBeFresh(mustBeFresh))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800165 , m_scope(scope)
166 , m_interestLifetime(interestLifetime)
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700167 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300168 if (nonce > 0) {
169 setNonce(nonce);
170 }
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700171 }
172
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700173 /**
174 * @brief Create from wire encoding
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700175 *
176 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
177 * created using `make_shared`:
178 *
179 * shared_ptr<Interest> interest = make_shared<Interest>(wire);
180 *
181 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700182 */
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800183 explicit
184 Interest(const Block& wire)
185 {
186 wireDecode(wire);
187 }
188
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800189 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800190 * @brief Fast encoding or block size estimation
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800191 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800192 template<bool T>
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700193 size_t
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700194 wireEncode(EncodingImpl<T>& block) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800195
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800196 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800197 * @brief Encode to a wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800198 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700199 const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800200 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800201
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800202 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800203 * @brief Decode from the wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800204 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700205 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700206 wireDecode(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800207
208 /**
209 * @brief Check if already has wire
210 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700211 bool
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800212 hasWire() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700213
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700214 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700215 * @brief Encode the name according to the NDN URI Scheme
216 *
217 * If there are interest selectors, this method will append "?" and add the selectors as
218 * a query string. For example, "/test/name?ndn.ChildSelector=1"
Jeff Thompson13e280b2013-12-03 13:12:23 -0800219 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700220 std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800221 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700222
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700223 /**
224 * @brief Check if Interest has any selectors present
225 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700226 bool
Alexander Afanasyev84681982014-01-03 13:26:09 -0800227 hasSelectors() const;
228
Alexander Afanasyev84681982014-01-03 13:26:09 -0800229 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700230 * @brief Check if Interest, including selectors, matches the given @p name
231 *
232 * @param name The name to be matched. If this is a Data name, it shall contain the
233 * implicit digest component
Alexander Afanasyev84681982014-01-03 13:26:09 -0800234 */
235 bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700236 matchesName(const Name& name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800237
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700238 /**
239 * @brief Check if Interest can be satisfied by @p data.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700240 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700241 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
242 * PublisherPublicKeyLocator, and Exclude.
243 * This method does not consider ChildSelector and MustBeFresh.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700244 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700245 * @todo recognize implicit digest component
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700246 */
247 bool
248 matchesData(const Data& data) const;
249
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800250 ///////////////////////////////////////////////////////////////////////////////
251 ///////////////////////////////////////////////////////////////////////////////
252 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800253 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700254
255 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800256 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700257 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800258 return m_name;
259 }
260
261 Interest&
262 setName(const Name& name)
263 {
264 m_name = name;
265 m_wire.reset();
266 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700267 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700268
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800269 //
Alexander Afanasyev84681982014-01-03 13:26:09 -0800270
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800271 const Selectors&
272 getSelectors() const
273 {
274 return m_selectors;
275 }
276
277 Interest&
278 setSelectors(const Selectors& selectors)
279 {
280 m_selectors = selectors;
281 m_wire.reset();
282 return *this;
283 }
284
285 //
286
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700287 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800288 getScope() const
289 {
290 return m_scope;
291 }
292
293 Interest&
294 setScope(int scope)
295 {
296 m_scope = scope;
297 m_wire.reset();
298 return *this;
299 }
300
301 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700302
303 const time::milliseconds&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800304 getInterestLifetime() const
305 {
306 return m_interestLifetime;
307 }
308
309 Interest&
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700310 setInterestLifetime(const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800311 {
312 m_interestLifetime = interestLifetime;
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 /**
320 * @brief Get Interest's nonce
321 *
322 * If nonce was not set before this call, it will be automatically assigned to a random value
323 *
324 * Const reference needed for C decoding
325 */
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300326 uint32_t
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800327 getNonce() const;
328
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300329 /**
330 * @brief Check if Nonce set
331 */
332 bool
333 hasNonce() const
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800334 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300335 return m_nonce.hasWire();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800336 }
337
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300338 /**
339 * @brief Set Interest's nonce
340 *
341 * Note that if wire format already exists, this call simply replaces nonce in the
342 * existing wire format, without resetting and recreating it.
343 */
344 Interest&
345 setNonce(uint32_t nonce);
346
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700347 /**
348 * @brief Refresh nonce
349 *
350 * Refresh guarantees that new nonce value is different from the existing one.
351 *
352 * If nonce is already set, it will be updated to a different random value.
353 * If nonce is not set, this method will do nothing.
354 */
355 void
356 refreshNonce();
357
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800358 //
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800359
360 nfd::LocalControlHeader&
361 getLocalControlHeader()
362 {
363 return m_localControlHeader;
364 }
365
366 const nfd::LocalControlHeader&
367 getLocalControlHeader() const
368 {
369 return m_localControlHeader;
370 }
371
372 // helper methods for LocalControlHeader
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700373
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800374 uint64_t
375 getIncomingFaceId() const
376 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800377 return getLocalControlHeader().getIncomingFaceId();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800378 }
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800379
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800380 Interest&
381 setIncomingFaceId(uint64_t incomingFaceId)
382 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800383 getLocalControlHeader().setIncomingFaceId(incomingFaceId);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800384 // ! do not reset Interest's wire !
385 return *this;
386 }
387
388 //
389
390 // NextHopFaceId helpers make sense only for Interests
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700391
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800392 uint64_t
393 getNextHopFaceId() const
394 {
395 return getLocalControlHeader().getNextHopFaceId();
396 }
397
398 Interest&
399 setNextHopFaceId(uint64_t nextHopFaceId)
400 {
401 getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
402 // ! do not reset Interest's wire !
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800403 return *this;
404 }
405
406 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700407
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800408 ///////////////////////////////////////////////////////////////////////////////
409 ///////////////////////////////////////////////////////////////////////////////
410 ///////////////////////////////////////////////////////////////////////////////
411 // Wrappers for Selectors
412 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700413
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800414 int
415 getMinSuffixComponents() const
416 {
417 return m_selectors.getMinSuffixComponents();
418 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700419
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800420 Interest&
421 setMinSuffixComponents(int minSuffixComponents)
422 {
423 m_selectors.setMinSuffixComponents(minSuffixComponents);
424 m_wire.reset();
425 return *this;
426 }
427
428 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700429
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800430 int
431 getMaxSuffixComponents() const
432 {
433 return m_selectors.getMaxSuffixComponents();
434 }
435
436 Interest&
437 setMaxSuffixComponents(int maxSuffixComponents)
438 {
439 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
440 m_wire.reset();
441 return *this;
442 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700443
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800444 //
445
Junxiao Shib332e782014-03-31 14:23:46 -0700446 const KeyLocator&
447 getPublisherPublicKeyLocator() const
448 {
449 return m_selectors.getPublisherPublicKeyLocator();
450 }
451
452 Interest&
453 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
454 {
455 m_selectors.setPublisherPublicKeyLocator(keyLocator);
456 m_wire.reset();
457 return *this;
458 }
459
460 //
461
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800462 const Exclude&
463 getExclude() const
464 {
465 return m_selectors.getExclude();
466 }
467
468 Interest&
469 setExclude(const Exclude& exclude)
470 {
471 m_selectors.setExclude(exclude);
472 m_wire.reset();
473 return *this;
474 }
475
476 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700477
478 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800479 getChildSelector() const
480 {
481 return m_selectors.getChildSelector();
482 }
483
484 Interest&
485 setChildSelector(int childSelector)
486 {
487 m_selectors.setChildSelector(childSelector);
488 m_wire.reset();
489 return *this;
490 }
491
492 //
493
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700494 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800495 getMustBeFresh() const
496 {
497 return m_selectors.getMustBeFresh();
498 }
499
500 Interest&
501 setMustBeFresh(bool mustBeFresh)
502 {
503 m_selectors.setMustBeFresh(mustBeFresh);
504 m_wire.reset();
505 return *this;
506 }
507
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700508public: // EqualityComparable concept
509 bool
510 operator==(const Interest& other) const
511 {
512 return wireEncode() == other.wireEncode();
513 }
514
515 bool
516 operator!=(const Interest& other) const
517 {
518 return !(*this == other);
519 }
520
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800521private:
522 Name m_name;
523 Selectors m_selectors;
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300524 mutable Block m_nonce;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800525 int m_scope;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700526 time::milliseconds m_interestLifetime;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800527
528 mutable Block m_wire;
Yingdi Yua4e57672014-02-06 11:16:17 -0800529
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800530 nfd::LocalControlHeader m_localControlHeader;
531 friend class nfd::LocalControlHeader;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700532};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800533
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700534std::ostream&
535operator<<(std::ostream& os, const Interest& interest);
Alexander Afanasyev84681982014-01-03 13:26:09 -0800536
537inline std::string
538Interest::toUri() const
539{
540 std::ostringstream os;
541 os << *this;
542 return os.str();
543}
544
545inline bool
546Interest::hasSelectors() const
547{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800548 return !m_selectors.empty();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800549}
550
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800551
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800552inline bool
553Interest::hasWire() const
554{
555 return m_wire.hasWire();
556}
557
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800558
559} // namespace ndn
560
561#endif // NDN_INTEREST_HPP