29 , m_index(m_container.get<0>())
30 , m_queue(m_container.get<1>())
32 if (inner ==
nullptr) {
33 NDN_THROW(std::invalid_argument(
"inner policy is missing"));
51 auto [isOk, keyName, timestamp] = parseCommandInterest(interest, state);
56 if (!checkTimestamp(state, keyName, timestamp)) {
63 std::tuple<bool, Name, time::system_clock::time_point>
64 ValidationPolicyCommandInterest::parseCommandInterest(
const Interest& interest,
65 const shared_ptr<ValidationState>& state)
68 if (!state->getOutcome()) {
69 return {
false, {}, {}};
79 auto optionalTimestamp = sigInfo.getTime();
80 if (!optionalTimestamp) {
82 interest.
getName().toUri() +
"` lacks required SignatureTime element"});
83 return {
false, {}, {}};
86 timestamp = *optionalTimestamp;
92 "Command Interest name too short `" + interest.
getName().toUri() +
"`"});
93 return {
false, {}, {}};
97 if (!timestampComp.isNumber()) {
99 interest.
getName().toUri() +
"` lacks required timestamp component"});
100 return {
false, {}, {}};
107 if (!state->getOutcome()) {
108 return {
false, {}, {}};
111 return {
true, klName, timestamp};
115 ValidationPolicyCommandInterest::cleanup()
119 while ((!m_queue.empty() && m_queue.front().lastRefreshed <= expiring) ||
121 m_queue.size() >
static_cast<size_t>(m_options.
maxRecords))) {
127 ValidationPolicyCommandInterest::checkTimestamp(
const shared_ptr<ValidationState>& state,
134 if (timestamp < now - m_options.gracePeriod || timestamp > now + m_options.
gracePeriod) {
136 "Timestamp is outside the grace period for key " + keyName.toUri()});
140 auto it = m_index.find(keyName);
141 if (it != m_index.end()) {
142 if (timestamp <= it->timestamp) {
144 "Timestamp is reordered for key " + keyName.toUri()});
149 auto interestState = std::dynamic_pointer_cast<InterestValidationState>(state);
150 BOOST_ASSERT(interestState !=
nullptr);
151 interestState->afterSuccess.connect([=] (
const Interest&) { insertNewRecord(keyName, timestamp); });
160 auto [i, isNew] = m_queue.push_back(newRecord);
163 BOOST_ASSERT(i->keyName == keyName);
167 isNew = m_queue.push_back(newRecord).second;
Represents a Data packet.
Represents an Interest packet.
const Name & getName() const noexcept
Get the Interest name.
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking.
@ POLICY_ERROR
The packet violates the validation rules enforced by the policy.
time::nanoseconds gracePeriod
Tolerance of initial timestamp.
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.
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.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
ValidationPolicy & getInnerPolicy()
Return the inner policy.
virtual void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check data against the policy.
void setInnerPolicy(unique_ptr< ValidationPolicy > innerPolicy)
Set inner policy.
static time_point now() noexcept
static time_point now() noexcept
::boost::chrono::time_point< system_clock > time_point
constexpr size_t MIN_SIZE
Minimum number of name components for a Command Interest.
constexpr ssize_t POS_TIMESTAMP
Contains the ndn-cxx security framework.
SimpleTag< SignedInterestFormat, 1002 > SignedInterestFormatTag
@ V03
Sign Interest using Packet Specification v0.3 semantics.
SignatureInfo getSignatureInfo(const Interest &interest, ValidationState &state)
Extract SignatureInfo from a signed Interest.
Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
Extract the KeyLocator name from a SignatureInfo element.
constexpr system_clock::time_point fromUnixTimestamp(system_clock::duration d)
Convert UNIX timestamp to system_clock::time_point.
::boost::chrono::milliseconds milliseconds