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