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 | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 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 | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 24 | #include "util/crypto.hpp" |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 25 | #include "util/concepts.hpp" |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 26 | #include "data.hpp" |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 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>)); |
| 32 | BOOST_CONCEPT_ASSERT((WireDecodable<Interest>)); |
| 33 | static_assert(std::is_base_of<tlv::Error, Interest::Error>::value, |
| 34 | "Interest::Error must inherit from tlv::Error"); |
| 35 | |
Junxiao Shi | 2af905b | 2014-11-27 13:10:54 -0700 | [diff] [blame] | 36 | Interest::Interest() |
| 37 | : m_scope(-1) |
| 38 | , m_interestLifetime(time::milliseconds::min()) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | Interest::Interest(const Name& name) |
| 43 | : m_name(name) |
| 44 | , m_scope(-1) |
| 45 | , m_interestLifetime(time::milliseconds::min()) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | Interest::Interest(const Name& name, const time::milliseconds& interestLifetime) |
| 50 | : m_name(name) |
| 51 | , m_scope(-1) |
| 52 | , m_interestLifetime(interestLifetime) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | Interest::Interest(const Name& name, |
| 57 | const Selectors& selectors, |
| 58 | int scope, |
| 59 | const time::milliseconds& interestLifetime, |
| 60 | uint32_t nonce) |
| 61 | : m_name(name) |
| 62 | , m_selectors(selectors) |
| 63 | , m_scope(scope) |
| 64 | , m_interestLifetime(interestLifetime) |
| 65 | { |
| 66 | if (nonce > 0) { |
| 67 | setNonce(nonce); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | Interest::Interest(const Block& wire) |
| 72 | { |
| 73 | wireDecode(wire); |
| 74 | } |
| 75 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 76 | uint32_t |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 77 | Interest::getNonce() const |
| 78 | { |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 79 | if (!m_nonce.hasWire()) |
| 80 | const_cast<Interest*>(this)->setNonce(random::generateWord32()); |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 81 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 82 | if (m_nonce.value_size() == sizeof(uint32_t)) |
| 83 | return *reinterpret_cast<const uint32_t*>(m_nonce.value()); |
| 84 | else { |
| 85 | // for compatibility reasons. Should be removed eventually |
| 86 | return readNonNegativeInteger(m_nonce); |
| 87 | } |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 90 | Interest& |
| 91 | Interest::setNonce(uint32_t nonce) |
| 92 | { |
| 93 | if (m_wire.hasWire() && m_nonce.value_size() == sizeof(uint32_t)) { |
| 94 | std::memcpy(const_cast<uint8_t*>(m_nonce.value()), &nonce, sizeof(nonce)); |
| 95 | } |
| 96 | else { |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 97 | m_nonce = dataBlock(tlv::Nonce, |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 98 | reinterpret_cast<const uint8_t*>(&nonce), |
| 99 | sizeof(nonce)); |
| 100 | m_wire.reset(); |
| 101 | } |
| 102 | return *this; |
| 103 | } |
Alexander Afanasyev | 840139f | 2013-12-28 15:02:50 -0800 | [diff] [blame] | 104 | |
Alexander Afanasyev | c393217 | 2014-07-10 18:53:56 -0700 | [diff] [blame] | 105 | void |
| 106 | Interest::refreshNonce() |
| 107 | { |
| 108 | if (!hasNonce()) |
| 109 | return; |
| 110 | |
| 111 | uint32_t oldNonce = getNonce(); |
| 112 | uint32_t newNonce = oldNonce; |
| 113 | while (newNonce == oldNonce) |
| 114 | newNonce = random::generateWord32(); |
| 115 | |
| 116 | setNonce(newNonce); |
| 117 | } |
| 118 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 119 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 120 | Interest::matchesName(const Name& name) const |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 121 | { |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 122 | if (name.size() < m_name.size()) |
| 123 | return false; |
| 124 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 125 | if (!m_name.isPrefixOf(name)) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 126 | return false; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 127 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 128 | if (getMinSuffixComponents() >= 0 && |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 129 | // name must include implicit digest |
| 130 | !(name.size() - m_name.size() >= static_cast<size_t>(getMinSuffixComponents()))) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 131 | return false; |
| 132 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 133 | if (getMaxSuffixComponents() >= 0 && |
Alexander Afanasyev | 3b70310 | 2014-06-13 17:01:14 -0700 | [diff] [blame] | 134 | // name must include implicit digest |
| 135 | !(name.size() - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents()))) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 136 | return false; |
| 137 | |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame] | 138 | if (!getExclude().empty() && |
| 139 | name.size() > m_name.size() && |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 140 | getExclude().isExcluded(name[m_name.size()])) |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 141 | return false; |
| 142 | |
| 143 | return true; |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 146 | bool |
| 147 | Interest::matchesData(const Data& data) const |
| 148 | { |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 149 | size_t interestNameLength = m_name.size(); |
| 150 | const Name& dataName = data.getName(); |
| 151 | size_t fullNameLength = dataName.size() + 1; |
| 152 | |
| 153 | // check MinSuffixComponents |
| 154 | bool hasMinSuffixComponents = getMinSuffixComponents() >= 0; |
| 155 | size_t minSuffixComponents = hasMinSuffixComponents ? |
| 156 | static_cast<size_t>(getMinSuffixComponents()) : 0; |
| 157 | if (!(interestNameLength + minSuffixComponents <= fullNameLength)) |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 158 | return false; |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 159 | |
| 160 | // check MaxSuffixComponents |
| 161 | bool hasMaxSuffixComponents = getMaxSuffixComponents() >= 0; |
| 162 | if (hasMaxSuffixComponents && |
| 163 | !(interestNameLength + getMaxSuffixComponents() >= fullNameLength)) |
| 164 | return false; |
| 165 | |
| 166 | // check prefix |
| 167 | if (interestNameLength == fullNameLength) { |
Alexander Afanasyev | 56860f5 | 2014-11-07 11:51:17 -0800 | [diff] [blame] | 168 | if (m_name.get(-1).isImplicitSha256Digest()) { |
| 169 | if (m_name != data.getFullName()) |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 170 | return false; |
| 171 | } |
| 172 | else { |
| 173 | // Interest Name is same length as Data full Name, but last component isn't digest |
| 174 | // so there's no possibility of matching |
| 175 | return false; |
| 176 | } |
| 177 | } |
| 178 | else { |
| 179 | // Interest Name is a strict prefix of Data full Name |
| 180 | if (!m_name.isPrefixOf(dataName)) |
| 181 | return false; |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 184 | // check Exclude |
| 185 | // Exclude won't be violated if Interest Name is same as Data full Name |
| 186 | if (!getExclude().empty() && fullNameLength > interestNameLength) { |
| 187 | if (interestNameLength == fullNameLength - 1) { |
| 188 | // component to exclude is the digest |
| 189 | if (getExclude().isExcluded(data.getFullName().get(interestNameLength))) |
| 190 | return false; |
| 191 | // There's opportunity to inspect the Exclude filter and determine whether |
| 192 | // the digest would make a difference. |
Junxiao Shi | 08d0708 | 2014-12-03 11:31:44 -0700 | [diff] [blame] | 193 | // eg. "<NameComponent>AA</NameComponent><Any/>" doesn't exclude any digest - |
| 194 | // fullName not needed; |
| 195 | // "<Any/><NameComponent>AA</NameComponent>" and |
| 196 | // "<Any/><ImplicitSha256DigestComponent>ffffffffffffffffffffffffffffffff |
| 197 | // </ImplicitSha256DigestComponent>" |
| 198 | // excludes all digests - fullName not needed; |
| 199 | // "<Any/><ImplicitSha256DigestComponent>80000000000000000000000000000000 |
| 200 | // </ImplicitSha256DigestComponent>" |
| 201 | // excludes some digests - fullName required |
Junxiao Shi | 42c2362 | 2014-07-03 00:55:11 -0700 | [diff] [blame] | 202 | // But Interests that contain the exact Data Name before digest and also |
| 203 | // contain Exclude filter is too rare to optimize for, so we request |
| 204 | // fullName no mater what's in the Exclude filter. |
| 205 | } |
| 206 | else { |
| 207 | // component to exclude is not the digest |
| 208 | if (getExclude().isExcluded(dataName.get(interestNameLength))) |
| 209 | return false; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | // check PublisherPublicKeyLocator |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 214 | const KeyLocator& publisherPublicKeyLocator = this->getPublisherPublicKeyLocator(); |
| 215 | if (!publisherPublicKeyLocator.empty()) { |
| 216 | const Signature& signature = data.getSignature(); |
| 217 | const Block& signatureInfo = signature.getInfo(); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 218 | Block::element_const_iterator it = signatureInfo.find(tlv::KeyLocator); |
Junxiao Shi | af8eeea | 2014-03-31 20:10:56 -0700 | [diff] [blame] | 219 | if (it == signatureInfo.elements_end()) { |
| 220 | return false; |
| 221 | } |
| 222 | if (publisherPublicKeyLocator.wireEncode() != *it) { |
| 223 | return false; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return true; |
| 228 | } |
| 229 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 230 | template<encoding::Tag TAG> |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 231 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 232 | Interest::wireEncode(EncodingImpl<TAG>& block) const |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 233 | { |
| 234 | size_t totalLength = 0; |
| 235 | |
| 236 | // Interest ::= INTEREST-TYPE TLV-LENGTH |
| 237 | // Name |
| 238 | // Selectors? |
| 239 | // Nonce |
| 240 | // Scope? |
| 241 | // InterestLifetime? |
| 242 | |
| 243 | // (reverse encoding) |
| 244 | |
| 245 | // InterestLifetime |
| 246 | if (getInterestLifetime() >= time::milliseconds::zero() && |
| 247 | getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) |
| 248 | { |
| 249 | totalLength += prependNonNegativeIntegerBlock(block, |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 250 | tlv::InterestLifetime, |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 251 | getInterestLifetime().count()); |
| 252 | } |
| 253 | |
| 254 | // Scope |
| 255 | if (getScope() >= 0) |
| 256 | { |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 257 | totalLength += prependNonNegativeIntegerBlock(block, tlv::Scope, getScope()); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Nonce |
| 261 | getNonce(); // to ensure that Nonce is properly set |
| 262 | totalLength += block.prependBlock(m_nonce); |
| 263 | |
| 264 | // Selectors |
| 265 | if (hasSelectors()) |
| 266 | { |
| 267 | totalLength += getSelectors().wireEncode(block); |
| 268 | } |
| 269 | |
| 270 | // Name |
| 271 | totalLength += getName().wireEncode(block); |
| 272 | |
| 273 | totalLength += block.prependVarNumber(totalLength); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 274 | totalLength += block.prependVarNumber(tlv::Interest); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 275 | return totalLength; |
| 276 | } |
| 277 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 278 | template size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 279 | Interest::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& block) const; |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 280 | |
| 281 | template size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 282 | Interest::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& block) const; |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 283 | |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 284 | const Block& |
| 285 | Interest::wireEncode() const |
| 286 | { |
| 287 | if (m_wire.hasWire()) |
| 288 | return m_wire; |
| 289 | |
| 290 | EncodingEstimator estimator; |
| 291 | size_t estimatedSize = wireEncode(estimator); |
| 292 | |
| 293 | EncodingBuffer buffer(estimatedSize, 0); |
| 294 | wireEncode(buffer); |
| 295 | |
| 296 | // to ensure that Nonce block points to the right memory location |
| 297 | const_cast<Interest*>(this)->wireDecode(buffer.block()); |
| 298 | |
| 299 | return m_wire; |
| 300 | } |
| 301 | |
| 302 | void |
| 303 | Interest::wireDecode(const Block& wire) |
| 304 | { |
| 305 | m_wire = wire; |
| 306 | m_wire.parse(); |
| 307 | |
| 308 | // Interest ::= INTEREST-TYPE TLV-LENGTH |
| 309 | // Name |
| 310 | // Selectors? |
| 311 | // Nonce |
| 312 | // Scope? |
| 313 | // InterestLifetime? |
| 314 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 315 | if (m_wire.type() != tlv::Interest) |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 316 | throw Error("Unexpected TLV number when decoding Interest"); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 317 | |
| 318 | // Name |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 319 | m_name.wireDecode(m_wire.get(tlv::Name)); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 320 | |
| 321 | // Selectors |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 322 | Block::element_const_iterator val = m_wire.find(tlv::Selectors); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 323 | if (val != m_wire.elements_end()) |
| 324 | { |
| 325 | m_selectors.wireDecode(*val); |
| 326 | } |
| 327 | else |
| 328 | m_selectors = Selectors(); |
| 329 | |
| 330 | // Nonce |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 331 | m_nonce = m_wire.get(tlv::Nonce); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 332 | |
| 333 | // Scope |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 334 | val = m_wire.find(tlv::Scope); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 335 | if (val != m_wire.elements_end()) |
| 336 | { |
| 337 | m_scope = readNonNegativeInteger(*val); |
| 338 | } |
| 339 | else |
| 340 | m_scope = -1; |
| 341 | |
| 342 | // InterestLifetime |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 343 | val = m_wire.find(tlv::InterestLifetime); |
Alexander Afanasyev | 197e565 | 2014-06-13 16:56:31 -0700 | [diff] [blame] | 344 | if (val != m_wire.elements_end()) |
| 345 | { |
| 346 | m_interestLifetime = time::milliseconds(readNonNegativeInteger(*val)); |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | m_interestLifetime = DEFAULT_INTEREST_LIFETIME; |
| 351 | } |
| 352 | } |
| 353 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 354 | std::ostream& |
| 355 | operator<<(std::ostream& os, const Interest& interest) |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 356 | { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 357 | os << interest.getName(); |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 358 | |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 359 | char delim = '?'; |
| 360 | |
| 361 | if (interest.getMinSuffixComponents() >= 0) { |
| 362 | os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents(); |
| 363 | delim = '&'; |
Jeff Thompson | fe55686 | 2013-07-09 13:52:55 -0700 | [diff] [blame] | 364 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 365 | if (interest.getMaxSuffixComponents() >= 0) { |
| 366 | os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents(); |
| 367 | delim = '&'; |
Jeff Thompson | 37527d6 | 2013-08-21 11:15:54 -0700 | [diff] [blame] | 368 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 369 | if (interest.getChildSelector() >= 0) { |
| 370 | os << delim << "ndn.ChildSelector=" << interest.getChildSelector(); |
| 371 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 372 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 373 | if (interest.getMustBeFresh()) { |
| 374 | os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh(); |
| 375 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 376 | } |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 377 | if (interest.getScope() >= 0) { |
| 378 | os << delim << "ndn.Scope=" << interest.getScope(); |
| 379 | delim = '&'; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 380 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 381 | if (interest.getInterestLifetime() >= time::milliseconds::zero() |
| 382 | && interest.getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) { |
Alexander Afanasyev | a0c5f83 | 2014-06-19 13:27:56 -0700 | [diff] [blame] | 383 | os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime().count(); |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 384 | delim = '&'; |
| 385 | } |
| 386 | |
Alexander Afanasyev | e881e93 | 2014-06-08 14:47:03 +0300 | [diff] [blame] | 387 | if (interest.hasNonce()) { |
Alexander Afanasyev | 8468198 | 2014-01-03 13:26:09 -0800 | [diff] [blame] | 388 | os << delim << "ndn.Nonce=" << interest.getNonce(); |
| 389 | delim = '&'; |
| 390 | } |
| 391 | if (!interest.getExclude().empty()) { |
| 392 | os << delim << "ndn.Exclude=" << interest.getExclude(); |
| 393 | delim = '&'; |
| 394 | } |
| 395 | |
| 396 | return os; |
Jeff Thompson | 13e280b | 2013-12-03 13:12:23 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Junxiao Shi | 08d0708 | 2014-12-03 11:31:44 -0700 | [diff] [blame] | 399 | } // namespace ndn |