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 | 9016496 | 2014-03-06 08:29:59 +0000 | [diff] [blame] | 31 | #include "interest-filter.hpp" |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 32 | #include "util/time.hpp" |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 33 | #include "management/nfd-local-control-header.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 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 39 | const time::seconds DEFAULT_INTEREST_LIFETIME = time::seconds(4); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 40 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 41 | /** @brief represents an Interest packet |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 42 | */ |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 43 | class Interest : public enable_shared_from_this<Interest> |
| 44 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 45 | public: |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 46 | class Error : public tlv::Error |
| 47 | { |
| 48 | public: |
| 49 | explicit |
| 50 | Error(const std::string& what) |
| 51 | : tlv::Error(what) |
| 52 | { |
| 53 | } |
| 54 | }; |
| 55 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 56 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 57 | * @brief Create a new Interest with an empty name (`ndn:/`) |
| 58 | * |
| 59 | * Note that in certain contexts that use Interest::shared_from_this(), Interest must be |
| 60 | * created using `make_shared`: |
| 61 | * |
| 62 | * shared_ptr<Interest> interest = make_shared<Interest>(); |
| 63 | * |
| 64 | * Otherwise, Interest::shared_from_this() will throw an exception. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 65 | */ |
| 66 | Interest() |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 67 | : m_scope(-1) |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 68 | , m_interestLifetime(time::milliseconds::min()) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 69 | { |
| 70 | } |
| 71 | |
| 72 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 73 | * @brief Create a new Interest with the given name |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 74 | * |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 75 | * @param name The name for the interest. |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 76 | * |
| 77 | * Note that in certain contexts that use Interest::shared_from_this(), Interest must be |
| 78 | * created using `make_shared`: |
| 79 | * |
| 80 | * shared_ptr<Interest> interest = make_shared<Interest>(name); |
| 81 | * |
| 82 | * Otherwise, Interest::shared_from_this() will throw an exception. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 83 | */ |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 84 | Interest(const Name& name) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 85 | : m_name(name) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 86 | , m_scope(-1) |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 87 | , m_interestLifetime(time::milliseconds::min()) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 88 | { |
| 89 | } |
| 90 | |
| 91 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 92 | * @brief Create a new Interest with the given name and interest lifetime |
| 93 | * |
| 94 | * @param name The name for the interest. |
| 95 | * @param interestLifetime The interest lifetime in time::milliseconds, or -1 for none. |
| 96 | * |
| 97 | * Note that in certain contexts that use Interest::shared_from_this(), Interest must be |
| 98 | * created using `make_shared`: |
| 99 | * |
| 100 | * shared_ptr<Interest> interest = make_shared<Interest>(name, time::seconds(1)); |
| 101 | * |
| 102 | * Otherwise, Interest::shared_from_this() will throw an exception. |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 103 | */ |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 104 | Interest(const Name& name, const time::milliseconds& interestLifetime) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 105 | : m_name(name) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 106 | , m_scope(-1) |
| 107 | , m_interestLifetime(interestLifetime) |
| 108 | { |
| 109 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 111 | /** |
| 112 | * @brief Create a new Interest for the given name, selectors, and guiders |
| 113 | * |
| 114 | * Note that in certain contexts that use Interest::shared_from_this(), Interest must be |
| 115 | * created using `make_shared`: |
| 116 | * |
| 117 | * shared_ptr<Interest> interest = make_shared<Interest>(...); |
| 118 | * |
| 119 | * Otherwise, Interest::shared_from_this() will throw an exception. |
| 120 | */ |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 121 | Interest(const Name& name, |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 122 | const Selectors& selectors, |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 123 | int scope, |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 124 | const time::milliseconds& interestLifetime, |
| 125 | uint32_t nonce = 0) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 126 | : m_name(name) |
| 127 | , m_selectors(selectors) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 128 | , m_scope(scope) |
| 129 | , m_interestLifetime(interestLifetime) |
| 130 | { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 131 | if (nonce > 0) { |
| 132 | setNonce(nonce); |
| 133 | } |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 134 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 136 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 137 | * @brief Create a new Interest for the given name and parameters |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 138 | * |
| 139 | * @deprecated Interest().setX(...).setY(...) |
| 140 | * or use the overload taking Selectors |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 141 | * |
| 142 | * Note that in certain contexts that use Interest::shared_from_this(), Interest must be |
| 143 | * created using `make_shared`: |
| 144 | * |
| 145 | * shared_ptr<Interest> interest = make_shared<Interest>(...); |
| 146 | * |
| 147 | * Otherwise, Interest::shared_from_this() will throw an exception. |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 148 | */ |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 149 | DEPRECATED( |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 150 | Interest(const Name& name, |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 151 | int minSuffixComponents, int maxSuffixComponents, |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 152 | const Exclude& exclude, |
| 153 | int childSelector, |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 154 | bool mustBeFresh, |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 155 | int scope, |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 156 | const time::milliseconds& interestLifetime, |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 157 | uint32_t nonce = 0)) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 158 | : m_name(name) |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 159 | , m_selectors(Selectors() |
| 160 | .setMinSuffixComponents(minSuffixComponents) |
| 161 | .setMaxSuffixComponents(maxSuffixComponents) |
| 162 | .setExclude(exclude) |
| 163 | .setChildSelector(childSelector) |
| 164 | .setMustBeFresh(mustBeFresh)) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 165 | , m_scope(scope) |
| 166 | , m_interestLifetime(interestLifetime) |
Jeff Thompson | 3f76e9e | 2013-08-21 13:14:58 -0700 | [diff] [blame] | 167 | { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 168 | if (nonce > 0) { |
| 169 | setNonce(nonce); |
| 170 | } |
Jeff Thompson | 3f76e9e | 2013-08-21 13:14:58 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 173 | /** |
| 174 | * @brief Create from wire encoding |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 175 | * |
| 176 | * Note that in certain contexts that use Interest::shared_from_this(), Interest must be |
| 177 | * created using `make_shared`: |
| 178 | * |
| 179 | * shared_ptr<Interest> interest = make_shared<Interest>(wire); |
| 180 | * |
| 181 | * Otherwise, Interest::shared_from_this() will throw an exception. |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 182 | */ |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 183 | explicit |
| 184 | Interest(const Block& wire) |
| 185 | { |
| 186 | wireDecode(wire); |
| 187 | } |
| 188 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 189 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 190 | * @brief Fast encoding or block size estimation |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 191 | */ |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 192 | template<bool T> |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 193 | size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 194 | wireEncode(EncodingImpl<T>& block) const; |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 195 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 196 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 197 | * @brief Encode to a wire format |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 198 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 199 | const Block& |
Alexander Afanasyev | 1eb961a | 2014-01-03 13:51:49 -0800 | [diff] [blame] | 200 | wireEncode() const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 201 | |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 202 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 203 | * @brief Decode from the wire format |
Jeff Thompson | 1b4a7b1 | 2013-11-15 12:00:02 -0800 | [diff] [blame] | 204 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 205 | void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 206 | wireDecode(const Block& wire); |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * @brief Check if already has wire |
| 210 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 211 | bool |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 212 | hasWire() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 213 | |
Jeff Thompson | d9e278c | 2013-07-08 15:20:13 -0700 | [diff] [blame] | 214 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 215 | * @brief Encode the name according to the NDN URI Scheme |
| 216 | * |
| 217 | * If there are interest selectors, this method will append "?" and add the selectors as |
| 218 | * a query string. For example, "/test/name?ndn.ChildSelector=1" |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 219 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 220 | std::string |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 221 | toUri() const; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 222 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 223 | /** |
| 224 | * @brief Check if Interest has any selectors present |
| 225 | */ |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 226 | bool |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 227 | hasSelectors() const; |
| 228 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 229 | /** |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 230 | * @brief Check if Interest, including selectors, matches the given @p name |
| 231 | * |
| 232 | * @param name The name to be matched. If this is a Data name, it shall contain the |
| 233 | * implicit digest component |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 234 | */ |
| 235 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 236 | matchesName(const Name& name) const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 237 | |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 238 | /** |
| 239 | * @brief Check if Interest can be satisfied by @p data. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 240 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 241 | * This method considers Name, MinSuffixComponents, MaxSuffixComponents, |
| 242 | * PublisherPublicKeyLocator, and Exclude. |
| 243 | * This method does not consider ChildSelector and MustBeFresh. |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 244 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 245 | * @todo recognize implicit digest component |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 246 | */ |
| 247 | bool |
| 248 | matchesData(const Data& data) const; |
| 249 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 250 | /////////////////////////////////////////////////////////////////////////////// |
| 251 | /////////////////////////////////////////////////////////////////////////////// |
| 252 | /////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 253 | // Getters/setters |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 254 | |
| 255 | const Name& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 256 | getName() const |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 257 | { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 258 | return m_name; |
| 259 | } |
| 260 | |
| 261 | Interest& |
| 262 | setName(const Name& name) |
| 263 | { |
| 264 | m_name = name; |
| 265 | m_wire.reset(); |
| 266 | return *this; |
Jeff Thompson | c0486c1 | 2013-07-16 14:36:16 -0700 | [diff] [blame] | 267 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 268 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 269 | // |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 270 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 271 | const Selectors& |
| 272 | getSelectors() const |
| 273 | { |
| 274 | return m_selectors; |
| 275 | } |
| 276 | |
| 277 | Interest& |
| 278 | setSelectors(const Selectors& selectors) |
| 279 | { |
| 280 | m_selectors = selectors; |
| 281 | m_wire.reset(); |
| 282 | return *this; |
| 283 | } |
| 284 | |
| 285 | // |
| 286 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 287 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 288 | getScope() const |
| 289 | { |
| 290 | return m_scope; |
| 291 | } |
| 292 | |
| 293 | Interest& |
| 294 | setScope(int scope) |
| 295 | { |
| 296 | m_scope = scope; |
| 297 | m_wire.reset(); |
| 298 | return *this; |
| 299 | } |
| 300 | |
| 301 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 302 | |
| 303 | const time::milliseconds& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 304 | getInterestLifetime() const |
| 305 | { |
| 306 | return m_interestLifetime; |
| 307 | } |
| 308 | |
| 309 | Interest& |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 310 | setInterestLifetime(const time::milliseconds& interestLifetime) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 311 | { |
| 312 | m_interestLifetime = interestLifetime; |
| 313 | m_wire.reset(); |
| 314 | return *this; |
| 315 | } |
| 316 | |
| 317 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 318 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 319 | /** |
| 320 | * @brief Get Interest's nonce |
| 321 | * |
| 322 | * If nonce was not set before this call, it will be automatically assigned to a random value |
| 323 | * |
| 324 | * Const reference needed for C decoding |
| 325 | */ |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 326 | uint32_t |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 327 | getNonce() const; |
| 328 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 329 | /** |
| 330 | * @brief Check if Nonce set |
| 331 | */ |
| 332 | bool |
| 333 | hasNonce() const |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 334 | { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 335 | return m_nonce.hasWire(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 338 | /** |
| 339 | * @brief Set Interest's nonce |
| 340 | * |
| 341 | * Note that if wire format already exists, this call simply replaces nonce in the |
| 342 | * existing wire format, without resetting and recreating it. |
| 343 | */ |
| 344 | Interest& |
| 345 | setNonce(uint32_t nonce); |
| 346 | |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 347 | /** |
| 348 | * @brief Refresh nonce |
| 349 | * |
| 350 | * Refresh guarantees that new nonce value is different from the existing one. |
| 351 | * |
| 352 | * If nonce is already set, it will be updated to a different random value. |
| 353 | * If nonce is not set, this method will do nothing. |
| 354 | */ |
| 355 | void |
| 356 | refreshNonce(); |
| 357 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 358 | // |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 359 | |
| 360 | nfd::LocalControlHeader& |
| 361 | getLocalControlHeader() |
| 362 | { |
| 363 | return m_localControlHeader; |
| 364 | } |
| 365 | |
| 366 | const nfd::LocalControlHeader& |
| 367 | getLocalControlHeader() const |
| 368 | { |
| 369 | return m_localControlHeader; |
| 370 | } |
| 371 | |
| 372 | // helper methods for LocalControlHeader |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 373 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 374 | uint64_t |
| 375 | getIncomingFaceId() const |
| 376 | { |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 377 | return getLocalControlHeader().getIncomingFaceId(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 378 | } |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 379 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 380 | Interest& |
| 381 | setIncomingFaceId(uint64_t incomingFaceId) |
| 382 | { |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 383 | getLocalControlHeader().setIncomingFaceId(incomingFaceId); |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 384 | // ! do not reset Interest's wire ! |
| 385 | return *this; |
| 386 | } |
| 387 | |
| 388 | // |
| 389 | |
| 390 | // NextHopFaceId helpers make sense only for Interests |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 391 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 392 | uint64_t |
| 393 | getNextHopFaceId() const |
| 394 | { |
| 395 | return getLocalControlHeader().getNextHopFaceId(); |
| 396 | } |
| 397 | |
| 398 | Interest& |
| 399 | setNextHopFaceId(uint64_t nextHopFaceId) |
| 400 | { |
| 401 | getLocalControlHeader().setNextHopFaceId(nextHopFaceId); |
| 402 | // ! do not reset Interest's wire ! |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 403 | return *this; |
| 404 | } |
| 405 | |
| 406 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 407 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 408 | /////////////////////////////////////////////////////////////////////////////// |
| 409 | /////////////////////////////////////////////////////////////////////////////// |
| 410 | /////////////////////////////////////////////////////////////////////////////// |
| 411 | // Wrappers for Selectors |
| 412 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 413 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 414 | int |
| 415 | getMinSuffixComponents() const |
| 416 | { |
| 417 | return m_selectors.getMinSuffixComponents(); |
| 418 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 419 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 420 | Interest& |
| 421 | setMinSuffixComponents(int minSuffixComponents) |
| 422 | { |
| 423 | m_selectors.setMinSuffixComponents(minSuffixComponents); |
| 424 | m_wire.reset(); |
| 425 | return *this; |
| 426 | } |
| 427 | |
| 428 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 429 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 430 | int |
| 431 | getMaxSuffixComponents() const |
| 432 | { |
| 433 | return m_selectors.getMaxSuffixComponents(); |
| 434 | } |
| 435 | |
| 436 | Interest& |
| 437 | setMaxSuffixComponents(int maxSuffixComponents) |
| 438 | { |
| 439 | m_selectors.setMaxSuffixComponents(maxSuffixComponents); |
| 440 | m_wire.reset(); |
| 441 | return *this; |
| 442 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 443 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 444 | // |
| 445 | |
Junxiao Shi | b332e78 | 2014-03-31 14:23:46 -0700 | [diff] [blame] | 446 | const KeyLocator& |
| 447 | getPublisherPublicKeyLocator() const |
| 448 | { |
| 449 | return m_selectors.getPublisherPublicKeyLocator(); |
| 450 | } |
| 451 | |
| 452 | Interest& |
| 453 | setPublisherPublicKeyLocator(const KeyLocator& keyLocator) |
| 454 | { |
| 455 | m_selectors.setPublisherPublicKeyLocator(keyLocator); |
| 456 | m_wire.reset(); |
| 457 | return *this; |
| 458 | } |
| 459 | |
| 460 | // |
| 461 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 462 | const Exclude& |
| 463 | getExclude() const |
| 464 | { |
| 465 | return m_selectors.getExclude(); |
| 466 | } |
| 467 | |
| 468 | Interest& |
| 469 | setExclude(const Exclude& exclude) |
| 470 | { |
| 471 | m_selectors.setExclude(exclude); |
| 472 | m_wire.reset(); |
| 473 | return *this; |
| 474 | } |
| 475 | |
| 476 | // |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 477 | |
| 478 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 479 | getChildSelector() const |
| 480 | { |
| 481 | return m_selectors.getChildSelector(); |
| 482 | } |
| 483 | |
| 484 | Interest& |
| 485 | setChildSelector(int childSelector) |
| 486 | { |
| 487 | m_selectors.setChildSelector(childSelector); |
| 488 | m_wire.reset(); |
| 489 | return *this; |
| 490 | } |
| 491 | |
| 492 | // |
| 493 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 494 | int |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 495 | getMustBeFresh() const |
| 496 | { |
| 497 | return m_selectors.getMustBeFresh(); |
| 498 | } |
| 499 | |
| 500 | Interest& |
| 501 | setMustBeFresh(bool mustBeFresh) |
| 502 | { |
| 503 | m_selectors.setMustBeFresh(mustBeFresh); |
| 504 | m_wire.reset(); |
| 505 | return *this; |
| 506 | } |
| 507 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 508 | public: // EqualityComparable concept |
| 509 | bool |
| 510 | operator==(const Interest& other) const |
| 511 | { |
| 512 | return wireEncode() == other.wireEncode(); |
| 513 | } |
| 514 | |
| 515 | bool |
| 516 | operator!=(const Interest& other) const |
| 517 | { |
| 518 | return !(*this == other); |
| 519 | } |
| 520 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 521 | private: |
| 522 | Name m_name; |
| 523 | Selectors m_selectors; |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 524 | mutable Block m_nonce; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 525 | int m_scope; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 526 | time::milliseconds m_interestLifetime; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 527 | |
| 528 | mutable Block m_wire; |
Yingdi Yu | a4e5767 | 2014-02-06 11:16:17 -0800 | [diff] [blame] | 529 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 530 | nfd::LocalControlHeader m_localControlHeader; |
| 531 | friend class nfd::LocalControlHeader; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 532 | }; |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 533 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 534 | std::ostream& |
| 535 | operator<<(std::ostream& os, const Interest& interest); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 536 | |
| 537 | inline std::string |
| 538 | Interest::toUri() const |
| 539 | { |
| 540 | std::ostringstream os; |
| 541 | os << *this; |
| 542 | return os.str(); |
| 543 | } |
| 544 | |
| 545 | inline bool |
| 546 | Interest::hasSelectors() const |
| 547 | { |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 548 | return !m_selectors.empty(); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 551 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 552 | inline bool |
| 553 | Interest::hasWire() const |
| 554 | { |
| 555 | return m_wire.hasWire(); |
| 556 | } |
| 557 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 558 | |
| 559 | } // namespace ndn |
| 560 | |
| 561 | #endif // NDN_INTEREST_HPP |