mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Limit response to getblocks to half of output buffer size
Introduce SendBufferSize() and ReceiveBufferSize(), and limit the blocks sent as response to the "getblocks" message to half of the active send buffer size.
This commit is contained in:
parent
44d16327c1
commit
4973174534
10
src/main.cpp
10
src/main.cpp
@ -2040,20 +2040,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
if (pindex)
|
if (pindex)
|
||||||
pindex = pindex->pnext;
|
pindex = pindex->pnext;
|
||||||
int nLimit = 500 + locator.GetDistanceBack();
|
int nLimit = 500 + locator.GetDistanceBack();
|
||||||
|
unsigned int nBytes = 0;
|
||||||
printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);
|
printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);
|
||||||
for (; pindex; pindex = pindex->pnext)
|
for (; pindex; pindex = pindex->pnext)
|
||||||
{
|
{
|
||||||
if (pindex->GetBlockHash() == hashStop)
|
if (pindex->GetBlockHash() == hashStop)
|
||||||
{
|
{
|
||||||
printf(" getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str());
|
printf(" getblocks stopping at %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
|
pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash()));
|
||||||
if (--nLimit <= 0)
|
CBlock block;
|
||||||
|
block.ReadFromDisk(pindex, true);
|
||||||
|
nBytes += block.GetSerializeSize(SER_NETWORK);
|
||||||
|
if (--nLimit <= 0 || nBytes >= SendBufferSize()/2)
|
||||||
{
|
{
|
||||||
// When this block is requested, we'll send an inv that'll make them
|
// When this block is requested, we'll send an inv that'll make them
|
||||||
// getblocks the next batch of inventory.
|
// getblocks the next batch of inventory.
|
||||||
printf(" getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str());
|
printf(" getblocks stopping at limit %d %s (%u bytes)\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str(), nBytes);
|
||||||
pfrom->hashContinue = pindex->GetBlockHash();
|
pfrom->hashContinue = pindex->GetBlockHash();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -915,7 +915,7 @@ void ThreadSocketHandler2(void* parg)
|
|||||||
CDataStream& vRecv = pnode->vRecv;
|
CDataStream& vRecv = pnode->vRecv;
|
||||||
unsigned int nPos = vRecv.size();
|
unsigned int nPos = vRecv.size();
|
||||||
|
|
||||||
if (nPos > 1000*GetArg("-maxreceivebuffer", 10*1000)) {
|
if (nPos > ReceiveBufferSize()) {
|
||||||
if (!pnode->fDisconnect)
|
if (!pnode->fDisconnect)
|
||||||
printf("socket recv flood control disconnect (%d bytes)\n", vRecv.size());
|
printf("socket recv flood control disconnect (%d bytes)\n", vRecv.size());
|
||||||
pnode->CloseSocketDisconnect();
|
pnode->CloseSocketDisconnect();
|
||||||
@ -980,7 +980,7 @@ void ThreadSocketHandler2(void* parg)
|
|||||||
pnode->CloseSocketDisconnect();
|
pnode->CloseSocketDisconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vSend.size() > 1000*GetArg("-maxsendbuffer", 10*1000)) {
|
if (vSend.size() > SendBufferSize()) {
|
||||||
if (!pnode->fDisconnect)
|
if (!pnode->fDisconnect)
|
||||||
printf("socket send flood control disconnect (%d bytes)\n", vSend.size());
|
printf("socket send flood control disconnect (%d bytes)\n", vSend.size());
|
||||||
pnode->CloseSocketDisconnect();
|
pnode->CloseSocketDisconnect();
|
||||||
|
@ -23,6 +23,8 @@ extern int nConnectTimeout;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 10*1000); }
|
||||||
|
inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 10*1000); }
|
||||||
inline unsigned short GetDefaultPort() { return fTestNet ? 18333 : 8333; }
|
inline unsigned short GetDefaultPort() { return fTestNet ? 18333 : 8333; }
|
||||||
static const unsigned int PUBLISH_HOPS = 5;
|
static const unsigned int PUBLISH_HOPS = 5;
|
||||||
enum
|
enum
|
||||||
|
Loading…
Reference in New Issue
Block a user