obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
87 lines
1.9 KiB
C++
87 lines
1.9 KiB
C++
#include <vanetza/security/peer_request_tracker.hpp>
|
|
#include <cassert>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace security
|
|
{
|
|
|
|
PeerRequestTracker::PeerRequestTracker(std::size_t limit) : m_limit(limit)
|
|
{
|
|
}
|
|
|
|
void PeerRequestTracker::add_request(const HashedId3& id)
|
|
{
|
|
if (!is_pending(id)) {
|
|
// drop tail item when queue becomes full
|
|
if (m_fifo.size() >= m_limit && !m_fifo.empty()) {
|
|
m_lookup.erase(m_fifo.front());
|
|
m_fifo.pop_front();
|
|
}
|
|
|
|
auto inserted = m_fifo.insert(m_fifo.end(), id);
|
|
m_lookup.emplace(id, inserted);
|
|
}
|
|
|
|
assert(m_fifo.size() == m_lookup.size());
|
|
}
|
|
|
|
void PeerRequestTracker::discard_request(const HashedId3& id)
|
|
{
|
|
auto found = m_lookup.find(id);
|
|
if (found != m_lookup.end()) {
|
|
m_fifo.erase(found->second);
|
|
m_lookup.erase(found);
|
|
}
|
|
|
|
assert(m_fifo.size() == m_lookup.size());
|
|
}
|
|
|
|
bool PeerRequestTracker::is_pending(const HashedId3& id) const
|
|
{
|
|
return m_lookup.find(id) != m_lookup.end();
|
|
}
|
|
|
|
boost::optional<HashedId3> PeerRequestTracker::next_one()
|
|
{
|
|
boost::optional<HashedId3> next;
|
|
if (!m_fifo.empty()) {
|
|
next = m_fifo.front();
|
|
m_fifo.pop_front();
|
|
m_lookup.erase(*next);
|
|
}
|
|
|
|
assert(m_fifo.size() == m_lookup.size());
|
|
return next;
|
|
}
|
|
|
|
std::list<HashedId3> PeerRequestTracker::next_n(std::size_t max)
|
|
{
|
|
if (max >= m_fifo.size()) {
|
|
return all();
|
|
} else {
|
|
std::list<HashedId3> next;
|
|
auto from = m_fifo.begin();
|
|
auto to = std::next(from, max);
|
|
next.splice(next.begin(), m_fifo, from, to);
|
|
|
|
for (const HashedId3& id : next) {
|
|
m_lookup.erase(id);
|
|
}
|
|
|
|
assert(m_fifo.size() == m_lookup.size());
|
|
return next;
|
|
}
|
|
}
|
|
|
|
std::list<HashedId3> PeerRequestTracker::all()
|
|
{
|
|
m_lookup.clear();
|
|
std::list<HashedId3> all;
|
|
all.splice(all.begin(), m_fifo, m_fifo.begin(), m_fifo.end());
|
|
return all;
|
|
}
|
|
|
|
} // namespace security
|
|
} // namespace vanetza
|