@ -123,11 +123,6 @@ namespace {
@@ -123,11 +123,6 @@ namespace {
std : : deque < std : : pair < int64_t , MapRelay : : iterator > > vRelayExpiration ;
} // namespace
//////////////////////////////////////////////////////////////////////////////
//
// Registration of network node signals.
//
namespace {
struct CBlockReject {
@ -265,49 +260,6 @@ void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime)
@@ -265,49 +260,6 @@ void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime)
}
}
void InitializeNode ( CNode * pnode , CConnman * connman ) {
CAddress addr = pnode - > addr ;
std : : string addrName = pnode - > GetAddrName ( ) ;
NodeId nodeid = pnode - > GetId ( ) ;
{
LOCK ( cs_main ) ;
mapNodeState . emplace_hint ( mapNodeState . end ( ) , std : : piecewise_construct , std : : forward_as_tuple ( nodeid ) , std : : forward_as_tuple ( addr , std : : move ( addrName ) ) ) ;
}
if ( ! pnode - > fInbound )
PushNodeVersion ( pnode , connman , GetTime ( ) ) ;
}
void FinalizeNode ( NodeId nodeid , bool & fUpdateConnectionTime ) {
fUpdateConnectionTime = false ;
LOCK ( cs_main ) ;
CNodeState * state = State ( nodeid ) ;
if ( state - > fSyncStarted )
nSyncStarted - - ;
if ( state - > nMisbehavior = = 0 & & state - > fCurrentlyConnected ) {
fUpdateConnectionTime = true ;
}
for ( const QueuedBlock & entry : state - > vBlocksInFlight ) {
mapBlocksInFlight . erase ( entry . hash ) ;
}
EraseOrphansFor ( nodeid ) ;
nPreferredDownload - = state - > fPreferredDownload ;
nPeersWithValidatedDownloads - = ( state - > nBlocksInFlightValidHeaders ! = 0 ) ;
assert ( nPeersWithValidatedDownloads > = 0 ) ;
mapNodeState . erase ( nodeid ) ;
if ( mapNodeState . empty ( ) ) {
// Do a consistency check after the last peer is removed.
assert ( mapBlocksInFlight . empty ( ) ) ;
assert ( nPreferredDownload = = 0 ) ;
assert ( nPeersWithValidatedDownloads = = 0 ) ;
}
LogPrint ( BCLog : : NET , " Cleared nodestate for peer=%d \n " , nodeid ) ;
}
// Requires cs_main.
// Returns a bool indicating whether we requested this block.
// Also used if a block was /not/ received and timed out or started with another peer
@ -543,6 +495,50 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<con
@@ -543,6 +495,50 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<con
} // namespace
void PeerLogicValidation : : InitializeNode ( CNode * pnode , CConnman * connman ) {
CAddress addr = pnode - > addr ;
std : : string addrName = pnode - > GetAddrName ( ) ;
NodeId nodeid = pnode - > GetId ( ) ;
{
LOCK ( cs_main ) ;
mapNodeState . emplace_hint ( mapNodeState . end ( ) , std : : piecewise_construct , std : : forward_as_tuple ( nodeid ) , std : : forward_as_tuple ( addr , std : : move ( addrName ) ) ) ;
}
if ( ! pnode - > fInbound )
PushNodeVersion ( pnode , connman , GetTime ( ) ) ;
}
void PeerLogicValidation : : FinalizeNode ( NodeId nodeid , bool & fUpdateConnectionTime ) {
fUpdateConnectionTime = false ;
LOCK ( cs_main ) ;
CNodeState * state = State ( nodeid ) ;
assert ( state ! = nullptr ) ;
if ( state - > fSyncStarted )
nSyncStarted - - ;
if ( state - > nMisbehavior = = 0 & & state - > fCurrentlyConnected ) {
fUpdateConnectionTime = true ;
}
for ( const QueuedBlock & entry : state - > vBlocksInFlight ) {
mapBlocksInFlight . erase ( entry . hash ) ;
}
EraseOrphansFor ( nodeid ) ;
nPreferredDownload - = state - > fPreferredDownload ;
nPeersWithValidatedDownloads - = ( state - > nBlocksInFlightValidHeaders ! = 0 ) ;
assert ( nPeersWithValidatedDownloads > = 0 ) ;
mapNodeState . erase ( nodeid ) ;
if ( mapNodeState . empty ( ) ) {
// Do a consistency check after the last peer is removed.
assert ( mapBlocksInFlight . empty ( ) ) ;
assert ( nPreferredDownload = = 0 ) ;
assert ( nPeersWithValidatedDownloads = = 0 ) ;
}
LogPrint ( BCLog : : NET , " Cleared nodestate for peer=%d \n " , nodeid ) ;
}
bool GetNodeStateStats ( NodeId nodeid , CNodeStateStats & stats ) {
LOCK ( cs_main ) ;
CNodeState * state = State ( nodeid ) ;
@ -558,22 +554,6 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
@@ -558,22 +554,6 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) {
return true ;
}
void RegisterNodeSignals ( CNodeSignals & nodeSignals )
{
nodeSignals . ProcessMessages . connect ( & ProcessMessages ) ;
nodeSignals . SendMessages . connect ( & SendMessages ) ;
nodeSignals . InitializeNode . connect ( & InitializeNode ) ;
nodeSignals . FinalizeNode . connect ( & FinalizeNode ) ;
}
void UnregisterNodeSignals ( CNodeSignals & nodeSignals )
{
nodeSignals . ProcessMessages . disconnect ( & ProcessMessages ) ;
nodeSignals . SendMessages . disconnect ( & SendMessages ) ;
nodeSignals . InitializeNode . disconnect ( & InitializeNode ) ;
nodeSignals . FinalizeNode . disconnect ( & FinalizeNode ) ;
}
//////////////////////////////////////////////////////////////////////////////
//
// mapOrphanTransactions
@ -2672,7 +2652,7 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman)
@@ -2672,7 +2652,7 @@ static bool SendRejectsAndCheckIfBanned(CNode* pnode, CConnman* connman)
return false ;
}
bool ProcessMessages ( CNode * pfrom , CConnman * connman , const std : : atomic < bool > & interruptMsgProc )
bool PeerLogicValidation : : P rocessMessages ( CNode * pfrom , CConnman * connman , std : : atomic < bool > & interruptMsgProc )
{
const CChainParams & chainparams = Params ( ) ;
//
@ -2809,7 +2789,7 @@ public:
@@ -2809,7 +2789,7 @@ public:
}
} ;
bool SendMessages ( CNode * pto , CConnman * connman , const std : : atomic < bool > & interruptMsgProc )
bool PeerLogicValidation : : SendMessages ( CNode * pto , CConnman * connman , std : : atomic < bool > & interruptMsgProc )
{
const Consensus : : Params & consensusParams = Params ( ) . GetConsensus ( ) ;
{