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