Skip to content

Commit 956c670

Browse files
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>
1 parent 3c43d9d commit 956c670

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,13 +3274,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32743274
m_num_preferred_download_peers += state->fPreferredDownload;
32753275
}
32763276

3277-
if (!pfrom.IsInboundConn() && SetupAddressRelay(pfrom, *peer)) {
3278-
// For outbound peers, we do a one-time address fetch
3279-
// (to help populate/update our addrman).
3277+
// Attempt to initialize address relay for outbound peers and use result
3278+
// to decide whether to send GETADDR, so that we don't send it to
3279+
// inbound or outbound block-relay-only peers.
3280+
bool send_getaddr{false};
3281+
if (!pfrom.IsInboundConn()) {
3282+
send_getaddr = SetupAddressRelay(pfrom, *peer);
3283+
}
3284+
if (send_getaddr) {
3285+
// Do a one-time address fetch to help populate/update our addrman.
32803286
// If we're starting up for the first time, our addrman may be pretty
3281-
// empty and no one will know who we are, so this mechanism is
3282-
// important to help us connect to the network.
3283-
//
3287+
// empty, so this mechanism is important to help us connect to the network.
32843288
// We skip this for block-relay-only peers. We want to avoid
32853289
// potentially leaking addr information and we do not want to
32863290
// indicate to the peer that we will participate in addr relay.
@@ -5214,8 +5218,9 @@ bool PeerManagerImpl::SetupAddressRelay(const CNode& node, Peer& peer)
52145218
if (node.IsBlockOnlyConn()) return false;
52155219

52165220
if (!peer.m_addr_relay_enabled.exchange(true)) {
5217-
// First addr message we have received from the peer, initialize
5218-
// m_addr_known
5221+
// During version message processing (non-block-relay-only outbound peers)
5222+
// or on first addr-related message we have received (inbound peers), initialize
5223+
// m_addr_known.
52195224
peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
52205225
}
52215226

0 commit comments

Comments
 (0)