validation-policy-command-interest.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
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.
20  */
21 
22 #ifndef NDN_CXX_SECURITY_VALIDATION_POLICY_COMMAND_INTEREST_HPP
23 #define NDN_CXX_SECURITY_VALIDATION_POLICY_COMMAND_INTEREST_HPP
24 
26 
27 #include <boost/multi_index_container.hpp>
28 #include <boost/multi_index/ordered_index.hpp>
29 #include <boost/multi_index/sequenced_index.hpp>
30 #include <boost/multi_index/key_extractors.hpp>
31 
32 namespace ndn {
33 namespace security {
34 inline namespace v2 {
35 
45 {
46 public:
47  class Options
48  {
49  public:
51  {
52  }
53 
54  public:
69 
85  ssize_t maxRecords = 1000;
86 
95  };
96 
103  explicit
104  ValidationPolicyCommandInterest(unique_ptr<ValidationPolicy> inner,
105  const Options& options = {});
106 
107 protected:
108  void
109  checkPolicy(const Data& data, const shared_ptr<ValidationState>& state,
110  const ValidationContinuation& continueValidation) override;
111 
112  void
113  checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state,
114  const ValidationContinuation& continueValidation) override;
115 
116 private:
117  static std::tuple<bool, Name, time::system_clock::TimePoint>
118  parseCommandInterest(const Interest& interest, const shared_ptr<ValidationState>& state);
119 
120  void
121  cleanup();
122 
123  bool
124  checkTimestamp(const shared_ptr<ValidationState>& state,
125  const Name& keyName, time::system_clock::TimePoint timestamp);
126 
127  void
128  insertNewRecord(const Name& keyName, time::system_clock::TimePoint timestamp);
129 
130 private:
131  Options m_options;
132 
133  struct LastTimestampRecord
134  {
135  Name keyName;
137  time::steady_clock::TimePoint lastRefreshed;
138  };
139 
140  using Container = boost::multi_index_container<
141  LastTimestampRecord,
142  boost::multi_index::indexed_by<
143  boost::multi_index::ordered_unique<
144  boost::multi_index::member<LastTimestampRecord, Name, &LastTimestampRecord::keyName>
145  >,
146  boost::multi_index::sequenced<>
147  >
148  >;
149  using Index = Container::nth_index<0>::type;
150  using Queue = Container::nth_index<1>::type;
151 
152  Container m_container;
153  Index& m_index;
154  Queue& m_queue;
155 };
156 
157 } // inline namespace v2
158 } // namespace security
159 } // namespace ndn
160 
161 #endif // NDN_CXX_SECURITY_VALIDATION_POLICY_COMMAND_INTEREST_HPP
Represents a Data packet.
Definition: data.hpp:39
Represents an Interest packet.
Definition: interest.hpp:50
Represents an absolute name.
Definition: name.hpp:44
time::nanoseconds recordLifetime
Max lifetime of a last timestamp record.
ssize_t maxRecords
Max number of distinct public keys of which to record the last timestamp.
Validation policy for stop-and-wait command Interests.
void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Check data against the policy.
ValidationPolicyCommandInterest(unique_ptr< ValidationPolicy > inner, const Options &options={})
Constructor.
Abstraction that implements a validation policy for Interest and Data packets.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
time_point TimePoint
Definition: time.hpp:233
time_point TimePoint
Definition: time.hpp:203
boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:50
Definition: data.cpp:25