Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Functions
eviction.cpp File Reference
#include <node/eviction.h>
#include <algorithm>
#include <array>
#include <chrono>
#include <cstdint>
#include <functional>
#include <map>
#include <vector>
Include dependency graph for eviction.cpp:

Go to the source code of this file.

Classes

struct  CompareNodeNetworkTime
 Sort eviction candidates by network/localhost and connection uptime. More...
 

Functions

static bool ReverseCompareNodeMinPingTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool ReverseCompareNodeTimeConnected (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNetGroupKeyed (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNodeBlockTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNodeTXTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNodeBlockRelayOnlyTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
template<typename T , typename Comparator >
static void EraseLastKElements (std::vector< T > &elements, Comparator comparator, size_t k, std::function< bool(const NodeEvictionCandidate &)> predicate=[](const NodeEvictionCandidate &n) { return true;})
 Sort an array by the specified comparator, then erase the last K elements where predicate is true. More...
 
void ProtectNoBanConnections (std::vector< NodeEvictionCandidate > &eviction_candidates)
 
void ProtectOutboundConnections (std::vector< NodeEvictionCandidate > &eviction_candidates)
 
void ProtectEvictionCandidatesByRatio (std::vector< NodeEvictionCandidate > &eviction_candidates)
 Protect desirable or disadvantaged inbound peers from eviction by ratio. More...
 
std::optional< NodeIdSelectNodeToEvict (std::vector< NodeEvictionCandidate > &&vEvictionCandidates)
 Select an inbound peer to evict after filtering out (protecting) peers having distinct, difficult-to-forge characteristics. More...
 

Function Documentation

◆ CompareNetGroupKeyed()

static bool CompareNetGroupKeyed ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

Definition at line 26 of file eviction.cpp.

Here is the caller graph for this function:

◆ CompareNodeBlockRelayOnlyTime()

static bool CompareNodeBlockRelayOnlyTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

Definition at line 48 of file eviction.cpp.

Here is the caller graph for this function:

◆ CompareNodeBlockTime()

static bool CompareNodeBlockTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

Definition at line 30 of file eviction.cpp.

Here is the caller graph for this function:

◆ CompareNodeTXTime()

static bool CompareNodeTXTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

Definition at line 38 of file eviction.cpp.

Here is the caller graph for this function:

◆ EraseLastKElements()

template<typename T , typename Comparator >
static void EraseLastKElements ( std::vector< T > &  elements,
Comparator  comparator,
size_t  k,
std::function< bool(const NodeEvictionCandidate &)>  predicate = [](const NodeEvictionCandidate& n) { return true; } 
)
static

Sort an array by the specified comparator, then erase the last K elements where predicate is true.

Definition at line 78 of file eviction.cpp.

Here is the caller graph for this function:

◆ ProtectEvictionCandidatesByRatio()

void ProtectEvictionCandidatesByRatio ( std::vector< NodeEvictionCandidate > &  vEvictionCandidates)

Protect desirable or disadvantaged inbound peers from eviction by ratio.

This function protects half of the peers which have been connected the longest, to replicate the non-eviction implicit behavior and preclude attacks that start later.

Half of these protected spots (1/4 of the total) are reserved for the following categories of peers, sorted by longest uptime, even if they're not longest uptime overall:

  • onion peers connected via our tor control service
  • localhost peers, as manually configured hidden services not using -bind=addr[:port]=onion will not be detected as inbound onion connections
  • I2P peers
  • CJDNS peers

This helps protect these privacy network peers, which tend to be otherwise disadvantaged under our eviction criteria for their higher min ping times relative to IPv4/IPv6 peers, and favorise the diversity of peer connections.

Definition at line 105 of file eviction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProtectNoBanConnections()

void ProtectNoBanConnections ( std::vector< NodeEvictionCandidate > &  eviction_candidates)

Definition at line 87 of file eviction.cpp.

Here is the caller graph for this function:

◆ ProtectOutboundConnections()

void ProtectOutboundConnections ( std::vector< NodeEvictionCandidate > &  eviction_candidates)

Definition at line 96 of file eviction.cpp.

Here is the caller graph for this function:

◆ ReverseCompareNodeMinPingTime()

static bool ReverseCompareNodeMinPingTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

Definition at line 16 of file eviction.cpp.

Here is the caller graph for this function:

◆ ReverseCompareNodeTimeConnected()

static bool ReverseCompareNodeTimeConnected ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

Definition at line 21 of file eviction.cpp.

Here is the caller graph for this function:

◆ SelectNodeToEvict()

std::optional< NodeId > SelectNodeToEvict ( std::vector< NodeEvictionCandidate > &&  vEvictionCandidates)

Select an inbound peer to evict after filtering out (protecting) peers having distinct, difficult-to-forge characteristics.

The protection logic picks out fixed numbers of desirable peers per various criteria, followed by (mostly) ratios of desirable or disadvantaged peers. If any eviction candidates remain, the selection logic chooses a peer to evict.

Definition at line 178 of file eviction.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: