Skip to content

Commit c87423c

Browse files
committed
[net processing] Change MaybeSendAddr() to take a reference
Change name of CNode parameter to node now that it's no longer a pointer.
1 parent ad71929 commit c87423c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/net_processing.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class PeerManagerImpl final : public PeerManager
323323
void MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now);
324324

325325
/** Send `addr` messages on a regular schedule. */
326-
void MaybeSendAddr(CNode* pto, std::chrono::microseconds current_time);
326+
void MaybeSendAddr(CNode& node, std::chrono::microseconds current_time);
327327

328328
const CChainParams& m_chainparams;
329329
CConnman& m_connman;
@@ -4141,69 +4141,69 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic
41414141
}
41424142
}
41434143

4144-
void PeerManagerImpl::MaybeSendAddr(CNode* pto, std::chrono::microseconds current_time)
4144+
void PeerManagerImpl::MaybeSendAddr(CNode& node, std::chrono::microseconds current_time)
41454145
{
4146-
LOCK(pto->m_addr_send_times_mutex);
4147-
const CNetMsgMaker msgMaker(pto->GetCommonVersion());
4146+
LOCK(node.m_addr_send_times_mutex);
4147+
const CNetMsgMaker msgMaker(node.GetCommonVersion());
41484148

4149-
if (fListen && pto->RelayAddrsWithConn() &&
4149+
if (fListen && node.RelayAddrsWithConn() &&
41504150
!m_chainman.ActiveChainstate().IsInitialBlockDownload() &&
4151-
pto->m_next_local_addr_send < current_time) {
4151+
node.m_next_local_addr_send < current_time) {
41524152
// If we've sent before, clear the bloom filter for the peer, so that our
41534153
// self-announcement will actually go out.
41544154
// This might be unnecessary if the bloom filter has already rolled
41554155
// over since our last self-announcement, but there is only a small
41564156
// bandwidth cost that we can incur by doing this (which happens
41574157
// once a day on average).
4158-
if (pto->m_next_local_addr_send != 0us) {
4159-
pto->m_addr_known->reset();
4158+
if (node.m_next_local_addr_send != 0us) {
4159+
node.m_addr_known->reset();
41604160
}
4161-
if (std::optional<CAddress> local_addr = GetLocalAddrForPeer(pto)) {
4161+
if (std::optional<CAddress> local_addr = GetLocalAddrForPeer(&node)) {
41624162
FastRandomContext insecure_rand;
4163-
pto->PushAddress(*local_addr, insecure_rand);
4163+
node.PushAddress(*local_addr, insecure_rand);
41644164
}
4165-
pto->m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
4165+
node.m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
41664166
}
41674167

41684168
//
41694169
// Message: addr
41704170
//
4171-
if (pto->RelayAddrsWithConn() && pto->m_next_addr_send < current_time) {
4172-
pto->m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
4171+
if (node.RelayAddrsWithConn() && node.m_next_addr_send < current_time) {
4172+
node.m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
41734173
std::vector<CAddress> vAddr;
4174-
vAddr.reserve(pto->vAddrToSend.size());
4175-
assert(pto->m_addr_known);
4174+
vAddr.reserve(node.vAddrToSend.size());
4175+
assert(node.m_addr_known);
41764176

41774177
const char* msg_type;
41784178
int make_flags;
4179-
if (pto->m_wants_addrv2) {
4179+
if (node.m_wants_addrv2) {
41804180
msg_type = NetMsgType::ADDRV2;
41814181
make_flags = ADDRV2_FORMAT;
41824182
} else {
41834183
msg_type = NetMsgType::ADDR;
41844184
make_flags = 0;
41854185
}
41864186

4187-
for (const CAddress& addr : pto->vAddrToSend)
4187+
for (const CAddress& addr : node.vAddrToSend)
41884188
{
4189-
if (!pto->m_addr_known->contains(addr.GetKey()))
4189+
if (!node.m_addr_known->contains(addr.GetKey()))
41904190
{
4191-
pto->m_addr_known->insert(addr.GetKey());
4191+
node.m_addr_known->insert(addr.GetKey());
41924192
vAddr.push_back(addr);
41934193
// receiver rejects addr messages larger than MAX_ADDR_TO_SEND
41944194
if (vAddr.size() >= MAX_ADDR_TO_SEND)
41954195
{
4196-
m_connman.PushMessage(pto, msgMaker.Make(make_flags, msg_type, vAddr));
4196+
m_connman.PushMessage(&node, msgMaker.Make(make_flags, msg_type, vAddr));
41974197
vAddr.clear();
41984198
}
41994199
}
42004200
}
4201-
pto->vAddrToSend.clear();
4201+
node.vAddrToSend.clear();
42024202
if (!vAddr.empty())
4203-
m_connman.PushMessage(pto, msgMaker.Make(make_flags, msg_type, vAddr));
4203+
m_connman.PushMessage(&node, msgMaker.Make(make_flags, msg_type, vAddr));
42044204
// we only send the big addr message once
4205-
if (pto->vAddrToSend.capacity() > 40)
4206-
pto->vAddrToSend.shrink_to_fit();
4205+
if (node.vAddrToSend.capacity() > 40)
4206+
node.vAddrToSend.shrink_to_fit();
42074207
}
42084208
}
42094209

@@ -4252,7 +4252,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
42524252
// MaybeSendPing may have marked peer for disconnection
42534253
if (pto->fDisconnect) return true;
42544254

4255-
MaybeSendAddr(pto, current_time);
4255+
MaybeSendAddr(*pto, current_time);
42564256

42574257
{
42584258
LOCK(cs_main);

0 commit comments

Comments
 (0)