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