From 956c67059caf3807b3ceacdd5de1caaae538f009 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Fri, 30 Sep 2022 11:30:51 -0400 Subject: [PATCH] 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 --- src/net_processing.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 1adcb3695b..bc40a244c4 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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. @@ -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(5000, 0.001); }