24#include "util/rats_export.h"
29#include "peer/peer_book.h"
33#include <condition_variable>
38#include <unordered_map>
45 std::string store_path =
"";
46 bool persist_discovered =
true;
47 size_t max_targets = 1024;
48 size_t max_attempts = 0;
49 size_t startup_targets = 32;
50 size_t archive_max = 4096;
51 std::chrono::seconds archive_max_age{std::chrono::hours(24 * 30)};
52 std::chrono::milliseconds base_backoff{1000};
53 std::chrono::milliseconds max_backoff{60000};
54 std::chrono::milliseconds tick{1000};
55 std::chrono::milliseconds dial_timeout{15000};
88 std::chrono::steady_clock::time_point next_attempt;
89 std::chrono::steady_clock::time_point dial_deadline;
96 void mark_connected(std::chrono::steady_clock::time_point now) {
103 void on_connected(
const Peer& peer);
104 void on_disconnected(
const PeerId&
id);
105 void on_dial_failed(
const Address& address);
107 std::chrono::milliseconds backoff_for(
int attempts)
const;
110 PeerNetwork* network_ =
nullptr;
115 std::unique_ptr<PeerBook> book_;
118 std::atomic<bool> running_{
false};
119 std::mutex wait_mutex_;
120 std::condition_variable wake_;
122 mutable std::mutex mutex_;
123 std::unordered_map<Address, Target> targets_;
A dialable transport endpoint: a numeric IP + port.
ReconnectionService(Config config)
std::vector< Address > known_peers(size_t n) const
The passive reserve pool: up to n best-known peer addresses from the book (history of everyone we hav...
size_t target_count() const
void add(const Address &address)
Register an address to keep connected. Persists it if a store is configured.
void remove(const Address &address)
Stop reconnecting to an address: drops it as a target and from the store.
~ReconnectionService() override
void attach(NodeContext &ctx) override
A pluggable network subsystem.
A lightweight handle to a connected peer.
Self-certifying peer identity.
The narrow contract a subsystem needs from the node — and nothing more.