mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-09 18:00:13 +02:00
Merge bitcoin/bitcoin#24165: p2p: extend inbound eviction protection by network to CJDNS peers
b7be28cac5
test: add combined CJDNS/I2P/localhost/onion eviction protection tests (Jon Atack)0a1bb84770
test: add tests for inbound eviction protection of CJDNS peers (Jon Atack)0c00c0c981
test: fix off-by-one logic in an eviction protection test (Jon Atack)f7b8094d61
p2p: extend inbound eviction protection by network to CJDNS peers (Jon Atack) Pull request description: Extend inbound eviction protection for peers connected over CJDNS, as is the case for peers connected via onion, localhost, and I2P since #21261 and #20197. CJDNS peers seem to have better min ping latency than onion and I2P peers but still higher than that of unencrypted IPv4/6 peers and can be disadvantaged under our eviction criteria. They are also very few in number, which is a further reason to protect them, as the goal of this logic is to favorise the diversity of our peer connections. CJDNS support was added in #23077 for the upcoming v23 release. ACKs for top commit: laanwj: Concept and code review ACKb7be28cac5
w0xlt: tACKb7be28c
Tree-SHA512: 89ebdd217602e16ae14b9bd0d5a25fc09f9b2384c951f820bc0f5a6d8452bbc9042065db817d5d5296c0ad22988491a83fc5b9a611e660c40ebd4f03448c4061
This commit is contained in:
12
src/net.cpp
12
src/net.cpp
@ -928,17 +928,17 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
|
||||
// Protect the half of the remaining nodes which have been connected the longest.
|
||||
// This replicates the non-eviction implicit behavior, and precludes attacks that start later.
|
||||
// To favorise the diversity of our peer connections, reserve up to half of these protected
|
||||
// spots for Tor/onion, localhost and I2P peers, even if they're not longest uptime overall.
|
||||
// This helps protect these higher-latency peers that tend to be otherwise
|
||||
// spots for Tor/onion, localhost, I2P, and CJDNS peers, even if they're not longest uptime
|
||||
// overall. This helps protect these higher-latency peers that tend to be otherwise
|
||||
// disadvantaged under our eviction criteria.
|
||||
const size_t initial_size = eviction_candidates.size();
|
||||
const size_t total_protect_size{initial_size / 2};
|
||||
|
||||
// Disadvantaged networks to protect: I2P, localhost, Tor/onion. In case of equal counts, earlier
|
||||
// array members have first opportunity to recover unused slots from the previous iteration.
|
||||
// Disadvantaged networks to protect. In the case of equal counts, earlier array members
|
||||
// have the first opportunity to recover unused slots from the previous iteration.
|
||||
struct Net { bool is_local; Network id; size_t count; };
|
||||
std::array<Net, 3> networks{
|
||||
{{false, NET_I2P, 0}, {/* localhost */ true, NET_MAX, 0}, {false, NET_ONION, 0}}};
|
||||
std::array<Net, 4> networks{
|
||||
{{false, NET_CJDNS, 0}, {false, NET_I2P, 0}, {/*localhost=*/true, NET_MAX, 0}, {false, NET_ONION, 0}}};
|
||||
|
||||
// Count and store the number of eviction candidates per network.
|
||||
for (Net& n : networks) {
|
||||
|
Reference in New Issue
Block a user