All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interest.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
8 #include "common.hpp"
9 
10 #include "interest.hpp"
11 #include "util/random.hpp"
12 #include "data.hpp"
13 
14 namespace ndn {
15 
16 const uint32_t&
18 {
19  if (m_nonce == 0)
20  m_nonce = random::generateWord32();
21 
22  return m_nonce;
23 }
24 
25 
26 bool
27 Interest::matchesName(const Name& name) const
28 {
29  if (name.size() < m_name.size())
30  return false;
31 
32  if (!m_name.isPrefixOf(name))
33  return false;
34 
35  if (getMinSuffixComponents() >= 0 &&
36  // Add 1 for the implicit digest.
37  !(name.size() + 1 - m_name.size() >= static_cast<size_t>(getMinSuffixComponents())))
38  return false;
39 
40  if (getMaxSuffixComponents() >= 0 &&
41  // Add 1 for the implicit digest.
42  !(name.size() + 1 - m_name.size() <= static_cast<size_t>(getMaxSuffixComponents())))
43  return false;
44 
45  if (!getExclude().empty() &&
46  name.size() > m_name.size() &&
47  getExclude().isExcluded(name[m_name.size()]))
48  return false;
49 
50  return true;
51 }
52 
53 bool
54 Interest::matchesData(const Data& data) const
55 {
56  if (!this->matchesName(data.getName())) {
57  return false;
58  }
59 
60  const KeyLocator& publisherPublicKeyLocator = this->getPublisherPublicKeyLocator();
61  if (!publisherPublicKeyLocator.empty()) {
62  const Signature& signature = data.getSignature();
63  const Block& signatureInfo = signature.getInfo();
65  if (it == signatureInfo.elements_end()) {
66  return false;
67  }
68  if (publisherPublicKeyLocator.wireEncode() != *it) {
69  return false;
70  }
71  }
72 
73  return true;
74 }
75 
76 std::ostream&
77 operator<<(std::ostream& os, const Interest& interest)
78 {
79  os << interest.getName();
80 
81  char delim = '?';
82 
83  if (interest.getMinSuffixComponents() >= 0) {
84  os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
85  delim = '&';
86  }
87  if (interest.getMaxSuffixComponents() >= 0) {
88  os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
89  delim = '&';
90  }
91  if (interest.getChildSelector() >= 0) {
92  os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
93  delim = '&';
94  }
95  if (interest.getMustBeFresh()) {
96  os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
97  delim = '&';
98  }
99  if (interest.getScope() >= 0) {
100  os << delim << "ndn.Scope=" << interest.getScope();
101  delim = '&';
102  }
103  if (interest.getInterestLifetime() >= time::milliseconds::zero()
105  os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime();
106  delim = '&';
107  }
108 
109  if (interest.getNonce() > 0) {
110  os << delim << "ndn.Nonce=" << interest.getNonce();
111  delim = '&';
112  }
113  if (!interest.getExclude().empty()) {
114  os << delim << "ndn.Exclude=" << interest.getExclude();
115  delim = '&';
116  }
117 
118  return os;
119 }
120 
121 }
int getMinSuffixComponents() const
Definition: interest.hpp:320
int getMaxSuffixComponents() const
Definition: interest.hpp:336
const Name & getName() const
Definition: interest.hpp:182
bool matchesName(const Name &name) const
Check if Interest name matches the given name (using ndn_Name_match) and the given name also conforms...
Definition: interest.cpp:27
element_const_iterator find(uint32_t type) const
Definition: block.hpp:343
Class representing wire element of the NDN packet.
Definition: block.hpp:26
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:24
const time::milliseconds & getInterestLifetime() const
Definition: interest.hpp:230
int getChildSelector() const
Definition: interest.hpp:384
const Name & getName() const
Definition: data.hpp:346
element_const_iterator elements_end() const
Definition: block.hpp:476
uint32_t generateWord32()
Definition: random.cpp:17
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
Definition: exclude.cpp:33
int getMustBeFresh() const
Definition: interest.hpp:400
const time::seconds DEFAULT_INTEREST_LIFETIME
Definition: interest.hpp:19
bool empty() const
Definition: key-locator.hpp:70
const Exclude & getExclude() const
Definition: interest.hpp:368
element_container::const_iterator element_const_iterator
Definition: block.hpp:31
size_t size() const
Get the number of components.
Definition: name.hpp:329
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:26
bool matchesData(const Data &data) const
Determines whether this Interest can be satisfied by data.
Definition: interest.cpp:54
const Signature & getSignature() const
Definition: data.hpp:450
int getScope() const
Definition: interest.hpp:214
bool empty() const
Check if exclude filter is empty.
Definition: exclude.hpp:203
const Block & getInfo() const
Definition: signature.hpp:56
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
Definition: name.hpp:669
const KeyLocator & getPublisherPublicKeyLocator() const
Definition: interest.hpp:352
size_t wireEncode(EncodingImpl< T > &block) const
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.hpp:523
const uint32_t & getNonce() const
Get Interest&#39;s nonce.
Definition: interest.cpp:17
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:15