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 | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 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. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * Based on code originally written by Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef NDN_INTEREST_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 25 | #define NDN_INTEREST_HPP |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 27 | #include "common.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 28 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 29 | #include "name.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 30 | #include "selectors.hpp" |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 31 | #include "util/time.hpp" |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 32 | #include "management/nfd-local-control-header.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 | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 45 | class Interest : public enable_shared_from_this<Interest> |
| 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 | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 100 | template<bool T> |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 101 | size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 102 | wireEncode(EncodingImpl<T>& 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 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 134 | public: // matching |
| 135 | /** @brief Check if Interest, including selectors, matches the given @p name |
| 136 | * @param name The name to be matched. If this is a Data name, it shall contain the |
| 137 | * implicit digest component |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 138 | */ |
| 139 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 140 | matchesName(const Name& name) const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 142 | /** |
| 143 | * @brief Check if Interest can be satisfied by @p data. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 144 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 145 | * This method considers Name, MinSuffixComponents, MaxSuffixComponents, |
| 146 | * PublisherPublicKeyLocator, and Exclude. |
| 147 | * This method does not consider ChildSelector and MustBeFresh. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 148 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 149 | * @todo recognize implicit digest component |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 150 | */ |
| 151 | bool |
| 152 | matchesData(const Data& data) const; |
| 153 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 154 | public: // Name and guiders |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 155 | const Name& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 156 | getName() const |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 157 | { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 158 | return m_name; |
| 159 | } |
| 160 | |
| 161 | Interest& |
| 162 | setName(const Name& name) |
| 163 | { |
| 164 | m_name = name; |
| 165 | m_wire.reset(); |
| 166 | return *this; |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 167 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 169 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 170 | getScope() const |
| 171 | { |
| 172 | return m_scope; |
| 173 | } |
| 174 | |
| 175 | Interest& |
| 176 | setScope(int scope) |
| 177 | { |
| 178 | m_scope = scope; |
| 179 | m_wire.reset(); |
| 180 | return *this; |
| 181 | } |
| 182 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 183 | const time::milliseconds& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 184 | getInterestLifetime() const |
| 185 | { |
| 186 | return m_interestLifetime; |
| 187 | } |
| 188 | |
| 189 | Interest& |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 190 | setInterestLifetime(const time::milliseconds& interestLifetime) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 191 | { |
| 192 | m_interestLifetime = interestLifetime; |
| 193 | m_wire.reset(); |
| 194 | return *this; |
| 195 | } |
| 196 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 197 | /** @brief Check if Nonce set |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 198 | */ |
| 199 | bool |
| 200 | hasNonce() const |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 201 | { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 202 | return m_nonce.hasWire(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 205 | /** @brief Get Interest's nonce |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 206 | * |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 207 | * If nonce was not set before this call, it will be automatically assigned to a random value |
| 208 | */ |
| 209 | uint32_t |
| 210 | getNonce() const; |
| 211 | |
| 212 | /** @brief Set Interest's nonce |
| 213 | * |
| 214 | * If wire format already exists, this call simply replaces nonce in the |
| 215 | * existing wire format, without resetting and recreating it. |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 216 | */ |
| 217 | Interest& |
| 218 | setNonce(uint32_t nonce); |
| 219 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 220 | /** @brief Refresh nonce |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 221 | * |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 222 | * It's guaranteed that new nonce value differs from the existing one. |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 223 | * |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 224 | * If nonce is already set, it will be updated to a different random value. |
| 225 | * If nonce is not set, this method does nothing. |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 226 | */ |
| 227 | void |
| 228 | refreshNonce(); |
| 229 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 230 | public: // local control header |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 231 | nfd::LocalControlHeader& |
| 232 | getLocalControlHeader() |
| 233 | { |
| 234 | return m_localControlHeader; |
| 235 | } |
| 236 | |
| 237 | const nfd::LocalControlHeader& |
| 238 | getLocalControlHeader() const |
| 239 | { |
| 240 | return m_localControlHeader; |
| 241 | } |
| 242 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 243 | uint64_t |
| 244 | getIncomingFaceId() const |
| 245 | { |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 246 | return getLocalControlHeader().getIncomingFaceId(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 247 | } |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 248 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 249 | Interest& |
| 250 | setIncomingFaceId(uint64_t incomingFaceId) |
| 251 | { |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 252 | getLocalControlHeader().setIncomingFaceId(incomingFaceId); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 253 | // ! do not reset Interest's wire ! |
| 254 | return *this; |
| 255 | } |
| 256 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 257 | uint64_t |
| 258 | getNextHopFaceId() const |
| 259 | { |
| 260 | return getLocalControlHeader().getNextHopFaceId(); |
| 261 | } |
| 262 | |
| 263 | Interest& |
| 264 | setNextHopFaceId(uint64_t nextHopFaceId) |
| 265 | { |
| 266 | getLocalControlHeader().setNextHopFaceId(nextHopFaceId); |
| 267 | // ! do not reset Interest's wire ! |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 268 | return *this; |
| 269 | } |
| 270 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 271 | public: // Selectors |
| 272 | /** |
| 273 | * @return true if Interest has any selector present |
| 274 | */ |
| 275 | bool |
| 276 | hasSelectors() const |
| 277 | { |
| 278 | return !m_selectors.empty(); |
| 279 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 280 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 281 | const Selectors& |
| 282 | getSelectors() const |
| 283 | { |
| 284 | return m_selectors; |
| 285 | } |
| 286 | |
| 287 | Interest& |
| 288 | setSelectors(const Selectors& selectors) |
| 289 | { |
| 290 | m_selectors = selectors; |
| 291 | m_wire.reset(); |
| 292 | return *this; |
| 293 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 294 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 295 | int |
| 296 | getMinSuffixComponents() const |
| 297 | { |
| 298 | return m_selectors.getMinSuffixComponents(); |
| 299 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 300 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 301 | Interest& |
| 302 | setMinSuffixComponents(int minSuffixComponents) |
| 303 | { |
| 304 | m_selectors.setMinSuffixComponents(minSuffixComponents); |
| 305 | m_wire.reset(); |
| 306 | return *this; |
| 307 | } |
| 308 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 309 | int |
| 310 | getMaxSuffixComponents() const |
| 311 | { |
| 312 | return m_selectors.getMaxSuffixComponents(); |
| 313 | } |
| 314 | |
| 315 | Interest& |
| 316 | setMaxSuffixComponents(int maxSuffixComponents) |
| 317 | { |
| 318 | m_selectors.setMaxSuffixComponents(maxSuffixComponents); |
| 319 | m_wire.reset(); |
| 320 | return *this; |
| 321 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 322 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 323 | const KeyLocator& |
| 324 | getPublisherPublicKeyLocator() const |
| 325 | { |
| 326 | return m_selectors.getPublisherPublicKeyLocator(); |
| 327 | } |
| 328 | |
| 329 | Interest& |
| 330 | setPublisherPublicKeyLocator(const KeyLocator& keyLocator) |
| 331 | { |
| 332 | m_selectors.setPublisherPublicKeyLocator(keyLocator); |
| 333 | m_wire.reset(); |
| 334 | return *this; |
| 335 | } |
| 336 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 337 | const Exclude& |
| 338 | getExclude() const |
| 339 | { |
| 340 | return m_selectors.getExclude(); |
| 341 | } |
| 342 | |
| 343 | Interest& |
| 344 | setExclude(const Exclude& exclude) |
| 345 | { |
| 346 | m_selectors.setExclude(exclude); |
| 347 | m_wire.reset(); |
| 348 | return *this; |
| 349 | } |
| 350 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 351 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 352 | getChildSelector() const |
| 353 | { |
| 354 | return m_selectors.getChildSelector(); |
| 355 | } |
| 356 | |
| 357 | Interest& |
| 358 | setChildSelector(int childSelector) |
| 359 | { |
| 360 | m_selectors.setChildSelector(childSelector); |
| 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 | getMustBeFresh() const |
| 367 | { |
| 368 | return m_selectors.getMustBeFresh(); |
| 369 | } |
| 370 | |
| 371 | Interest& |
| 372 | setMustBeFresh(bool mustBeFresh) |
| 373 | { |
| 374 | m_selectors.setMustBeFresh(mustBeFresh); |
| 375 | m_wire.reset(); |
| 376 | return *this; |
| 377 | } |
| 378 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 379 | public: // EqualityComparable concept |
| 380 | bool |
| 381 | operator==(const Interest& other) const |
| 382 | { |
| 383 | return wireEncode() == other.wireEncode(); |
| 384 | } |
| 385 | |
| 386 | bool |
| 387 | operator!=(const Interest& other) const |
| 388 | { |
| 389 | return !(*this == other); |
| 390 | } |
| 391 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 392 | private: |
| 393 | Name m_name; |
| 394 | Selectors m_selectors; |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 395 | mutable Block m_nonce; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 396 | int m_scope; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 397 | time::milliseconds m_interestLifetime; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 398 | |
| 399 | mutable Block m_wire; |
Yingdi Yu | a4e5767 | 2014-02-06 11:16:17 -0800 | [diff] [blame] | 400 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 401 | nfd::LocalControlHeader m_localControlHeader; |
| 402 | friend class nfd::LocalControlHeader; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 403 | }; |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 404 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 405 | std::ostream& |
| 406 | operator<<(std::ostream& os, const Interest& interest); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 407 | |
| 408 | inline std::string |
| 409 | Interest::toUri() const |
| 410 | { |
| 411 | std::ostringstream os; |
| 412 | os << *this; |
| 413 | return os.str(); |
| 414 | } |
| 415 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 416 | } // namespace ndn |
| 417 | |
| 418 | #endif // NDN_INTEREST_HPP |