blob: bde5c9782b7b1d4a8542f90e4d6f0972e3b9d92e [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi899277a2017-07-07 22:12:12 +00002/*
Davide Pesavento0f830802018-01-16 23:58:58 -05003 * Copyright (c) 2013-2018 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.
Jeff Thompsonb7f95562013-07-03 18:36:42 -070020 */
21
22#ifndef NDN_INTEREST_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070023#define NDN_INTEREST_HPP
Jeff Thompsonb7f95562013-07-03 18:36:42 -070024
Junxiao Shi9c154cb2017-07-07 22:14:54 +000025#include "delegation-list.hpp"
Jeff Thompson53412192013-08-06 13:35:50 -070026#include "name.hpp"
Eric Newberryc3a46792017-09-24 14:54:24 -070027#include "packet-base.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080028#include "selectors.hpp"
Junxiao Shi899277a2017-07-07 22:12:12 +000029#include "util/time.hpp"
Junxiao Shib55e5d32018-07-18 13:32:00 -060030#include <boost/logic/tribool.hpp>
Jeff Thompsonb7f95562013-07-03 18:36:42 -070031
32namespace ndn {
Alexander Afanasyevc348f832014-02-17 16:35:17 -080033
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070034class Data;
35
Junxiao Shi7007a3c2014-11-20 22:37:55 -070036/** @var const unspecified_duration_type DEFAULT_INTEREST_LIFETIME;
37 * @brief default value for InterestLifetime
38 */
Davide Pesavento0f830802018-01-16 23:58:58 -050039const time::milliseconds DEFAULT_INTEREST_LIFETIME = 4_s;
Alexander Afanasyevc348f832014-02-17 16:35:17 -080040
Junxiao Shi8d3f8342018-04-04 12:46:37 +000041/** @brief Represents an Interest packet.
Jeff Thompson8238d002013-07-10 11:56:49 -070042 */
Davide Pesavento1fd00242018-05-20 00:11:01 -040043class Interest : public PacketBase, public std::enable_shared_from_this<Interest>
Alexander Afanasyevc348f832014-02-17 16:35:17 -080044{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070045public:
Junxiao Shic2b8d242014-11-04 08:35:29 -070046 class Error : public tlv::Error
47 {
48 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060049 using tlv::Error::Error;
Junxiao Shic2b8d242014-11-04 08:35:29 -070050 };
51
Junxiao Shi8d3f8342018-04-04 12:46:37 +000052 /** @brief Construct an Interest with given @p name and @p lifetime.
53 * @throw std::invalid_argument @p lifetime is negative
54 * @warning In certain contexts that use `Interest::shared_from_this()`, Interest must be created
55 * using `make_shared`. Otherwise, `shared_from_this()` will trigger undefined behavior.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080056 */
Junxiao Shi909ffef2017-07-07 22:12:27 +000057 explicit
Junxiao Shi8d3f8342018-04-04 12:46:37 +000058 Interest(const Name& name = Name(), time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070059
Junxiao Shi8d3f8342018-04-04 12:46:37 +000060 /** @brief Construct an Interest by decoding from @p wire.
61 * @warning In certain contexts that use `Interest::shared_from_this()`, Interest must be created
62 * using `make_shared`. Otherwise, `shared_from_this()` will trigger undefined behavior.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070063 */
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080064 explicit
Junxiao Shi2af905b2014-11-27 13:10:54 -070065 Interest(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080066
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -070067 /** @brief Prepend wire encoding to @p encoder.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080068 */
Alexander Afanasyev74633892015-02-08 18:08:46 -080069 template<encoding::Tag TAG>
Alexander Afanasyev197e5652014-06-13 16:56:31 -070070 size_t
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070071 wireEncode(EncodingImpl<TAG>& encoder) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080072
Junxiao Shi6efa3b72018-04-14 15:54:08 +000073 /** @brief Encode to a @c Block.
74 *
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -070075 * Encodes into NDN Packet Format v0.3 if Parameters element is present. In this case, Selectors
76 * are not encoded. Otherwise, encodes into NDN Packet Format v0.2.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080077 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070078 const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -080079 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -080080
Junxiao Shi6efa3b72018-04-14 15:54:08 +000081 /** @brief Decode from @p wire in NDN Packet Format v0.2 or v0.3.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080082 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070083 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070084 wireDecode(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080085
Junxiao Shi8d3f8342018-04-04 12:46:37 +000086 /** @brief Check if this instance has cached wire encoding.
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080087 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070088 bool
Junxiao Shi2af905b2014-11-27 13:10:54 -070089 hasWire() const
90 {
91 return m_wire.hasWire();
92 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070093
Junxiao Shi8d3f8342018-04-04 12:46:37 +000094 /** @brief Return a URI-like string that represents the Interest.
Alexander Afanasyev770827c2014-05-13 17:42:55 -070095 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +000096 * The string starts with `getName().toUri()`.
97 * If the Interest contains selectors, they are included as a query string.
98 * Example: "/test/name?ndn.MustBeFresh=1"
Jeff Thompson13e280b2013-12-03 13:12:23 -080099 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700100 std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800101 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700102
Junxiao Shi2af905b2014-11-27 13:10:54 -0700103public: // matching
104 /** @brief Check if Interest, including selectors, matches the given @p name
105 * @param name The name to be matched. If this is a Data name, it shall contain the
106 * implicit digest component
Alexander Afanasyev84681982014-01-03 13:26:09 -0800107 */
108 bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700109 matchesName(const Name& name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800110
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000111 /** @brief Check if Interest can be satisfied by @p data.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700112 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000113 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
114 * PublisherPublicKeyLocator, and Exclude.
115 * This method does not consider ChildSelector and MustBeFresh.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700116 */
117 bool
118 matchesData(const Data& data) const;
119
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000120 /** @brief Check if Interest matches @p other interest
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800121 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000122 * Interest matches @p other if both have the same name, selectors, and link. Other fields
123 * (e.g., Nonce) may be different.
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800124 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000125 * @todo Implement distinguishing Interests by forwarding hint. The current implementation
126 * checks only name+selectors (Issue #3162).
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800127 */
128 bool
129 matchesInterest(const Interest& other) const;
130
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000131public: // element access
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700132 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800133 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700134 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800135 return m_name;
136 }
137
138 Interest&
139 setName(const Name& name)
140 {
141 m_name = name;
142 m_wire.reset();
143 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700144 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700145
Junxiao Shib55e5d32018-07-18 13:32:00 -0600146 /** @brief Declare the default CanBePrefix setting of the application.
147 *
148 * As part of transitioning to NDN Packet Format v0.3, the default setting for CanBePrefix
149 * will be changed from "true" to "false". Application developers are advised to review all
150 * Interests expressed by their application and decide what CanBePrefix setting is appropriate
151 * for each Interest, to avoid breaking changes when the transition occurs. Application may
152 * either set CanBePrefix on a per-Interest basis, or declare a default CanBePrefix setting for
153 * all Interests expressed by the application using this function. If an application neither
154 * declares a default nor sets CanBePrefix on every Interest, Interest::wireEncode will print a
155 * one-time warning message.
156 *
157 * @note This function should not be used in libraries or in ndn-cxx unit tests.
158 * @sa https://redmine.named-data.net/projects/nfd/wiki/Packet03Transition
159 */
160 static void
161 setDefaultCanBePrefix(bool canBePrefix)
162 {
163 s_defaultCanBePrefix = canBePrefix;
164 }
165
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000166 /** @brief Check whether the CanBePrefix element is present.
167 *
168 * This is a getter for the CanBePrefix element as defined in NDN Packet Format v0.3.
169 * In this implementation, it is mapped to the closest v0.2 semantics:
170 * MaxSuffixComponents=1 means CanBePrefix is absent.
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300171 */
172 bool
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000173 getCanBePrefix() const
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800174 {
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000175 return m_selectors.getMaxSuffixComponents() != 1;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800176 }
177
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000178 /** @brief Add or remove CanBePrefix element.
179 * @param canBePrefix whether CanBePrefix element should be present.
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300180 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000181 * This is a setter for the CanBePrefix element as defined in NDN Packet Format v0.3.
182 * In this implementation, it is mapped to the closest v0.2 semantics:
183 * MaxSuffixComponents=1 means CanBePrefix is absent.
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300184 */
185 Interest&
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000186 setCanBePrefix(bool canBePrefix)
Junxiao Shi899277a2017-07-07 22:12:12 +0000187 {
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000188 m_selectors.setMaxSuffixComponents(canBePrefix ? -1 : 1);
189 m_wire.reset();
Junxiao Shib55e5d32018-07-18 13:32:00 -0600190 m_isCanBePrefixSet = true;
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000191 return *this;
Junxiao Shi899277a2017-07-07 22:12:12 +0000192 }
193
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000194 /** @brief Check whether the MustBeFresh element is present.
195 *
196 * This is a getter for the MustBeFresh element as defined in NDN Packet Format v0.3.
197 * In this implementation, it is mapped to the closest v0.2 semantics and appears as
198 * MustBeFresh element under Selectors.
199 */
200 bool
201 getMustBeFresh() const
202 {
203 return m_selectors.getMustBeFresh();
204 }
205
206 /** @brief Add or remove MustBeFresh element.
207 * @param mustBeFresh whether MustBeFresh element should be present.
208 *
209 * This is a setter for the MustBeFresh element as defined in NDN Packet Format v0.3.
210 * In this implementation, it is mapped to the closest v0.2 semantics and appears as
211 * MustBeFresh element under Selectors.
Junxiao Shi899277a2017-07-07 22:12:12 +0000212 */
213 Interest&
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000214 setMustBeFresh(bool mustBeFresh)
215 {
216 m_selectors.setMustBeFresh(mustBeFresh);
217 m_wire.reset();
218 return *this;
219 }
Junxiao Shi899277a2017-07-07 22:12:12 +0000220
Junxiao Shi9c154cb2017-07-07 22:14:54 +0000221 const DelegationList&
222 getForwardingHint() const
223 {
224 return m_forwardingHint;
225 }
226
227 Interest&
228 setForwardingHint(const DelegationList& value);
229
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000230 /** @brief Modify ForwardingHint in-place.
Junxiao Shib2a70332017-07-07 22:15:03 +0000231 * @tparam Modifier a unary function that accepts DelegationList&
232 *
233 * This is equivalent to, but more efficient (avoids copying) than:
234 * @code
235 * auto fh = interest.getForwardingHint();
236 * modifier(fh);
237 * interest.setForwardingHint(fh);
238 * @endcode
239 */
240 template<typename Modifier>
241 Interest&
242 modifyForwardingHint(const Modifier& modifier)
243 {
244 modifier(m_forwardingHint);
245 m_wire.reset();
246 return *this;
247 }
248
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000249 /** @brief Check if the Nonce element is present.
Junxiao Shi2af905b2014-11-27 13:10:54 -0700250 */
251 bool
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000252 hasNonce() const
253 {
254 return static_cast<bool>(m_nonce);
255 }
256
257 /** @brief Get nonce value.
258 *
259 * If nonce was not present, it is added and assigned a random value.
260 */
261 uint32_t
262 getNonce() const;
263
264 /** @brief Set nonce value.
265 */
266 Interest&
267 setNonce(uint32_t nonce);
268
269 /** @brief Change nonce value.
270 *
271 * If the Nonce element is present, the new nonce value will differ from the old value.
272 * If the Nonce element is not present, this method does nothing.
273 */
274 void
275 refreshNonce();
276
277 time::milliseconds
278 getInterestLifetime() const
279 {
280 return m_interestLifetime;
281 }
282
283 /** @brief Set Interest's lifetime
284 * @throw std::invalid_argument @p lifetime is negative
285 */
286 Interest&
287 setInterestLifetime(time::milliseconds lifetime);
288
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700289 bool
290 hasParameters() const
291 {
292 return !m_parameters.empty();
293 }
294
295 const Block&
296 getParameters() const
297 {
298 return m_parameters;
299 }
300
301 /** @brief Set parameters from a Block
302 *
303 * If the block's TLV-TYPE is Parameters, it will be used directly as this Interest's Parameters element.
304 * If the block's TLV-TYPE is not Parameters, it will be nested into a Parameters element.
305 * @return a reference to this Interest
306 */
307 Interest&
308 setParameters(const Block& parameters);
309
310 /** @brief Copy parameters from raw buffer
311 *
312 * @param buffer pointer to the first octet of parameters
313 * @param bufferSize size of the raw buffer
314 * @return a reference to this Interest
315 */
316 Interest&
317 setParameters(const uint8_t* buffer, size_t bufferSize);
318
319 /** @brief Set parameters from a wire buffer
320 *
321 * @param buffer containing the Interest parameters
322 * @return a reference to this Interest
323 */
324 Interest&
325 setParameters(ConstBufferPtr buffer);
326
327 /** @brief Remove the Parameters element from this Interest
328 *
329 * @post hasParameters() == false
330 */
331 Interest&
332 unsetParameters();
333
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000334public: // Selectors (deprecated)
335 /** @brief Check if Interest has any selector present.
336 */
Davide Pesavento1fd00242018-05-20 00:11:01 -0400337 [[deprecated]]
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000338 bool
Junxiao Shi2af905b2014-11-27 13:10:54 -0700339 hasSelectors() const
340 {
341 return !m_selectors.empty();
342 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700343
Davide Pesavento1fd00242018-05-20 00:11:01 -0400344 [[deprecated]]
Junxiao Shi2af905b2014-11-27 13:10:54 -0700345 const Selectors&
346 getSelectors() const
347 {
348 return m_selectors;
349 }
350
Davide Pesavento1fd00242018-05-20 00:11:01 -0400351 [[deprecated]]
Junxiao Shi2af905b2014-11-27 13:10:54 -0700352 Interest&
353 setSelectors(const Selectors& selectors)
354 {
355 m_selectors = selectors;
356 m_wire.reset();
357 return *this;
358 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700359
Davide Pesavento1fd00242018-05-20 00:11:01 -0400360 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800361 int
362 getMinSuffixComponents() const
363 {
364 return m_selectors.getMinSuffixComponents();
365 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700366
Davide Pesavento1fd00242018-05-20 00:11:01 -0400367 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800368 Interest&
369 setMinSuffixComponents(int minSuffixComponents)
370 {
371 m_selectors.setMinSuffixComponents(minSuffixComponents);
372 m_wire.reset();
373 return *this;
374 }
375
Davide Pesavento1fd00242018-05-20 00:11:01 -0400376 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800377 int
378 getMaxSuffixComponents() const
379 {
380 return m_selectors.getMaxSuffixComponents();
381 }
382
Davide Pesavento1fd00242018-05-20 00:11:01 -0400383 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800384 Interest&
385 setMaxSuffixComponents(int maxSuffixComponents)
386 {
387 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
388 m_wire.reset();
389 return *this;
390 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700391
Davide Pesavento1fd00242018-05-20 00:11:01 -0400392 [[deprecated]]
Junxiao Shib332e782014-03-31 14:23:46 -0700393 const KeyLocator&
394 getPublisherPublicKeyLocator() const
395 {
396 return m_selectors.getPublisherPublicKeyLocator();
397 }
398
Davide Pesavento1fd00242018-05-20 00:11:01 -0400399 [[deprecated]]
Junxiao Shib332e782014-03-31 14:23:46 -0700400 Interest&
401 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
402 {
403 m_selectors.setPublisherPublicKeyLocator(keyLocator);
404 m_wire.reset();
405 return *this;
406 }
407
Davide Pesavento1fd00242018-05-20 00:11:01 -0400408 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800409 const Exclude&
410 getExclude() const
411 {
412 return m_selectors.getExclude();
413 }
414
Davide Pesavento1fd00242018-05-20 00:11:01 -0400415 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800416 Interest&
417 setExclude(const Exclude& exclude)
418 {
419 m_selectors.setExclude(exclude);
420 m_wire.reset();
421 return *this;
422 }
423
Davide Pesavento1fd00242018-05-20 00:11:01 -0400424 [[deprecated]]
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700425 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800426 getChildSelector() const
427 {
428 return m_selectors.getChildSelector();
429 }
430
Davide Pesavento1fd00242018-05-20 00:11:01 -0400431 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800432 Interest&
433 setChildSelector(int childSelector)
434 {
435 m_selectors.setChildSelector(childSelector);
436 m_wire.reset();
437 return *this;
438 }
439
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800440private:
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700441 /** @brief Prepend wire encoding to @p encoder in NDN Packet Format v0.2.
442 */
443 template<encoding::Tag TAG>
444 size_t
445 encode02(EncodingImpl<TAG>& encoder) const;
446
447 /** @brief Prepend wire encoding to @p encoder in NDN Packet Format v0.3.
448 */
449 template<encoding::Tag TAG>
450 size_t
451 encode03(EncodingImpl<TAG>& encoder) const;
452
Junxiao Shi6efa3b72018-04-14 15:54:08 +0000453 /** @brief Decode @c m_wire as NDN Packet Format v0.2.
454 * @retval true decoding successful.
455 * @retval false decoding failed due to structural error.
456 * @throw tlv::Error decoding error within a sub-element.
457 */
458 bool
459 decode02();
460
461 /** @brief Decode @c m_wire as NDN Packet Format v0.3.
462 * @throw tlv::Error decoding error.
463 */
464 void
465 decode03();
466
Junxiao Shib55e5d32018-07-18 13:32:00 -0600467#ifdef NDN_CXX_HAVE_TESTS
468public:
469 /** @brief If true, not setting CanBePrefix results in an error in wireEncode().
470 */
471 static bool s_errorIfCanBePrefixUnset;
472#endif // NDN_CXX_HAVE_TESTS
473
Junxiao Shi6efa3b72018-04-14 15:54:08 +0000474private:
Junxiao Shib55e5d32018-07-18 13:32:00 -0600475 static boost::logic::tribool s_defaultCanBePrefix;
476
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800477 Name m_name;
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700478 Selectors m_selectors; // NDN Packet Format v0.2 only
Junxiao Shib55e5d32018-07-18 13:32:00 -0600479 mutable bool m_isCanBePrefixSet;
Junxiao Shi2dd711d2017-07-21 13:40:52 +0000480 mutable optional<uint32_t> m_nonce;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700481 time::milliseconds m_interestLifetime;
Junxiao Shi9c154cb2017-07-07 22:14:54 +0000482 DelegationList m_forwardingHint;
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700483 Block m_parameters; // NDN Packet Format v0.3 only
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800484
485 mutable Block m_wire;
Junxiao Shib55e5d32018-07-18 13:32:00 -0600486
487 friend bool operator==(const Interest& lhs, const Interest& rhs);
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700488};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800489
Davide Pesavento88a0d812017-08-19 21:31:42 -0400490NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Interest);
491
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700492std::ostream&
493operator<<(std::ostream& os, const Interest& interest);
Alexander Afanasyev84681982014-01-03 13:26:09 -0800494
Junxiao Shib55e5d32018-07-18 13:32:00 -0600495bool
496operator==(const Interest& lhs, const Interest& rhs);
Junxiao Shi899277a2017-07-07 22:12:12 +0000497
498inline bool
499operator!=(const Interest& lhs, const Interest& rhs)
500{
501 return !(lhs == rhs);
502}
503
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800504} // namespace ndn
505
506#endif // NDN_INTEREST_HPP