refactor, doc: Improve SetupAddressRelay call in version processing

This code was a bit hard to understand, so make it less dense and
add more explanations. Doesn't change behavior.

Co-authored-by: Amiti Uttarwar <amiti@uttarwar.org>
This commit is contained in:
Martin Zumsande 2022-09-30 11:30:51 -04:00
parent 3c43d9db1e
commit 956c67059c

View File

@ -3274,13 +3274,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
m_num_preferred_download_peers += state->fPreferredDownload; m_num_preferred_download_peers += state->fPreferredDownload;
} }
if (!pfrom.IsInboundConn() && SetupAddressRelay(pfrom, *peer)) { // Attempt to initialize address relay for outbound peers and use result
// For outbound peers, we do a one-time address fetch // to decide whether to send GETADDR, so that we don't send it to
// (to help populate/update our addrman). // inbound or outbound block-relay-only peers.
bool send_getaddr{false};
if (!pfrom.IsInboundConn()) {
send_getaddr = SetupAddressRelay(pfrom, *peer);
}
if (send_getaddr) {
// Do a one-time address fetch to help populate/update our addrman.
// If we're starting up for the first time, our addrman may be pretty // If we're starting up for the first time, our addrman may be pretty
// empty and no one will know who we are, so this mechanism is // empty, so this mechanism is important to help us connect to the network.
// important to help us connect to the network.
//
// We skip this for block-relay-only peers. We want to avoid // We skip this for block-relay-only peers. We want to avoid
// potentially leaking addr information and we do not want to // potentially leaking addr information and we do not want to
// indicate to the peer that we will participate in addr relay. // indicate to the peer that we will participate in addr relay.
@ -5214,8 +5218,9 @@ bool PeerManagerImpl::SetupAddressRelay(const CNode& node, Peer& peer)
if (node.IsBlockOnlyConn()) return false; if (node.IsBlockOnlyConn()) return false;
if (!peer.m_addr_relay_enabled.exchange(true)) { if (!peer.m_addr_relay_enabled.exchange(true)) {
// First addr message we have received from the peer, initialize // During version message processing (non-block-relay-only outbound peers)
// m_addr_known // or on first addr-related message we have received (inbound peers), initialize
// m_addr_known.
peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001); peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
} }