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