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"));
55 uint64_t timestamp = 0;
56 std::tie(isOk, keyName, timestamp) = parseCommandInterest(interest, state);
61 if (!checkTimestamp(state, keyName, timestamp)) {
68 ValidationPolicyCommandInterest::cleanup()
72 while ((!m_queue.empty() && m_queue.front().lastRefreshed <= expiring) ||
74 m_queue.size() >
static_cast<size_t>(m_options.
maxRecords))) {
79 std::tuple<bool, Name, uint64_t>
80 ValidationPolicyCommandInterest::parseCommandInterest(
const Interest& interest,
81 const shared_ptr<ValidationState>& state)
const
86 interest.
getName().toUri() +
"` is too short"});
87 return std::make_tuple(
false,
Name(), 0);
93 interest.
getName().toUri() +
"` doesn't include timestamp component"});
94 return std::make_tuple(
false,
Name(), 0);
98 if (!state->getOutcome()) {
99 return std::make_tuple(
false,
Name(), 0);
102 return std::make_tuple(
true, klName, timestampComp.
toNumber());
106 ValidationPolicyCommandInterest::checkTimestamp(
const shared_ptr<ValidationState>& state,
107 const Name& keyName, uint64_t timestamp)
113 if (timestampPoint < now - m_options.gracePeriod || timestampPoint > now + m_options.
gracePeriod) {
115 "Timestamp is outside the grace period for key " + keyName.toUri()});
119 auto it = m_index.find(keyName);
120 if (it != m_index.end()) {
121 if (timestamp <= it->timestamp) {
123 "Timestamp is reordered for key " + keyName.toUri()});
128 auto interestState = dynamic_pointer_cast<InterestValidationState>(state);
129 BOOST_ASSERT(interestState !=
nullptr);
130 interestState->afterSuccess.connect([=] (
const Interest&) { insertNewRecord(keyName, timestamp); });
135 ValidationPolicyCommandInterest::insertNewRecord(
const Name& keyName, uint64_t timestamp)
139 auto i = m_queue.end();
141 LastTimestampRecord newRecord{keyName, timestamp, now};
142 std::tie(i, isNew) = m_queue.push_back(newRecord);
145 BOOST_ASSERT(i->keyName == keyName);
149 isNew = m_queue.push_back(newRecord).second;