@@ -6512,7 +6512,7 @@ bool SendMessages(CNode* pto, CConnman& connman)
6512
6512
const Consensus::Params& consensusParams = Params ().GetConsensus ();
6513
6513
{
6514
6514
// Don't send anything until we get its version message
6515
- if (pto->nVersion == 0 )
6515
+ if (pto->nVersion == 0 || pto-> fDisconnect )
6516
6516
return true ;
6517
6517
6518
6518
//
@@ -6548,6 +6548,28 @@ bool SendMessages(CNode* pto, CConnman& connman)
6548
6548
if (!lockMain)
6549
6549
return true ;
6550
6550
6551
+ CNodeState &state = *State (pto->GetId ());
6552
+
6553
+ BOOST_FOREACH (const CBlockReject& reject, state.rejects )
6554
+ connman.PushMessage (pto, NetMsgType::REJECT, (string)NetMsgType::BLOCK, reject.chRejectCode , reject.strRejectReason , reject.hashBlock );
6555
+ state.rejects .clear ();
6556
+
6557
+ if (state.fShouldBan ) {
6558
+ state.fShouldBan = false ;
6559
+ if (pto->fWhitelisted )
6560
+ LogPrintf (" Warning: not punishing whitelisted peer %s!\n " , pto->addr .ToString ());
6561
+ else {
6562
+ pto->fDisconnect = true ;
6563
+ if (pto->addr .IsLocal ())
6564
+ LogPrintf (" Warning: not banning local peer %s!\n " , pto->addr .ToString ());
6565
+ else
6566
+ {
6567
+ connman.Ban (pto->addr , BanReasonNodeMisbehaving);
6568
+ }
6569
+ return true ;
6570
+ }
6571
+ }
6572
+
6551
6573
// Address refresh broadcast
6552
6574
int64_t nNow = GetTimeMicros ();
6553
6575
if (!IsInitialBlockDownload () && pto->nNextLocalAddrSend < nNow) {
@@ -6584,26 +6606,6 @@ bool SendMessages(CNode* pto, CConnman& connman)
6584
6606
pto->vAddrToSend .shrink_to_fit ();
6585
6607
}
6586
6608
6587
- CNodeState &state = *State (pto->GetId ());
6588
- if (state.fShouldBan ) {
6589
- if (pto->fWhitelisted )
6590
- LogPrintf (" Warning: not punishing whitelisted peer %s!\n " , pto->addr .ToString ());
6591
- else {
6592
- pto->fDisconnect = true ;
6593
- if (pto->addr .IsLocal ())
6594
- LogPrintf (" Warning: not banning local peer %s!\n " , pto->addr .ToString ());
6595
- else
6596
- {
6597
- connman.Ban (pto->addr , BanReasonNodeMisbehaving);
6598
- }
6599
- }
6600
- state.fShouldBan = false ;
6601
- }
6602
-
6603
- BOOST_FOREACH (const CBlockReject& reject, state.rejects )
6604
- connman.PushMessage (pto, NetMsgType::REJECT, (string)NetMsgType::BLOCK, reject.chRejectCode , reject.strRejectReason , reject.hashBlock );
6605
- state.rejects .clear ();
6606
-
6607
6609
// Start block sync
6608
6610
if (pindexBestHeader == NULL )
6609
6611
pindexBestHeader = chainActive.Tip ();
@@ -6901,6 +6903,7 @@ bool SendMessages(CNode* pto, CConnman& connman)
6901
6903
// should only happen during initial block download.
6902
6904
LogPrintf (" Peer=%d is stalling block download, disconnecting\n " , pto->id );
6903
6905
pto->fDisconnect = true ;
6906
+ return true ;
6904
6907
}
6905
6908
// In case there is a block that has been in flight from this peer for 2 + 0.5 * N times the block interval
6906
6909
// (with N the number of peers from which we're downloading validated blocks), disconnect due to timeout.
@@ -6913,6 +6916,7 @@ bool SendMessages(CNode* pto, CConnman& connman)
6913
6916
if (nNow > state.nDownloadingSince + consensusParams.nPowTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
6914
6917
LogPrintf (" Timeout downloading block %s from peer=%d, disconnecting\n " , queuedBlock.hash .ToString (), pto->id );
6915
6918
pto->fDisconnect = true ;
6919
+ return true ;
6916
6920
}
6917
6921
}
6918
6922
0 commit comments