Skip to content

Commit

Permalink
refactor, doc: Improve SetupAddressRelay call in version processing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mzumsande and amitiuttarwar committed Nov 23, 2022
1 parent 3c43d9d commit 956c670
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3274,13 +3274,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
m_num_preferred_download_peers += state->fPreferredDownload;
}

if (!pfrom.IsInboundConn() && SetupAddressRelay(pfrom, *peer)) {
// For outbound peers, we do a one-time address fetch
// (to help populate/update our addrman).
// Attempt to initialize address relay for outbound peers and use result
// to decide whether to send GETADDR, so that we don't send it to
// 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
// empty and no one will know who we are, so this mechanism is
// important to help us connect to the network.
//
// empty, so this mechanism is important to help us connect to the network.
// We skip this for block-relay-only peers. We want to avoid
// potentially leaking addr information and we do not want to
// indicate to the peer that we will participate in addr relay.
Expand Down Expand Up @@ -5214,8 +5218,9 @@ bool PeerManagerImpl::SetupAddressRelay(const CNode& node, Peer& peer)
if (node.IsBlockOnlyConn()) return false;

if (!peer.m_addr_relay_enabled.exchange(true)) {
// First addr message we have received from the peer, initialize
// m_addr_known
// During version message processing (non-block-relay-only outbound peers)
// 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);
}

Expand Down

0 comments on commit 956c670

Please sign in to comment.