2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2020-01-30 17:23:16 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/util/decaying_hashset.hpp>
|
2023-09-13 19:57:18 +00:00
|
|
|
#include "outbound_message_handler.hpp"
|
|
|
|
#include <llarp/link/link_manager.hpp>
|
2020-01-30 17:23:16 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
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-09-13 19:57:18 +00:00
|
|
|
GossipRC(const RouterContact& 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-09-13 19:57:18 +00:00
|
|
|
IsOurRC(const RouterContact& 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
|