Skip to content

Commit 0dbcd4c

Browse files
committed
net: prevent sending messages in NetEventsInterface::InitializeNode
Now that the queueing of the VERSION messages has been moved out of `InitializeNode`, there is no need to pass a mutable `CNode` reference any more. With a const reference, trying to send messages in this method would lead to a compile-time error, e.g.: ---------------------------------------------------------------------------------------------------------------------------------- ... net_processing.cpp: In member function ‘virtual void {anonymous}::PeerManagerImpl::InitializeNode(const CNode&, ServiceFlags)’: net_processing.cpp:1683:21: error: binding reference of type ‘CNode&’ to ‘const CNode’ discards qualifiers 1683 | PushNodeVersion(node, *peer); ... ----------------------------------------------------------------------------------------------------------------------------------
1 parent 66673f1 commit 0dbcd4c

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ class NetEventsInterface
992992
static Mutex g_msgproc_mutex;
993993

994994
/** Initialize a peer (setup state) */
995-
virtual void InitializeNode(CNode& node, ServiceFlags our_services) = 0;
995+
virtual void InitializeNode(const CNode& node, ServiceFlags our_services) = 0;
996996

997997
/** Handle removal of a peer (clear state) */
998998
virtual void FinalizeNode(const CNode& node) = 0;

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ class PeerManagerImpl final : public PeerManager
501501
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex);
502502

503503
/** Implement NetEventsInterface */
504-
void InitializeNode(CNode& node, ServiceFlags our_services) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
504+
void InitializeNode(const CNode& node, ServiceFlags our_services) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
505505
void FinalizeNode(const CNode& node) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_headers_presync_mutex);
506506
bool HasAllDesirableServiceFlags(ServiceFlags services) const override;
507507
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override
@@ -1662,7 +1662,7 @@ void PeerManagerImpl::UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_s
16621662
if (state) state->m_last_block_announcement = time_in_seconds;
16631663
}
16641664

1665-
void PeerManagerImpl::InitializeNode(CNode& node, ServiceFlags our_services)
1665+
void PeerManagerImpl::InitializeNode(const CNode& node, ServiceFlags our_services)
16661666
{
16671667
NodeId nodeid = node.GetId();
16681668
{

0 commit comments

Comments
 (0)