31 , m_index(m_container.get<0>())
32 , m_queue(m_container.get<1>())
34 if (inner ==
nullptr) {
35 NDN_THROW(std::invalid_argument(
"inner policy is missing"));
56 std::tie(isOk, keyName, timestamp) = parseCommandInterest(interest, state);
61 if (!checkTimestamp(state, keyName, timestamp)) {
68 std::tuple<bool, Name, time::system_clock::TimePoint>
69 ValidationPolicyCommandInterest::parseCommandInterest(
const Interest& interest,
70 const shared_ptr<ValidationState>& state)
73 if (!state->getOutcome()) {
84 auto optionalTimestamp = sigInfo.getTime();
85 if (!optionalTimestamp) {
87 interest.
getName().toUri() +
"` lacks required SignatureTime element"});
91 timestamp = *optionalTimestamp;
97 "Command Interest name too short `" + interest.
getName().toUri() +
"`"});
102 if (!timestampComp.isNumber()) {
104 interest.
getName().toUri() +
"` lacks required timestamp component"});
112 if (!state->getOutcome()) {
116 return std::make_tuple(
true, klName, timestamp);
120 ValidationPolicyCommandInterest::cleanup()
124 while ((!m_queue.empty() && m_queue.front().lastRefreshed <= expiring) ||
126 m_queue.size() >
static_cast<size_t>(m_options.
maxRecords))) {
132 ValidationPolicyCommandInterest::checkTimestamp(
const shared_ptr<ValidationState>& state,
139 if (timestamp < now - m_options.gracePeriod || timestamp > now + m_options.
gracePeriod) {
141 "Timestamp is outside the grace period for key " + keyName.toUri()});
145 auto it = m_index.find(keyName);
146 if (it != m_index.end()) {
147 if (timestamp <= it->timestamp) {
149 "Timestamp is reordered for key " + keyName.toUri()});
154 auto interestState = dynamic_pointer_cast<InterestValidationState>(state);
155 BOOST_ASSERT(interestState !=
nullptr);
156 interestState->afterSuccess.connect([=] (
const Interest&) { insertNewRecord(keyName, timestamp); });
165 auto i = m_queue.end();
167 LastTimestampRecord newRecord{keyName, timestamp, now};
168 std::tie(i, isNew) = m_queue.push_back(newRecord);
171 BOOST_ASSERT(i->keyName == keyName);
175 isNew = m_queue.push_back(newRecord).second;
Represents a Data packet.
Represents an Interest packet.
const Name & getName() const noexcept
Represents an absolute 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 recordLifetime
Max lifetime of a last timestamp record.
ssize_t maxRecords
Max number of distinct public keys of which to record the last timestamp.
time::nanoseconds gracePeriod
Tolerance of initial timestamp.
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.
ValidationPolicy & getInnerPolicy()
Return the inner policy.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
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
const size_t MIN_SIZE
Minimum number of name components for a Command Interest.
const ssize_t POS_TIMESTAMP
SimpleTag< SignedInterestFormat, 1002 > SignedInterestFormatTag
Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
Extract the KeyLocator name from a SignatureInfo element.
SignatureInfo getSignatureInfo(const Interest &interest, ValidationState &state)
Extract SignatureInfo from a signed Interest.
@ V03
Sign Interest using Packet Specification v0.3 semantics.
boost::chrono::milliseconds milliseconds
system_clock::time_point fromUnixTimestamp(milliseconds duration)
Convert UNIX timestamp to system_clock::time_point.