Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * 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 Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_INTEREST_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 23 | #define NDN_INTEREST_HPP |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 24 | |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 25 | #include "delegation-list.hpp" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 26 | #include "name.hpp" |
Eric Newberry | c3a4679 | 2017-09-24 14:54:24 -0700 | [diff] [blame] | 27 | #include "packet-base.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 28 | #include "selectors.hpp" |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 29 | #include "util/time.hpp" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 30 | |
| 31 | namespace ndn { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 32 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 33 | class Data; |
| 34 | |
Junxiao Shi | 7007a3c | 2014-11-20 22:37:55 -0700 | [diff] [blame] | 35 | /** @var const unspecified_duration_type DEFAULT_INTEREST_LIFETIME; |
| 36 | * @brief default value for InterestLifetime |
| 37 | */ |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 38 | const time::milliseconds DEFAULT_INTEREST_LIFETIME = 4_s; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 39 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 40 | /** @brief Represents an Interest packet. |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 41 | */ |
Eric Newberry | c3a4679 | 2017-09-24 14:54:24 -0700 | [diff] [blame] | 42 | class Interest : public PacketBase, public enable_shared_from_this<Interest> |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 43 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 44 | public: |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 45 | class Error : public tlv::Error |
| 46 | { |
| 47 | public: |
| 48 | explicit |
| 49 | Error(const std::string& what) |
| 50 | : tlv::Error(what) |
| 51 | { |
| 52 | } |
| 53 | }; |
| 54 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 55 | /** @brief Construct an Interest with given @p name and @p lifetime. |
| 56 | * @throw std::invalid_argument @p lifetime is negative |
| 57 | * @warning In certain contexts that use `Interest::shared_from_this()`, Interest must be created |
| 58 | * using `make_shared`. Otherwise, `shared_from_this()` will trigger undefined behavior. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 59 | */ |
Junxiao Shi | 909ffef | 2017-07-07 22:12:27 +0000 | [diff] [blame] | 60 | explicit |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 61 | Interest(const Name& name = Name(), time::milliseconds lifetime = DEFAULT_INTEREST_LIFETIME); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 62 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 63 | /** @brief Construct an Interest by decoding from @p wire. |
| 64 | * @warning In certain contexts that use `Interest::shared_from_this()`, Interest must be created |
| 65 | * using `make_shared`. Otherwise, `shared_from_this()` will trigger undefined behavior. |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 66 | */ |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 67 | explicit |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 68 | Interest(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 69 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 70 | /** @brief Prepend wire encoding to @p encoder in NDN Packet Format v0.2. |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 71 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 72 | template<encoding::Tag TAG> |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 73 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 74 | wireEncode(EncodingImpl<TAG>& encoder) const; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 75 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 76 | /** @brief Encode to a @c Block in NDN Packet Format v0.2. |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 77 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 78 | const Block& |
Alexander Afanasyev | 1eb961a | 2014-01-03 13:51:49 -0800 | [diff] [blame] | 79 | wireEncode() const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 80 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 81 | /** @brief Decode from @p wire in NDN Packet Format v0.2. |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 82 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 83 | void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 84 | wireDecode(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 85 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 86 | /** @brief Check if this instance has cached wire encoding. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 87 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 88 | bool |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 89 | hasWire() const |
| 90 | { |
| 91 | return m_wire.hasWire(); |
| 92 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 93 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 94 | /** @brief Return a URI-like string that represents the Interest. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 95 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 96 | * 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 Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 99 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 100 | std::string |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 101 | toUri() const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 102 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 103 | public: // 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 Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 107 | */ |
| 108 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 109 | matchesName(const Name& name) const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 110 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 111 | /** @brief Check if Interest can be satisfied by @p data. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 112 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 113 | * This method considers Name, MinSuffixComponents, MaxSuffixComponents, |
| 114 | * PublisherPublicKeyLocator, and Exclude. |
| 115 | * This method does not consider ChildSelector and MustBeFresh. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 116 | */ |
| 117 | bool |
| 118 | matchesData(const Data& data) const; |
| 119 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 120 | /** @brief Check if Interest matches @p other interest |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 121 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 122 | * Interest matches @p other if both have the same name, selectors, and link. Other fields |
| 123 | * (e.g., Nonce) may be different. |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 124 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 125 | * @todo Implement distinguishing Interests by forwarding hint. The current implementation |
| 126 | * checks only name+selectors (Issue #3162). |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 127 | */ |
| 128 | bool |
| 129 | matchesInterest(const Interest& other) const; |
| 130 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 131 | public: // element access |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 132 | const Name& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 133 | getName() const |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 134 | { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 135 | 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 Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 144 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 145 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 146 | /** @brief Check whether the CanBePrefix element is present. |
| 147 | * |
| 148 | * This is a getter for the CanBePrefix element as defined in NDN Packet Format v0.3. |
| 149 | * In this implementation, it is mapped to the closest v0.2 semantics: |
| 150 | * MaxSuffixComponents=1 means CanBePrefix is absent. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 151 | */ |
| 152 | bool |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 153 | getCanBePrefix() const |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 154 | { |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 155 | return m_selectors.getMaxSuffixComponents() != 1; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 158 | /** @brief Add or remove CanBePrefix element. |
| 159 | * @param canBePrefix whether CanBePrefix element should be present. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 160 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 161 | * This is a setter for the CanBePrefix element as defined in NDN Packet Format v0.3. |
| 162 | * In this implementation, it is mapped to the closest v0.2 semantics: |
| 163 | * MaxSuffixComponents=1 means CanBePrefix is absent. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 164 | */ |
| 165 | Interest& |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 166 | setCanBePrefix(bool canBePrefix) |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 167 | { |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 168 | m_selectors.setMaxSuffixComponents(canBePrefix ? -1 : 1); |
| 169 | m_wire.reset(); |
| 170 | return *this; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 173 | /** @brief Check whether the MustBeFresh element is present. |
| 174 | * |
| 175 | * This is a getter for the MustBeFresh element as defined in NDN Packet Format v0.3. |
| 176 | * In this implementation, it is mapped to the closest v0.2 semantics and appears as |
| 177 | * MustBeFresh element under Selectors. |
| 178 | */ |
| 179 | bool |
| 180 | getMustBeFresh() const |
| 181 | { |
| 182 | return m_selectors.getMustBeFresh(); |
| 183 | } |
| 184 | |
| 185 | /** @brief Add or remove MustBeFresh element. |
| 186 | * @param mustBeFresh whether MustBeFresh element should be present. |
| 187 | * |
| 188 | * This is a setter for the MustBeFresh element as defined in NDN Packet Format v0.3. |
| 189 | * In this implementation, it is mapped to the closest v0.2 semantics and appears as |
| 190 | * MustBeFresh element under Selectors. |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 191 | */ |
| 192 | Interest& |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 193 | setMustBeFresh(bool mustBeFresh) |
| 194 | { |
| 195 | m_selectors.setMustBeFresh(mustBeFresh); |
| 196 | m_wire.reset(); |
| 197 | return *this; |
| 198 | } |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 199 | |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 200 | const DelegationList& |
| 201 | getForwardingHint() const |
| 202 | { |
| 203 | return m_forwardingHint; |
| 204 | } |
| 205 | |
| 206 | Interest& |
| 207 | setForwardingHint(const DelegationList& value); |
| 208 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 209 | /** @brief Modify ForwardingHint in-place. |
Junxiao Shi | b2a7033 | 2017-07-07 22:15:03 +0000 | [diff] [blame] | 210 | * @tparam Modifier a unary function that accepts DelegationList& |
| 211 | * |
| 212 | * This is equivalent to, but more efficient (avoids copying) than: |
| 213 | * @code |
| 214 | * auto fh = interest.getForwardingHint(); |
| 215 | * modifier(fh); |
| 216 | * interest.setForwardingHint(fh); |
| 217 | * @endcode |
| 218 | */ |
| 219 | template<typename Modifier> |
| 220 | Interest& |
| 221 | modifyForwardingHint(const Modifier& modifier) |
| 222 | { |
| 223 | modifier(m_forwardingHint); |
| 224 | m_wire.reset(); |
| 225 | return *this; |
| 226 | } |
| 227 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 228 | /** @brief Check if the Nonce element is present. |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 229 | */ |
| 230 | bool |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 231 | hasNonce() const |
| 232 | { |
| 233 | return static_cast<bool>(m_nonce); |
| 234 | } |
| 235 | |
| 236 | /** @brief Get nonce value. |
| 237 | * |
| 238 | * If nonce was not present, it is added and assigned a random value. |
| 239 | */ |
| 240 | uint32_t |
| 241 | getNonce() const; |
| 242 | |
| 243 | /** @brief Set nonce value. |
| 244 | */ |
| 245 | Interest& |
| 246 | setNonce(uint32_t nonce); |
| 247 | |
| 248 | /** @brief Change nonce value. |
| 249 | * |
| 250 | * If the Nonce element is present, the new nonce value will differ from the old value. |
| 251 | * If the Nonce element is not present, this method does nothing. |
| 252 | */ |
| 253 | void |
| 254 | refreshNonce(); |
| 255 | |
| 256 | time::milliseconds |
| 257 | getInterestLifetime() const |
| 258 | { |
| 259 | return m_interestLifetime; |
| 260 | } |
| 261 | |
| 262 | /** @brief Set Interest's lifetime |
| 263 | * @throw std::invalid_argument @p lifetime is negative |
| 264 | */ |
| 265 | Interest& |
| 266 | setInterestLifetime(time::milliseconds lifetime); |
| 267 | |
| 268 | public: // Selectors (deprecated) |
| 269 | /** @brief Check if Interest has any selector present. |
| 270 | */ |
| 271 | NDN_CXX_DEPRECATED |
| 272 | bool |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 273 | hasSelectors() const |
| 274 | { |
| 275 | return !m_selectors.empty(); |
| 276 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 277 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 278 | NDN_CXX_DEPRECATED |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 279 | const Selectors& |
| 280 | getSelectors() const |
| 281 | { |
| 282 | return m_selectors; |
| 283 | } |
| 284 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 285 | NDN_CXX_DEPRECATED |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 286 | Interest& |
| 287 | setSelectors(const Selectors& selectors) |
| 288 | { |
| 289 | m_selectors = selectors; |
| 290 | m_wire.reset(); |
| 291 | return *this; |
| 292 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 293 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 294 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 295 | int |
| 296 | getMinSuffixComponents() const |
| 297 | { |
| 298 | return m_selectors.getMinSuffixComponents(); |
| 299 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 300 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 301 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 302 | Interest& |
| 303 | setMinSuffixComponents(int minSuffixComponents) |
| 304 | { |
| 305 | m_selectors.setMinSuffixComponents(minSuffixComponents); |
| 306 | m_wire.reset(); |
| 307 | return *this; |
| 308 | } |
| 309 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 310 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 311 | int |
| 312 | getMaxSuffixComponents() const |
| 313 | { |
| 314 | return m_selectors.getMaxSuffixComponents(); |
| 315 | } |
| 316 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 317 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 318 | Interest& |
| 319 | setMaxSuffixComponents(int maxSuffixComponents) |
| 320 | { |
| 321 | m_selectors.setMaxSuffixComponents(maxSuffixComponents); |
| 322 | m_wire.reset(); |
| 323 | return *this; |
| 324 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 325 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 326 | NDN_CXX_DEPRECATED |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 327 | const KeyLocator& |
| 328 | getPublisherPublicKeyLocator() const |
| 329 | { |
| 330 | return m_selectors.getPublisherPublicKeyLocator(); |
| 331 | } |
| 332 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 333 | NDN_CXX_DEPRECATED |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 334 | Interest& |
| 335 | setPublisherPublicKeyLocator(const KeyLocator& keyLocator) |
| 336 | { |
| 337 | m_selectors.setPublisherPublicKeyLocator(keyLocator); |
| 338 | m_wire.reset(); |
| 339 | return *this; |
| 340 | } |
| 341 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 342 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 343 | const Exclude& |
| 344 | getExclude() const |
| 345 | { |
| 346 | return m_selectors.getExclude(); |
| 347 | } |
| 348 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 349 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 350 | Interest& |
| 351 | setExclude(const Exclude& exclude) |
| 352 | { |
| 353 | m_selectors.setExclude(exclude); |
| 354 | m_wire.reset(); |
| 355 | return *this; |
| 356 | } |
| 357 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 358 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 359 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 360 | getChildSelector() const |
| 361 | { |
| 362 | return m_selectors.getChildSelector(); |
| 363 | } |
| 364 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 365 | NDN_CXX_DEPRECATED |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 366 | Interest& |
| 367 | setChildSelector(int childSelector) |
| 368 | { |
| 369 | m_selectors.setChildSelector(childSelector); |
| 370 | m_wire.reset(); |
| 371 | return *this; |
| 372 | } |
| 373 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 374 | private: |
| 375 | Name m_name; |
| 376 | Selectors m_selectors; |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 377 | mutable optional<uint32_t> m_nonce; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 378 | time::milliseconds m_interestLifetime; |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 379 | DelegationList m_forwardingHint; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 380 | |
| 381 | mutable Block m_wire; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 382 | }; |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 383 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 384 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Interest); |
| 385 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 386 | std::ostream& |
| 387 | operator<<(std::ostream& os, const Interest& interest); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 388 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 389 | inline bool |
| 390 | operator==(const Interest& lhs, const Interest& rhs) |
| 391 | { |
| 392 | return lhs.wireEncode() == rhs.wireEncode(); |
| 393 | } |
| 394 | |
| 395 | inline bool |
| 396 | operator!=(const Interest& lhs, const Interest& rhs) |
| 397 | { |
| 398 | return !(lhs == rhs); |
| 399 | } |
| 400 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 401 | } // namespace ndn |
| 402 | |
| 403 | #endif // NDN_INTEREST_HPP |