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