Vanetza
Loading...
Searching...
No Matches
peer_request_tracker.hpp
1#ifndef A5037FF9_14E0_4DA9_8027_6C0692B1462B
2#define A5037FF9_14E0_4DA9_8027_6C0692B1462B
3
4#include <vanetza/security/hashed_id.hpp>
5#include <boost/optional/optional.hpp>
6#include <list>
7#include <unordered_map>
8
9namespace vanetza
10{
11namespace security
12{
13
14class PeerRequestTracker
15{
16public:
17 explicit PeerRequestTracker(std::size_t limit = 16);
18
19 /**
20 * Add a certificate request to the tracker.
21 *
22 * \param id hash of requested certificate
23 */
24 void add_request(const HashedId3&);
25
26 /**
27 * Discard a pending certificate request.
28 *
29 * \param id hash of certificate
30 */
31 void discard_request(const HashedId3&);
32
33 /**
34 * Check if a certificate request is pending.
35 *
36 * \param id hash of certificate
37 * \return true if request of this certificate is pending
38 */
39 bool is_pending(const HashedId3&) const;
40
41 /**
42 * Determine which request shall be handled next and remove it from the queue.
43 *
44 * \return hash of requested certificate if any
45 */
46 boost::optional<HashedId3> next_one();
47
48 /**
49 * Retrieve next n pending requests from tracker.
50 *
51 * \return list of up to n certificate hashes
52 */
53 std::list<HashedId3> next_n(std::size_t max);
54
55 /**
56 * Retrieve all pending requests from tracker.
57 *
58 * \return list of all pending certificate hashes
59 */
60 std::list<HashedId3> all();
61
62private:
63 using FifoQueue = std::list<HashedId3>;
64 using LookupMap = std::unordered_map<HashedId3, FifoQueue::iterator>;
65
66 std::size_t m_limit;
67 FifoQueue m_fifo;
68 LookupMap m_lookup;
69};
70
71} // namespace security
72} // namespace vanetza
73
74#endif /* A5037FF9_14E0_4DA9_8027_6C0692B1462B */
std::list< HashedId3 > next_n(std::size_t max)
bool is_pending(const HashedId3 &) const
boost::optional< HashedId3 > next_one()