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