24 #include <boost/lexical_cast.hpp> 36 return os <<
"command Interest name is too short";
38 return os <<
"cannot parse timestamp";
40 return os <<
"cannot parse SignatureInfo";
42 return os <<
"KeyLocator is missing";
44 return os <<
"KeyLocator type is not Name";
46 return os <<
"cannot parse certificate name";
48 return os <<
"timestamp is out of grace period";
50 return os <<
"timestamp is less than or equal to last timestamp";
59 reject(interest.shared_from_this(), boost::lexical_cast<std::string>(error));
64 : m_inner(
std::move(inner))
66 , m_index(m_container.get<0>())
67 , m_queue(m_container.get<1>())
69 if (m_inner ==
nullptr) {
70 BOOST_THROW_EXCEPTION(std::invalid_argument(
"inner validator is nullptr"));
80 std::vector<shared_ptr<ValidationRequest>>& nextSteps)
82 BOOST_ASSERT(nSteps == 0);
87 ErrorCode res = this->parseCommandInterest(interest, keyName, timestamp);
94 m_inner->validate(interest,
95 [=] (
const shared_ptr<const Interest>& interest) {
96 ErrorCode res = this->checkTimestamp(keyName, timestamp, receiveTime);
105 CommandInterestValidator::cleanup()
109 while ((!m_queue.empty() && m_queue.front().lastRefreshed <= expiring) ||
111 m_queue.size() >
static_cast<size_t>(m_options.
maxTimestamps))) {
117 CommandInterestValidator::parseCommandInterest(
const Interest& interest,
Name& keyName,
118 uint64_t& timestamp)
const 129 timestamp = timestampComp.
toNumber();
159 CommandInterestValidator::checkTimestamp(
const Name& keyName, uint64_t timestamp,
167 std::tie(i, isNew) = m_queue.push_back({keyName, timestamp, now});
179 BOOST_ASSERT(i->keyName == keyName);
182 if (timestamp <= i->timestamp) {
188 isNew = m_queue.push_back({keyName, timestamp, now}).second;
199 std::vector<shared_ptr<ValidationRequest>>& nextSteps)
201 BOOST_ASSERT(nSteps == 0);
202 m_inner->validate(data, accept, reject);
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
Copyright (c) 2011-2015 Regents of the University of California.
const KeyLocator & getKeyLocator() const
Get KeyLocator.
static time_point now() noexcept
time::nanoseconds timestampTtl
max lifetime of a last timestamp record
const Name & getName() const
get Name element
represents an Interest packet
const ssize_t POS_TIMESTAMP
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.
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.
bool isNumber() const
Check if the component is nonNegativeInteger.
Table::const_iterator iterator
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
const size_t MIN_LENGTH
minimal number of components for Command Interest
bool hasKeyLocator() const
Check if KeyLocator is set.
CommandInterestValidator(unique_ptr< Validator > inner, const Options &options=Options())
constructor
static void invokeReject(const OnInterestValidationFailed &reject, const Interest &interest, CommandInterestValidator::ErrorCode error)
virtual 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
Name abstraction to represent an absolute name.
size_t size() const
Get the number of components.
uint64_t toNumber() const
Interpret this name component as nonNegativeInteger.
Component holds a read-only name component value.
void wireDecode(const Block &wire)
Decode from a wire format.
system_clock::TimePoint fromUnixTimestamp(const milliseconds &duration)
Convert UNIX timestamp to system_clock::TimePoint.
const ssize_t POS_SIG_INFO
ssize_t maxTimestamps
max number of distinct public keys to record last timestamp
represents an error in TLV encoding or decoding
const Name & getName() const