@@ -123,11 +123,6 @@ namespace {
123123 std::deque<std::pair<int64_t , MapRelay::iterator>> vRelayExpiration;
124124} // namespace
125125
126- // ////////////////////////////////////////////////////////////////////////////
127- //
128- // Registration of network node signals.
129- //
130-
131126namespace {
132127
133128struct CBlockReject {
@@ -265,50 +260,6 @@ void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime)
265260 }
266261}
267262
268- void InitializeNode (CNode *pnode, CConnman* connman) {
269- CAddress addr = pnode->addr ;
270- std::string addrName = pnode->GetAddrName ();
271- NodeId nodeid = pnode->GetId ();
272- {
273- LOCK (cs_main);
274- mapNodeState.emplace_hint (mapNodeState.end (), std::piecewise_construct, std::forward_as_tuple (nodeid), std::forward_as_tuple (addr, std::move (addrName)));
275- }
276- if (!pnode->fInbound )
277- PushNodeVersion (pnode, connman, GetTime ());
278- }
279-
280- void FinalizeNode (NodeId nodeid, bool & fUpdateConnectionTime ) {
281- fUpdateConnectionTime = false ;
282- LOCK (cs_main);
283- CNodeState *state = State (nodeid);
284- assert (state != nullptr );
285-
286- if (state->fSyncStarted )
287- nSyncStarted--;
288-
289- if (state->nMisbehavior == 0 && state->fCurrentlyConnected ) {
290- fUpdateConnectionTime = true ;
291- }
292-
293- for (const QueuedBlock& entry : state->vBlocksInFlight ) {
294- mapBlocksInFlight.erase (entry.hash );
295- }
296- EraseOrphansFor (nodeid);
297- nPreferredDownload -= state->fPreferredDownload ;
298- nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0 );
299- assert (nPeersWithValidatedDownloads >= 0 );
300-
301- mapNodeState.erase (nodeid);
302-
303- if (mapNodeState.empty ()) {
304- // Do a consistency check after the last peer is removed.
305- assert (mapBlocksInFlight.empty ());
306- assert (nPreferredDownload == 0 );
307- assert (nPeersWithValidatedDownloads == 0 );
308- }
309- LogPrint (BCLog::NET, " Cleared nodestate for peer=%d\n " , nodeid);
310- }
311-
312263// Requires cs_main.
313264// Returns a bool indicating whether we requested this block.
314265// Also used if a block was /not/ received and timed out or started with another peer
@@ -545,6 +496,50 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<con
545496
546497} // namespace
547498
499+ void PeerLogicValidation::InitializeNode (CNode *pnode, CConnman* connman) {
500+ CAddress addr = pnode->addr ;
501+ std::string addrName = pnode->GetAddrName ();
502+ NodeId nodeid = pnode->GetId ();
503+ {
504+ LOCK (cs_main);
505+ mapNodeState.emplace_hint (mapNodeState.end (), std::piecewise_construct, std::forward_as_tuple (nodeid), std::forward_as_tuple (addr, std::move (addrName)));
506+ }
507+ if (!pnode->fInbound )
508+ PushNodeVersion (pnode, connman, GetTime ());
509+ }
510+
511+ void PeerLogicValidation::FinalizeNode (NodeId nodeid, bool & fUpdateConnectionTime ) {
512+ fUpdateConnectionTime = false ;
513+ LOCK (cs_main);
514+ CNodeState *state = State (nodeid);
515+ assert (state != nullptr );
516+
517+ if (state->fSyncStarted )
518+ nSyncStarted--;
519+
520+ if (state->nMisbehavior == 0 && state->fCurrentlyConnected ) {
521+ fUpdateConnectionTime = true ;
522+ }
523+
524+ for (const QueuedBlock& entry : state->vBlocksInFlight ) {
525+ mapBlocksInFlight.erase (entry.hash );
526+ }
527+ EraseOrphansFor (nodeid);
528+ nPreferredDownload -= state->fPreferredDownload ;
529+ nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0 );
530+ assert (nPeersWithValidatedDownloads >= 0 );
531+
532+ mapNodeState.erase (nodeid);
533+
534+ if (mapNodeState.empty ()) {
535+ // Do a consistency check after the last peer is removed.
536+ assert (mapBlocksInFlight.empty ());
537+ assert (nPreferredDownload == 0 );
538+ assert (nPeersWithValidatedDownloads == 0 );
539+ }
540+ LogPrint (BCLog::NET, " Cleared nodestate for peer=%d\n " , nodeid);
541+ }
542+
548543bool GetNodeStateStats (NodeId nodeid, CNodeStateStats &stats) {
549544 LOCK (cs_main);
550545 CNodeState *state = State (nodeid);
@@ -560,22 +555,6 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
560555 return true ;
561556}
562557
563- void RegisterNodeSignals (CNodeSignals& nodeSignals)
564- {
565- nodeSignals.ProcessMessages .connect (&ProcessMessages);
566- nodeSignals.SendMessages .connect (&SendMessages);
567- nodeSignals.InitializeNode .connect (&InitializeNode);
568- nodeSignals.FinalizeNode .connect (&FinalizeNode);
569- }
570-
571- void UnregisterNodeSignals (CNodeSignals& nodeSignals)
572- {
573- nodeSignals.ProcessMessages .disconnect (&ProcessMessages);
574- nodeSignals.SendMessages .disconnect (&SendMessages);
575- nodeSignals.InitializeNode .disconnect (&InitializeNode);
576- nodeSignals.FinalizeNode .disconnect (&FinalizeNode);
577- }
578-
579558// ////////////////////////////////////////////////////////////////////////////
580559//
581560// mapOrphanTransactions
@@ -2661,7 +2640,7 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman)
26612640 return false ;
26622641}
26632642
2664- bool ProcessMessages (CNode* pfrom, CConnman* connman, const std::atomic<bool >& interruptMsgProc)
2643+ bool PeerLogicValidation:: ProcessMessages (CNode* pfrom, CConnman* connman, std::atomic<bool >& interruptMsgProc)
26652644{
26662645 const CChainParams& chainparams = Params ();
26672646 //
@@ -2798,7 +2777,7 @@ class CompareInvMempoolOrder
27982777 }
27992778};
28002779
2801- bool SendMessages (CNode* pto, CConnman* connman, const std::atomic<bool >& interruptMsgProc)
2780+ bool PeerLogicValidation:: SendMessages (CNode* pto, CConnman* connman, std::atomic<bool >& interruptMsgProc)
28022781{
28032782 const Consensus::Params& consensusParams = Params ().GetConsensus ();
28042783 {
0 commit comments