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-2023 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::security {
33 
43 {
44 public:
45  class Options
46  {
47  public:
49  {
50  }
51 
52  public:
67 
83  ssize_t maxRecords = 1000;
84 
93  };
94 
101  explicit
102  ValidationPolicyCommandInterest(unique_ptr<ValidationPolicy> inner,
103  const Options& options = {});
104 
105 protected:
106  void
107  checkPolicy(const Data& data, const shared_ptr<ValidationState>& state,
108  const ValidationContinuation& continueValidation) override;
109 
110  void
111  checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state,
112  const ValidationContinuation& continueValidation) override;
113 
114 private:
115  static std::tuple<bool, Name, time::system_clock::time_point>
116  parseCommandInterest(const Interest& interest, const shared_ptr<ValidationState>& state);
117 
118  void
119  cleanup();
120 
121  bool
122  checkTimestamp(const shared_ptr<ValidationState>& state,
123  const Name& keyName, time::system_clock::time_point timestamp);
124 
125  void
126  insertNewRecord(const Name& keyName, time::system_clock::time_point timestamp);
127 
128 private:
129  Options m_options;
130 
131  struct LastTimestampRecord
132  {
133  Name keyName;
135  time::steady_clock::time_point lastRefreshed;
136  };
137 
138  using Container = boost::multi_index_container<
139  LastTimestampRecord,
140  boost::multi_index::indexed_by<
141  boost::multi_index::ordered_unique<
142  boost::multi_index::member<LastTimestampRecord, Name, &LastTimestampRecord::keyName>
143  >,
144  boost::multi_index::sequenced<>
145  >
146  >;
147  using Index = Container::nth_index<0>::type;
148  using Queue = Container::nth_index<1>::type;
149 
150  Container m_container;
151  Index& m_index;
152  Queue& m_queue;
153 };
154 
155 } // namespace ndn::security
156 
157 #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:45
ssize_t maxRecords
Max number of distinct public keys of which to record the last timestamp.
time::nanoseconds recordLifetime
Max lifetime of a last timestamp record.
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
::boost::chrono::time_point< steady_clock > time_point
Definition: time.hpp:232
::boost::chrono::time_point< system_clock > time_point
Definition: time.hpp:205
Contains the ndn-cxx security framework.
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54