28#include "peer/peer_book.h"
32#include <condition_variable>
37#include <unordered_map>
53 std::chrono::milliseconds
tick{1000};
87 std::chrono::steady_clock::time_point next_attempt;
88 std::chrono::steady_clock::time_point dial_deadline;
91 void on_connected(
const Peer& peer);
92 void on_disconnected(
const PeerId&
id);
93 void on_dial_failed(
const Address& address);
95 std::chrono::milliseconds backoff_for(
int attempts)
const;
103 std::unique_ptr<PeerBook> book_;
106 std::atomic<bool> running_{
false};
107 std::mutex wait_mutex_;
108 std::condition_variable wake_;
110 mutable std::mutex mutex_;
111 std::unordered_map<std::string, Target> targets_;
A dialable transport address (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.
size_t max_targets
cap on ACTIVE re-dial targets (bounds memory + dial fan-out)
size_t startup_targets
on start, actively re-dial this many best peers from the book
std::chrono::milliseconds base_backoff
std::chrono::milliseconds max_backoff
size_t max_attempts
give up actively dialing a target after this many consecutive failures; 0 = retry forever
std::chrono::milliseconds tick
bool persist_discovered
remember dialed peers automatically
std::chrono::milliseconds dial_timeout
assume an in-flight dial is dead after this if no connect/fail event arrives (backstop only)
size_t archive_max
cap on the persistent peer book (history of everyone we met)
std::string store_path
persist the peer book here (empty = memory only)
std::chrono::seconds archive_max_age
forget peers unseen this long (30 days)