blob: 9f16affe8c7938132952a8f3260801c7479846f5 [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 Pesaventofccb2dc2019-02-09 01:02:35 -05003 * Copyright (c) 2013-2019 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
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/delegation-list.hpp"
26#include "ndn-cxx/name.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050027#include "ndn-cxx/selectors.hpp"
Junxiao Shi1e36ceb2018-12-17 13:20:26 -070028#include "ndn-cxx/detail/packet-base.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050029#include "ndn-cxx/util/time.hpp"
30
Junxiao Shib55e5d32018-07-18 13:32:00 -060031#include <boost/logic/tribool.hpp>
Jeff Thompsonb7f95562013-07-03 18:36:42 -070032
33namespace ndn {
Alexander Afanasyevc348f832014-02-17 16:35:17 -080034
Junxiao Shiaf8eeea2014-03-31 20:10:56 -070035class Data;
36
Junxiao Shi7007a3c2014-11-20 22:37:55 -070037/** @var const unspecified_duration_type DEFAULT_INTEREST_LIFETIME;
38 * @brief default value for InterestLifetime
39 */
Davide Pesavento0f830802018-01-16 23:58:58 -050040const time::milliseconds DEFAULT_INTEREST_LIFETIME = 4_s;
Alexander Afanasyevc348f832014-02-17 16:35:17 -080041
Junxiao Shi8d3f8342018-04-04 12:46:37 +000042/** @brief Represents an Interest packet.
Jeff Thompson8238d002013-07-10 11:56:49 -070043 */
Davide Pesavento1fd00242018-05-20 00:11:01 -040044class Interest : public PacketBase, public std::enable_shared_from_this<Interest>
Alexander Afanasyevc348f832014-02-17 16:35:17 -080045{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070046public:
Junxiao Shic2b8d242014-11-04 08:35:29 -070047 class Error : public tlv::Error
48 {
49 public:
Junxiao Shi68b53852018-07-25 13:56:38 -060050 using tlv::Error::Error;
Junxiao Shic2b8d242014-11-04 08:35:29 -070051 };
52
Junxiao Shi8d3f8342018-04-04 12:46:37 +000053 /** @brief Construct an Interest with given @p name and @p lifetime.
54 * @throw std::invalid_argument @p lifetime is negative
55 * @warning In certain contexts that use `Interest::shared_from_this()`, Interest must be created
56 * using `make_shared`. Otherwise, `shared_from_this()` will trigger undefined behavior.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080057 */
Junxiao Shi909ffef2017-07-07 22:12:27 +000058 explicit
Junxiao Shi8d3f8342018-04-04 12:46:37 +000059 Interest(const Name& name = Name(), time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070060
Junxiao Shi8d3f8342018-04-04 12:46:37 +000061 /** @brief Construct an Interest by decoding from @p wire.
62 * @warning In certain contexts that use `Interest::shared_from_this()`, Interest must be created
63 * using `make_shared`. Otherwise, `shared_from_this()` will trigger undefined behavior.
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064 */
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080065 explicit
Junxiao Shi2af905b2014-11-27 13:10:54 -070066 Interest(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080067
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -070068 /** @brief Prepend wire encoding to @p encoder.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080069 */
Alexander Afanasyev74633892015-02-08 18:08:46 -080070 template<encoding::Tag TAG>
Alexander Afanasyev197e5652014-06-13 16:56:31 -070071 size_t
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070072 wireEncode(EncodingImpl<TAG>& encoder) const;
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080073
Junxiao Shi6efa3b72018-04-14 15:54:08 +000074 /** @brief Encode to a @c Block.
75 *
Davide Pesavento9c19a392019-04-06 15:07:54 -040076 * Encodes into NDN Packet Format v0.3 if ApplicationParameters element is present, in which
77 * case Selectors are not encoded. Otherwise, encodes into NDN Packet Format v0.2.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080078 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070079 const Block&
Alexander Afanasyev1eb961a2014-01-03 13:51:49 -080080 wireEncode() const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -080081
Junxiao Shi6efa3b72018-04-14 15:54:08 +000082 /** @brief Decode from @p wire in NDN Packet Format v0.2 or v0.3.
Jeff Thompson1b4a7b12013-11-15 12:00:02 -080083 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070084 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070085 wireDecode(const Block& wire);
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080086
Junxiao Shi8d3f8342018-04-04 12:46:37 +000087 /** @brief Check if this instance has cached wire encoding.
Alexander Afanasyev6d48bc12014-02-18 00:10:51 -080088 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -070089 bool
Junxiao Shi2af905b2014-11-27 13:10:54 -070090 hasWire() const
91 {
92 return m_wire.hasWire();
93 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070094
Junxiao Shi8d3f8342018-04-04 12:46:37 +000095 /** @brief Return a URI-like string that represents the Interest.
Alexander Afanasyev770827c2014-05-13 17:42:55 -070096 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +000097 * The string starts with `getName().toUri()`.
98 * If the Interest contains selectors, they are included as a query string.
99 * Example: "/test/name?ndn.MustBeFresh=1"
Jeff Thompson13e280b2013-12-03 13:12:23 -0800100 */
Alexander Afanasyev197e5652014-06-13 16:56:31 -0700101 std::string
Jeff Thompson13e280b2013-12-03 13:12:23 -0800102 toUri() const;
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700103
Junxiao Shi2af905b2014-11-27 13:10:54 -0700104public: // matching
105 /** @brief Check if Interest, including selectors, matches the given @p name
106 * @param name The name to be matched. If this is a Data name, it shall contain the
107 * implicit digest component
Alexander Afanasyev84681982014-01-03 13:26:09 -0800108 */
109 bool
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700110 matchesName(const Name& name) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800111
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000112 /** @brief Check if Interest can be satisfied by @p data.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700113 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000114 * This method considers Name, MinSuffixComponents, MaxSuffixComponents,
115 * PublisherPublicKeyLocator, and Exclude.
116 * This method does not consider ChildSelector and MustBeFresh.
Junxiao Shiaf8eeea2014-03-31 20:10:56 -0700117 */
118 bool
119 matchesData(const Data& data) const;
120
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000121 /** @brief Check if Interest matches @p other interest
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800122 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000123 * Interest matches @p other if both have the same name, selectors, and link. Other fields
124 * (e.g., Nonce) may be different.
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800125 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000126 * @todo Implement distinguishing Interests by forwarding hint. The current implementation
127 * checks only name+selectors (Issue #3162).
Alexander Afanasyev1013fd02017-01-03 13:19:03 -0800128 */
129 bool
130 matchesInterest(const Interest& other) const;
131
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000132public: // element access
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700133 const Name&
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800134 getName() const
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700135 {
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800136 return m_name;
137 }
138
139 Interest&
140 setName(const Name& name)
141 {
142 m_name = name;
143 m_wire.reset();
144 return *this;
Jeff Thompsonc0486c12013-07-16 14:36:16 -0700145 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700146
Junxiao Shib55e5d32018-07-18 13:32:00 -0600147 /** @brief Declare the default CanBePrefix setting of the application.
148 *
149 * As part of transitioning to NDN Packet Format v0.3, the default setting for CanBePrefix
150 * will be changed from "true" to "false". Application developers are advised to review all
151 * Interests expressed by their application and decide what CanBePrefix setting is appropriate
152 * for each Interest, to avoid breaking changes when the transition occurs. Application may
153 * either set CanBePrefix on a per-Interest basis, or declare a default CanBePrefix setting for
154 * all Interests expressed by the application using this function. If an application neither
155 * declares a default nor sets CanBePrefix on every Interest, Interest::wireEncode will print a
156 * one-time warning message.
157 *
158 * @note This function should not be used in libraries or in ndn-cxx unit tests.
159 * @sa https://redmine.named-data.net/projects/nfd/wiki/Packet03Transition
160 */
161 static void
162 setDefaultCanBePrefix(bool canBePrefix)
163 {
164 s_defaultCanBePrefix = canBePrefix;
165 }
166
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000167 /** @brief Check whether the CanBePrefix element is present.
168 *
169 * This is a getter for the CanBePrefix element as defined in NDN Packet Format v0.3.
170 * In this implementation, it is mapped to the closest v0.2 semantics:
171 * MaxSuffixComponents=1 means CanBePrefix is absent.
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300172 */
173 bool
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000174 getCanBePrefix() const
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800175 {
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000176 return m_selectors.getMaxSuffixComponents() != 1;
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800177 }
178
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000179 /** @brief Add or remove CanBePrefix element.
180 * @param canBePrefix whether CanBePrefix element should be present.
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300181 *
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000182 * This is a setter for the CanBePrefix element as defined in NDN Packet Format v0.3.
183 * In this implementation, it is mapped to the closest v0.2 semantics:
184 * MaxSuffixComponents=1 means CanBePrefix is absent.
Alexander Afanasyeve881e932014-06-08 14:47:03 +0300185 */
186 Interest&
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000187 setCanBePrefix(bool canBePrefix)
Junxiao Shi899277a2017-07-07 22:12:12 +0000188 {
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000189 m_selectors.setMaxSuffixComponents(canBePrefix ? -1 : 1);
190 m_wire.reset();
Junxiao Shib55e5d32018-07-18 13:32:00 -0600191 m_isCanBePrefixSet = true;
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000192 return *this;
Junxiao Shi899277a2017-07-07 22:12:12 +0000193 }
194
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000195 /** @brief Check whether the MustBeFresh element is present.
196 *
197 * This is a getter for the MustBeFresh element as defined in NDN Packet Format v0.3.
198 * In this implementation, it is mapped to the closest v0.2 semantics and appears as
199 * MustBeFresh element under Selectors.
200 */
201 bool
202 getMustBeFresh() const
203 {
204 return m_selectors.getMustBeFresh();
205 }
206
207 /** @brief Add or remove MustBeFresh element.
208 * @param mustBeFresh whether MustBeFresh element should be present.
209 *
210 * This is a setter for the MustBeFresh element as defined in NDN Packet Format v0.3.
211 * In this implementation, it is mapped to the closest v0.2 semantics and appears as
212 * MustBeFresh element under Selectors.
Junxiao Shi899277a2017-07-07 22:12:12 +0000213 */
214 Interest&
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000215 setMustBeFresh(bool mustBeFresh)
216 {
217 m_selectors.setMustBeFresh(mustBeFresh);
218 m_wire.reset();
219 return *this;
220 }
Junxiao Shi899277a2017-07-07 22:12:12 +0000221
Junxiao Shi9c154cb2017-07-07 22:14:54 +0000222 const DelegationList&
223 getForwardingHint() const
224 {
225 return m_forwardingHint;
226 }
227
228 Interest&
229 setForwardingHint(const DelegationList& value);
230
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000231 /** @brief Modify ForwardingHint in-place.
Junxiao Shib2a70332017-07-07 22:15:03 +0000232 * @tparam Modifier a unary function that accepts DelegationList&
233 *
234 * This is equivalent to, but more efficient (avoids copying) than:
235 * @code
236 * auto fh = interest.getForwardingHint();
237 * modifier(fh);
238 * interest.setForwardingHint(fh);
239 * @endcode
240 */
241 template<typename Modifier>
242 Interest&
243 modifyForwardingHint(const Modifier& modifier)
244 {
245 modifier(m_forwardingHint);
246 m_wire.reset();
247 return *this;
248 }
249
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000250 /** @brief Check if the Nonce element is present.
Junxiao Shi2af905b2014-11-27 13:10:54 -0700251 */
252 bool
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000253 hasNonce() const
254 {
Davide Pesaventofccb2dc2019-02-09 01:02:35 -0500255 return m_nonce.has_value();
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000256 }
257
258 /** @brief Get nonce value.
259 *
260 * If nonce was not present, it is added and assigned a random value.
261 */
262 uint32_t
263 getNonce() const;
264
265 /** @brief Set nonce value.
266 */
267 Interest&
268 setNonce(uint32_t nonce);
269
270 /** @brief Change nonce value.
271 *
272 * If the Nonce element is present, the new nonce value will differ from the old value.
273 * If the Nonce element is not present, this method does nothing.
274 */
275 void
276 refreshNonce();
277
278 time::milliseconds
279 getInterestLifetime() const
280 {
281 return m_interestLifetime;
282 }
283
284 /** @brief Set Interest's lifetime
285 * @throw std::invalid_argument @p lifetime is negative
286 */
287 Interest&
288 setInterestLifetime(time::milliseconds lifetime);
289
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700290 bool
Davide Pesavento9c19a392019-04-06 15:07:54 -0400291 hasApplicationParameters() const
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700292 {
293 return !m_parameters.empty();
294 }
295
296 const Block&
Davide Pesavento9c19a392019-04-06 15:07:54 -0400297 getApplicationParameters() const
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700298 {
299 return m_parameters;
300 }
301
Davide Pesavento9c19a392019-04-06 15:07:54 -0400302 /** @brief Set ApplicationParameters from a Block
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700303 *
Davide Pesavento38912442019-04-06 22:03:39 -0400304 * If the block is default-constructed, this will set a zero-length
305 * ApplicationParameters element.
306 * Else, if the block's TLV-TYPE is ApplicationParameters, it will be
307 * used directly as this Interest's ApplicationParameters element.
308 * Else, the block will be nested into an ApplicationParameters element.
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700309 * @return a reference to this Interest
310 */
311 Interest&
Davide Pesavento9c19a392019-04-06 15:07:54 -0400312 setApplicationParameters(const Block& parameters);
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700313
Davide Pesavento9c19a392019-04-06 15:07:54 -0400314 /** @brief Copy ApplicationParameters from raw buffer
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700315 *
316 * @param buffer pointer to the first octet of parameters
317 * @param bufferSize size of the raw buffer
318 * @return a reference to this Interest
319 */
320 Interest&
Davide Pesavento9c19a392019-04-06 15:07:54 -0400321 setApplicationParameters(const uint8_t* buffer, size_t bufferSize);
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700322
Davide Pesavento9c19a392019-04-06 15:07:54 -0400323 /** @brief Set ApplicationParameters from a wire buffer
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700324 *
Davide Pesavento38912442019-04-06 22:03:39 -0400325 * @param buffer buffer containing the parameters, must not be nullptr
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700326 * @return a reference to this Interest
327 */
328 Interest&
Davide Pesavento9c19a392019-04-06 15:07:54 -0400329 setApplicationParameters(ConstBufferPtr buffer);
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700330
Davide Pesavento9c19a392019-04-06 15:07:54 -0400331 /** @brief Remove the ApplicationParameters element from this Interest
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700332 *
Davide Pesavento9c19a392019-04-06 15:07:54 -0400333 * @post hasApplicationParameters() == false
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700334 */
335 Interest&
Davide Pesavento9c19a392019-04-06 15:07:54 -0400336 unsetApplicationParameters();
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700337
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000338public: // Selectors (deprecated)
339 /** @brief Check if Interest has any selector present.
340 */
Davide Pesavento1fd00242018-05-20 00:11:01 -0400341 [[deprecated]]
Junxiao Shi8d3f8342018-04-04 12:46:37 +0000342 bool
Junxiao Shi2af905b2014-11-27 13:10:54 -0700343 hasSelectors() const
344 {
345 return !m_selectors.empty();
346 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700347
Davide Pesavento1fd00242018-05-20 00:11:01 -0400348 [[deprecated]]
Junxiao Shi2af905b2014-11-27 13:10:54 -0700349 const Selectors&
350 getSelectors() const
351 {
352 return m_selectors;
353 }
354
Davide Pesavento1fd00242018-05-20 00:11:01 -0400355 [[deprecated]]
Junxiao Shi2af905b2014-11-27 13:10:54 -0700356 Interest&
357 setSelectors(const Selectors& selectors)
358 {
359 m_selectors = selectors;
360 m_wire.reset();
361 return *this;
362 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700363
Davide Pesavento1fd00242018-05-20 00:11:01 -0400364 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800365 int
366 getMinSuffixComponents() const
367 {
368 return m_selectors.getMinSuffixComponents();
369 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700370
Davide Pesavento1fd00242018-05-20 00:11:01 -0400371 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800372 Interest&
373 setMinSuffixComponents(int minSuffixComponents)
374 {
375 m_selectors.setMinSuffixComponents(minSuffixComponents);
376 m_wire.reset();
377 return *this;
378 }
379
Davide Pesavento1fd00242018-05-20 00:11:01 -0400380 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800381 int
382 getMaxSuffixComponents() const
383 {
384 return m_selectors.getMaxSuffixComponents();
385 }
386
Davide Pesavento1fd00242018-05-20 00:11:01 -0400387 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800388 Interest&
389 setMaxSuffixComponents(int maxSuffixComponents)
390 {
391 m_selectors.setMaxSuffixComponents(maxSuffixComponents);
392 m_wire.reset();
393 return *this;
394 }
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700395
Davide Pesavento1fd00242018-05-20 00:11:01 -0400396 [[deprecated]]
Junxiao Shib332e782014-03-31 14:23:46 -0700397 const KeyLocator&
398 getPublisherPublicKeyLocator() const
399 {
400 return m_selectors.getPublisherPublicKeyLocator();
401 }
402
Davide Pesavento1fd00242018-05-20 00:11:01 -0400403 [[deprecated]]
Junxiao Shib332e782014-03-31 14:23:46 -0700404 Interest&
405 setPublisherPublicKeyLocator(const KeyLocator& keyLocator)
406 {
407 m_selectors.setPublisherPublicKeyLocator(keyLocator);
408 m_wire.reset();
409 return *this;
410 }
411
Davide Pesavento1fd00242018-05-20 00:11:01 -0400412 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800413 const Exclude&
414 getExclude() const
415 {
416 return m_selectors.getExclude();
417 }
418
Davide Pesavento1fd00242018-05-20 00:11:01 -0400419 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800420 Interest&
421 setExclude(const Exclude& exclude)
422 {
423 m_selectors.setExclude(exclude);
424 m_wire.reset();
425 return *this;
426 }
427
Davide Pesavento1fd00242018-05-20 00:11:01 -0400428 [[deprecated]]
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700429 int
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800430 getChildSelector() const
431 {
432 return m_selectors.getChildSelector();
433 }
434
Davide Pesavento1fd00242018-05-20 00:11:01 -0400435 [[deprecated]]
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800436 Interest&
437 setChildSelector(int childSelector)
438 {
439 m_selectors.setChildSelector(childSelector);
440 m_wire.reset();
441 return *this;
442 }
443
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800444private:
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700445 /** @brief Prepend wire encoding to @p encoder in NDN Packet Format v0.2.
446 */
447 template<encoding::Tag TAG>
448 size_t
449 encode02(EncodingImpl<TAG>& encoder) const;
450
451 /** @brief Prepend wire encoding to @p encoder in NDN Packet Format v0.3.
452 */
453 template<encoding::Tag TAG>
454 size_t
455 encode03(EncodingImpl<TAG>& encoder) const;
456
Junxiao Shi6efa3b72018-04-14 15:54:08 +0000457 /** @brief Decode @c m_wire as NDN Packet Format v0.2.
458 * @retval true decoding successful.
459 * @retval false decoding failed due to structural error.
460 * @throw tlv::Error decoding error within a sub-element.
461 */
462 bool
463 decode02();
464
465 /** @brief Decode @c m_wire as NDN Packet Format v0.3.
466 * @throw tlv::Error decoding error.
467 */
468 void
469 decode03();
470
Junxiao Shib55e5d32018-07-18 13:32:00 -0600471#ifdef NDN_CXX_HAVE_TESTS
472public:
473 /** @brief If true, not setting CanBePrefix results in an error in wireEncode().
474 */
475 static bool s_errorIfCanBePrefixUnset;
476#endif // NDN_CXX_HAVE_TESTS
477
Junxiao Shi6efa3b72018-04-14 15:54:08 +0000478private:
Junxiao Shib55e5d32018-07-18 13:32:00 -0600479 static boost::logic::tribool s_defaultCanBePrefix;
480
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800481 Name m_name;
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700482 Selectors m_selectors; // NDN Packet Format v0.2 only
Junxiao Shib55e5d32018-07-18 13:32:00 -0600483 mutable bool m_isCanBePrefixSet;
Junxiao Shi2dd711d2017-07-21 13:40:52 +0000484 mutable optional<uint32_t> m_nonce;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700485 time::milliseconds m_interestLifetime;
Junxiao Shi9c154cb2017-07-07 22:14:54 +0000486 DelegationList m_forwardingHint;
Arthi Padmanabhanb38664e2018-07-18 11:13:12 -0700487 Block m_parameters; // NDN Packet Format v0.3 only
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800488
489 mutable Block m_wire;
Junxiao Shib55e5d32018-07-18 13:32:00 -0600490
491 friend bool operator==(const Interest& lhs, const Interest& rhs);
Jeff Thompsonb7f95562013-07-03 18:36:42 -0700492};
Alexander Afanasyev84681982014-01-03 13:26:09 -0800493
Davide Pesavento88a0d812017-08-19 21:31:42 -0400494NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Interest);
495
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -0700496std::ostream&
497operator<<(std::ostream& os, const Interest& interest);
Alexander Afanasyev84681982014-01-03 13:26:09 -0800498
Junxiao Shib55e5d32018-07-18 13:32:00 -0600499bool
500operator==(const Interest& lhs, const Interest& rhs);
Junxiao Shi899277a2017-07-07 22:12:12 +0000501
502inline bool
503operator!=(const Interest& lhs, const Interest& rhs)
504{
505 return !(lhs == rhs);
506}
507
Alexander Afanasyevc348f832014-02-17 16:35:17 -0800508} // namespace ndn
509
510#endif // NDN_INTEREST_HPP