All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
validation-policy-command-interest.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_VALIDATION_POLICY_COMMAND_INTEREST_HPP
24 #define NDN_VALIDATION_POLICY_COMMAND_INTEREST_HPP
25 
26 #include <map>
27 #include "validation-policy.hpp"
28 
29 namespace ndn {
30 
41 {
42 public:
43  class Options {
44  public:
55  Options
56  (Milliseconds gracePeriod = 2 * 60 * 1000.0, int maxRecords = 1000,
57  Milliseconds recordLifetime = 3600 * 1000.0)
58  : gracePeriod_(gracePeriod),
59  maxRecords_(maxRecords),
60  recordLifetime_(recordLifetime)
61  {
62  }
63 
79 
98 
109  };
110 
119  (const ptr_lib::shared_ptr<ValidationPolicy>& innerPolicy,
120  const Options& options = Options());
121 
122  virtual void
124  (const Data& data, const ptr_lib::shared_ptr<ValidationState>& state,
125  const ValidationContinuation& continueValidation);
126 
127  virtual void
129  (const Interest& interest, const ptr_lib::shared_ptr<ValidationState>& state,
130  const ValidationContinuation& continueValidation);
131 
137  void
139  {
140  nowOffsetMilliseconds_ = nowOffsetMilliseconds;
141  }
142 
143 private:
144  class LastTimestampRecord
145  {
146  public:
147  LastTimestampRecord
148  (const Name& keyName, MillisecondsSince1970 timestamp,
149  MillisecondsSince1970 lastRefreshed)
150  : keyName_(keyName), timestamp_(timestamp), lastRefreshed_(lastRefreshed)
151  {}
152 
153  Name keyName_;
154  MillisecondsSince1970 timestamp_;
155  MillisecondsSince1970 lastRefreshed_;
156  };
157 
158  void
159  cleanUp();
160 
170  static bool
171  parseCommandInterest
172  (const Interest& interest, const ptr_lib::shared_ptr<ValidationState>& state,
173  Name& keyLocatorName, MillisecondsSince1970& timestamp);
174 
182  bool
183  checkTimestamp
184  (const ptr_lib::shared_ptr<ValidationState>& state, const Name& keyName,
185  MillisecondsSince1970 timestamp);
186 
187  void
188  insertNewRecord
189  (const Interest& interest, const Name& keyName,
190  MillisecondsSince1970 timestamp);
191 
197  int
198  findByKeyName(const Name& keyName);
199 
200  Options options_;
201  std::vector<ptr_lib::shared_ptr<LastTimestampRecord> > container_;
202  Milliseconds nowOffsetMilliseconds_;
203 };
204 
205 }
206 
207 #endif
void setNowOffsetMilliseconds_(Milliseconds nowOffsetMilliseconds)
Set the offset when insertNewRecord() and cleanUp() get the current time, which should only be used f...
Definition: validation-policy-command-interest.hpp:138
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
Definition: validation-policy-command-interest.hpp:43
Definition: data.hpp:37
ValidationPolicyCommandInterest extends ValidationPolicy as a policy for stop-and-wait command Intere...
Definition: validation-policy-command-interest.hpp:40
ValidationPolicy is an abstract base class that implements a validation policy for Data and Interest ...
Definition: validation-policy.hpp:41
ValidationPolicyCommandInterest(const ptr_lib::shared_ptr< ValidationPolicy > &innerPolicy, const Options &options=Options())
Definition: validation-policy-command-interest.cpp:32
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:119
Options(Milliseconds gracePeriod=2 *60 *1000.0, int maxRecords=1000, Milliseconds recordLifetime=3600 *1000.0)
Create a ValidationPolicyCommandInterest::Options with the optional values.
Definition: validation-policy-command-interest.hpp:56
int maxRecords_
maxRecords is the maximum number of distinct public keys of which to record the last timestamp...
Definition: validation-policy-command-interest.hpp:97
Milliseconds recordLifetime_
recordLifetime is the maximum lifetime of a last timestamp record in milliseconds.
Definition: validation-policy-command-interest.hpp:108
Milliseconds gracePeriod_
gracePeriod is the tolerance of the initial timestamp in milliseconds.
Definition: validation-policy-command-interest.hpp:78
virtual void checkPolicy(const Data &data, const ptr_lib::shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Check the Data packet against the policy.
Definition: validation-policy-command-interest.cpp:48