Skip to content

Commit 3c43d9d

Browse files
naumenkogsmzumsande
andcommitted
p2p: Don't self-advertise during VERSION processing
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(self) 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. Co-authored-by: Martin Zumsande <[email protected]>
1 parent b2da6dd commit 3c43d9d

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/net_processing.cpp

+4-27
Original file line numberDiff line numberDiff line change
@@ -3274,39 +3274,16 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32743274
m_num_preferred_download_peers += state->fPreferredDownload;
32753275
}
32763276

3277-
// Self advertisement & GETADDR logic
32783277
if (!pfrom.IsInboundConn() && SetupAddressRelay(pfrom, *peer)) {
3279-
// For outbound peers, we try to relay our address (so that other
3280-
// nodes can try to find us more quickly, as we have no guarantee
3281-
// that an outbound peer is even aware of how to reach us) and do a
3282-
// one-time address fetch (to help populate/update our addrman). If
3283-
// we're starting up for the first time, our addrman may be pretty
3284-
// empty and no one will know who we are, so these mechanisms are
3278+
// For outbound peers, we do a one-time address fetch
3279+
// (to help populate/update our addrman).
3280+
// 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
32853282
// important to help us connect to the network.
32863283
//
32873284
// We skip this for block-relay-only peers. We want to avoid
32883285
// potentially leaking addr information and we do not want to
32893286
// indicate to the peer that we will participate in addr relay.
3290-
if (fListen && !m_chainman.ActiveChainstate().IsInitialBlockDownload())
3291-
{
3292-
CAddress addr{GetLocalAddress(pfrom.addr), peer->m_our_services, Now<NodeSeconds>()};
3293-
FastRandomContext insecure_rand;
3294-
if (addr.IsRoutable())
3295-
{
3296-
LogPrint(BCLog::NET, "ProcessMessages: advertising address %s\n", addr.ToString());
3297-
PushAddress(*peer, addr, insecure_rand);
3298-
} else if (IsPeerAddrLocalGood(&pfrom)) {
3299-
// Override just the address with whatever the peer sees us as.
3300-
// Leave the port in addr as it was returned by GetLocalAddress()
3301-
// above, as this is an outbound connection and the peer cannot
3302-
// observe our listening port.
3303-
addr.SetIP(addrMe);
3304-
LogPrint(BCLog::NET, "ProcessMessages: advertising address %s\n", addr.ToString());
3305-
PushAddress(*peer, addr, insecure_rand);
3306-
}
3307-
}
3308-
3309-
// Get recent addresses
33103287
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make(NetMsgType::GETADDR));
33113288
peer->m_getaddr_sent = true;
33123289
// When requesting a getaddr, accept an additional MAX_ADDR_TO_SEND addresses in response

0 commit comments

Comments
 (0)