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