@@ -2661,100 +2661,100 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic<bool>& i
2661
2661
// this maintains the order of responses
2662
2662
if (!pfrom->vRecvGetData .empty ()) return true ;
2663
2663
2664
- // Don't bother if send buffer is too full to respond anyway
2665
- if (pfrom->fPauseSend )
2666
- return false ;
2664
+ // Don't bother if send buffer is too full to respond anyway
2665
+ if (pfrom->fPauseSend )
2666
+ return false ;
2667
2667
2668
- std::list<CNetMessage> msgs;
2669
- {
2670
- LOCK (pfrom->cs_vProcessMsg );
2671
- if (pfrom->vProcessMsg .empty ())
2672
- return false ;
2673
- // Just take one message
2674
- msgs.splice (msgs.begin (), pfrom->vProcessMsg , pfrom->vProcessMsg .begin ());
2675
- pfrom->nProcessQueueSize -= msgs.front ().vRecv .size () + CMessageHeader::HEADER_SIZE;
2676
- pfrom->fPauseRecv = pfrom->nProcessQueueSize > connman.GetReceiveFloodSize ();
2677
- fMoreWork = !pfrom->vProcessMsg .empty ();
2678
- }
2679
- CNetMessage& msg (msgs.front ());
2680
-
2681
- msg.SetVersion (pfrom->GetRecvVersion ());
2682
- // Scan for message start
2683
- if (memcmp (msg.hdr .pchMessageStart , chainparams.MessageStart (), CMessageHeader::MESSAGE_START_SIZE) != 0 ) {
2684
- LogPrintf (" PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n " , SanitizeString (msg.hdr .GetCommand ()), pfrom->id );
2685
- pfrom->fDisconnect = true ;
2668
+ std::list<CNetMessage> msgs;
2669
+ {
2670
+ LOCK (pfrom->cs_vProcessMsg );
2671
+ if (pfrom->vProcessMsg .empty ())
2686
2672
return false ;
2687
- }
2673
+ // Just take one message
2674
+ msgs.splice (msgs.begin (), pfrom->vProcessMsg , pfrom->vProcessMsg .begin ());
2675
+ pfrom->nProcessQueueSize -= msgs.front ().vRecv .size () + CMessageHeader::HEADER_SIZE;
2676
+ pfrom->fPauseRecv = pfrom->nProcessQueueSize > connman.GetReceiveFloodSize ();
2677
+ fMoreWork = !pfrom->vProcessMsg .empty ();
2678
+ }
2679
+ CNetMessage& msg (msgs.front ());
2680
+
2681
+ msg.SetVersion (pfrom->GetRecvVersion ());
2682
+ // Scan for message start
2683
+ if (memcmp (msg.hdr .pchMessageStart , chainparams.MessageStart (), CMessageHeader::MESSAGE_START_SIZE) != 0 ) {
2684
+ LogPrintf (" PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n " , SanitizeString (msg.hdr .GetCommand ()), pfrom->id );
2685
+ pfrom->fDisconnect = true ;
2686
+ return false ;
2687
+ }
2688
2688
2689
- // Read header
2690
- CMessageHeader& hdr = msg.hdr ;
2691
- if (!hdr.IsValid (chainparams.MessageStart ()))
2692
- {
2693
- LogPrintf (" PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n " , SanitizeString (hdr.GetCommand ()), pfrom->id );
2694
- return fMoreWork ;
2695
- }
2696
- std::string strCommand = hdr.GetCommand ();
2689
+ // Read header
2690
+ CMessageHeader& hdr = msg.hdr ;
2691
+ if (!hdr.IsValid (chainparams.MessageStart ()))
2692
+ {
2693
+ LogPrintf (" PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n " , SanitizeString (hdr.GetCommand ()), pfrom->id );
2694
+ return fMoreWork ;
2695
+ }
2696
+ std::string strCommand = hdr.GetCommand ();
2697
+
2698
+ // Message size
2699
+ unsigned int nMessageSize = hdr.nMessageSize ;
2697
2700
2698
- // Message size
2699
- unsigned int nMessageSize = hdr.nMessageSize ;
2701
+ // Checksum
2702
+ CDataStream& vRecv = msg.vRecv ;
2703
+ const uint256& hash = msg.GetMessageHash ();
2704
+ if (memcmp (hash.begin (), hdr.pchChecksum , CMessageHeader::CHECKSUM_SIZE) != 0 )
2705
+ {
2706
+ LogPrintf (" %s(%s, %u bytes): CHECKSUM ERROR expected %s was %s\n " , __func__,
2707
+ SanitizeString (strCommand), nMessageSize,
2708
+ HexStr (hash.begin (), hash.begin ()+CMessageHeader::CHECKSUM_SIZE),
2709
+ HexStr (hdr.pchChecksum , hdr.pchChecksum +CMessageHeader::CHECKSUM_SIZE));
2710
+ return fMoreWork ;
2711
+ }
2700
2712
2701
- // Checksum
2702
- CDataStream& vRecv = msg.vRecv ;
2703
- const uint256& hash = msg.GetMessageHash ();
2704
- if (memcmp (hash.begin (), hdr.pchChecksum , CMessageHeader::CHECKSUM_SIZE) != 0 )
2713
+ // Process message
2714
+ bool fRet = false ;
2715
+ try
2716
+ {
2717
+ fRet = ProcessMessage (pfrom, strCommand, vRecv, msg.nTime , chainparams, connman, interruptMsgProc);
2718
+ if (interruptMsgProc)
2719
+ return false ;
2720
+ if (!pfrom->vRecvGetData .empty ())
2721
+ fMoreWork = true ;
2722
+ }
2723
+ catch (const std::ios_base::failure& e)
2724
+ {
2725
+ connman.PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_MALFORMED, std::string (" error parsing message" )));
2726
+ if (strstr (e.what (), " end of data" ))
2705
2727
{
2706
- LogPrintf (" %s(%s, %u bytes): CHECKSUM ERROR expected %s was %s\n " , __func__,
2707
- SanitizeString (strCommand), nMessageSize,
2708
- HexStr (hash.begin (), hash.begin ()+CMessageHeader::CHECKSUM_SIZE),
2709
- HexStr (hdr.pchChecksum , hdr.pchChecksum +CMessageHeader::CHECKSUM_SIZE));
2710
- return fMoreWork ;
2728
+ // Allow exceptions from under-length message on vRecv
2729
+ LogPrintf (" %s(%s, %u bytes): Exception '%s' caught, normally caused by a message being shorter than its stated length\n " , __func__, SanitizeString (strCommand), nMessageSize, e.what ());
2711
2730
}
2712
-
2713
- // Process message
2714
- bool fRet = false ;
2715
- try
2731
+ else if (strstr (e.what (), " size too large" ))
2716
2732
{
2717
- fRet = ProcessMessage (pfrom, strCommand, vRecv, msg.nTime , chainparams, connman, interruptMsgProc);
2718
- if (interruptMsgProc)
2719
- return false ;
2720
- if (!pfrom->vRecvGetData .empty ())
2721
- fMoreWork = true ;
2733
+ // Allow exceptions from over-long size
2734
+ LogPrintf (" %s(%s, %u bytes): Exception '%s' caught\n " , __func__, SanitizeString (strCommand), nMessageSize, e.what ());
2722
2735
}
2723
- catch ( const std::ios_base::failure& e )
2736
+ else if ( strstr (e. what (), " non-canonical ReadCompactSize() " ) )
2724
2737
{
2725
- connman.PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_MALFORMED, std::string (" error parsing message" )));
2726
- if (strstr (e.what (), " end of data" ))
2727
- {
2728
- // Allow exceptions from under-length message on vRecv
2729
- LogPrintf (" %s(%s, %u bytes): Exception '%s' caught, normally caused by a message being shorter than its stated length\n " , __func__, SanitizeString (strCommand), nMessageSize, e.what ());
2730
- }
2731
- else if (strstr (e.what (), " size too large" ))
2732
- {
2733
- // Allow exceptions from over-long size
2734
- LogPrintf (" %s(%s, %u bytes): Exception '%s' caught\n " , __func__, SanitizeString (strCommand), nMessageSize, e.what ());
2735
- }
2736
- else if (strstr (e.what (), " non-canonical ReadCompactSize()" ))
2737
- {
2738
- // Allow exceptions from non-canonical encoding
2739
- LogPrintf (" %s(%s, %u bytes): Exception '%s' caught\n " , __func__, SanitizeString (strCommand), nMessageSize, e.what ());
2740
- }
2741
- else
2742
- {
2743
- PrintExceptionContinue (&e, " ProcessMessages()" );
2744
- }
2738
+ // Allow exceptions from non-canonical encoding
2739
+ LogPrintf (" %s(%s, %u bytes): Exception '%s' caught\n " , __func__, SanitizeString (strCommand), nMessageSize, e.what ());
2745
2740
}
2746
- catch (const std::exception& e) {
2741
+ else
2742
+ {
2747
2743
PrintExceptionContinue (&e, " ProcessMessages()" );
2748
- } catch (...) {
2749
- PrintExceptionContinue (NULL , " ProcessMessages()" );
2750
2744
}
2745
+ }
2746
+ catch (const std::exception& e) {
2747
+ PrintExceptionContinue (&e, " ProcessMessages()" );
2748
+ } catch (...) {
2749
+ PrintExceptionContinue (NULL , " ProcessMessages()" );
2750
+ }
2751
2751
2752
- if (!fRet ) {
2753
- LogPrintf (" %s(%s, %u bytes) FAILED peer=%d\n " , __func__, SanitizeString (strCommand), nMessageSize, pfrom->id );
2754
- }
2752
+ if (!fRet ) {
2753
+ LogPrintf (" %s(%s, %u bytes) FAILED peer=%d\n " , __func__, SanitizeString (strCommand), nMessageSize, pfrom->id );
2754
+ }
2755
2755
2756
- LOCK (cs_main);
2757
- SendRejectsAndCheckIfBanned (pfrom, connman);
2756
+ LOCK (cs_main);
2757
+ SendRejectsAndCheckIfBanned (pfrom, connman);
2758
2758
2759
2759
return fMoreWork ;
2760
2760
}
0 commit comments