Bitcoin Core 28.99.0
P2P Digital Currency
|
#include <node/eviction.h>
#include <algorithm>
#include <array>
#include <chrono>
#include <cstdint>
#include <functional>
#include <map>
#include <vector>
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< NodeId > | SelectNodeToEvict (std::vector< NodeEvictionCandidate > &&vEvictionCandidates) |
Select an inbound peer to evict after filtering out (protecting) peers having distinct, difficult-to-forge characteristics. More... | |
|
static |
|
static |
|
static |
|
static |
|
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.
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:
-bind=addr[:port]=onion
will not be detected as inbound onion connectionsThis 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.
void ProtectNoBanConnections | ( | std::vector< NodeEvictionCandidate > & | eviction_candidates | ) |
void ProtectOutboundConnections | ( | std::vector< NodeEvictionCandidate > & | eviction_candidates | ) |
|
static |
|
static |
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.