Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/security/peer_request_tracker.cpp
T
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

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