blob: e075ca7f63242f3d7e943ebd805da6b8aad50440 [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
Jeff Thompson8238d002013-07-10 11:56:49 -070041/**
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070042 * An Interest holds a Name and other fields for an Interest
Jeff Thompson8238d002013-07-10 11:56:49 -070043 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -080044class Interest : public enable_shared_from_this<Interest>
45{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070046public:
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080047 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070048 * @brief Create a new Interest with an empty name (`ndn:/`)
49 *
50 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
51 * created using `make_shared`:
52 *
53 * shared_ptr<Interest> interest = make_shared<Interest>();
54 *
55 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080056 */
57 Interest()
Alexander Afanasyeve881e932014-06-08 14:47:03 +030058 : m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070059 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080060 {
61 }
62
63 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070064 * @brief Create a new Interest with the given name
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070065 *
Alexander Afanasyevc348f832014-02-17 16:35:17 -080066 * @param name The name for the interest.
Alexander Afanasyev770827c2014-05-13 17:42:55 -070067 *
68 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
69 * created using `make_shared`:
70 *
71 * shared_ptr<Interest> interest = make_shared<Interest>(name);
72 *
73 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080074 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070075 Interest(const Name& name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080076 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080077 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070078 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080079 {
80 }
81
82 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070083 * @brief Create a new Interest with the given name and interest lifetime
84 *
85 * @param name The name for the interest.
86 * @param interestLifetime The interest lifetime in time::milliseconds, or -1 for none.
87 *
88 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
89 * created using `make_shared`:
90 *
91 * shared_ptr<Interest> interest = make_shared<Interest>(name, time::seconds(1));
92 *
93 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080094 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070095 Interest(const Name& name, const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080096 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080097 , m_scope(-1)
98 , m_interestLifetime(interestLifetime)
99 {
100 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700101
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700102 /**
103 * @brief Create a new Interest for the given name, selectors, and guiders
104 *
105 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
106 * created using `make_shared`:
107 *
108 * shared_ptr<Interest> interest = make_shared<Interest>(...);
109 *
110 * Otherwise, Interest::shared_from_this() will throw an exception.
111 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800112 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700113 const Selectors& selectors,
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800114 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700115 const time::milliseconds& interestLifetime,
116 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800117 : m_name(name)
118 , m_selectors(selectors)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800119 , m_scope(scope)
120 , m_interestLifetime(interestLifetime)
121 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300122 if (nonce > 0) {
123 setNonce(nonce);
124 }
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800125 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700126
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800127 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700128 * @brief Create a new Interest for the given name and parameters
Junxiao Shib332e782014-03-31 14:23:46 -0700129 *
130 * @deprecated Interest().setX(...).setY(...)
131 * or use the overload taking Selectors
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700132 *
133 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
134 * created using `make_shared`:
135 *
136 * shared_ptr<Interest> interest = make_shared<Interest>(...);
137 *
138 * Otherwise, Interest::shared_from_this() will throw an exception.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800139 */
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700140 DEPRECATED(
Alexander Afanasyev84681982014-01-03 13:26:09 -0800141 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700142 int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800143 const Exclude& exclude,
144 int childSelector,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700145 bool mustBeFresh,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800146 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700147 const time::milliseconds& interestLifetime,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700148 uint32_t nonce = 0))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800149 : m_name(name)
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700150 , m_selectors(Selectors()
151 .setMinSuffixComponents(minSuffixComponents)
152 .setMaxSuffixComponents(maxSuffixComponents)
153 .setExclude(exclude)
154 .setChildSelector(childSelector)
155 .setMustBeFresh(mustBeFresh))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800156 , m_scope(scope)
157 , m_interestLifetime(interestLifetime)
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700158 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300159 if (nonce > 0) {
160 setNonce(nonce);
161 }
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700162 }
163
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700164 /**
165 * @brief Create from wire encoding
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700166 *
167 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
168 * created using `make_shared`:
169 *
170 * shared_ptr<Interest> interest = make_shared<Interest>(wire);
171 *
172 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700173 */
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800174 explicit
175 Interest(const Block& wire)
176 {
177 wireDecode(wire);
178 }
179
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800180 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800181 * @brief Fast encoding or block size estimation
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800182 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800183 template<bool T>
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700184 size_t
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700185 wireEncode(EncodingImpl<T>& block) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800186
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800187 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800188 * @brief Encode to a wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800189 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700190 const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800191 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800192
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800193 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800194 * @brief Decode from the wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800195 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700196 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700197 wireDecode(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800198
199 /**
200 * @brief Check if already has wire
201 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700202 bool
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800203 hasWire() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700204
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700205 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700206 * @brief Encode the name according to the NDN URI Scheme
207 *
208 * If there are interest selectors, this method will append "?" and add the selectors as
209 * a query string. For example, "/test/name?ndn.ChildSelector=1"
Jeff Thompson13e280b2013-12-03 13:12:23 -0800210 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700211 std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800212 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700213
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700214 /**
215 * @brief Check if Interest has any selectors present
216 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700217 bool
Alexander Afanasyev84681982014-01-03 13:26:09 -0800218 hasSelectors() const;
219
Alexander Afanasyev84681982014-01-03 13:26:09 -0800220 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700221 * @brief Check if Interest, including selectors, matches the given @p name
222 *
223 * @param name The name to be matched. If this is a Data name, it shall contain the
224 * implicit digest component
Alexander Afanasyev84681982014-01-03 13:26:09 -0800225 */
226 bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700227 matchesName(const Name& name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800228
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700229 /**
230 * @brief Check if Interest can be satisfied by @p data.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700231 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700232 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
233 * PublisherPublicKeyLocator, and Exclude.
234 * This method does not consider ChildSelector and MustBeFresh.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700235 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700236 * @todo recognize implicit digest component
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700237 */
238 bool
239 matchesData(const Data& data) const;
240
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800241 ///////////////////////////////////////////////////////////////////////////////
242 ///////////////////////////////////////////////////////////////////////////////
243 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800244 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700245
246 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800247 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700248 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800249 return m_name;
250 }
251
252 Interest&
253 setName(const Name& name)
254 {
255 m_name = name;
256 m_wire.reset();
257 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700258 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700259
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800260 //
Alexander Afanasyev84681982014-01-03 13:26:09 -0800261
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800262 const Selectors&
263 getSelectors() const
264 {
265 return m_selectors;
266 }
267
268 Interest&
269 setSelectors(const Selectors& selectors)
270 {
271 m_selectors = selectors;
272 m_wire.reset();
273 return *this;
274 }
275
276 //
277
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700278 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800279 getScope() const
280 {
281 return m_scope;
282 }
283
284 Interest&
285 setScope(int scope)
286 {
287 m_scope = scope;
288 m_wire.reset();
289 return *this;
290 }
291
292 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700293
294 const time::milliseconds&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800295 getInterestLifetime() const
296 {
297 return m_interestLifetime;
298 }
299
300 Interest&
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700301 setInterestLifetime(const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800302 {
303 m_interestLifetime = interestLifetime;
304 m_wire.reset();
305 return *this;
306 }
307
308 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700309
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800310 /**
311 * @brief Get Interest's nonce
312 *
313 * If nonce was not set before this call, it will be automatically assigned to a random value
314 *
315 * Const reference needed for C decoding
316 */
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300317 uint32_t
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800318 getNonce() const;
319
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300320 /**
321 * @brief Check if Nonce set
322 */
323 bool
324 hasNonce() const
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800325 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300326 return m_nonce.hasWire();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800327 }
328
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300329 /**
330 * @brief Set Interest's nonce
331 *
332 * Note that if wire format already exists, this call simply replaces nonce in the
333 * existing wire format, without resetting and recreating it.
334 */
335 Interest&
336 setNonce(uint32_t nonce);
337
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700338 /**
339 * @brief Refresh nonce
340 *
341 * Refresh guarantees that new nonce value is different from the existing one.
342 *
343 * If nonce is already set, it will be updated to a different random value.
344 * If nonce is not set, this method will do nothing.
345 */
346 void
347 refreshNonce();
348
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800349 //
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800350
351 nfd::LocalControlHeader&
352 getLocalControlHeader()
353 {
354 return m_localControlHeader;
355 }
356
357 const nfd::LocalControlHeader&
358 getLocalControlHeader() const
359 {
360 return m_localControlHeader;
361 }
362
363 // helper methods for LocalControlHeader
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700364
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800365 uint64_t
366 getIncomingFaceId() const
367 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800368 return getLocalControlHeader().getIncomingFaceId();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800369 }
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800370
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800371 Interest&
372 setIncomingFaceId(uint64_t incomingFaceId)
373 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800374 getLocalControlHeader().setIncomingFaceId(incomingFaceId);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800375 // ! do not reset Interest's wire !
376 return *this;
377 }
378
379 //
380
381 // NextHopFaceId helpers make sense only for Interests
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700382
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800383 uint64_t
384 getNextHopFaceId() const
385 {
386 return getLocalControlHeader().getNextHopFaceId();
387 }
388
389 Interest&
390 setNextHopFaceId(uint64_t nextHopFaceId)
391 {
392 getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
393 // ! do not reset Interest's wire !
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800394 return *this;
395 }
396
397 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700398
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800399 ///////////////////////////////////////////////////////////////////////////////
400 ///////////////////////////////////////////////////////////////////////////////
401 ///////////////////////////////////////////////////////////////////////////////
402 // Wrappers for Selectors
403 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700404
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800405 int
406 getMinSuffixComponents() const
407 {
408 return m_selectors.getMinSuffixComponents();
409 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700410
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800411 Interest&
412 setMinSuffixComponents(int minSuffixComponents)
413 {
414 m_selectors.setMinSuffixComponents(minSuffixComponents);
415 m_wire.reset();
416 return *this;
417 }
418
419 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700420
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800421 int
422 getMaxSuffixComponents() const
423 {
424 return m_selectors.getMaxSuffixComponents();
425 }
426
427 Interest&
428 setMaxSuffixComponents(int maxSuffixComponents)
429 {
430 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
431 m_wire.reset();
432 return *this;
433 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700434
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800435 //
436
Junxiao Shib332e782014-03-31 14:23:46 -0700437 const KeyLocator&
438 getPublisherPublicKeyLocator() const
439 {
440 return m_selectors.getPublisherPublicKeyLocator();
441 }
442
443 Interest&
444 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
445 {
446 m_selectors.setPublisherPublicKeyLocator(keyLocator);
447 m_wire.reset();
448 return *this;
449 }
450
451 //
452
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800453 const Exclude&
454 getExclude() const
455 {
456 return m_selectors.getExclude();
457 }
458
459 Interest&
460 setExclude(const Exclude& exclude)
461 {
462 m_selectors.setExclude(exclude);
463 m_wire.reset();
464 return *this;
465 }
466
467 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700468
469 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800470 getChildSelector() const
471 {
472 return m_selectors.getChildSelector();
473 }
474
475 Interest&
476 setChildSelector(int childSelector)
477 {
478 m_selectors.setChildSelector(childSelector);
479 m_wire.reset();
480 return *this;
481 }
482
483 //
484
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700485 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800486 getMustBeFresh() const
487 {
488 return m_selectors.getMustBeFresh();
489 }
490
491 Interest&
492 setMustBeFresh(bool mustBeFresh)
493 {
494 m_selectors.setMustBeFresh(mustBeFresh);
495 m_wire.reset();
496 return *this;
497 }
498
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700499public: // EqualityComparable concept
500 bool
501 operator==(const Interest& other) const
502 {
503 return wireEncode() == other.wireEncode();
504 }
505
506 bool
507 operator!=(const Interest& other) const
508 {
509 return !(*this == other);
510 }
511
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800512private:
513 Name m_name;
514 Selectors m_selectors;
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300515 mutable Block m_nonce;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800516 int m_scope;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700517 time::milliseconds m_interestLifetime;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800518
519 mutable Block m_wire;
Yingdi Yua4e57672014-02-06 11:16:17 -0800520
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800521 nfd::LocalControlHeader m_localControlHeader;
522 friend class nfd::LocalControlHeader;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700523};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800524
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700525std::ostream&
526operator<<(std::ostream& os, const Interest& interest);
Alexander Afanasyev84681982014-01-03 13:26:09 -0800527
528inline std::string
529Interest::toUri() const
530{
531 std::ostringstream os;
532 os << *this;
533 return os.str();
534}
535
536inline bool
537Interest::hasSelectors() const
538{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800539 return !m_selectors.empty();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800540}
541
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800542
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800543inline bool
544Interest::hasWire() const
545{
546 return m_wire.hasWire();
547}
548
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800549
550} // namespace ndn
551
552#endif // NDN_INTEREST_HPP