lokinet/llarp/router/rc_gossiper.hpp

58 lines
997 B
C++
Raw Normal View History

#pragma once
2020-01-30 17:23:16 +00:00
#include <llarp/router_id.hpp>
#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;
/// The maximum number of peers we will flood a gossiped RC to when propagating an RC
constexpr size_t MaxGossipPeers = 20;
struct LinkManager;
struct LocalRC;
struct RCGossiper
2020-01-30 17:23:16 +00:00
{
using Time_t = Duration_t;
2020-01-30 17:23:16 +00:00
RCGossiper();
~RCGossiper() = default;
2020-01-30 17:23:16 +00:00
bool
GossipRC(const LocalRC& rc);
2020-01-30 17:23:16 +00:00
void
Decay(Time_t now);
bool
ShouldGossipOurRC(Time_t now) const;
bool
IsOurRC(const LocalRC& rc) const;
2020-01-30 17:23:16 +00:00
void
Init(LinkManager*, const RouterID&, Router*);
2020-01-30 17:23:16 +00:00
void
Forget(const RouterID& router);
TimePoint_t
NextGossipAt() const;
std::optional<TimePoint_t>
LastGossipAt() const;
2020-01-30 17:23:16 +00:00
private:
RouterID rid;
Time_t last_rc_gossip = 0s;
LinkManager* link_manager = nullptr;
util::DecayingHashSet<RouterID> filter;
2020-03-04 00:50:20 +00:00
Router* router;
2020-01-30 17:23:16 +00:00
};
} // namespace llarp