blob: 89c5c24d77dd5b50b8ac93ae5559da680a587c9d [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 Afanasyev6d48bc12014-02-18 00:10:51 -080032#include "management/nfd-local-control-header.hpp"
Jeff Thompsonb7f95562013-07-03 18:36:42 -070033
34namespace ndn {
Alexander Afanasyevc348f832014-02-17 16:35:17 -080035
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070036class Data;
37
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070038const time::seconds DEFAULT_INTEREST_LIFETIME = time::seconds(4);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080039
Jeff Thompson8238d002013-07-10 11:56:49 -070040/**
Alexander Afanasyev258ec2b2014-05-14 16:15:37 -070041 * An Interest holds a Name and other fields for an Interest
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:
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080046 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070047 * @brief Create a new Interest with an empty name (`ndn:/`)
48 *
49 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
50 * created using `make_shared`:
51 *
52 * shared_ptr<Interest> interest = make_shared<Interest>();
53 *
54 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080055 */
56 Interest()
Alexander Afanasyeve881e932014-06-08 14:47:03 +030057 : m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070058 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080059 {
60 }
61
62 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070063 * @brief Create a new Interest with the given name
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070064 *
Alexander Afanasyevc348f832014-02-17 16:35:17 -080065 * @param name The name for the interest.
Alexander Afanasyev770827c2014-05-13 17:42:55 -070066 *
67 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
68 * created using `make_shared`:
69 *
70 * shared_ptr<Interest> interest = make_shared<Interest>(name);
71 *
72 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080073 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070074 Interest(const Name& name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080075 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080076 , m_scope(-1)
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070077 , m_interestLifetime(time::milliseconds::min())
Alexander Afanasyevc348f832014-02-17 16:35:17 -080078 {
79 }
80
81 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -070082 * @brief Create a new Interest with the given name and interest lifetime
83 *
84 * @param name The name for the interest.
85 * @param interestLifetime The interest lifetime in time::milliseconds, or -1 for none.
86 *
87 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
88 * created using `make_shared`:
89 *
90 * shared_ptr<Interest> interest = make_shared<Interest>(name, time::seconds(1));
91 *
92 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080093 */
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070094 Interest(const Name& name, const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080095 : m_name(name)
Alexander Afanasyevc348f832014-02-17 16:35:17 -080096 , m_scope(-1)
97 , m_interestLifetime(interestLifetime)
98 {
99 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700100
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700101 /**
102 * @brief Create a new Interest for the given name, selectors, and guiders
103 *
104 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
105 * created using `make_shared`:
106 *
107 * shared_ptr<Interest> interest = make_shared<Interest>(...);
108 *
109 * Otherwise, Interest::shared_from_this() will throw an exception.
110 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800111 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700112 const Selectors& selectors,
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800113 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700114 const time::milliseconds& interestLifetime,
115 uint32_t nonce = 0)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800116 : m_name(name)
117 , m_selectors(selectors)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800118 , m_scope(scope)
119 , m_interestLifetime(interestLifetime)
120 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300121 if (nonce > 0) {
122 setNonce(nonce);
123 }
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800124 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700125
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800126 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700127 * @brief Create a new Interest for the given name and parameters
Junxiao Shib332e782014-03-31 14:23:46 -0700128 *
129 * @deprecated Interest().setX(...).setY(...)
130 * or use the overload taking Selectors
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700131 *
132 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
133 * created using `make_shared`:
134 *
135 * shared_ptr<Interest> interest = make_shared<Interest>(...);
136 *
137 * Otherwise, Interest::shared_from_this() will throw an exception.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800138 */
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700139 DEPRECATED(
Alexander Afanasyev84681982014-01-03 13:26:09 -0800140 Interest(const Name& name,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700141 int minSuffixComponents, int maxSuffixComponents,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800142 const Exclude& exclude,
143 int childSelector,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700144 bool mustBeFresh,
Alexander Afanasyev84681982014-01-03 13:26:09 -0800145 int scope,
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700146 const time::milliseconds& interestLifetime,
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700147 uint32_t nonce = 0))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800148 : m_name(name)
Alexander Afanasyev9c578182014-05-14 17:28:28 -0700149 , m_selectors(Selectors()
150 .setMinSuffixComponents(minSuffixComponents)
151 .setMaxSuffixComponents(maxSuffixComponents)
152 .setExclude(exclude)
153 .setChildSelector(childSelector)
154 .setMustBeFresh(mustBeFresh))
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800155 , m_scope(scope)
156 , m_interestLifetime(interestLifetime)
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700157 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300158 if (nonce > 0) {
159 setNonce(nonce);
160 }
Jeff Thompson3f76e9e2013-08-21 13:14:58 -0700161 }
162
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700163 /**
164 * @brief Create from wire encoding
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700165 *
166 * Note that in certain contexts that use Interest::shared_from_this(), Interest must be
167 * created using `make_shared`:
168 *
169 * shared_ptr<Interest> interest = make_shared<Interest>(wire);
170 *
171 * Otherwise, Interest::shared_from_this() will throw an exception.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700172 */
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800173 explicit
174 Interest(const Block& wire)
175 {
176 wireDecode(wire);
177 }
178
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800179 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800180 * @brief Fast encoding or block size estimation
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800181 */
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800182 template<bool T>
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700183 size_t
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700184 wireEncode(EncodingImpl<T>& block) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800185
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800186 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800187 * @brief Encode to a wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800188 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700189 const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -0800190 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800191
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800192 /**
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800193 * @brief Decode from the wire format
Jeff Thompson1b4a7b12013-11-15 12:00:02 -0800194 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700195 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700196 wireDecode(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800197
198 /**
199 * @brief Check if already has wire
200 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700201 bool
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800202 hasWire() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700203
Jeff Thompsond9e278c2013-07-08 15:20:13 -0700204 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700205 * @brief Encode the name according to the NDN URI Scheme
206 *
207 * If there are interest selectors, this method will append "?" and add the selectors as
208 * a query string. For example, "/test/name?ndn.ChildSelector=1"
Jeff Thompson13e280b2013-12-03 13:12:23 -0800209 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700210 std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800211 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700212
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700213 /**
214 * @brief Check if Interest has any selectors present
215 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700216 bool
Alexander Afanasyev84681982014-01-03 13:26:09 -0800217 hasSelectors() const;
218
Alexander Afanasyev84681982014-01-03 13:26:09 -0800219 /**
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700220 * @brief Check if Interest, including selectors, matches the given @p name
221 *
222 * @param name The name to be matched. If this is a Data name, it shall contain the
223 * implicit digest component
Alexander Afanasyev84681982014-01-03 13:26:09 -0800224 */
225 bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700226 matchesName(const Name& name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800227
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700228 /**
229 * @brief Check if Interest can be satisfied by @p data.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700230 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700231 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
232 * PublisherPublicKeyLocator, and Exclude.
233 * This method does not consider ChildSelector and MustBeFresh.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700234 *
Alexander Afanasyev770827c2014-05-13 17:42:55 -0700235 * @todo recognize implicit digest component
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700236 */
237 bool
238 matchesData(const Data& data) const;
239
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800240 ///////////////////////////////////////////////////////////////////////////////
241 ///////////////////////////////////////////////////////////////////////////////
242 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800243 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700244
245 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800246 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700247 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800248 return m_name;
249 }
250
251 Interest&
252 setName(const Name& name)
253 {
254 m_name = name;
255 m_wire.reset();
256 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700257 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700258
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800259 //
Alexander Afanasyev84681982014-01-03 13:26:09 -0800260
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800261 const Selectors&
262 getSelectors() const
263 {
264 return m_selectors;
265 }
266
267 Interest&
268 setSelectors(const Selectors& selectors)
269 {
270 m_selectors = selectors;
271 m_wire.reset();
272 return *this;
273 }
274
275 //
276
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700277 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800278 getScope() const
279 {
280 return m_scope;
281 }
282
283 Interest&
284 setScope(int scope)
285 {
286 m_scope = scope;
287 m_wire.reset();
288 return *this;
289 }
290
291 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700292
293 const time::milliseconds&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800294 getInterestLifetime() const
295 {
296 return m_interestLifetime;
297 }
298
299 Interest&
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700300 setInterestLifetime(const time::milliseconds& interestLifetime)
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800301 {
302 m_interestLifetime = interestLifetime;
303 m_wire.reset();
304 return *this;
305 }
306
307 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700308
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800309 /**
310 * @brief Get Interest's nonce
311 *
312 * If nonce was not set before this call, it will be automatically assigned to a random value
313 *
314 * Const reference needed for C decoding
315 */
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300316 uint32_t
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800317 getNonce() const;
318
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300319 /**
320 * @brief Check if Nonce set
321 */
322 bool
323 hasNonce() const
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800324 {
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300325 return m_nonce.hasWire();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800326 }
327
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300328 /**
329 * @brief Set Interest's nonce
330 *
331 * Note that if wire format already exists, this call simply replaces nonce in the
332 * existing wire format, without resetting and recreating it.
333 */
334 Interest&
335 setNonce(uint32_t nonce);
336
Alexander Afanasyevc3932172014-07-10 18:53:56 -0700337 /**
338 * @brief Refresh nonce
339 *
340 * Refresh guarantees that new nonce value is different from the existing one.
341 *
342 * If nonce is already set, it will be updated to a different random value.
343 * If nonce is not set, this method will do nothing.
344 */
345 void
346 refreshNonce();
347
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800348 //
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800349
350 nfd::LocalControlHeader&
351 getLocalControlHeader()
352 {
353 return m_localControlHeader;
354 }
355
356 const nfd::LocalControlHeader&
357 getLocalControlHeader() const
358 {
359 return m_localControlHeader;
360 }
361
362 // helper methods for LocalControlHeader
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700363
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800364 uint64_t
365 getIncomingFaceId() const
366 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800367 return getLocalControlHeader().getIncomingFaceId();
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800368 }
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800369
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800370 Interest&
371 setIncomingFaceId(uint64_t incomingFaceId)
372 {
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800373 getLocalControlHeader().setIncomingFaceId(incomingFaceId);
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800374 // ! do not reset Interest's wire !
375 return *this;
376 }
377
378 //
379
380 // NextHopFaceId helpers make sense only for Interests
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700381
Alexander Afanasyev5964fb72014-02-18 12:42:45 -0800382 uint64_t
383 getNextHopFaceId() const
384 {
385 return getLocalControlHeader().getNextHopFaceId();
386 }
387
388 Interest&
389 setNextHopFaceId(uint64_t nextHopFaceId)
390 {
391 getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
392 // ! do not reset Interest's wire !
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800393 return *this;
394 }
395
396 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700397
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800398 ///////////////////////////////////////////////////////////////////////////////
399 ///////////////////////////////////////////////////////////////////////////////
400 ///////////////////////////////////////////////////////////////////////////////
401 // Wrappers for Selectors
402 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700403
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800404 int
405 getMinSuffixComponents() const
406 {
407 return m_selectors.getMinSuffixComponents();
408 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700409
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800410 Interest&
411 setMinSuffixComponents(int minSuffixComponents)
412 {
413 m_selectors.setMinSuffixComponents(minSuffixComponents);
414 m_wire.reset();
415 return *this;
416 }
417
418 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700419
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800420 int
421 getMaxSuffixComponents() const
422 {
423 return m_selectors.getMaxSuffixComponents();
424 }
425
426 Interest&
427 setMaxSuffixComponents(int maxSuffixComponents)
428 {
429 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
430 m_wire.reset();
431 return *this;
432 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700433
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800434 //
435
Junxiao Shib332e782014-03-31 14:23:46 -0700436 const KeyLocator&
437 getPublisherPublicKeyLocator() const
438 {
439 return m_selectors.getPublisherPublicKeyLocator();
440 }
441
442 Interest&
443 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
444 {
445 m_selectors.setPublisherPublicKeyLocator(keyLocator);
446 m_wire.reset();
447 return *this;
448 }
449
450 //
451
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800452 const Exclude&
453 getExclude() const
454 {
455 return m_selectors.getExclude();
456 }
457
458 Interest&
459 setExclude(const Exclude& exclude)
460 {
461 m_selectors.setExclude(exclude);
462 m_wire.reset();
463 return *this;
464 }
465
466 //
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700467
468 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800469 getChildSelector() const
470 {
471 return m_selectors.getChildSelector();
472 }
473
474 Interest&
475 setChildSelector(int childSelector)
476 {
477 m_selectors.setChildSelector(childSelector);
478 m_wire.reset();
479 return *this;
480 }
481
482 //
483
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700484 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800485 getMustBeFresh() const
486 {
487 return m_selectors.getMustBeFresh();
488 }
489
490 Interest&
491 setMustBeFresh(bool mustBeFresh)
492 {
493 m_selectors.setMustBeFresh(mustBeFresh);
494 m_wire.reset();
495 return *this;
496 }
497
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700498public: // EqualityComparable concept
499 bool
500 operator==(const Interest& other) const
501 {
502 return wireEncode() == other.wireEncode();
503 }
504
505 bool
506 operator!=(const Interest& other) const
507 {
508 return !(*this == other);
509 }
510
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800511private:
512 Name m_name;
513 Selectors m_selectors;
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300514 mutable Block m_nonce;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800515 int m_scope;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700516 time::milliseconds m_interestLifetime;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800517
518 mutable Block m_wire;
Yingdi Yua4e57672014-02-06 11:16:17 -0800519
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800520 nfd::LocalControlHeader m_localControlHeader;
521 friend class nfd::LocalControlHeader;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700522};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800523
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700524std::ostream&
525operator<<(std::ostream& os, const Interest& interest);
Alexander Afanasyev84681982014-01-03 13:26:09 -0800526
527inline std::string
528Interest::toUri() const
529{
530 std::ostringstream os;
531 os << *this;
532 return os.str();
533}
534
535inline bool
536Interest::hasSelectors() const
537{
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800538 return !m_selectors.empty();
Alexander Afanasyev84681982014-01-03 13:26:09 -0800539}
540
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800541
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -0800542inline bool
543Interest::hasWire() const
544{
545 return m_wire.hasWire();
546}
547
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800548
549} // namespace ndn
550
551#endif // NDN_INTEREST_HPP