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