aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-07-31 21:56:59 +0200
committerJon Atack <jon@atack.com>2021-08-04 19:03:51 +0200
commitd930c7f5b091687eb4208a5ffe8a2abe311d8054 (patch)
treee0460df9eb8367667dd86406f2193925caef42a5 /src/net_processing.cpp
parent2b06af17470667a9c9ee68cb241936839b46bc33 (diff)
downloadbitcoin-d930c7f5b091687eb4208a5ffe8a2abe311d8054.tar.xz
p2p, rpc, test: address rate-limiting follow-ups
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 9da2fe5d6f..823ff9e92f 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -161,7 +161,7 @@ static constexpr size_t MAX_ADDR_TO_SEND{1000};
static constexpr double MAX_ADDR_RATE_PER_SECOND{0.1};
/** The soft limit of the address processing token bucket (the regular MAX_ADDR_RATE_PER_SECOND
* based increments won't go above this, but the MAX_ADDR_TO_SEND increment following GETADDR
- * is exempt from this limit. */
+ * is exempt from this limit). */
static constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET{MAX_ADDR_TO_SEND};
// Internal stuff
@@ -263,14 +263,14 @@ struct Peer {
std::atomic_bool m_wants_addrv2{false};
/** Whether this peer has already sent us a getaddr message. */
bool m_getaddr_recvd{false};
- /** Number of addr messages that can be processed from this peer. Start at 1 to
+ /** Number of addresses that can be processed from this peer. Start at 1 to
* permit self-announcement. */
double m_addr_token_bucket{1.0};
/** When m_addr_token_bucket was last updated */
std::chrono::microseconds m_addr_token_timestamp{GetTime<std::chrono::microseconds>()};
/** Total number of addresses that were dropped due to rate limiting. */
std::atomic<uint64_t> m_addr_rate_limited{0};
- /** Total number of addresses that were processed (excludes rate limited ones). */
+ /** Total number of addresses that were processed (excludes rate-limited ones). */
std::atomic<uint64_t> m_addr_processed{0};
/** Set of txids to reconsider once their parent transactions have been accepted **/
@@ -2848,11 +2848,12 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
return;
// Apply rate limiting.
- if (rate_limited) {
- if (peer->m_addr_token_bucket < 1.0) {
+ if (peer->m_addr_token_bucket < 1.0) {
+ if (rate_limited) {
++num_rate_limit;
continue;
}
+ } else {
peer->m_addr_token_bucket -= 1.0;
}
// We only bother storing full nodes, though this may include
@@ -2880,12 +2881,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
}
peer->m_addr_processed += num_proc;
peer->m_addr_rate_limited += num_rate_limit;
- LogPrint(BCLog::NET, "Received addr: %u addresses (%u processed, %u rate-limited) from peer=%d%s\n",
- vAddr.size(),
- num_proc,
- num_rate_limit,
- pfrom.GetId(),
- fLogIPs ? ", peeraddr=" + pfrom.addr.ToString() : "");
+ LogPrint(BCLog::NET, "Received addr: %u addresses (%u processed, %u rate-limited) from peer=%d\n",
+ vAddr.size(), num_proc, num_rate_limit, pfrom.GetId());
m_addrman.Add(vAddrOk, pfrom.addr, 2 * 60 * 60);
if (vAddr.size() < 1000) peer->m_getaddr_sent = false;