lokinet/llarp/router/rc_gossiper.hpp

58 lines
1015 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 RouterContact;
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 RouterContact& rc);
2020-01-30 17:23:16 +00:00
void
Decay(Time_t now);
bool
ShouldGossipOurRC(Time_t now) const;
bool
IsOurRC(const RouterContact& 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