Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 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 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 25 | #include "common.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 26 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 27 | #include "name.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 28 | #include "selectors.hpp" |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 29 | #include "util/time.hpp" |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 30 | #include "lp/tags.hpp" |
Alexander Afanasyev | a3887ae | 2014-12-29 16:11:57 -0800 | [diff] [blame] | 31 | #include "tag-host.hpp" |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 32 | #include "link.hpp" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 33 | |
| 34 | namespace ndn { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 35 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 36 | class Data; |
| 37 | |
Junxiao Shi | 7007a3c | 2014-11-20 22:37:55 -0700 | [diff] [blame] | 38 | /** @var const unspecified_duration_type DEFAULT_INTEREST_LIFETIME; |
| 39 | * @brief default value for InterestLifetime |
| 40 | */ |
| 41 | const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 42 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 43 | /** @brief represents an Interest packet |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 44 | */ |
Alexander Afanasyev | a3887ae | 2014-12-29 16:11:57 -0800 | [diff] [blame] | 45 | class Interest : public TagHost, public enable_shared_from_this<Interest> |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 46 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 47 | public: |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 48 | class Error : public tlv::Error |
| 49 | { |
| 50 | public: |
| 51 | explicit |
| 52 | Error(const std::string& what) |
| 53 | : tlv::Error(what) |
| 54 | { |
| 55 | } |
| 56 | }; |
| 57 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 58 | /** @brief Create a new Interest with an empty name (`ndn:/`) |
| 59 | * @warning In certain contexts that use Interest::shared_from_this(), Interest must be created |
| 60 | * using `make_shared`. Otherwise, .shared_from_this() will throw an exception. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 61 | */ |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 62 | Interest(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 63 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 64 | /** @brief Create a new Interest with the given name |
| 65 | * @param name The name for the interest. |
| 66 | * @note This constructor allows implicit conversion from Name. |
| 67 | * @warning In certain contexts that use Interest::shared_from_this(), Interest must be created |
| 68 | * using `make_shared`. Otherwise, .shared_from_this() will throw an exception. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 69 | */ |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 70 | Interest(const Name& name); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 71 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 72 | /** @brief Create a new Interest with the given name and interest lifetime |
| 73 | * @param name The name for the interest. |
| 74 | * @param interestLifetime The interest lifetime in time::milliseconds, or -1 for none. |
| 75 | * @warning In certain contexts that use Interest::shared_from_this(), Interest must be created |
| 76 | * using `make_shared`. Otherwise, .shared_from_this() will throw an exception. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 77 | */ |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 78 | Interest(const Name& name, const time::milliseconds& interestLifetime); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 79 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 80 | /** @brief Create from wire encoding |
| 81 | * @warning In certain contexts that use Interest::shared_from_this(), Interest must be created |
| 82 | * using `make_shared`. Otherwise, .shared_from_this() will throw an exception. |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 83 | */ |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 84 | explicit |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 85 | Interest(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 86 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 87 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 88 | * @brief Fast encoding or block size estimation |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 89 | */ |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 90 | template<encoding::Tag TAG> |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 91 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 92 | wireEncode(EncodingImpl<TAG>& encoder) const; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 93 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 94 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 95 | * @brief Encode to a wire format |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 96 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 97 | const Block& |
Alexander Afanasyev | 1eb961a | 2014-01-03 13:51:49 -0800 | [diff] [blame] | 98 | wireEncode() const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 99 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 100 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 101 | * @brief Decode from the wire format |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 102 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 103 | void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 104 | wireDecode(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * @brief Check if already has wire |
| 108 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 109 | bool |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 110 | hasWire() const |
| 111 | { |
| 112 | return m_wire.hasWire(); |
| 113 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 114 | |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 115 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 116 | * @brief Encode the name according to the NDN URI Scheme |
| 117 | * |
| 118 | * If there are interest selectors, this method will append "?" and add the selectors as |
| 119 | * a query string. For example, "/test/name?ndn.ChildSelector=1" |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 120 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 121 | std::string |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 122 | toUri() const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 123 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 124 | public: // Link and forwarding hint |
| 125 | |
| 126 | /** |
| 127 | * @brief Check whether the Interest contains a Link object |
| 128 | * @return True if there is a link object, otherwise false |
| 129 | */ |
| 130 | bool |
| 131 | hasLink() const; |
| 132 | |
| 133 | /** |
| 134 | * @brief Get the link object for this interest |
| 135 | * @return The link object if there is one contained in this interest |
| 136 | * @throws Interest::Error if there is no link object contained in the interest |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 137 | * @throws tlv::Error if the incorporated link object is malformed |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 138 | */ |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 139 | const Link& |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 140 | getLink() const; |
| 141 | |
| 142 | /** |
| 143 | * @brief Set the link object for this interest |
| 144 | * @param link The link object that will be included in this interest (in wire format) |
| 145 | * @post !hasSelectedDelegation() |
| 146 | */ |
| 147 | void |
| 148 | setLink(const Block& link); |
| 149 | |
| 150 | /** |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 151 | * @brief Delete the link object for this interest |
| 152 | * @post !hasLink() |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 153 | */ |
| 154 | void |
| 155 | unsetLink(); |
| 156 | |
| 157 | /** |
| 158 | * @brief Check whether the Interest includes a selected delegation |
| 159 | * @return True if there is a selected delegation, otherwise false |
| 160 | */ |
| 161 | bool |
| 162 | hasSelectedDelegation() const; |
| 163 | |
| 164 | /** |
| 165 | * @brief Get the name of the selected delegation |
| 166 | * @return The name of the selected delegation |
| 167 | * @throw Error SelectedDelegation is not set. |
| 168 | */ |
| 169 | Name |
| 170 | getSelectedDelegation() const; |
| 171 | |
| 172 | /** |
| 173 | * @brief Set the selected delegation |
| 174 | * @param delegationName The name of the selected delegation |
| 175 | * @throw Error Link is not set. |
| 176 | * @throw std::invalid_argument @p delegationName does not exist in Link. |
| 177 | */ |
| 178 | void |
| 179 | setSelectedDelegation(const Name& delegationName); |
| 180 | |
| 181 | /** |
| 182 | * @brief Set the selected delegation |
Davide Pesavento | 18cf81b | 2015-09-12 23:36:43 +0200 | [diff] [blame] | 183 | * @param delegationIndex The index of the selected delegation |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 184 | * @throw Error Link is not set. |
| 185 | * @throw std::out_of_range @p delegationIndex is out of bound in Link. |
| 186 | */ |
| 187 | void |
| 188 | setSelectedDelegation(size_t delegationIndex); |
| 189 | |
| 190 | /** |
| 191 | * @brief Unset the selected delegation |
| 192 | */ |
| 193 | void |
| 194 | unsetSelectedDelegation(); |
| 195 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 196 | public: // matching |
| 197 | /** @brief Check if Interest, including selectors, matches the given @p name |
| 198 | * @param name The name to be matched. If this is a Data name, it shall contain the |
| 199 | * implicit digest component |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 200 | */ |
| 201 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 202 | matchesName(const Name& name) const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 203 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 204 | /** |
| 205 | * @brief Check if Interest can be satisfied by @p data. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 206 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 207 | * This method considers Name, MinSuffixComponents, MaxSuffixComponents, |
| 208 | * PublisherPublicKeyLocator, and Exclude. |
| 209 | * This method does not consider ChildSelector and MustBeFresh. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 210 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 211 | * @todo recognize implicit digest component |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 212 | */ |
| 213 | bool |
| 214 | matchesData(const Data& data) const; |
| 215 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 216 | public: // Name and guiders |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 217 | const Name& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 218 | getName() const |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 219 | { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 220 | return m_name; |
| 221 | } |
| 222 | |
| 223 | Interest& |
| 224 | setName(const Name& name) |
| 225 | { |
| 226 | m_name = name; |
| 227 | m_wire.reset(); |
| 228 | return *this; |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 229 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 230 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 231 | const time::milliseconds& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 232 | getInterestLifetime() const |
| 233 | { |
| 234 | return m_interestLifetime; |
| 235 | } |
| 236 | |
| 237 | Interest& |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 238 | setInterestLifetime(const time::milliseconds& interestLifetime) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 239 | { |
| 240 | m_interestLifetime = interestLifetime; |
| 241 | m_wire.reset(); |
| 242 | return *this; |
| 243 | } |
| 244 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 245 | /** @brief Check if Nonce set |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 246 | */ |
| 247 | bool |
| 248 | hasNonce() const |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 249 | { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 250 | return m_nonce.hasWire(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 253 | /** @brief Get Interest's nonce |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 254 | * |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 255 | * If nonce was not set before this call, it will be automatically assigned to a random value |
| 256 | */ |
| 257 | uint32_t |
| 258 | getNonce() const; |
| 259 | |
| 260 | /** @brief Set Interest's nonce |
| 261 | * |
| 262 | * If wire format already exists, this call simply replaces nonce in the |
| 263 | * existing wire format, without resetting and recreating it. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 264 | */ |
| 265 | Interest& |
| 266 | setNonce(uint32_t nonce); |
| 267 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 268 | /** @brief Refresh nonce |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 269 | * |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 270 | * It's guaranteed that new nonce value differs from the existing one. |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 271 | * |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 272 | * If nonce is already set, it will be updated to a different random value. |
| 273 | * If nonce is not set, this method does nothing. |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 274 | */ |
| 275 | void |
| 276 | refreshNonce(); |
| 277 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 278 | #ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 279 | public: // local control header |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 280 | /** @deprecated use getTag and setTag with lp::IncomingFaceIdTag, lp::NextHopFaceIdTag |
| 281 | */ |
| 282 | DEPRECATED( |
| 283 | lp::LocalControlHeaderFacade |
| 284 | getLocalControlHeader()); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 285 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 286 | /** @deprecated use getTag with lp::IncomingFaceIdTag, lp::NextHopFaceIdTag |
| 287 | */ |
| 288 | DEPRECATED( |
| 289 | const lp::LocalControlHeaderFacade |
| 290 | getLocalControlHeader() const); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 291 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 292 | /** @deprecated use getTag<lp::IncomingFaceIdTag> |
| 293 | */ |
| 294 | DEPRECATED( |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 295 | uint64_t |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 296 | getIncomingFaceId() const); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 297 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 298 | /** @deprecated use setTag<lp::IncomingFaceIdTag> |
| 299 | */ |
| 300 | DEPRECATED( |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 301 | Interest& |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 302 | setIncomingFaceId(uint64_t incomingFaceId)); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 303 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 304 | /** @deprecated use getTag<lp::NextHopFaceIdTag> |
| 305 | */ |
| 306 | DEPRECATED( |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 307 | uint64_t |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 308 | getNextHopFaceId() const); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 309 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 310 | /** @deprecated use setTag<lp::NextHopFaceIdTag> |
| 311 | */ |
| 312 | DEPRECATED( |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 313 | Interest& |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame^] | 314 | setNextHopFaceId(uint64_t nextHopFaceId)); |
| 315 | #endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 316 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 317 | public: // Selectors |
| 318 | /** |
| 319 | * @return true if Interest has any selector present |
| 320 | */ |
| 321 | bool |
| 322 | hasSelectors() const |
| 323 | { |
| 324 | return !m_selectors.empty(); |
| 325 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 326 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 327 | const Selectors& |
| 328 | getSelectors() const |
| 329 | { |
| 330 | return m_selectors; |
| 331 | } |
| 332 | |
| 333 | Interest& |
| 334 | setSelectors(const Selectors& selectors) |
| 335 | { |
| 336 | m_selectors = selectors; |
| 337 | m_wire.reset(); |
| 338 | return *this; |
| 339 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 340 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 341 | int |
| 342 | getMinSuffixComponents() const |
| 343 | { |
| 344 | return m_selectors.getMinSuffixComponents(); |
| 345 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 346 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 347 | Interest& |
| 348 | setMinSuffixComponents(int minSuffixComponents) |
| 349 | { |
| 350 | m_selectors.setMinSuffixComponents(minSuffixComponents); |
| 351 | m_wire.reset(); |
| 352 | return *this; |
| 353 | } |
| 354 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 355 | int |
| 356 | getMaxSuffixComponents() const |
| 357 | { |
| 358 | return m_selectors.getMaxSuffixComponents(); |
| 359 | } |
| 360 | |
| 361 | Interest& |
| 362 | setMaxSuffixComponents(int maxSuffixComponents) |
| 363 | { |
| 364 | m_selectors.setMaxSuffixComponents(maxSuffixComponents); |
| 365 | m_wire.reset(); |
| 366 | return *this; |
| 367 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 368 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 369 | const KeyLocator& |
| 370 | getPublisherPublicKeyLocator() const |
| 371 | { |
| 372 | return m_selectors.getPublisherPublicKeyLocator(); |
| 373 | } |
| 374 | |
| 375 | Interest& |
| 376 | setPublisherPublicKeyLocator(const KeyLocator& keyLocator) |
| 377 | { |
| 378 | m_selectors.setPublisherPublicKeyLocator(keyLocator); |
| 379 | m_wire.reset(); |
| 380 | return *this; |
| 381 | } |
| 382 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 383 | const Exclude& |
| 384 | getExclude() const |
| 385 | { |
| 386 | return m_selectors.getExclude(); |
| 387 | } |
| 388 | |
| 389 | Interest& |
| 390 | setExclude(const Exclude& exclude) |
| 391 | { |
| 392 | m_selectors.setExclude(exclude); |
| 393 | m_wire.reset(); |
| 394 | return *this; |
| 395 | } |
| 396 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 397 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 398 | getChildSelector() const |
| 399 | { |
| 400 | return m_selectors.getChildSelector(); |
| 401 | } |
| 402 | |
| 403 | Interest& |
| 404 | setChildSelector(int childSelector) |
| 405 | { |
| 406 | m_selectors.setChildSelector(childSelector); |
| 407 | m_wire.reset(); |
| 408 | return *this; |
| 409 | } |
| 410 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 411 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 412 | getMustBeFresh() const |
| 413 | { |
| 414 | return m_selectors.getMustBeFresh(); |
| 415 | } |
| 416 | |
| 417 | Interest& |
| 418 | setMustBeFresh(bool mustBeFresh) |
| 419 | { |
| 420 | m_selectors.setMustBeFresh(mustBeFresh); |
| 421 | m_wire.reset(); |
| 422 | return *this; |
| 423 | } |
| 424 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 425 | public: // EqualityComparable concept |
| 426 | bool |
| 427 | operator==(const Interest& other) const |
| 428 | { |
| 429 | return wireEncode() == other.wireEncode(); |
| 430 | } |
| 431 | |
| 432 | bool |
| 433 | operator!=(const Interest& other) const |
| 434 | { |
| 435 | return !(*this == other); |
| 436 | } |
| 437 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 438 | private: |
| 439 | Name m_name; |
| 440 | Selectors m_selectors; |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 441 | mutable Block m_nonce; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 442 | time::milliseconds m_interestLifetime; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 443 | |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 444 | mutable Block m_link; |
Alexander Afanasyev | cac0838 | 2015-09-02 14:52:40 -0700 | [diff] [blame] | 445 | mutable shared_ptr<Link> m_linkCached; |
Spyridon Mastorakis | c8188b3 | 2015-04-18 18:33:38 -0700 | [diff] [blame] | 446 | size_t m_selectedDelegationIndex; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 447 | mutable Block m_wire; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 448 | }; |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 449 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 450 | std::ostream& |
| 451 | operator<<(std::ostream& os, const Interest& interest); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 452 | |
| 453 | inline std::string |
| 454 | Interest::toUri() const |
| 455 | { |
| 456 | std::ostringstream os; |
| 457 | os << *this; |
| 458 | return os.str(); |
| 459 | } |
| 460 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 461 | } // namespace ndn |
| 462 | |
| 463 | #endif // NDN_INTEREST_HPP |