@@ -1618,8 +1618,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1618
1618
return true ;
1619
1619
}
1620
1620
1621
- else if (strCommand == NetMsgType::VERSION)
1622
- {
1621
+ if (strCommand == NetMsgType::VERSION) {
1623
1622
// Each connection can only send one version message
1624
1623
if (pfrom->nVersion != 0 )
1625
1624
{
@@ -1793,9 +1792,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1793
1792
return true ;
1794
1793
}
1795
1794
1796
-
1797
- else if (pfrom->nVersion == 0 )
1798
- {
1795
+ if (pfrom->nVersion == 0 ) {
1799
1796
// Must have a version message before anything else
1800
1797
LOCK (cs_main);
1801
1798
Misbehaving (pfrom->GetId (), 1 );
@@ -1839,18 +1836,17 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1839
1836
connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion));
1840
1837
}
1841
1838
pfrom->fSuccessfullyConnected = true ;
1839
+ return true ;
1842
1840
}
1843
1841
1844
- else if (!pfrom->fSuccessfullyConnected )
1845
- {
1842
+ if (!pfrom->fSuccessfullyConnected ) {
1846
1843
// Must have a verack message before anything else
1847
1844
LOCK (cs_main);
1848
1845
Misbehaving (pfrom->GetId (), 1 );
1849
1846
return false ;
1850
1847
}
1851
1848
1852
- else if (strCommand == NetMsgType::ADDR)
1853
- {
1849
+ if (strCommand == NetMsgType::ADDR) {
1854
1850
std::vector<CAddress> vAddr;
1855
1851
vRecv >> vAddr;
1856
1852
@@ -1897,16 +1893,16 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1897
1893
pfrom->fGetAddr = false ;
1898
1894
if (pfrom->fOneShot )
1899
1895
pfrom->fDisconnect = true ;
1896
+ return true ;
1900
1897
}
1901
1898
1902
- else if (strCommand == NetMsgType::SENDHEADERS)
1903
- {
1899
+ if (strCommand == NetMsgType::SENDHEADERS) {
1904
1900
LOCK (cs_main);
1905
1901
State (pfrom->GetId ())->fPreferHeaders = true ;
1902
+ return true ;
1906
1903
}
1907
1904
1908
- else if (strCommand == NetMsgType::SENDCMPCT)
1909
- {
1905
+ if (strCommand == NetMsgType::SENDCMPCT) {
1910
1906
bool fAnnounceUsingCMPCTBLOCK = false ;
1911
1907
uint64_t nCMPCTBLOCKVersion = 0 ;
1912
1908
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
@@ -1926,11 +1922,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1926
1922
State (pfrom->GetId ())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1 );
1927
1923
}
1928
1924
}
1925
+ return true ;
1929
1926
}
1930
1927
1931
-
1932
- else if (strCommand == NetMsgType::INV)
1933
- {
1928
+ if (strCommand == NetMsgType::INV) {
1934
1929
std::vector<CInv> vInv;
1935
1930
vRecv >> vInv;
1936
1931
if (vInv.size () > MAX_INV_SZ)
@@ -1984,11 +1979,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1984
1979
}
1985
1980
}
1986
1981
}
1982
+ return true ;
1987
1983
}
1988
1984
1989
-
1990
- else if (strCommand == NetMsgType::GETDATA)
1991
- {
1985
+ if (strCommand == NetMsgType::GETDATA) {
1992
1986
std::vector<CInv> vInv;
1993
1987
vRecv >> vInv;
1994
1988
if (vInv.size () > MAX_INV_SZ)
@@ -2006,11 +2000,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2006
2000
2007
2001
pfrom->vRecvGetData .insert (pfrom->vRecvGetData .end (), vInv.begin (), vInv.end ());
2008
2002
ProcessGetData (pfrom, chainparams, connman, interruptMsgProc);
2003
+ return true ;
2009
2004
}
2010
2005
2011
-
2012
- else if (strCommand == NetMsgType::GETBLOCKS)
2013
- {
2006
+ if (strCommand == NetMsgType::GETBLOCKS) {
2014
2007
CBlockLocator locator;
2015
2008
uint256 hashStop;
2016
2009
vRecv >> locator >> hashStop;
@@ -2075,11 +2068,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2075
2068
break ;
2076
2069
}
2077
2070
}
2071
+ return true ;
2078
2072
}
2079
2073
2080
-
2081
- else if (strCommand == NetMsgType::GETBLOCKTXN)
2082
- {
2074
+ if (strCommand == NetMsgType::GETBLOCKTXN) {
2083
2075
BlockTransactionsRequest req;
2084
2076
vRecv >> req;
2085
2077
@@ -2125,11 +2117,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2125
2117
assert (ret);
2126
2118
2127
2119
SendBlockTransactions (block, req, pfrom, connman);
2120
+ return true ;
2128
2121
}
2129
2122
2130
-
2131
- else if (strCommand == NetMsgType::GETHEADERS)
2132
- {
2123
+ if (strCommand == NetMsgType::GETHEADERS) {
2133
2124
CBlockLocator locator;
2134
2125
uint256 hashStop;
2135
2126
vRecv >> locator >> hashStop;
@@ -2193,11 +2184,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2193
2184
// in the SendMessages logic.
2194
2185
nodestate->pindexBestHeaderSent = pindex ? pindex : chainActive.Tip ();
2195
2186
connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::HEADERS, vHeaders));
2187
+ return true ;
2196
2188
}
2197
2189
2198
-
2199
- else if (strCommand == NetMsgType::TX)
2200
- {
2190
+ if (strCommand == NetMsgType::TX) {
2201
2191
// Stop processing the transaction early if
2202
2192
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
2203
2193
if (!fRelayTxes && (!pfrom->fWhitelisted || !gArgs .GetBoolArg (" -whitelistrelay" , DEFAULT_WHITELISTRELAY)))
@@ -2381,10 +2371,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2381
2371
Misbehaving (pfrom->GetId (), nDoS);
2382
2372
}
2383
2373
}
2374
+ return true ;
2384
2375
}
2385
2376
2386
-
2387
- else if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex ) // Ignore blocks received while importing
2377
+ if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex ) // Ignore blocks received while importing
2388
2378
{
2389
2379
CBlockHeaderAndShortTxIDs cmpctblock;
2390
2380
vRecv >> cmpctblock;
@@ -2602,10 +2592,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2602
2592
MarkBlockAsReceived (pblock->GetHash ());
2603
2593
}
2604
2594
}
2605
-
2595
+ return true ;
2606
2596
}
2607
2597
2608
- else if (strCommand == NetMsgType::BLOCKTXN && !fImporting && !fReindex ) // Ignore blocks received while importing
2598
+ if (strCommand == NetMsgType::BLOCKTXN && !fImporting && !fReindex ) // Ignore blocks received while importing
2609
2599
{
2610
2600
BlockTransactions resp;
2611
2601
vRecv >> resp;
@@ -2677,10 +2667,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2677
2667
mapBlockSource.erase (pblock->GetHash ());
2678
2668
}
2679
2669
}
2670
+ return true ;
2680
2671
}
2681
2672
2682
-
2683
- else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex ) // Ignore headers received while importing
2673
+ if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex ) // Ignore headers received while importing
2684
2674
{
2685
2675
std::vector<CBlockHeader> headers;
2686
2676
@@ -2705,7 +2695,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2705
2695
return ProcessHeadersMessage (pfrom, connman, headers, chainparams, should_punish);
2706
2696
}
2707
2697
2708
- else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex ) // Ignore blocks received while importing
2698
+ if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex ) // Ignore blocks received while importing
2709
2699
{
2710
2700
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
2711
2701
vRecv >> *pblock;
@@ -2731,11 +2721,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2731
2721
LOCK (cs_main);
2732
2722
mapBlockSource.erase (pblock->GetHash ());
2733
2723
}
2724
+ return true ;
2734
2725
}
2735
2726
2736
-
2737
- else if (strCommand == NetMsgType::GETADDR)
2738
- {
2727
+ if (strCommand == NetMsgType::GETADDR) {
2739
2728
// This asymmetric behavior for inbound and outbound connections was introduced
2740
2729
// to prevent a fingerprinting attack: an attacker can send specific fake addresses
2741
2730
// to users' AddrMan and later request them by sending getaddr messages.
@@ -2759,11 +2748,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2759
2748
FastRandomContext insecure_rand;
2760
2749
for (const CAddress &addr : vAddr)
2761
2750
pfrom->PushAddress (addr, insecure_rand);
2751
+ return true ;
2762
2752
}
2763
2753
2764
-
2765
- else if (strCommand == NetMsgType::MEMPOOL)
2766
- {
2754
+ if (strCommand == NetMsgType::MEMPOOL) {
2767
2755
if (!(pfrom->GetLocalServices () & NODE_BLOOM) && !pfrom->fWhitelisted )
2768
2756
{
2769
2757
LogPrint (BCLog::NET, " mempool request with bloom filters disabled, disconnect peer=%d\n " , pfrom->GetId ());
@@ -2780,11 +2768,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2780
2768
2781
2769
LOCK (pfrom->cs_inventory );
2782
2770
pfrom->fSendMempool = true ;
2771
+ return true ;
2783
2772
}
2784
2773
2785
-
2786
- else if (strCommand == NetMsgType::PING)
2787
- {
2774
+ if (strCommand == NetMsgType::PING) {
2788
2775
if (pfrom->nVersion > BIP0031_VERSION)
2789
2776
{
2790
2777
uint64_t nonce = 0 ;
@@ -2802,11 +2789,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2802
2789
// return very quickly.
2803
2790
connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::PONG, nonce));
2804
2791
}
2792
+ return true ;
2805
2793
}
2806
2794
2807
-
2808
- else if (strCommand == NetMsgType::PONG)
2809
- {
2795
+ if (strCommand == NetMsgType::PONG) {
2810
2796
int64_t pingUsecEnd = nTimeReceived;
2811
2797
uint64_t nonce = 0 ;
2812
2798
size_t nAvail = vRecv.in_avail ();
@@ -2859,11 +2845,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2859
2845
if (bPingFinished) {
2860
2846
pfrom->nPingNonceSent = 0 ;
2861
2847
}
2848
+ return true ;
2862
2849
}
2863
2850
2864
-
2865
- else if (strCommand == NetMsgType::FILTERLOAD)
2866
- {
2851
+ if (strCommand == NetMsgType::FILTERLOAD) {
2867
2852
CBloomFilter filter;
2868
2853
vRecv >> filter;
2869
2854
@@ -2880,11 +2865,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2880
2865
pfrom->pfilter ->UpdateEmptyFull ();
2881
2866
pfrom->fRelayTxes = true ;
2882
2867
}
2868
+ return true ;
2883
2869
}
2884
2870
2885
-
2886
- else if (strCommand == NetMsgType::FILTERADD)
2887
- {
2871
+ if (strCommand == NetMsgType::FILTERADD) {
2888
2872
std::vector<unsigned char > vData;
2889
2873
vRecv >> vData;
2890
2874
@@ -2905,19 +2889,19 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2905
2889
LOCK (cs_main);
2906
2890
Misbehaving (pfrom->GetId (), 100 );
2907
2891
}
2892
+ return true ;
2908
2893
}
2909
2894
2910
-
2911
- else if (strCommand == NetMsgType::FILTERCLEAR)
2912
- {
2895
+ if (strCommand == NetMsgType::FILTERCLEAR) {
2913
2896
LOCK (pfrom->cs_filter );
2914
2897
if (pfrom->GetLocalServices () & NODE_BLOOM) {
2915
2898
pfrom->pfilter .reset (new CBloomFilter ());
2916
2899
}
2917
2900
pfrom->fRelayTxes = true ;
2901
+ return true ;
2918
2902
}
2919
2903
2920
- else if (strCommand == NetMsgType::FEEFILTER) {
2904
+ if (strCommand == NetMsgType::FEEFILTER) {
2921
2905
CAmount newFeeFilter = 0 ;
2922
2906
vRecv >> newFeeFilter;
2923
2907
if (MoneyRange (newFeeFilter)) {
@@ -2927,20 +2911,17 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2927
2911
}
2928
2912
LogPrint (BCLog::NET, " received: feefilter of %s from peer=%d\n " , CFeeRate (newFeeFilter).ToString (), pfrom->GetId ());
2929
2913
}
2914
+ return true ;
2930
2915
}
2931
2916
2932
- else if (strCommand == NetMsgType::NOTFOUND) {
2917
+ if (strCommand == NetMsgType::NOTFOUND) {
2933
2918
// We do not care about the NOTFOUND message, but logging an Unknown Command
2934
2919
// message would be undesirable as we transmit it ourselves.
2920
+ return true ;
2935
2921
}
2936
2922
2937
- else {
2938
- // Ignore unknown commands for extensibility
2939
- LogPrint (BCLog::NET, " Unknown command \" %s\" from peer=%d\n " , SanitizeString (strCommand), pfrom->GetId ());
2940
- }
2941
-
2942
-
2943
-
2923
+ // Ignore unknown commands for extensibility
2924
+ LogPrint (BCLog::NET, " Unknown command \" %s\" from peer=%d\n " , SanitizeString (strCommand), pfrom->GetId ());
2944
2925
return true ;
2945
2926
}
2946
2927
0 commit comments