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