Skip to content

Commit 8b1e156

Browse files
committed
Add m_inbound_onion to AttemptToEvictConnection()
and an `m_is_onion` struct member to NodeEvictionCandidate and tests. We'll use these in the peer eviction logic to protect inbound onion peers in addition to the existing protection of localhost peers.
1 parent 72e30e8 commit 8b1e156

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-1
lines changed

src/net.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,8 @@ bool CConnman::AttemptToEvictConnection()
992992
node->nLastBlockTime, node->nLastTXTime,
993993
HasAllDesirableServiceFlags(node->nServices),
994994
peer_relay_txes, peer_filter_not_null, node->nKeyedNetGroup,
995-
node->m_prefer_evict, node->addr.IsLocal()};
995+
node->m_prefer_evict, node->addr.IsLocal(),
996+
node->m_inbound_onion};
996997
vEvictionCandidates.push_back(candidate);
997998
}
998999
}

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class CNode
425425

426426
std::atomic<int64_t> nLastSend{0};
427427
std::atomic<int64_t> nLastRecv{0};
428+
//! Unix epoch time at peer connection, in seconds.
428429
const int64_t nTimeConnected;
429430
std::atomic<int64_t> nTimeOffset{0};
430431
// Address of this peer
@@ -1281,6 +1282,7 @@ struct NodeEvictionCandidate
12811282
uint64_t nKeyedNetGroup;
12821283
bool prefer_evict;
12831284
bool m_is_local;
1285+
bool m_is_onion;
12841286
};
12851287

12861288
/**

src/test/fuzz/node_eviction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ FUZZ_TARGET(node_eviction)
3131
/* nKeyedNetGroup */ fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
3232
/* prefer_evict */ fuzzed_data_provider.ConsumeBool(),
3333
/* m_is_local */ fuzzed_data_provider.ConsumeBool(),
34+
/* m_is_onion */ fuzzed_data_provider.ConsumeBool(),
3435
});
3536
}
3637
// Make a copy since eviction_candidates may be in some valid but otherwise

src/test/net_peer_eviction_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(const int n_c
3636
/* nKeyedNetGroup */ random_context.randrange(100),
3737
/* prefer_evict */ random_context.randbool(),
3838
/* m_is_local */ random_context.randbool(),
39+
/* m_is_onion */ random_context.randbool(),
3940
});
4041
}
4142
return candidates;

0 commit comments

Comments
 (0)