Back to Site
Loading...
Searching...
No Matches
reconnection.h File Reference

Keeps connections to a set of peer addresses alive with backoff. More...

#include "node/peer_network.h"
#include "peer/peer.h"
#include "core/address.h"
#include "peer/peer_id.h"
#include "peer/peer_book.h"
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
Include dependency graph for reconnection.h:

Go to the source code of this file.

Classes

class  librats::ReconnectionService
 
struct  librats::ReconnectionService::Config
 

Namespaces

namespace  librats
 

Detailed Description

Keeps connections to a set of peer addresses alive with backoff.

A Subsystem that remembers peer addresses (optionally persisted via PeerBook) and re-dials them when they drop, using exponential backoff. Built only on PeerNetwork: it dials via connect() and, each tick, reconciles its targets against the set of currently-connected peers (PeerNetwork::peers(), whose addresses include the dialable endpoints learned via identify). A target whose address is served by a live peer — over ANY route, inbound or outbound — is left alone; only the rest are dialed. Reconciling against this snapshot, rather than trusting a flag toggled on the connect event, is what stops us from endlessly re-dialing a peer already connected over a link we did not initiate (an inbound link, or a cross-connect the directory resolved to the other side).

A target is dropped when the app calls remove(), or — if Config::max_attempts is set — after that many consecutive failed dials without ever connecting (it "gives up", freeing memory and pruning the store). A successful connection resets the attempt counter, so only persistently-dead addresses are reaped.

Definition in file reconnection.h.