refactor: Separate peer/maybe_peer in ProcessMessages and SendMessages
What changed, and why it matters
This is a pure code cleanup change. It renames a local variable from 'peer' to 'maybe_peer' and then creates a reference alias 'peer' pointing to the same object. The behavior is identical; no security issue is introduced or fixed.
No action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors ProcessMessages and SendMessages in src/net_processing.cpp so that GetPeerRef’s result is stored in ‘maybe_peer’ and then bound to a reference ‘peer’. This is preparatory work for a later commit where one name may hold a non-null reference. The diff shows no functional change: the null check still occurs before the alias is used, and all subsequent references to ‘peer’ remain valid.
Changed components
src/net_processing.cppInspect captured patch +6 / −4
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 17f8192c..ebf5dcbc 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -5186,8 +5186,9 @@ bool PeerManagerImpl::ProcessMessages(CNode& node, std::atomic<bool>& interruptM
AssertLockHeld(g_msgproc_mutex);
CNode* pfrom{&node}; // alias removed in a later commit.
- PeerRef peer = GetPeerRef(pfrom->GetId());
- if (peer == nullptr) return false;
+ PeerRef maybe_peer{GetPeerRef(pfrom->GetId())};
+ if (maybe_peer == nullptr) return false;
+ auto& peer{maybe_peer}; // alias cleaned up in later commit.
// For outbound connections, ensure that the initial VERSION message
// has been sent first before processing any incoming messages
@@ -5689,8 +5690,9 @@ bool PeerManagerImpl::SendMessages(CNode& node)
AssertLockHeld(g_msgproc_mutex);
CNode* pto{&node}; // alias removed in a later commit
- PeerRef peer = GetPeerRef(pto->GetId());
- if (!peer) return false;
+ PeerRef maybe_peer{GetPeerRef(pto->GetId())};
+ if (!maybe_peer) return false;
+ auto& peer{maybe_peer}; // alias cleaned up in later commit
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
// We must call MaybeDiscourageAndDisconnect first, to ensure that we'll
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.