diff options
author | John Newbery <john@johnnewbery.com> | 2021-02-28 11:16:52 +0000 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2021-03-29 12:15:23 +0100 |
commit | 38c0be5da3af17208b165e73cee7612d3670b038 (patch) | |
tree | b847f7d629bd1d07121ee54ebbefb0ca53b77c2d | |
parent | c87423c58b5165de835a49bebd566538a70c07ab (diff) |
[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.
-rw-r--r-- | src/net_processing.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cc0231afac..fd8c653837 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -4143,11 +4143,16 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic void PeerManagerImpl::MaybeSendAddr(CNode& node, std::chrono::microseconds current_time) { - LOCK(node.m_addr_send_times_mutex); + // Nothing to do for non-address-relay peers + if (!node.RelayAddrsWithConn()) return; + + assert(node.m_addr_known); + const CNetMsgMaker msgMaker(node.GetCommonVersion()); - if (fListen && node.RelayAddrsWithConn() && - !m_chainman.ActiveChainstate().IsInitialBlockDownload() && + LOCK(node.m_addr_send_times_mutex); + // Periodically advertise our local address to the peer. + if (fListen && !m_chainman.ActiveChainstate().IsInitialBlockDownload() && node.m_next_local_addr_send < current_time) { // If we've sent before, clear the bloom filter for the peer, so that our // self-announcement will actually go out. @@ -4165,14 +4170,12 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, std::chrono::microseconds curre node.m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); } - // - // Message: addr - // - if (node.RelayAddrsWithConn() && node.m_next_addr_send < current_time) { + // We sent an `addr` message to this peer recently. Nothing more to do. + if (current_time <= node.m_next_addr_send) return; + { node.m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL); std::vector<CAddress> vAddr; vAddr.reserve(node.vAddrToSend.size()); - assert(node.m_addr_known); const char* msg_type; int make_flags; |