net: move SendBufferSize/ReceiveFloodSize to CConnman
This commit is contained in:
parent
63cafa6329
commit
be9c796dc5
3 changed files with 23 additions and 10 deletions
10
src/main.cpp
10
src/main.cpp
|
@ -4769,6 +4769,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman& connma
|
||||||
void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman& connman)
|
void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParams, CConnman& connman)
|
||||||
{
|
{
|
||||||
std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin();
|
std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin();
|
||||||
|
unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
|
||||||
|
|
||||||
vector<CInv> vNotFound;
|
vector<CInv> vNotFound;
|
||||||
|
|
||||||
|
@ -4776,7 +4777,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
|
||||||
|
|
||||||
while (it != pfrom->vRecvGetData.end()) {
|
while (it != pfrom->vRecvGetData.end()) {
|
||||||
// Don't bother if send buffer is too full to respond anyway
|
// Don't bother if send buffer is too full to respond anyway
|
||||||
if (pfrom->nSendSize >= SendBufferSize())
|
if (pfrom->nSendSize >= nMaxSendBufferSize)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const CInv &inv = *it;
|
const CInv &inv = *it;
|
||||||
|
@ -4934,6 +4935,8 @@ uint32_t GetFetchFlags(CNode* pfrom, CBlockIndex* pprev, const Consensus::Params
|
||||||
|
|
||||||
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman)
|
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman& connman)
|
||||||
{
|
{
|
||||||
|
unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
|
||||||
|
|
||||||
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
|
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
|
||||||
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
|
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
|
||||||
{
|
{
|
||||||
|
@ -5283,7 +5286,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||||
// Track requests for our stuff
|
// Track requests for our stuff
|
||||||
GetMainSignals().Inventory(inv.hash);
|
GetMainSignals().Inventory(inv.hash);
|
||||||
|
|
||||||
if (pfrom->nSendSize > (SendBufferSize() * 2)) {
|
if (pfrom->nSendSize > (nMaxSendBufferSize * 2)) {
|
||||||
Misbehaving(pfrom->GetId(), 50);
|
Misbehaving(pfrom->GetId(), 50);
|
||||||
return error("send buffer size() = %u", pfrom->nSendSize);
|
return error("send buffer size() = %u", pfrom->nSendSize);
|
||||||
}
|
}
|
||||||
|
@ -6188,6 +6191,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||||
bool ProcessMessages(CNode* pfrom, CConnman& connman)
|
bool ProcessMessages(CNode* pfrom, CConnman& connman)
|
||||||
{
|
{
|
||||||
const CChainParams& chainparams = Params();
|
const CChainParams& chainparams = Params();
|
||||||
|
unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
|
||||||
//if (fDebug)
|
//if (fDebug)
|
||||||
// LogPrintf("%s(%u messages)\n", __func__, pfrom->vRecvMsg.size());
|
// LogPrintf("%s(%u messages)\n", __func__, pfrom->vRecvMsg.size());
|
||||||
|
|
||||||
|
@ -6210,7 +6214,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman)
|
||||||
std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin();
|
std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin();
|
||||||
while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) {
|
while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) {
|
||||||
// Don't bother if send buffer is too full to respond anyway
|
// Don't bother if send buffer is too full to respond anyway
|
||||||
if (pfrom->nSendSize >= SendBufferSize())
|
if (pfrom->nSendSize >= nMaxSendBufferSize)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// get next message
|
// get next message
|
||||||
|
|
13
src/net.cpp
13
src/net.cpp
|
@ -1181,7 +1181,7 @@ void CConnman::ThreadSocketHandler()
|
||||||
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
|
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
|
||||||
if (lockRecv && (
|
if (lockRecv && (
|
||||||
pnode->vRecvMsg.empty() || !pnode->vRecvMsg.front().complete() ||
|
pnode->vRecvMsg.empty() || !pnode->vRecvMsg.front().complete() ||
|
||||||
pnode->GetTotalRecvSize() <= ReceiveFloodSize()))
|
pnode->GetTotalRecvSize() <= GetReceiveFloodSize()))
|
||||||
FD_SET(pnode->hSocket, &fdsetRecv);
|
FD_SET(pnode->hSocket, &fdsetRecv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1851,7 +1851,7 @@ void CConnman::ThreadMessageHandler()
|
||||||
if (!GetNodeSignals().ProcessMessages(pnode, *this))
|
if (!GetNodeSignals().ProcessMessages(pnode, *this))
|
||||||
pnode->CloseSocketDisconnect();
|
pnode->CloseSocketDisconnect();
|
||||||
|
|
||||||
if (pnode->nSendSize < SendBufferSize())
|
if (pnode->nSendSize < GetSendBufferSize())
|
||||||
{
|
{
|
||||||
if (!pnode->vRecvGetData.empty() || (!pnode->vRecvMsg.empty() && pnode->vRecvMsg[0].complete()))
|
if (!pnode->vRecvGetData.empty() || (!pnode->vRecvMsg.empty() && pnode->vRecvMsg[0].complete()))
|
||||||
{
|
{
|
||||||
|
@ -2041,6 +2041,8 @@ CConnman::CConnman()
|
||||||
setBannedIsDirty = false;
|
setBannedIsDirty = false;
|
||||||
fAddressesInitialized = false;
|
fAddressesInitialized = false;
|
||||||
nLastNodeId = 0;
|
nLastNodeId = 0;
|
||||||
|
nSendBufferMaxSize = 0;
|
||||||
|
nReceiveFloodSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError)
|
bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError)
|
||||||
|
@ -2066,6 +2068,9 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, st
|
||||||
nMaxOutboundTimeframe = 60*60*24; //1 day
|
nMaxOutboundTimeframe = 60*60*24; //1 day
|
||||||
nMaxOutboundCycleStartTime = 0;
|
nMaxOutboundCycleStartTime = 0;
|
||||||
|
|
||||||
|
nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
|
||||||
|
nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
|
||||||
|
|
||||||
uiInterface.InitMessage(_("Loading addresses..."));
|
uiInterface.InitMessage(_("Loading addresses..."));
|
||||||
// Load addresses from peers.dat
|
// Load addresses from peers.dat
|
||||||
int64_t nStart = GetTimeMillis();
|
int64_t nStart = GetTimeMillis();
|
||||||
|
@ -2497,8 +2502,8 @@ void CNode::Fuzz(int nChance)
|
||||||
Fuzz(2);
|
Fuzz(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); }
|
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
|
||||||
unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); }
|
unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; }
|
||||||
|
|
||||||
CNode::CNode(NodeId idIn, SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNameIn, bool fInboundIn) :
|
CNode::CNode(NodeId idIn, SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNameIn, bool fInboundIn) :
|
||||||
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
|
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
|
||||||
|
|
10
src/net.h
10
src/net.h
|
@ -82,9 +82,6 @@ static const ServiceFlags REQUIRED_SERVICES = NODE_NETWORK;
|
||||||
// NOTE: When adjusting this, update rpcnet:setban's help ("24h")
|
// NOTE: When adjusting this, update rpcnet:setban's help ("24h")
|
||||||
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban
|
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban
|
||||||
|
|
||||||
unsigned int ReceiveFloodSize();
|
|
||||||
unsigned int SendBufferSize();
|
|
||||||
|
|
||||||
typedef int NodeId;
|
typedef int NodeId;
|
||||||
|
|
||||||
struct AddedNodeInfo
|
struct AddedNodeInfo
|
||||||
|
@ -170,6 +167,8 @@ public:
|
||||||
bool DisconnectNode(NodeId id);
|
bool DisconnectNode(NodeId id);
|
||||||
bool DisconnectSubnet(const CSubNet& subnet);
|
bool DisconnectSubnet(const CSubNet& subnet);
|
||||||
|
|
||||||
|
unsigned int GetSendBufferSize() const;
|
||||||
|
|
||||||
void AddWhitelistedRange(const CSubNet &subnet);
|
void AddWhitelistedRange(const CSubNet &subnet);
|
||||||
|
|
||||||
//!set the max outbound target in bytes
|
//!set the max outbound target in bytes
|
||||||
|
@ -235,6 +234,8 @@ private:
|
||||||
void DumpData();
|
void DumpData();
|
||||||
void DumpBanlist();
|
void DumpBanlist();
|
||||||
|
|
||||||
|
unsigned int GetReceiveFloodSize() const;
|
||||||
|
|
||||||
// Network stats
|
// Network stats
|
||||||
void RecordBytesRecv(uint64_t bytes);
|
void RecordBytesRecv(uint64_t bytes);
|
||||||
void RecordBytesSent(uint64_t bytes);
|
void RecordBytesSent(uint64_t bytes);
|
||||||
|
@ -256,6 +257,9 @@ private:
|
||||||
std::vector<CSubNet> vWhitelistedRange;
|
std::vector<CSubNet> vWhitelistedRange;
|
||||||
CCriticalSection cs_vWhitelistedRange;
|
CCriticalSection cs_vWhitelistedRange;
|
||||||
|
|
||||||
|
unsigned int nSendBufferMaxSize;
|
||||||
|
unsigned int nReceiveFloodSize;
|
||||||
|
|
||||||
std::vector<ListenSocket> vhListenSocket;
|
std::vector<ListenSocket> vhListenSocket;
|
||||||
banmap_t setBanned;
|
banmap_t setBanned;
|
||||||
CCriticalSection cs_setBanned;
|
CCriticalSection cs_setBanned;
|
||||||
|
|
Loading…
Reference in a new issue