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 | */ |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 42 | class Interest : public PacketBase, public std::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 | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 76 | /** @brief Encode to a @c Block. |
| 77 | * |
| 78 | * Normally, this function encodes to NDN Packet Format v0.2. However, if this instance has |
| 79 | * cached wire encoding (@c hasWire() is true), the cached encoding is returned and it might |
| 80 | * be in v0.3 format. |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 81 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 82 | const Block& |
Alexander Afanasyev | 1eb961a | 2014-01-03 13:51:49 -0800 | [diff] [blame] | 83 | wireEncode() const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 84 | |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 85 | /** @brief Decode from @p wire in NDN Packet Format v0.2 or v0.3. |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 86 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 87 | void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 88 | wireDecode(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 89 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 90 | /** @brief Check if this instance has cached wire encoding. |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 91 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 92 | bool |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 93 | hasWire() const |
| 94 | { |
| 95 | return m_wire.hasWire(); |
| 96 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 97 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 98 | /** @brief Return a URI-like string that represents the Interest. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 99 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 100 | * The string starts with `getName().toUri()`. |
| 101 | * If the Interest contains selectors, they are included as a query string. |
| 102 | * Example: "/test/name?ndn.MustBeFresh=1" |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 103 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 104 | std::string |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 105 | toUri() const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 106 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 107 | public: // matching |
| 108 | /** @brief Check if Interest, including selectors, matches the given @p name |
| 109 | * @param name The name to be matched. If this is a Data name, it shall contain the |
| 110 | * implicit digest component |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 111 | */ |
| 112 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 113 | matchesName(const Name& name) const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 114 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 115 | /** @brief Check if Interest can be satisfied by @p data. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 116 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 117 | * This method considers Name, MinSuffixComponents, MaxSuffixComponents, |
| 118 | * PublisherPublicKeyLocator, and Exclude. |
| 119 | * This method does not consider ChildSelector and MustBeFresh. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 120 | */ |
| 121 | bool |
| 122 | matchesData(const Data& data) const; |
| 123 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 124 | /** @brief Check if Interest matches @p other interest |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 125 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 126 | * Interest matches @p other if both have the same name, selectors, and link. Other fields |
| 127 | * (e.g., Nonce) may be different. |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 128 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 129 | * @todo Implement distinguishing Interests by forwarding hint. The current implementation |
| 130 | * checks only name+selectors (Issue #3162). |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 131 | */ |
| 132 | bool |
| 133 | matchesInterest(const Interest& other) const; |
| 134 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 135 | public: // element access |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 136 | const Name& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 137 | getName() const |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 138 | { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 139 | return m_name; |
| 140 | } |
| 141 | |
| 142 | Interest& |
| 143 | setName(const Name& name) |
| 144 | { |
| 145 | m_name = name; |
| 146 | m_wire.reset(); |
| 147 | return *this; |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 148 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 149 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 150 | /** @brief Check whether the CanBePrefix element is present. |
| 151 | * |
| 152 | * This is a getter for the CanBePrefix element as defined in NDN Packet Format v0.3. |
| 153 | * In this implementation, it is mapped to the closest v0.2 semantics: |
| 154 | * MaxSuffixComponents=1 means CanBePrefix is absent. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 155 | */ |
| 156 | bool |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 157 | getCanBePrefix() const |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 158 | { |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 159 | return m_selectors.getMaxSuffixComponents() != 1; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 162 | /** @brief Add or remove CanBePrefix element. |
| 163 | * @param canBePrefix whether CanBePrefix element should be present. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 164 | * |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 165 | * This is a setter for the CanBePrefix element as defined in NDN Packet Format v0.3. |
| 166 | * In this implementation, it is mapped to the closest v0.2 semantics: |
| 167 | * MaxSuffixComponents=1 means CanBePrefix is absent. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 168 | */ |
| 169 | Interest& |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 170 | setCanBePrefix(bool canBePrefix) |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 171 | { |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 172 | m_selectors.setMaxSuffixComponents(canBePrefix ? -1 : 1); |
| 173 | m_wire.reset(); |
| 174 | return *this; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 177 | /** @brief Check whether the MustBeFresh element is present. |
| 178 | * |
| 179 | * This is a getter for the MustBeFresh element as defined in NDN Packet Format v0.3. |
| 180 | * In this implementation, it is mapped to the closest v0.2 semantics and appears as |
| 181 | * MustBeFresh element under Selectors. |
| 182 | */ |
| 183 | bool |
| 184 | getMustBeFresh() const |
| 185 | { |
| 186 | return m_selectors.getMustBeFresh(); |
| 187 | } |
| 188 | |
| 189 | /** @brief Add or remove MustBeFresh element. |
| 190 | * @param mustBeFresh whether MustBeFresh element should be present. |
| 191 | * |
| 192 | * This is a setter for the MustBeFresh element as defined in NDN Packet Format v0.3. |
| 193 | * In this implementation, it is mapped to the closest v0.2 semantics and appears as |
| 194 | * MustBeFresh element under Selectors. |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 195 | */ |
| 196 | Interest& |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 197 | setMustBeFresh(bool mustBeFresh) |
| 198 | { |
| 199 | m_selectors.setMustBeFresh(mustBeFresh); |
| 200 | m_wire.reset(); |
| 201 | return *this; |
| 202 | } |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 203 | |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 204 | const DelegationList& |
| 205 | getForwardingHint() const |
| 206 | { |
| 207 | return m_forwardingHint; |
| 208 | } |
| 209 | |
| 210 | Interest& |
| 211 | setForwardingHint(const DelegationList& value); |
| 212 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 213 | /** @brief Modify ForwardingHint in-place. |
Junxiao Shi | b2a7033 | 2017-07-07 22:15:03 +0000 | [diff] [blame] | 214 | * @tparam Modifier a unary function that accepts DelegationList& |
| 215 | * |
| 216 | * This is equivalent to, but more efficient (avoids copying) than: |
| 217 | * @code |
| 218 | * auto fh = interest.getForwardingHint(); |
| 219 | * modifier(fh); |
| 220 | * interest.setForwardingHint(fh); |
| 221 | * @endcode |
| 222 | */ |
| 223 | template<typename Modifier> |
| 224 | Interest& |
| 225 | modifyForwardingHint(const Modifier& modifier) |
| 226 | { |
| 227 | modifier(m_forwardingHint); |
| 228 | m_wire.reset(); |
| 229 | return *this; |
| 230 | } |
| 231 | |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 232 | /** @brief Check if the Nonce element is present. |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 233 | */ |
| 234 | bool |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 235 | hasNonce() const |
| 236 | { |
| 237 | return static_cast<bool>(m_nonce); |
| 238 | } |
| 239 | |
| 240 | /** @brief Get nonce value. |
| 241 | * |
| 242 | * If nonce was not present, it is added and assigned a random value. |
| 243 | */ |
| 244 | uint32_t |
| 245 | getNonce() const; |
| 246 | |
| 247 | /** @brief Set nonce value. |
| 248 | */ |
| 249 | Interest& |
| 250 | setNonce(uint32_t nonce); |
| 251 | |
| 252 | /** @brief Change nonce value. |
| 253 | * |
| 254 | * If the Nonce element is present, the new nonce value will differ from the old value. |
| 255 | * If the Nonce element is not present, this method does nothing. |
| 256 | */ |
| 257 | void |
| 258 | refreshNonce(); |
| 259 | |
| 260 | time::milliseconds |
| 261 | getInterestLifetime() const |
| 262 | { |
| 263 | return m_interestLifetime; |
| 264 | } |
| 265 | |
| 266 | /** @brief Set Interest's lifetime |
| 267 | * @throw std::invalid_argument @p lifetime is negative |
| 268 | */ |
| 269 | Interest& |
| 270 | setInterestLifetime(time::milliseconds lifetime); |
| 271 | |
| 272 | public: // Selectors (deprecated) |
| 273 | /** @brief Check if Interest has any selector present. |
| 274 | */ |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 275 | [[deprecated]] |
Junxiao Shi | 8d3f834 | 2018-04-04 12:46:37 +0000 | [diff] [blame] | 276 | bool |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 277 | hasSelectors() const |
| 278 | { |
| 279 | return !m_selectors.empty(); |
| 280 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 281 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 282 | [[deprecated]] |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 283 | const Selectors& |
| 284 | getSelectors() const |
| 285 | { |
| 286 | return m_selectors; |
| 287 | } |
| 288 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 289 | [[deprecated]] |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 290 | Interest& |
| 291 | setSelectors(const Selectors& selectors) |
| 292 | { |
| 293 | m_selectors = selectors; |
| 294 | m_wire.reset(); |
| 295 | return *this; |
| 296 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 297 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 298 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 299 | int |
| 300 | getMinSuffixComponents() const |
| 301 | { |
| 302 | return m_selectors.getMinSuffixComponents(); |
| 303 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 304 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 305 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 306 | Interest& |
| 307 | setMinSuffixComponents(int minSuffixComponents) |
| 308 | { |
| 309 | m_selectors.setMinSuffixComponents(minSuffixComponents); |
| 310 | m_wire.reset(); |
| 311 | return *this; |
| 312 | } |
| 313 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 314 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 315 | int |
| 316 | getMaxSuffixComponents() const |
| 317 | { |
| 318 | return m_selectors.getMaxSuffixComponents(); |
| 319 | } |
| 320 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 321 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 322 | Interest& |
| 323 | setMaxSuffixComponents(int maxSuffixComponents) |
| 324 | { |
| 325 | m_selectors.setMaxSuffixComponents(maxSuffixComponents); |
| 326 | m_wire.reset(); |
| 327 | return *this; |
| 328 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 329 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 330 | [[deprecated]] |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 331 | const KeyLocator& |
| 332 | getPublisherPublicKeyLocator() const |
| 333 | { |
| 334 | return m_selectors.getPublisherPublicKeyLocator(); |
| 335 | } |
| 336 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 337 | [[deprecated]] |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 338 | Interest& |
| 339 | setPublisherPublicKeyLocator(const KeyLocator& keyLocator) |
| 340 | { |
| 341 | m_selectors.setPublisherPublicKeyLocator(keyLocator); |
| 342 | m_wire.reset(); |
| 343 | return *this; |
| 344 | } |
| 345 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 346 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 347 | const Exclude& |
| 348 | getExclude() const |
| 349 | { |
| 350 | return m_selectors.getExclude(); |
| 351 | } |
| 352 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 353 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 354 | Interest& |
| 355 | setExclude(const Exclude& exclude) |
| 356 | { |
| 357 | m_selectors.setExclude(exclude); |
| 358 | m_wire.reset(); |
| 359 | return *this; |
| 360 | } |
| 361 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 362 | [[deprecated]] |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 363 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 364 | getChildSelector() const |
| 365 | { |
| 366 | return m_selectors.getChildSelector(); |
| 367 | } |
| 368 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 369 | [[deprecated]] |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 370 | Interest& |
| 371 | setChildSelector(int childSelector) |
| 372 | { |
| 373 | m_selectors.setChildSelector(childSelector); |
| 374 | m_wire.reset(); |
| 375 | return *this; |
| 376 | } |
| 377 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 378 | private: |
Junxiao Shi | 6efa3b7 | 2018-04-14 15:54:08 +0000 | [diff] [blame] | 379 | /** @brief Decode @c m_wire as NDN Packet Format v0.2. |
| 380 | * @retval true decoding successful. |
| 381 | * @retval false decoding failed due to structural error. |
| 382 | * @throw tlv::Error decoding error within a sub-element. |
| 383 | */ |
| 384 | bool |
| 385 | decode02(); |
| 386 | |
| 387 | /** @brief Decode @c m_wire as NDN Packet Format v0.3. |
| 388 | * @throw tlv::Error decoding error. |
| 389 | */ |
| 390 | void |
| 391 | decode03(); |
| 392 | |
| 393 | private: |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 394 | Name m_name; |
| 395 | Selectors m_selectors; |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 396 | mutable optional<uint32_t> m_nonce; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 397 | time::milliseconds m_interestLifetime; |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 398 | DelegationList m_forwardingHint; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 399 | |
| 400 | mutable Block m_wire; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 401 | }; |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 402 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 403 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Interest); |
| 404 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 405 | std::ostream& |
| 406 | operator<<(std::ostream& os, const Interest& interest); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 407 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 408 | inline bool |
| 409 | operator==(const Interest& lhs, const Interest& rhs) |
| 410 | { |
| 411 | return lhs.wireEncode() == rhs.wireEncode(); |
| 412 | } |
| 413 | |
| 414 | inline bool |
| 415 | operator!=(const Interest& lhs, const Interest& rhs) |
| 416 | { |
| 417 | return !(lhs == rhs); |
| 418 | } |
| 419 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 420 | } // namespace ndn |
| 421 | |
| 422 | #endif // NDN_INTEREST_HPP |