NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
command-interest-validator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_SECURITY_COMMAND_INTEREST_VALIDATOR_HPP
23 #define NDN_SECURITY_COMMAND_INTEREST_VALIDATOR_HPP
24 
25 #include "validator.hpp"
26 #include <boost/multi_index_container.hpp>
27 #include <boost/multi_index/ordered_index.hpp>
28 #include <boost/multi_index/sequenced_index.hpp>
29 #include <boost/multi_index/key_extractors.hpp>
30 
31 namespace ndn {
32 namespace security {
33 
41 {
42 public:
43  class Options
44  {
45  public:
47  {
48  }
49 
50  public:
64  time::nanoseconds gracePeriod = time::seconds(120);
65 
81  ssize_t maxTimestamps = 1000;
82 
90  time::nanoseconds timestampTtl = time::hours(1);
91 
92  };
93 
97  enum class ErrorCode {
98  NONE = 0,
99  NAME_TOO_SHORT,
100  BAD_TIMESTAMP,
101  BAD_SIG_INFO,
102  MISSING_KEY_LOCATOR,
103  BAD_KEY_LOCATOR_TYPE,
104  BAD_CERT_NAME,
105  TIMESTAMP_OUT_OF_GRACE,
106  TIMESTAMP_REORDER
107  };
108 
115  explicit
116  CommandInterestValidator(unique_ptr<Validator> inner,
117  const Options& options = Options());
118 
119 protected:
132  virtual void
133  checkPolicy(const Interest& interest, int nSteps,
134  const OnInterestValidated& accept,
135  const OnInterestValidationFailed& reject,
136  std::vector<shared_ptr<ValidationRequest>>& nextSteps) override;
137 
142  virtual void
143  checkPolicy(const Data& data, int nSteps,
144  const OnDataValidated& accept,
145  const OnDataValidationFailed& reject,
146  std::vector<shared_ptr<ValidationRequest>>& nextSteps) override;
147 
148 private:
149  void
150  cleanup();
151 
152  ErrorCode
153  parseCommandInterest(const Interest& interest, Name& keyName, uint64_t& timestamp) const;
154 
155  ErrorCode
156  checkTimestamp(const Name& keyName, uint64_t timestamp,
157  time::system_clock::TimePoint receiveTime);
158 
159 private:
160  unique_ptr<Validator> m_inner;
161  Options m_options;
162 
163  struct LastTimestampRecord
164  {
165  Name keyName;
166  uint64_t timestamp;
167  time::steady_clock::TimePoint lastRefreshed;
168  };
169 
170  typedef boost::multi_index_container<
171  LastTimestampRecord,
172  boost::multi_index::indexed_by<
173  boost::multi_index::ordered_unique<
174  boost::multi_index::member<LastTimestampRecord, Name, &LastTimestampRecord::keyName>
175  >,
176  boost::multi_index::sequenced<>
177  >
178  > Container;
179  typedef Container::nth_index<0>::type Index;
180  typedef Container::nth_index<1>::type Queue;
181 
182  Container m_container;
183  Index& m_index;
184  Queue& m_queue;
185 };
186 
187 std::ostream&
188 operator<<(std::ostream& os, CommandInterestValidator::ErrorCode error);
189 
190 } // namespace security
191 } // namespace ndn
192 
193 
194 #endif // NDN_SECURITY_COMMAND_INTEREST_VALIDATOR_HPP
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
time_point TimePoint
Definition: time.hpp:120
Copyright (c) 2011-2015 Regents of the University of California.
time::nanoseconds timestampTtl
max lifetime of a last timestamp record
represents an Interest packet
Definition: interest.hpp:42
function< void(const shared_ptr< const Data > &, const std::string &)> OnDataValidationFailed
Callback to report a failed Data validation.
std::ostream & operator<<(std::ostream &os, CommandInterestValidator::ErrorCode error)
function< void(const shared_ptr< const Data > &)> OnDataValidated
Callback to report a successful Data validation.
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
CommandInterestValidator(unique_ptr< Validator > inner, const Options &options=Options())
constructor
provides the interfaces for packet validation.
Definition: validator.hpp:42
virtual void checkPolicy(const Interest &interest, int nSteps, const OnInterestValidated &accept, const OnInterestValidationFailed &reject, std::vector< shared_ptr< ValidationRequest >> &nextSteps) override
validate command Interest
time::nanoseconds gracePeriod
tolerance of initial timestamp
Name abstraction to represent an absolute name.
Definition: name.hpp:46
time_point TimePoint
Definition: time.hpp:90
ssize_t maxTimestamps
max number of distinct public keys to record last timestamp
a validator for stop-and-wait command Interests
represents a Data packet
Definition: data.hpp:37