Skip to content

Commit 38c0be5

Browse files
committed
[net processing] Refactor MaybeSendAddr() - early exits
Add early exit guard clauses if node.RelayAddrsWithConn() is false or if current_time < node.m_next_addr_send. Add comments. This commit leaves some lines over-indented. Those will be fixed in a subsequent whitespace-only commit.
1 parent c87423c commit 38c0be5

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/net_processing.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4143,11 +4143,16 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic
41434143

41444144
void PeerManagerImpl::MaybeSendAddr(CNode& node, std::chrono::microseconds current_time)
41454145
{
4146-
LOCK(node.m_addr_send_times_mutex);
4146+
// Nothing to do for non-address-relay peers
4147+
if (!node.RelayAddrsWithConn()) return;
4148+
4149+
assert(node.m_addr_known);
4150+
41474151
const CNetMsgMaker msgMaker(node.GetCommonVersion());
41484152

4149-
if (fListen && node.RelayAddrsWithConn() &&
4150-
!m_chainman.ActiveChainstate().IsInitialBlockDownload() &&
4153+
LOCK(node.m_addr_send_times_mutex);
4154+
// Periodically advertise our local address to the peer.
4155+
if (fListen && !m_chainman.ActiveChainstate().IsInitialBlockDownload() &&
41514156
node.m_next_local_addr_send < current_time) {
41524157
// If we've sent before, clear the bloom filter for the peer, so that our
41534158
// self-announcement will actually go out.
@@ -4165,14 +4170,12 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, std::chrono::microseconds curre
41654170
node.m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
41664171
}
41674172

4168-
//
4169-
// Message: addr
4170-
//
4171-
if (node.RelayAddrsWithConn() && node.m_next_addr_send < current_time) {
4173+
// We sent an `addr` message to this peer recently. Nothing more to do.
4174+
if (current_time <= node.m_next_addr_send) return;
4175+
{
41724176
node.m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
41734177
std::vector<CAddress> vAddr;
41744178
vAddr.reserve(node.vAddrToSend.size());
4175-
assert(node.m_addr_known);
41764179

41774180
const char* msg_type;
41784181
int make_flags;

0 commit comments

Comments
 (0)