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 
96  enum class ErrorCode {
97  NONE = 0,
98  NAME_TOO_SHORT,
99  BAD_TIMESTAMP,
100  BAD_SIG_INFO,
101  MISSING_KEY_LOCATOR,
102  BAD_KEY_LOCATOR_TYPE,
103  BAD_CERT_NAME,
104  TIMESTAMP_OUT_OF_GRACE,
105  TIMESTAMP_REORDER
106  };
107 
114  explicit
115  CommandInterestValidator(unique_ptr<Validator> inner,
116  const Options& options = Options());
117 
118 protected:
131  void
132  checkPolicy(const Interest& interest, int nSteps,
133  const OnInterestValidated& accept,
134  const OnInterestValidationFailed& reject,
135  std::vector<shared_ptr<ValidationRequest>>& nextSteps) override;
136 
141  void
142  checkPolicy(const Data& data, int nSteps,
143  const OnDataValidated& accept,
144  const OnDataValidationFailed& reject,
145  std::vector<shared_ptr<ValidationRequest>>& nextSteps) override;
146 
147 private:
148  void
149  cleanup();
150 
151  ErrorCode
152  parseCommandInterest(const Interest& interest, Name& keyName, uint64_t& timestamp) const;
153 
154  ErrorCode
155  checkTimestamp(const Name& keyName, uint64_t timestamp,
156  time::system_clock::TimePoint receiveTime);
157 
158 private:
159  unique_ptr<Validator> m_inner;
160  Options m_options;
161 
162  struct LastTimestampRecord
163  {
164  Name keyName;
165  uint64_t timestamp;
166  time::steady_clock::TimePoint lastRefreshed;
167  };
168 
169  typedef boost::multi_index_container<
170  LastTimestampRecord,
171  boost::multi_index::indexed_by<
172  boost::multi_index::ordered_unique<
173  boost::multi_index::member<LastTimestampRecord, Name, &LastTimestampRecord::keyName>
174  >,
175  boost::multi_index::sequenced<>
176  >
177  > Container;
178  typedef Container::nth_index<0>::type Index;
179  typedef Container::nth_index<1>::type Queue;
180 
181  Container m_container;
182  Index& m_index;
183  Queue& m_queue;
184 };
185 
186 std::ostream&
187 operator<<(std::ostream& os, CommandInterestValidator::ErrorCode error);
188 
189 } // namespace security
190 } // namespace ndn
191 
192 
193 #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) 2013-2017 Regents of the University of California.
Definition: common.hpp:75
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:39
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
Represents an absolute name.
Definition: name.hpp:42
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:35