blob: f0de53989132078f3d7851253b40894b207fabd9 [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
Junxiao Shi7007a3c2014-11-20 22:37:55 -070039/** @var const unspecified_duration_type DEFAULT_INTEREST_LIFETIME;
40 * @brief default value for InterestLifetime
41 */
42const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080043
Junxiao Shic2b8d242014-11-04 08:35:29 -070044/** @brief represents an Interest packet
Jeff Thompson8238d002013-07-10 11:56:49 -070045 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -080046class Interest : public enable_shared_from_this<Interest>
47{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070048public:
Junxiao Shic2b8d242014-11-04 08:35:29 -070049 class Error : public tlv::Error
50 {
51 public:
52 explicit
53 Error(const std::string& what)
54 : tlv::Error(what)
55 {
56 }
57 };
58
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080059 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070060 * @brief Create a new Interest with an empty name (`ndn:/`)
61 *
62 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
63 * created using `make_shared`:
64 *
65 * shared_ptr<Interest> interest = make_shared<Interest>();
66 *
67 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080068 */
69 Interest()
Alexander Afanasyeve881e932014-06-08 14:47:03 +030070 : m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070071 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080072 {
73 }
74
75 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070076 * @brief Create a new Interest with the given name
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070077 *
Alexander Afanasyevc348f832014-02-17 16:35:17 -080078 * @param name The name for the interest.
Alexander Afanasyev770827c2014-05-13 17:42:55 -070079 *
80 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
81 * created using `make_shared`:
82 *
83 * shared_ptr<Interest> interest = make_shared<Interest>(name);
84 *
85 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080086 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070087 Interest(const Name& name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080088 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080089 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070090 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080091 {
92 }
93
94 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070095 * @brief Create a new Interest with the given name and interest lifetime
96 *
97 * @param name The name for the interest.
98 * @param interestLifetime The interest lifetime in time::milliseconds, or -1 for none.
99 *
100 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
101 * created using `make_shared`:
102 *
103 * shared_ptr<Interest> interest = make_shared<Interest>(name, time::seconds(1));
104 *
105 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800106 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700107 Interest(const Name& name, const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800108 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800109 , m_scope(-1)
110 , m_interestLifetime(interestLifetime)
111 {
112 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700113
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700114 /**
115 * @brief Create a new Interest for the given name, selectors, and guiders
116 *
117 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
118 * created using `make_shared`:
119 *
120 * shared_ptr<Interest> interest = make_shared<Interest>(...);
121 *
122 * Otherwise, Interest::shared_from_this() will throw an exception.
123 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800124 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700125 const Selectors& selectors,
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800126 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700127 const time::milliseconds& interestLifetime,
128 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800129 : m_name(name)
130 , m_selectors(selectors)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800131 , m_scope(scope)
132 , m_interestLifetime(interestLifetime)
133 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300134 if (nonce > 0) {
135 setNonce(nonce);
136 }
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800137 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700138
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800139 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700140 * @brief Create a new Interest for the given name and parameters
Junxiao Shib332e782014-03-31 14:23:46 -0700141 *
142 * @deprecated Interest().setX(...).setY(...)
143 * or use the overload taking Selectors
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700144 *
145 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
146 * created using `make_shared`:
147 *
148 * shared_ptr<Interest> interest = make_shared<Interest>(...);
149 *
150 * Otherwise, Interest::shared_from_this() will throw an exception.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800151 */
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700152 DEPRECATED(
Alexander Afanasyev84681982014-01-03 13:26:09 -0800153 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700154 int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800155 const Exclude& exclude,
156 int childSelector,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700157 bool mustBeFresh,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800158 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700159 const time::milliseconds& interestLifetime,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700160 uint32_t nonce = 0))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800161 : m_name(name)
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700162 , m_selectors(Selectors()
163 .setMinSuffixComponents(minSuffixComponents)
164 .setMaxSuffixComponents(maxSuffixComponents)
165 .setExclude(exclude)
166 .setChildSelector(childSelector)
167 .setMustBeFresh(mustBeFresh))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800168 , m_scope(scope)
169 , m_interestLifetime(interestLifetime)
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700170 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300171 if (nonce > 0) {
172 setNonce(nonce);
173 }
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700174 }
175
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700176 /**
177 * @brief Create from wire encoding
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700178 *
179 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
180 * created using `make_shared`:
181 *
182 * shared_ptr<Interest> interest = make_shared<Interest>(wire);
183 *
184 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700185 */
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800186 explicit
187 Interest(const Block& wire)
188 {
189 wireDecode(wire);
190 }
191
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800192 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800193 * @brief Fast encoding or block size estimation
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800194 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800195 template<bool T>
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700196 size_t
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700197 wireEncode(EncodingImpl<T>& block) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800198
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800199 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800200 * @brief Encode to a wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800201 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700202 const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800203 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800204
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800205 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800206 * @brief Decode from the wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800207 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700208 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700209 wireDecode(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800210
211 /**
212 * @brief Check if already has wire
213 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700214 bool
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800215 hasWire() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700216
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700217 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700218 * @brief Encode the name according to the NDN URI Scheme
219 *
220 * If there are interest selectors, this method will append "?" and add the selectors as
221 * a query string. For example, "/test/name?ndn.ChildSelector=1"
Jeff Thompson13e280b2013-12-03 13:12:23 -0800222 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700223 std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800224 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700225
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700226 /**
227 * @brief Check if Interest has any selectors present
228 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700229 bool
Alexander Afanasyev84681982014-01-03 13:26:09 -0800230 hasSelectors() const;
231
Alexander Afanasyev84681982014-01-03 13:26:09 -0800232 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700233 * @brief Check if Interest, including selectors, matches the given @p name
234 *
235 * @param name The name to be matched. If this is a Data name, it shall contain the
236 * implicit digest component
Alexander Afanasyev84681982014-01-03 13:26:09 -0800237 */
238 bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700239 matchesName(const Name& name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800240
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700241 /**
242 * @brief Check if Interest can be satisfied by @p data.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700243 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700244 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
245 * PublisherPublicKeyLocator, and Exclude.
246 * This method does not consider ChildSelector and MustBeFresh.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700247 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700248 * @todo recognize implicit digest component
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700249 */
250 bool
251 matchesData(const Data& data) const;
252
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800253 ///////////////////////////////////////////////////////////////////////////////
254 ///////////////////////////////////////////////////////////////////////////////
255 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800256 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700257
258 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800259 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700260 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800261 return m_name;
262 }
263
264 Interest&
265 setName(const Name& name)
266 {
267 m_name = name;
268 m_wire.reset();
269 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700270 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700271
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800272 //
Alexander Afanasyev84681982014-01-03 13:26:09 -0800273
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800274 const Selectors&
275 getSelectors() const
276 {
277 return m_selectors;
278 }
279
280 Interest&
281 setSelectors(const Selectors& selectors)
282 {
283 m_selectors = selectors;
284 m_wire.reset();
285 return *this;
286 }
287
288 //
289
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700290 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800291 getScope() const
292 {
293 return m_scope;
294 }
295
296 Interest&
297 setScope(int scope)
298 {
299 m_scope = scope;
300 m_wire.reset();
301 return *this;
302 }
303
304 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700305
306 const time::milliseconds&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800307 getInterestLifetime() const
308 {
309 return m_interestLifetime;
310 }
311
312 Interest&
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700313 setInterestLifetime(const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800314 {
315 m_interestLifetime = interestLifetime;
316 m_wire.reset();
317 return *this;
318 }
319
320 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700321
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800322 /**
323 * @brief Get Interest's nonce
324 *
325 * If nonce was not set before this call, it will be automatically assigned to a random value
326 *
327 * Const reference needed for C decoding
328 */
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300329 uint32_t
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800330 getNonce() const;
331
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300332 /**
333 * @brief Check if Nonce set
334 */
335 bool
336 hasNonce() const
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800337 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300338 return m_nonce.hasWire();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800339 }
340
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300341 /**
342 * @brief Set Interest's nonce
343 *
344 * Note that if wire format already exists, this call simply replaces nonce in the
345 * existing wire format, without resetting and recreating it.
346 */
347 Interest&
348 setNonce(uint32_t nonce);
349
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700350 /**
351 * @brief Refresh nonce
352 *
353 * Refresh guarantees that new nonce value is different from the existing one.
354 *
355 * If nonce is already set, it will be updated to a different random value.
356 * If nonce is not set, this method will do nothing.
357 */
358 void
359 refreshNonce();
360
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800361 //
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800362
363 nfd::LocalControlHeader&
364 getLocalControlHeader()
365 {
366 return m_localControlHeader;
367 }
368
369 const nfd::LocalControlHeader&
370 getLocalControlHeader() const
371 {
372 return m_localControlHeader;
373 }
374
375 // helper methods for LocalControlHeader
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700376
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800377 uint64_t
378 getIncomingFaceId() const
379 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800380 return getLocalControlHeader().getIncomingFaceId();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800381 }
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800382
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800383 Interest&
384 setIncomingFaceId(uint64_t incomingFaceId)
385 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800386 getLocalControlHeader().setIncomingFaceId(incomingFaceId);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800387 // ! do not reset Interest's wire !
388 return *this;
389 }
390
391 //
392
393 // NextHopFaceId helpers make sense only for Interests
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700394
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800395 uint64_t
396 getNextHopFaceId() const
397 {
398 return getLocalControlHeader().getNextHopFaceId();
399 }
400
401 Interest&
402 setNextHopFaceId(uint64_t nextHopFaceId)
403 {
404 getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
405 // ! do not reset Interest's wire !
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800406 return *this;
407 }
408
409 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700410
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800411 ///////////////////////////////////////////////////////////////////////////////
412 ///////////////////////////////////////////////////////////////////////////////
413 ///////////////////////////////////////////////////////////////////////////////
414 // Wrappers for Selectors
415 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700416
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800417 int
418 getMinSuffixComponents() const
419 {
420 return m_selectors.getMinSuffixComponents();
421 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700422
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800423 Interest&
424 setMinSuffixComponents(int minSuffixComponents)
425 {
426 m_selectors.setMinSuffixComponents(minSuffixComponents);
427 m_wire.reset();
428 return *this;
429 }
430
431 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700432
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800433 int
434 getMaxSuffixComponents() const
435 {
436 return m_selectors.getMaxSuffixComponents();
437 }
438
439 Interest&
440 setMaxSuffixComponents(int maxSuffixComponents)
441 {
442 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
443 m_wire.reset();
444 return *this;
445 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700446
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800447 //
448
Junxiao Shib332e782014-03-31 14:23:46 -0700449 const KeyLocator&
450 getPublisherPublicKeyLocator() const
451 {
452 return m_selectors.getPublisherPublicKeyLocator();
453 }
454
455 Interest&
456 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
457 {
458 m_selectors.setPublisherPublicKeyLocator(keyLocator);
459 m_wire.reset();
460 return *this;
461 }
462
463 //
464
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800465 const Exclude&
466 getExclude() const
467 {
468 return m_selectors.getExclude();
469 }
470
471 Interest&
472 setExclude(const Exclude& exclude)
473 {
474 m_selectors.setExclude(exclude);
475 m_wire.reset();
476 return *this;
477 }
478
479 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700480
481 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800482 getChildSelector() const
483 {
484 return m_selectors.getChildSelector();
485 }
486
487 Interest&
488 setChildSelector(int childSelector)
489 {
490 m_selectors.setChildSelector(childSelector);
491 m_wire.reset();
492 return *this;
493 }
494
495 //
496
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700497 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800498 getMustBeFresh() const
499 {
500 return m_selectors.getMustBeFresh();
501 }
502
503 Interest&
504 setMustBeFresh(bool mustBeFresh)
505 {
506 m_selectors.setMustBeFresh(mustBeFresh);
507 m_wire.reset();
508 return *this;
509 }
510
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700511public: // EqualityComparable concept
512 bool
513 operator==(const Interest& other) const
514 {
515 return wireEncode() == other.wireEncode();
516 }
517
518 bool
519 operator!=(const Interest& other) const
520 {
521 return !(*this == other);
522 }
523
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800524private:
525 Name m_name;
526 Selectors m_selectors;
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300527 mutable Block m_nonce;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800528 int m_scope;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700529 time::milliseconds m_interestLifetime;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800530
531 mutable Block m_wire;
Yingdi Yua4e57672014-02-06 11:16:17 -0800532
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800533 nfd::LocalControlHeader m_localControlHeader;
534 friend class nfd::LocalControlHeader;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700535};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800536
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700537std::ostream&
538operator<<(std::ostream& os, const Interest& interest);
Alexander Afanasyev84681982014-01-03 13:26:09 -0800539
540inline std::string
541Interest::toUri() const
542{
543 std::ostringstream os;
544 os << *this;
545 return os.str();
546}
547
548inline bool
549Interest::hasSelectors() const
550{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800551 return !m_selectors.empty();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800552}
553
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800554
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800555inline bool
556Interest::hasWire() const
557{
558 return m_wire.hasWire();
559}
560
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800561
562} // namespace ndn
563
564#endif // NDN_INTEREST_HPP