From d4168c82bef0d86fd254a9d993906a09f5fd7fc0 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 9 Sep 2014 09:18:05 +0200 Subject: [PATCH 1/2] Limit CNode::mapAskFor Tighten resource constraints on CNode. --- src/net.cpp | 2 ++ src/net.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 2546826f9..6b7e62d7c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2106,6 +2106,8 @@ CNode::~CNode() void CNode::AskFor(const CInv& inv) { + if (mapAskFor.size() > MAPASKFOR_MAX_SZ) + return; // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent int64_t nRequestTime; diff --git a/src/net.h b/src/net.h index e2700c097..ad0a1df7e 100644 --- a/src/net.h +++ b/src/net.h @@ -51,6 +51,8 @@ static const bool DEFAULT_UPNP = USE_UPNP; #else static const bool DEFAULT_UPNP = false; #endif +/** The maximum number of entries in mapAskFor */ +static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ; unsigned int ReceiveFloodSize(); unsigned int SendBufferSize(); From 540ac4514dbe4e077917bad1750768218ef5f9cf Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 9 Sep 2014 09:26:52 +0200 Subject: [PATCH 2/2] Avoid returning many "inv" orphans --- src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2e24eb950..21a352f7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3639,6 +3639,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // Track requests for our stuff g_signals.Inventory(inv.hash); + + if (pfrom->nSendSize > (SendBufferSize() * 2)) { + Misbehaving(pfrom->GetId(), 50); + return error("send buffer size() = %u", pfrom->nSendSize); + } } }