diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1890,7 +1890,7 @@ return true; } - else if (strCommand == NetMsgType::VERSION) { + if (strCommand == NetMsgType::VERSION) { // Each connection can only send one version message if (pfrom->nVersion != 0) { if (enable_bip61) { @@ -2101,7 +2101,7 @@ return true; } - else if (pfrom->nVersion == 0) { + if (pfrom->nVersion == 0) { // Must have a version message before anything else LOCK(cs_main); Misbehaving(pfrom, 1, "missing-version"); @@ -2147,16 +2147,17 @@ nCMPCTBLOCKVersion)); } pfrom->fSuccessfullyConnected = true; + return true; } - else if (!pfrom->fSuccessfullyConnected) { + if (!pfrom->fSuccessfullyConnected) { // Must have a verack message before anything else LOCK(cs_main); Misbehaving(pfrom, 1, "missing-verack"); return false; } - else if (strCommand == NetMsgType::ADDR) { + if (strCommand == NetMsgType::ADDR) { std::vector vAddr; vRecv >> vAddr; @@ -2211,14 +2212,16 @@ if (pfrom->fOneShot) { pfrom->fDisconnect = true; } + return true; } - else if (strCommand == NetMsgType::SENDHEADERS) { + if (strCommand == NetMsgType::SENDHEADERS) { LOCK(cs_main); State(pfrom->GetId())->fPreferHeaders = true; + return true; } - else if (strCommand == NetMsgType::SENDCMPCT) { + if (strCommand == NetMsgType::SENDCMPCT) { bool fAnnounceUsingCMPCTBLOCK = false; uint64_t nCMPCTBLOCKVersion = 0; vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion; @@ -2236,9 +2239,10 @@ State(pfrom->GetId())->fSupportsDesiredCmpctVersion = true; } } + return true; } - else if (strCommand == NetMsgType::INV) { + if (strCommand == NetMsgType::INV) { std::vector vInv; vRecv >> vInv; if (vInv.size() > MAX_INV_SZ) { @@ -2300,9 +2304,10 @@ } } } + return true; } - else if (strCommand == NetMsgType::GETDATA) { + if (strCommand == NetMsgType::GETDATA) { std::vector vInv; vRecv >> vInv; if (vInv.size() > MAX_INV_SZ) { @@ -2322,9 +2327,10 @@ pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end()); ProcessGetData(config, pfrom, connman, interruptMsgProc); + return true; } - else if (strCommand == NetMsgType::GETBLOCKS) { + if (strCommand == NetMsgType::GETBLOCKS) { CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; @@ -2403,9 +2409,10 @@ break; } } + return true; } - else if (strCommand == NetMsgType::GETBLOCKTXN) { + if (strCommand == NetMsgType::GETBLOCKTXN) { BlockTransactionsRequest req; vRecv >> req; @@ -2458,9 +2465,10 @@ assert(ret); SendBlockTransactions(block, req, pfrom, connman); + return true; } - else if (strCommand == NetMsgType::GETHEADERS) { + if (strCommand == NetMsgType::GETHEADERS) { CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; @@ -2535,9 +2543,10 @@ nodestate->pindexBestHeaderSent = pindex ? pindex : chainActive.Tip(); connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::HEADERS, vHeaders)); + return true; } - else if (strCommand == NetMsgType::TX) { + if (strCommand == NetMsgType::TX) { // Stop processing the transaction early if // We are in blocks only mode and peer is either not whitelisted or // whitelistrelay is off @@ -2755,10 +2764,11 @@ Misbehaving(pfrom, nDoS, state.GetRejectReason()); } } + return true; } // Ignore blocks received while importing - else if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) { + if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) { CBlockHeaderAndShortTxIDs cmpctblock; vRecv >> cmpctblock; @@ -3027,12 +3037,11 @@ MarkBlockAsReceived(pblock->GetHash()); } } - + return true; } - else if (strCommand == NetMsgType::BLOCKTXN && !fImporting && - !fReindex) // Ignore blocks received while importing - { + // Ignore blocks received while importing + if (strCommand == NetMsgType::BLOCKTXN && !fImporting && !fReindex) { BlockTransactions resp; vRecv >> resp; @@ -3120,10 +3129,11 @@ mapBlockSource.erase(pblock->GetHash()); } } + return true; } // Ignore headers received while importing - else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) { + if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) { std::vector headers; // Bypass the normal CBlock deserialization, as we don't want to risk @@ -3150,8 +3160,8 @@ should_punish); } - else if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) { - // Ignore blocks received while importing. + // Ignore blocks received while importing + if (strCommand == NetMsgType::BLOCK && !fImporting && !fReindex) { std::shared_ptr pblock = std::make_shared(); vRecv >> *pblock; @@ -3182,9 +3192,10 @@ LOCK(cs_main); mapBlockSource.erase(pblock->GetHash()); } + return true; } - else if (strCommand == NetMsgType::GETADDR) { + if (strCommand == NetMsgType::GETADDR) { // This asymmetric behavior for inbound and outbound connections was // introduced to prevent a fingerprinting attack: an attacker can send // specific fake addresses to users' AddrMan and later request them by @@ -3213,9 +3224,10 @@ for (const CAddress &addr : vAddr) { pfrom->PushAddress(addr, insecure_rand); } + return true; } - else if (strCommand == NetMsgType::MEMPOOL) { + if (strCommand == NetMsgType::MEMPOOL) { if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->fWhitelisted) { LogPrint(BCLog::NET, "mempool request with bloom filters disabled, disconnect " @@ -3236,9 +3248,10 @@ LOCK(pfrom->cs_inventory); pfrom->fSendMempool = true; + return true; } - else if (strCommand == NetMsgType::PING) { + if (strCommand == NetMsgType::PING) { if (pfrom->nVersion > BIP0031_VERSION) { uint64_t nonce = 0; vRecv >> nonce; @@ -3258,9 +3271,10 @@ // ping the remote sends would appear to return very quickly. connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::PONG, nonce)); } + return true; } - else if (strCommand == NetMsgType::PONG) { + if (strCommand == NetMsgType::PONG) { int64_t pingUsecEnd = nTimeReceived; uint64_t nonce = 0; size_t nAvail = vRecv.in_avail(); @@ -3316,9 +3330,10 @@ if (bPingFinished) { pfrom->nPingNonceSent = 0; } + return true; } - else if (strCommand == NetMsgType::FILTERLOAD) { + if (strCommand == NetMsgType::FILTERLOAD) { CBloomFilter filter; vRecv >> filter; @@ -3332,9 +3347,10 @@ pfrom->pfilter->UpdateEmptyFull(); pfrom->fRelayTxes = true; } + return true; } - else if (strCommand == NetMsgType::FILTERADD) { + if (strCommand == NetMsgType::FILTERADD) { std::vector vData; vRecv >> vData; @@ -3358,17 +3374,19 @@ // code. We'll go generic. Misbehaving(pfrom, 100, "invalid-filteradd"); } + return true; } - else if (strCommand == NetMsgType::FILTERCLEAR) { + if (strCommand == NetMsgType::FILTERCLEAR) { LOCK(pfrom->cs_filter); if (pfrom->GetLocalServices() & NODE_BLOOM) { pfrom->pfilter.reset(new CBloomFilter()); } pfrom->fRelayTxes = true; + return true; } - else if (strCommand == NetMsgType::FEEFILTER) { + if (strCommand == NetMsgType::FEEFILTER) { Amount newFeeFilter = Amount::zero(); vRecv >> newFeeFilter; if (MoneyRange(newFeeFilter)) { @@ -3379,19 +3397,18 @@ LogPrint(BCLog::NET, "received: feefilter of %s from peer=%d\n", CFeeRate(newFeeFilter).ToString(), pfrom->GetId()); } + return true; } - else if (strCommand == NetMsgType::NOTFOUND) { + if (strCommand == NetMsgType::NOTFOUND) { // We do not care about the NOTFOUND message, but logging an Unknown // Command message would be undesirable as we transmit it ourselves. + return true; } - else { - // Ignore unknown commands for extensibility - LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", - SanitizeString(strCommand), pfrom->GetId()); - } - + // Ignore unknown commands for extensibility + LogPrint(BCLog::NET, "Unknown command \"%s\" from peer=%d\n", + SanitizeString(strCommand), pfrom->GetId()); return true; }