Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 22 | #include "interest.hpp" |
Alexander Afanasyev | e9fdb80 | 2014-02-05 17:36:51 -0800 | [diff] [blame] | 23 | #include "util/random.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 24 | #include "data.hpp" |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 25 | |
Davide Pesavento | e178989 | 2017-02-26 15:50:52 -0500 | [diff] [blame] | 26 | #include <cstring> |
| 27 | |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 28 | namespace ndn { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 29 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 30 | BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>)); |
| 31 | BOOST_CONCEPT_ASSERT((WireEncodable<Interest>)); |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 32 | BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Interest>)); |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 33 | BOOST_CONCEPT_ASSERT((WireDecodable<Interest>)); |
| 34 | static_assert(std::is_base_of<tlv::Error, Interest::Error>::value, |
| 35 | "Interest::Error must inherit from tlv::Error"); |
| 36 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 37 | Interest::Interest(const Name& name, time::milliseconds interestLifetime) |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 38 | : m_name(name) |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 39 | , m_interestLifetime(interestLifetime) |
| 40 | { |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 41 | if (interestLifetime < time::milliseconds::zero()) { |
| 42 | BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0")); |
| 43 | } |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 46 | Interest::Interest(const Block& wire) |
| 47 | { |
| 48 | wireDecode(wire); |
| 49 | } |
| 50 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 51 | // ---- encode and decode ---- |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 52 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 53 | template<encoding::Tag TAG> |
| 54 | size_t |
| 55 | Interest::wireEncode(EncodingImpl<TAG>& encoder) const |
| 56 | { |
| 57 | size_t totalLength = 0; |
| 58 | |
| 59 | // Interest ::= INTEREST-TYPE TLV-LENGTH |
| 60 | // Name |
| 61 | // Selectors? |
| 62 | // Nonce |
| 63 | // InterestLifetime? |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 64 | // ForwardingHint? |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 65 | |
| 66 | // (reverse encoding) |
| 67 | |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 68 | // ForwardingHint |
| 69 | if (m_forwardingHint.size() > 0) { |
| 70 | totalLength += m_forwardingHint.wireEncode(encoder); |
| 71 | } |
| 72 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 73 | // InterestLifetime |
| 74 | if (getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { |
| 75 | totalLength += prependNonNegativeIntegerBlock(encoder, |
| 76 | tlv::InterestLifetime, |
| 77 | getInterestLifetime().count()); |
| 78 | } |
| 79 | |
| 80 | // Nonce |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 81 | uint32_t nonce = this->getNonce(); // assigns random Nonce if needed |
| 82 | totalLength += encoder.prependByteArray(reinterpret_cast<uint8_t*>(&nonce), sizeof(nonce)); |
| 83 | totalLength += encoder.prependVarNumber(sizeof(nonce)); |
| 84 | totalLength += encoder.prependVarNumber(tlv::Nonce); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 85 | |
| 86 | // Selectors |
| 87 | if (hasSelectors()) { |
| 88 | totalLength += getSelectors().wireEncode(encoder); |
| 89 | } |
| 90 | |
| 91 | // Name |
| 92 | totalLength += getName().wireEncode(encoder); |
| 93 | |
| 94 | totalLength += encoder.prependVarNumber(totalLength); |
| 95 | totalLength += encoder.prependVarNumber(tlv::Interest); |
| 96 | return totalLength; |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 99 | template size_t |
| 100 | Interest::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder) const; |
| 101 | |
| 102 | template size_t |
| 103 | Interest::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder) const; |
| 104 | |
| 105 | const Block& |
| 106 | Interest::wireEncode() const |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 107 | { |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 108 | if (m_wire.hasWire()) |
| 109 | return m_wire; |
| 110 | |
| 111 | EncodingEstimator estimator; |
| 112 | size_t estimatedSize = wireEncode(estimator); |
| 113 | |
| 114 | EncodingBuffer buffer(estimatedSize, 0); |
| 115 | wireEncode(buffer); |
| 116 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 117 | const_cast<Interest*>(this)->wireDecode(buffer.block()); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 118 | return m_wire; |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 119 | } |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 121 | void |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 122 | Interest::wireDecode(const Block& wire) |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 123 | { |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 124 | m_wire = wire; |
| 125 | m_wire.parse(); |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 126 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 127 | if (m_wire.type() != tlv::Interest) |
| 128 | BOOST_THROW_EXCEPTION(Error("Unexpected TLV number when decoding Interest")); |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 129 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 130 | // Name |
| 131 | m_name.wireDecode(m_wire.get(tlv::Name)); |
| 132 | |
| 133 | // Selectors |
| 134 | Block::element_const_iterator val = m_wire.find(tlv::Selectors); |
| 135 | if (val != m_wire.elements_end()) { |
| 136 | m_selectors.wireDecode(*val); |
| 137 | } |
| 138 | else |
| 139 | m_selectors = Selectors(); |
| 140 | |
| 141 | // Nonce |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 142 | val = m_wire.find(tlv::Nonce); |
| 143 | if (val == m_wire.elements_end()) { |
| 144 | BOOST_THROW_EXCEPTION(Error("Nonce element is missing")); |
| 145 | } |
| 146 | uint32_t nonce = 0; |
| 147 | if (val->value_size() != sizeof(nonce)) { |
| 148 | BOOST_THROW_EXCEPTION(Error("Nonce element is malformed")); |
| 149 | } |
| 150 | std::memcpy(&nonce, val->value(), sizeof(nonce)); |
| 151 | m_nonce = nonce; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 152 | |
| 153 | // InterestLifetime |
| 154 | val = m_wire.find(tlv::InterestLifetime); |
| 155 | if (val != m_wire.elements_end()) { |
| 156 | m_interestLifetime = time::milliseconds(readNonNegativeInteger(*val)); |
| 157 | } |
| 158 | else { |
| 159 | m_interestLifetime = DEFAULT_INTEREST_LIFETIME; |
| 160 | } |
| 161 | |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 162 | // ForwardingHint |
| 163 | val = m_wire.find(tlv::ForwardingHint); |
| 164 | if (val != m_wire.elements_end()) { |
| 165 | m_forwardingHint.wireDecode(*val, false); |
| 166 | } |
| 167 | else { |
| 168 | m_forwardingHint = DelegationList(); |
| 169 | } |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 172 | // ---- matching ---- |
| 173 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 174 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 175 | Interest::matchesName(const Name& name) const |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 176 | { |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 177 | if (name.size() < m_name.size()) |
| 178 | return false; |
| 179 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 180 | if (!m_name.isPrefixOf(name)) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 181 | return false; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 182 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 183 | if (getMinSuffixComponents() >= 0 && |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 184 | // name must include implicit digest |
| 185 | !(name.size() - m_name.size() >= static_cast<size_t>(getMinSuffixComponents()))) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 186 | return false; |
| 187 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 188 | if (getMaxSuffixComponents() >= 0 && |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 189 | // name must include implicit digest |
| 190 | !(name.size() - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents()))) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 191 | return false; |
| 192 | |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 193 | if (!getExclude().empty() && |
| 194 | name.size() > m_name.size() && |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 195 | getExclude().isExcluded(name[m_name.size()])) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 196 | return false; |
| 197 | |
| 198 | return true; |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 201 | bool |
| 202 | Interest::matchesData(const Data& data) const |
| 203 | { |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 204 | size_t interestNameLength = m_name.size(); |
| 205 | const Name& dataName = data.getName(); |
| 206 | size_t fullNameLength = dataName.size() + 1; |
| 207 | |
| 208 | // check MinSuffixComponents |
| 209 | bool hasMinSuffixComponents = getMinSuffixComponents() >= 0; |
| 210 | size_t minSuffixComponents = hasMinSuffixComponents ? |
| 211 | static_cast<size_t>(getMinSuffixComponents()) : 0; |
| 212 | if (!(interestNameLength + minSuffixComponents <= fullNameLength)) |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 213 | return false; |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 214 | |
| 215 | // check MaxSuffixComponents |
| 216 | bool hasMaxSuffixComponents = getMaxSuffixComponents() >= 0; |
| 217 | if (hasMaxSuffixComponents && |
| 218 | !(interestNameLength + getMaxSuffixComponents() >= fullNameLength)) |
| 219 | return false; |
| 220 | |
| 221 | // check prefix |
| 222 | if (interestNameLength == fullNameLength) { |
Alexander Afanasyev | 56860f5 | 2014-11-07 11:51:17 -0800 | [diff] [blame] | 223 | if (m_name.get(-1).isImplicitSha256Digest()) { |
| 224 | if (m_name != data.getFullName()) |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 225 | return false; |
| 226 | } |
| 227 | else { |
| 228 | // Interest Name is same length as Data full Name, but last component isn't digest |
| 229 | // so there's no possibility of matching |
| 230 | return false; |
| 231 | } |
| 232 | } |
| 233 | else { |
| 234 | // Interest Name is a strict prefix of Data full Name |
| 235 | if (!m_name.isPrefixOf(dataName)) |
| 236 | return false; |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 239 | // check Exclude |
| 240 | // Exclude won't be violated if Interest Name is same as Data full Name |
| 241 | if (!getExclude().empty() && fullNameLength > interestNameLength) { |
| 242 | if (interestNameLength == fullNameLength - 1) { |
| 243 | // component to exclude is the digest |
| 244 | if (getExclude().isExcluded(data.getFullName().get(interestNameLength))) |
| 245 | return false; |
| 246 | // There's opportunity to inspect the Exclude filter and determine whether |
| 247 | // the digest would make a difference. |
Junxiao Shi | 08d0708 | 2014-12-03 11:31:44 -0700 | [diff] [blame] | 248 | // eg. "<NameComponent>AA</NameComponent><Any/>" doesn't exclude any digest - |
| 249 | // fullName not needed; |
| 250 | // "<Any/><NameComponent>AA</NameComponent>" and |
| 251 | // "<Any/><ImplicitSha256DigestComponent>ffffffffffffffffffffffffffffffff |
| 252 | // </ImplicitSha256DigestComponent>" |
| 253 | // excludes all digests - fullName not needed; |
| 254 | // "<Any/><ImplicitSha256DigestComponent>80000000000000000000000000000000 |
| 255 | // </ImplicitSha256DigestComponent>" |
| 256 | // excludes some digests - fullName required |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 257 | // But Interests that contain the exact Data Name before digest and also |
| 258 | // contain Exclude filter is too rare to optimize for, so we request |
Junxiao Shi | 6824783 | 2017-07-03 22:06:49 +0000 | [diff] [blame] | 259 | // fullName no matter what's in the Exclude filter. |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 260 | } |
| 261 | else { |
| 262 | // component to exclude is not the digest |
| 263 | if (getExclude().isExcluded(dataName.get(interestNameLength))) |
| 264 | return false; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // check PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 269 | const KeyLocator& publisherPublicKeyLocator = this->getPublisherPublicKeyLocator(); |
| 270 | if (!publisherPublicKeyLocator.empty()) { |
| 271 | const Signature& signature = data.getSignature(); |
| 272 | const Block& signatureInfo = signature.getInfo(); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 273 | Block::element_const_iterator it = signatureInfo.find(tlv::KeyLocator); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 274 | if (it == signatureInfo.elements_end()) { |
| 275 | return false; |
| 276 | } |
| 277 | if (publisherPublicKeyLocator.wireEncode() != *it) { |
| 278 | return false; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 285 | bool |
| 286 | Interest::matchesInterest(const Interest& other) const |
| 287 | { |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 288 | /// @todo #3162 match ForwardingHint field |
Alexander Afanasyev | 1013fd0 | 2017-01-03 13:19:03 -0800 | [diff] [blame] | 289 | return (this->getName() == other.getName() && |
| 290 | this->getSelectors() == other.getSelectors()); |
| 291 | } |
| 292 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 293 | // ---- field accessors ---- |
| 294 | |
| 295 | uint32_t |
| 296 | Interest::getNonce() const |
| 297 | { |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 298 | if (!m_nonce) { |
| 299 | m_nonce = random::generateWord32(); |
Junxiao Shi | c2ac5d2 | 2017-07-17 22:18:31 +0000 | [diff] [blame] | 300 | } |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 301 | return *m_nonce; |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | Interest& |
| 305 | Interest::setNonce(uint32_t nonce) |
| 306 | { |
Junxiao Shi | 2dd711d | 2017-07-21 13:40:52 +0000 | [diff] [blame] | 307 | m_nonce = nonce; |
| 308 | m_wire.reset(); |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 309 | return *this; |
| 310 | } |
| 311 | |
| 312 | void |
| 313 | Interest::refreshNonce() |
| 314 | { |
| 315 | if (!hasNonce()) |
| 316 | return; |
| 317 | |
| 318 | uint32_t oldNonce = getNonce(); |
| 319 | uint32_t newNonce = oldNonce; |
| 320 | while (newNonce == oldNonce) |
| 321 | newNonce = random::generateWord32(); |
| 322 | |
| 323 | setNonce(newNonce); |
| 324 | } |
| 325 | |
Eric Newberry | b555b00 | 2017-05-17 00:30:44 -0700 | [diff] [blame] | 326 | Interest& |
| 327 | Interest::setInterestLifetime(time::milliseconds interestLifetime) |
| 328 | { |
| 329 | if (interestLifetime < time::milliseconds::zero()) { |
| 330 | BOOST_THROW_EXCEPTION(std::invalid_argument("InterestLifetime must be >= 0")); |
| 331 | } |
| 332 | m_interestLifetime = interestLifetime; |
| 333 | m_wire.reset(); |
| 334 | return *this; |
| 335 | } |
| 336 | |
Junxiao Shi | 9c154cb | 2017-07-07 22:14:54 +0000 | [diff] [blame] | 337 | Interest& |
| 338 | Interest::setForwardingHint(const DelegationList& value) |
| 339 | { |
| 340 | m_forwardingHint = value; |
| 341 | m_wire.reset(); |
| 342 | return *this; |
| 343 | } |
| 344 | |
Junxiao Shi | 899277a | 2017-07-07 22:12:12 +0000 | [diff] [blame] | 345 | // ---- operators ---- |
| 346 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 347 | std::ostream& |
| 348 | operator<<(std::ostream& os, const Interest& interest) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 349 | { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 350 | os << interest.getName(); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 351 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 352 | char delim = '?'; |
| 353 | |
| 354 | if (interest.getMinSuffixComponents() >= 0) { |
| 355 | os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents(); |
| 356 | delim = '&'; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 357 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 358 | if (interest.getMaxSuffixComponents() >= 0) { |
| 359 | os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents(); |
| 360 | delim = '&'; |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 361 | } |
Eric Newberry | b555b00 | 2017-05-17 00:30:44 -0700 | [diff] [blame] | 362 | if (interest.getChildSelector() != DEFAULT_CHILD_SELECTOR) { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 363 | os << delim << "ndn.ChildSelector=" << interest.getChildSelector(); |
| 364 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 365 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 366 | if (interest.getMustBeFresh()) { |
| 367 | os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh(); |
| 368 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 369 | } |
Eric Newberry | b555b00 | 2017-05-17 00:30:44 -0700 | [diff] [blame] | 370 | if (interest.getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 371 | os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime().count(); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 372 | delim = '&'; |
| 373 | } |
| 374 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 375 | if (interest.hasNonce()) { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 376 | os << delim << "ndn.Nonce=" << interest.getNonce(); |
| 377 | delim = '&'; |
| 378 | } |
| 379 | if (!interest.getExclude().empty()) { |
| 380 | os << delim << "ndn.Exclude=" << interest.getExclude(); |
| 381 | delim = '&'; |
| 382 | } |
| 383 | |
| 384 | return os; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Junxiao Shi | 08d0708 | 2014-12-03 11:31:44 -0700 | [diff] [blame] | 387 | } // namespace ndn |