diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -573,7 +573,7 @@ uint64_t nRecvBytes; mapMsgCmdSize mapRecvBytesPerMsgCmd; NetPermissionFlags m_permissionFlags; - bool fWhitelisted; + bool m_legacyWhitelisted; double dPingTime; double dPingWait; double dMinPing; @@ -689,8 +689,9 @@ bool HasPermission(NetPermissionFlags permission) const { return NetPermissions::HasFlag(m_permissionFlags, permission); } - // This peer can bypass DoS banning. - bool fWhitelisted{false}; + // This boolean is unusued in actual processing, only present for backward + // compatibility at RPC/QT level + bool m_legacyWhitelisted{false}; // If true this node is being used as a short lived feeler. bool fFeeler{false}; bool fOneShot{false}; diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -534,7 +534,7 @@ stats.mapRecvBytesPerMsgCmd = mapRecvBytesPerMsgCmd; stats.nRecvBytes = nRecvBytes; } - stats.fWhitelisted = fWhitelisted; + stats.m_legacyWhitelisted = m_legacyWhitelisted; stats.m_permissionFlags = m_permissionFlags; { LOCK(cs_feeFilter); @@ -868,8 +868,14 @@ { LOCK(cs_vNodes); - for (CNode *node : vNodes) { - if (node->fWhitelisted || !node->fInbound || node->fDisconnect) { + for (const CNode *node : vNodes) { + if (node->HasPermission(PF_NOBAN)) { + continue; + } + if (!node->fInbound) { + continue; + } + if (node->fDisconnect) { continue; } LOCK(node->cs_filter); @@ -1074,7 +1080,7 @@ pnode->m_permissionFlags = permissionFlags; // If this flag is present, the user probably expect that RPC and QT report // it as whitelisted (backward compatibility) - pnode->fWhitelisted = legacyWhitelisted; + pnode->m_legacyWhitelisted = legacyWhitelisted; pnode->m_prefer_evict = bannedlevel > 0; m_msgproc->InitializeNode(*config, pnode); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -476,8 +476,9 @@ nPreferredDownload -= state->fPreferredDownload; // Whether this node should be marked as a preferred download node. - state->fPreferredDownload = (!node->fInbound || node->fWhitelisted) && - !node->fOneShot && !node->fClient; + state->fPreferredDownload = + (!node->fInbound || node->HasPermission(PF_NOBAN)) && !node->fOneShot && + !node->fClient; nPreferredDownload += state->fPreferredDownload; } @@ -1569,7 +1570,7 @@ (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) && - !pfrom->fWhitelisted) { + !pfrom->HasPermission(PF_NOBAN)) { LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom->GetId()); @@ -1581,7 +1582,7 @@ // Avoid leaking prune-height by never sending blocks below the // NODE_NETWORK_LIMITED threshold. // Add two blocks buffer extension for possible races - if (send && !pfrom->fWhitelisted && + if (send && !pfrom->HasPermission(PF_NOBAN) && ((((pfrom->GetLocalServices() & NODE_NETWORK_LIMITED) == NODE_NETWORK_LIMITED) && ((pfrom->GetLocalServices() & NODE_NETWORK) != NODE_NETWORK) && @@ -2470,8 +2471,7 @@ // Allow whitelisted peers to send data other than blocks in blocks only // mode if whitelistrelay is true - if (pfrom->fWhitelisted && - gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) { + if (pfrom->HasPermission(PF_RELAY)) { fBlocksOnly = false; } @@ -2701,7 +2701,7 @@ } LOCK(cs_main); - if (IsInitialBlockDownload() && !pfrom->fWhitelisted) { + if (IsInitialBlockDownload() && !pfrom->HasPermission(PF_NOBAN)) { LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because node is in " "initial block download\n", @@ -2770,9 +2770,7 @@ // Stop processing the transaction early if // We are in blocks only mode and peer is either not whitelisted or // whitelistrelay is off - if (!fRelayTxes && - (!pfrom->fWhitelisted || - !gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))) { + if (!fRelayTxes && !pfrom->HasPermission(PF_RELAY)) { LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId()); @@ -2947,9 +2945,7 @@ } } - if (pfrom->fWhitelisted && - gArgs.GetBoolArg("-whitelistforcerelay", - DEFAULT_WHITELISTFORCERELAY)) { + if (pfrom->HasPermission(PF_FORCERELAY)) { // Always relay transactions received from whitelisted peers, // even if they were already in the mempool or rejected from it // due to policy, allowing the node to function as a gateway for @@ -3402,7 +3398,8 @@ // unless we're still syncing with the network. Such an unrequested // block may still be processed, subject to the conditions in // AcceptBlock(). - bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload(); + bool forceProcessing = + pfrom->HasPermission(PF_NOBAN) && !IsInitialBlockDownload(); const uint256 hash(pblock->GetHash()); { LOCK(cs_main); @@ -3557,7 +3554,8 @@ } if (strCommand == NetMsgType::MEMPOOL) { - if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->fWhitelisted) { + if (!(pfrom->GetLocalServices() & NODE_BLOOM) && + !pfrom->HasPermission(PF_MEMPOOL)) { if (!pfrom->HasPermission(PF_NOBAN)) { LogPrint(BCLog::NET, "mempool request with bloom filters disabled, " @@ -3568,7 +3566,8 @@ return true; } - if (connman->OutboundTargetReached(false) && !pfrom->fWhitelisted) { + if (connman->OutboundTargetReached(false) && + !pfrom->HasPermission(PF_MEMPOOL)) { if (!pfrom->HasPermission(PF_NOBAN)) { LogPrint(BCLog::NET, "mempool request with bandwidth limit reached, " @@ -3788,7 +3787,7 @@ if (state.fShouldBan) { state.fShouldBan = false; - if (pnode->fWhitelisted) { + if (pnode->HasPermission(PF_NOBAN)) { LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString()); } else if (pnode->m_manual_connection) { @@ -4503,7 +4502,7 @@ pto->vInventoryBlockToSend.clear(); // Check whether periodic sends should happen - bool fSendTrickle = pto->fWhitelisted; + bool fSendTrickle = pto->HasPermission(PF_NOBAN); if (pto->nNextInvSend < nNow) { fSendTrickle = true; if (pto->fInbound) { @@ -4697,7 +4696,7 @@ // Note: If all our peers are inbound, then we won't disconnect // our sync peer for stalling; we have bigger problems if we // can't get any outbound peers. - if (!pto->fWhitelisted) { + if (!pto->HasPermission(PF_NOBAN)) { LogPrintf("Timeout downloading headers from peer=%d, " "disconnecting\n", pto->GetId()); @@ -4832,8 +4831,7 @@ // -whitelistforcerelay if (pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) && - !(pto->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", - DEFAULT_WHITELISTFORCERELAY))) { + !pto->HasPermission(PF_FORCERELAY)) { Amount currentFilter = g_mempool .GetMinFee( diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1310,8 +1310,8 @@ : tr("Outbound")); ui->peerHeight->setText( QString("%1").arg(QString::number(stats->nodeStats.nStartingHeight))); - ui->peerWhitelisted->setText(stats->nodeStats.fWhitelisted ? tr("Yes") - : tr("No")); + ui->peerWhitelisted->setText( + stats->nodeStats.m_legacyWhitelisted ? tr("Yes") : tr("No")); // This check fails for example if the lock was busy and // nodeStateStats couldn't be fetched. diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -222,7 +222,7 @@ } obj.pushKV("inflight", heights); } - obj.pushKV("whitelisted", stats.fWhitelisted); + obj.pushKV("whitelisted", stats.m_legacyWhitelisted); UniValue permissions(UniValue::VARR); for (const auto &permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {