[net processing] Change MaybeSendAddr() to take a reference

Change name of CNode parameter to node now that it's no longer a
pointer.
pull/826/head
John Newbery 4 years ago
parent ad719297f2
commit c87423c58b

@ -323,7 +323,7 @@ private:
void MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now); void MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now);
/** Send `addr` messages on a regular schedule. */ /** Send `addr` messages on a regular schedule. */
void MaybeSendAddr(CNode* pto, std::chrono::microseconds current_time); void MaybeSendAddr(CNode& node, std::chrono::microseconds current_time);
const CChainParams& m_chainparams; const CChainParams& m_chainparams;
CConnman& m_connman; CConnman& m_connman;
@ -4141,42 +4141,42 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic
} }
} }
void PeerManagerImpl::MaybeSendAddr(CNode* pto, std::chrono::microseconds current_time) void PeerManagerImpl::MaybeSendAddr(CNode& node, std::chrono::microseconds current_time)
{ {
LOCK(pto->m_addr_send_times_mutex); LOCK(node.m_addr_send_times_mutex);
const CNetMsgMaker msgMaker(pto->GetCommonVersion()); const CNetMsgMaker msgMaker(node.GetCommonVersion());
if (fListen && pto->RelayAddrsWithConn() && if (fListen && node.RelayAddrsWithConn() &&
!m_chainman.ActiveChainstate().IsInitialBlockDownload() && !m_chainman.ActiveChainstate().IsInitialBlockDownload() &&
pto->m_next_local_addr_send < current_time) { node.m_next_local_addr_send < current_time) {
// If we've sent before, clear the bloom filter for the peer, so that our // If we've sent before, clear the bloom filter for the peer, so that our
// self-announcement will actually go out. // self-announcement will actually go out.
// This might be unnecessary if the bloom filter has already rolled // This might be unnecessary if the bloom filter has already rolled
// over since our last self-announcement, but there is only a small // over since our last self-announcement, but there is only a small
// bandwidth cost that we can incur by doing this (which happens // bandwidth cost that we can incur by doing this (which happens
// once a day on average). // once a day on average).
if (pto->m_next_local_addr_send != 0us) { if (node.m_next_local_addr_send != 0us) {
pto->m_addr_known->reset(); node.m_addr_known->reset();
} }
if (std::optional<CAddress> local_addr = GetLocalAddrForPeer(pto)) { if (std::optional<CAddress> local_addr = GetLocalAddrForPeer(&node)) {
FastRandomContext insecure_rand; FastRandomContext insecure_rand;
pto->PushAddress(*local_addr, insecure_rand); node.PushAddress(*local_addr, insecure_rand);
} }
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); node.m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
} }
// //
// Message: addr // Message: addr
// //
if (pto->RelayAddrsWithConn() && pto->m_next_addr_send < current_time) { if (node.RelayAddrsWithConn() && node.m_next_addr_send < current_time) {
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL); node.m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
std::vector<CAddress> vAddr; std::vector<CAddress> vAddr;
vAddr.reserve(pto->vAddrToSend.size()); vAddr.reserve(node.vAddrToSend.size());
assert(pto->m_addr_known); assert(node.m_addr_known);
const char* msg_type; const char* msg_type;
int make_flags; int make_flags;
if (pto->m_wants_addrv2) { if (node.m_wants_addrv2) {
msg_type = NetMsgType::ADDRV2; msg_type = NetMsgType::ADDRV2;
make_flags = ADDRV2_FORMAT; make_flags = ADDRV2_FORMAT;
} else { } else {
@ -4184,26 +4184,26 @@ void PeerManagerImpl::MaybeSendAddr(CNode* pto, std::chrono::microseconds curren
make_flags = 0; make_flags = 0;
} }
for (const CAddress& addr : pto->vAddrToSend) for (const CAddress& addr : node.vAddrToSend)
{ {
if (!pto->m_addr_known->contains(addr.GetKey())) if (!node.m_addr_known->contains(addr.GetKey()))
{ {
pto->m_addr_known->insert(addr.GetKey()); node.m_addr_known->insert(addr.GetKey());
vAddr.push_back(addr); vAddr.push_back(addr);
// receiver rejects addr messages larger than MAX_ADDR_TO_SEND // receiver rejects addr messages larger than MAX_ADDR_TO_SEND
if (vAddr.size() >= MAX_ADDR_TO_SEND) if (vAddr.size() >= MAX_ADDR_TO_SEND)
{ {
m_connman.PushMessage(pto, msgMaker.Make(make_flags, msg_type, vAddr)); m_connman.PushMessage(&node, msgMaker.Make(make_flags, msg_type, vAddr));
vAddr.clear(); vAddr.clear();
} }
} }
} }
pto->vAddrToSend.clear(); node.vAddrToSend.clear();
if (!vAddr.empty()) if (!vAddr.empty())
m_connman.PushMessage(pto, msgMaker.Make(make_flags, msg_type, vAddr)); m_connman.PushMessage(&node, msgMaker.Make(make_flags, msg_type, vAddr));
// we only send the big addr message once // we only send the big addr message once
if (pto->vAddrToSend.capacity() > 40) if (node.vAddrToSend.capacity() > 40)
pto->vAddrToSend.shrink_to_fit(); node.vAddrToSend.shrink_to_fit();
} }
} }
@ -4252,7 +4252,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// MaybeSendPing may have marked peer for disconnection // MaybeSendPing may have marked peer for disconnection
if (pto->fDisconnect) return true; if (pto->fDisconnect) return true;
MaybeSendAddr(pto, current_time); MaybeSendAddr(*pto, current_time);
{ {
LOCK(cs_main); LOCK(cs_main);

Loading…
Cancel
Save