2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2020-01-30 17:23:16 +00:00
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <llarp/router_id.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/decaying_hashset.hpp>
|
2023-10-12 20:37:45 +00:00
|
|
|
|
|
|
|
#include <optional>
|
2020-01-30 17:23:16 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2023-10-12 20:37:45 +00:00
|
|
|
struct Router;
|
|
|
|
|
2023-09-13 19:57:18 +00:00
|
|
|
/// The maximum number of peers we will flood a gossiped RC to when propagating an RC
|
|
|
|
constexpr size_t MaxGossipPeers = 20;
|
2023-09-18 21:50:07 +00:00
|
|
|
struct LinkManager;
|
2023-11-02 12:30:38 +00:00
|
|
|
struct LocalRC;
|
2023-09-13 19:57:18 +00:00
|
|
|
|
|
|
|
struct RCGossiper
|
2020-01-30 17:23:16 +00:00
|
|
|
{
|
2023-09-13 19:57:18 +00:00
|
|
|
using Time_t = Duration_t;
|
|
|
|
|
2020-01-30 17:23:16 +00:00
|
|
|
RCGossiper();
|
|
|
|
|
2023-09-13 19:57:18 +00:00
|
|
|
~RCGossiper() = default;
|
2020-01-30 17:23:16 +00:00
|
|
|
|
|
|
|
bool
|
2023-11-02 12:30:38 +00:00
|
|
|
GossipRC(const LocalRC& rc);
|
2020-01-30 17:23:16 +00:00
|
|
|
|
|
|
|
void
|
2023-09-13 19:57:18 +00:00
|
|
|
Decay(Time_t now);
|
2020-01-30 22:10:56 +00:00
|
|
|
|
|
|
|
bool
|
2023-09-13 19:57:18 +00:00
|
|
|
ShouldGossipOurRC(Time_t now) const;
|
2020-01-30 22:10:56 +00:00
|
|
|
|
|
|
|
bool
|
2023-11-02 12:30:38 +00:00
|
|
|
IsOurRC(const LocalRC& rc) const;
|
2020-01-30 17:23:16 +00:00
|
|
|
|
|
|
|
void
|
2023-09-15 14:55:32 +00:00
|
|
|
Init(LinkManager*, const RouterID&, Router*);
|
2020-01-30 17:23:16 +00:00
|
|
|
|
2022-05-03 20:05:22 +00:00
|
|
|
void
|
2023-09-13 19:57:18 +00:00
|
|
|
Forget(const RouterID& router);
|
2022-05-03 20:05:22 +00:00
|
|
|
|
2022-05-04 14:37:35 +00:00
|
|
|
TimePoint_t
|
2023-09-13 19:57:18 +00:00
|
|
|
NextGossipAt() const;
|
2022-05-04 14:37:35 +00:00
|
|
|
|
|
|
|
std::optional<TimePoint_t>
|
2023-09-13 19:57:18 +00:00
|
|
|
LastGossipAt() const;
|
2022-05-04 14:37:35 +00:00
|
|
|
|
2020-01-30 17:23:16 +00:00
|
|
|
private:
|
2023-09-15 14:55:32 +00:00
|
|
|
RouterID rid;
|
|
|
|
Time_t last_rc_gossip = 0s;
|
|
|
|
LinkManager* link_manager = nullptr;
|
|
|
|
util::DecayingHashSet<RouterID> filter;
|
2020-03-04 00:50:20 +00:00
|
|
|
|
2023-09-15 14:55:32 +00:00
|
|
|
Router* router;
|
2020-01-30 17:23:16 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp
|