Skip to content

Commit 6061eb6

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26199: p2p: Don't self-advertise during version processing
956c670 refactor, doc: Improve SetupAddressRelay call in version processing (Martin Zumsande) 3c43d9d p2p: Don't self-advertise during VERSION processing (Gleb Naumenko) Pull request description: This picks up the last commit from #19843. Previously, we would prepare to self-announce to a new peer while parsing a `version` message from that peer. This is redundant, because we do something very similar in `MaybeSendAddr()`, which is called from `SendMessages()` after the version handshake is finished. There are a couple of differences: 1) `MaybeSendAddr()` self-advertises to all peers we do address relay with, not just outbound ones. 2) `GetLocalAddrForPeer()` called from `MaybeSendAddr()` makes a probabilistic decision to either advertise what they think we are or what we think we are, while `PushAddress()` on `version` deterministically only does the former if the address from the latter is unroutable. 3) During `version` processing, we haven't received a potential sendaddrv2 message from our peer yet, so self-advertisements with addresses from addrV2-only networks would always be dropped in `PushAddress()`. Since it's confusing to have two slightly different mechanisms for self-advertising, and the one in `MaybeSendAddr()` is better, remove the one in `version`. ACKs for top commit: stratospher: ACK 956c670 naumenkogs: ACK 956c670 amitiuttarwar: reACK 956c670 Tree-SHA512: 933d40615289f055c022170dde7bad0ac0a1d4be377538bfe9ba64375cfeb03bcd803901591f0739ac4850c880e8475a68fd1ab0330800030ab7f19e38c00274
2 parents 1ea0279 + 956c670 commit 6061eb6

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

src/net_processing.cpp

+14-32
Original file line numberDiff line numberDiff line change
@@ -3303,39 +3303,20 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
33033303
m_num_preferred_download_peers += state->fPreferredDownload;
33043304
}
33053305

3306-
// Self advertisement & GETADDR logic
3307-
if (!pfrom.IsInboundConn() && SetupAddressRelay(pfrom, *peer)) {
3308-
// For outbound peers, we try to relay our address (so that other
3309-
// nodes can try to find us more quickly, as we have no guarantee
3310-
// that an outbound peer is even aware of how to reach us) and do a
3311-
// one-time address fetch (to help populate/update our addrman). If
3312-
// we're starting up for the first time, our addrman may be pretty
3313-
// empty and no one will know who we are, so these mechanisms are
3314-
// important to help us connect to the network.
3315-
//
3306+
// Attempt to initialize address relay for outbound peers and use result
3307+
// to decide whether to send GETADDR, so that we don't send it to
3308+
// inbound or outbound block-relay-only peers.
3309+
bool send_getaddr{false};
3310+
if (!pfrom.IsInboundConn()) {
3311+
send_getaddr = SetupAddressRelay(pfrom, *peer);
3312+
}
3313+
if (send_getaddr) {
3314+
// Do a one-time address fetch to help populate/update our addrman.
3315+
// If we're starting up for the first time, our addrman may be pretty
3316+
// empty, so this mechanism is important to help us connect to the network.
33163317
// We skip this for block-relay-only peers. We want to avoid
33173318
// potentially leaking addr information and we do not want to
33183319
// indicate to the peer that we will participate in addr relay.
3319-
if (fListen && !m_chainman.ActiveChainstate().IsInitialBlockDownload())
3320-
{
3321-
CAddress addr{GetLocalAddress(pfrom.addr), peer->m_our_services, Now<NodeSeconds>()};
3322-
FastRandomContext insecure_rand;
3323-
if (addr.IsRoutable())
3324-
{
3325-
LogPrint(BCLog::NET, "ProcessMessages: advertising address %s\n", addr.ToString());
3326-
PushAddress(*peer, addr, insecure_rand);
3327-
} else if (IsPeerAddrLocalGood(&pfrom)) {
3328-
// Override just the address with whatever the peer sees us as.
3329-
// Leave the port in addr as it was returned by GetLocalAddress()
3330-
// above, as this is an outbound connection and the peer cannot
3331-
// observe our listening port.
3332-
addr.SetIP(addrMe);
3333-
LogPrint(BCLog::NET, "ProcessMessages: advertising address %s\n", addr.ToString());
3334-
PushAddress(*peer, addr, insecure_rand);
3335-
}
3336-
}
3337-
3338-
// Get recent addresses
33393320
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make(NetMsgType::GETADDR));
33403321
peer->m_getaddr_sent = true;
33413322
// When requesting a getaddr, accept an additional MAX_ADDR_TO_SEND addresses in response
@@ -5342,8 +5323,9 @@ bool PeerManagerImpl::SetupAddressRelay(const CNode& node, Peer& peer)
53425323
if (node.IsBlockOnlyConn()) return false;
53435324

53445325
if (!peer.m_addr_relay_enabled.exchange(true)) {
5345-
// First addr message we have received from the peer, initialize
5346-
// m_addr_known
5326+
// During version message processing (non-block-relay-only outbound peers)
5327+
// or on first addr-related message we have received (inbound peers), initialize
5328+
// m_addr_known.
53475329
peer.m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
53485330
}
53495331

0 commit comments

Comments
 (0)