23 #include <boost/lexical_cast.hpp> 35 return os <<
"command Interest name is too short";
37 return os <<
"cannot parse timestamp";
39 return os <<
"cannot parse SignatureInfo";
41 return os <<
"KeyLocator is missing";
43 return os <<
"KeyLocator type is not Name";
45 return os <<
"cannot parse certificate name";
47 return os <<
"timestamp is out of grace period";
49 return os <<
"timestamp is less than or equal to last timestamp";
58 reject(interest.shared_from_this(), boost::lexical_cast<std::string>(error));
63 : m_inner(
std::move(inner))
65 , m_index(m_container.get<0>())
66 , m_queue(m_container.get<1>())
68 if (m_inner ==
nullptr) {
69 BOOST_THROW_EXCEPTION(std::invalid_argument(
"inner validator is nullptr"));
79 std::vector<shared_ptr<ValidationRequest>>& nextSteps)
81 BOOST_ASSERT(nSteps == 0);
86 ErrorCode res = this->parseCommandInterest(interest, keyName, timestamp);
93 m_inner->validate(interest,
94 [=] (
const shared_ptr<const Interest>& interest) {
95 ErrorCode res = this->checkTimestamp(keyName, timestamp, receiveTime);
104 CommandInterestValidator::cleanup()
108 while ((!m_queue.empty() && m_queue.front().lastRefreshed <= expiring) ||
110 m_queue.size() >
static_cast<size_t>(m_options.
maxTimestamps))) {
116 CommandInterestValidator::parseCommandInterest(
const Interest& interest,
Name& keyName,
117 uint64_t& timestamp)
const 128 timestamp = timestampComp.
toNumber();
150 catch (
const std::invalid_argument&) {
154 keyName = keyLocator.
getName();
160 CommandInterestValidator::checkTimestamp(
const Name& keyName, uint64_t timestamp,
166 Queue::iterator i = m_queue.end();
168 std::tie(i, isNew) = m_queue.push_back({keyName, timestamp, now});
180 BOOST_ASSERT(i->keyName == keyName);
183 if (timestamp <= i->timestamp) {
189 isNew = m_queue.push_back({keyName, timestamp, now}).second;
200 std::vector<shared_ptr<ValidationRequest>>& nextSteps)
202 BOOST_ASSERT(nSteps == 0);
203 m_inner->validate(data, accept, reject);
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
const Name & getName() const
Copyright (c) 2013-2017 Regents of the University of California.
Represents a SignatureInfo TLV element.
static time_point now() noexcept
time::nanoseconds timestampTtl
max lifetime of a last timestamp record
represents an Interest packet
indicates KeyLocator contains a Name
static time_point now() noexcept
function< void(const shared_ptr< const Data > &, const std::string &)> OnDataValidationFailed
Callback to report a failed Data validation.
const KeyLocator & getKeyLocator() const
Get KeyLocator.
std::ostream & operator<<(std::ostream &os, CommandInterestValidator::ErrorCode error)
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
function< void(const shared_ptr< const Data > &)> OnDataValidated
Callback to report a successful Data validation.
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
const Name & getName() const
get Name element
CommandInterestValidator(unique_ptr< Validator > inner, const Options &options=Options())
constructor
static void invokeReject(const OnInterestValidationFailed &reject, const Interest &interest, CommandInterestValidator::ErrorCode error)
void checkPolicy(const Interest &interest, int nSteps, const OnInterestValidated &accept, const OnInterestValidationFailed &reject, std::vector< shared_ptr< ValidationRequest >> &nextSteps) override
validate command Interest
time::nanoseconds gracePeriod
tolerance of initial timestamp
size_t size() const
Get number of components.
const size_t MIN_SIZE
minimal number of components for Command Interest
Represents an absolute name.
const Component & at(ssize_t i) const
Get the component at the given index.
Component holds a read-only name component value.
void wireDecode(const Block &wire)
Decode from wire format.
const ssize_t POS_TIMESTAMP
system_clock::TimePoint fromUnixTimestamp(const milliseconds &duration)
Convert UNIX timestamp to system_clock::TimePoint.
const ssize_t POS_SIG_INFO
bool isNumber() const
Check if the component is nonNegativeInteger.
ssize_t maxTimestamps
max number of distinct public keys to record last timestamp
bool hasKeyLocator() const
Check if KeyLocator exists.
Represents a Data packet.
uint64_t toNumber() const
Interpret this name component as nonNegativeInteger.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
represents an error in TLV encoding or decoding