aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-04-19 00:01:19 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:24:06 -0400
commitbe9c796dc51c05cab0b84d2e66c928973c6e5ed6 (patch)
tree5ee7a73b713fcdc8501db979e867782b56e8ac7f /src
parent63cafa6329e1a0a1daf2d324931aca42ba1cbb19 (diff)
downloadbitcoin-be9c796dc51c05cab0b84d2e66c928973c6e5ed6.tar.xz
net: move SendBufferSize/ReceiveFloodSize to CConnman
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp10
-rw-r--r--src/net.cpp13
-rw-r--r--src/net.h10
3 files changed, 23 insertions, 10 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 019db0bdb3..db9d0d3f18 100644
--- a/src/main.cpp
+++ b/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)
{
std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin();
+ unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
vector<CInv> vNotFound;
@@ -4776,7 +4777,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
while (it != pfrom->vRecvGetData.end()) {
// Don't bother if send buffer is too full to respond anyway
- if (pfrom->nSendSize >= SendBufferSize())
+ if (pfrom->nSendSize >= nMaxSendBufferSize)
break;
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)
{
+ unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
+
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
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
GetMainSignals().Inventory(inv.hash);
- if (pfrom->nSendSize > (SendBufferSize() * 2)) {
+ if (pfrom->nSendSize > (nMaxSendBufferSize * 2)) {
Misbehaving(pfrom->GetId(), 50);
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)
{
const CChainParams& chainparams = Params();
+ unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
//if (fDebug)
// 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();
while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) {
// Don't bother if send buffer is too full to respond anyway
- if (pfrom->nSendSize >= SendBufferSize())
+ if (pfrom->nSendSize >= nMaxSendBufferSize)
break;
// get next message
diff --git a/src/net.cpp b/src/net.cpp
index 0787b16ad6..2839474cb9 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1181,7 +1181,7 @@ void CConnman::ThreadSocketHandler()
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv && (
pnode->vRecvMsg.empty() || !pnode->vRecvMsg.front().complete() ||
- pnode->GetTotalRecvSize() <= ReceiveFloodSize()))
+ pnode->GetTotalRecvSize() <= GetReceiveFloodSize()))
FD_SET(pnode->hSocket, &fdsetRecv);
}
}
@@ -1851,7 +1851,7 @@ void CConnman::ThreadMessageHandler()
if (!GetNodeSignals().ProcessMessages(pnode, *this))
pnode->CloseSocketDisconnect();
- if (pnode->nSendSize < SendBufferSize())
+ if (pnode->nSendSize < GetSendBufferSize())
{
if (!pnode->vRecvGetData.empty() || (!pnode->vRecvMsg.empty() && pnode->vRecvMsg[0].complete()))
{
@@ -2041,6 +2041,8 @@ CConnman::CConnman()
setBannedIsDirty = false;
fAddressesInitialized = false;
nLastNodeId = 0;
+ nSendBufferMaxSize = 0;
+ nReceiveFloodSize = 0;
}
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
nMaxOutboundCycleStartTime = 0;
+ nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
+ nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
+
uiInterface.InitMessage(_("Loading addresses..."));
// Load addresses from peers.dat
int64_t nStart = GetTimeMillis();
@@ -2497,8 +2502,8 @@ void CNode::Fuzz(int nChance)
Fuzz(2);
}
-unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); }
-unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); }
+unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }
+unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; }
CNode::CNode(NodeId idIn, SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNameIn, bool fInboundIn) :
ssSend(SER_NETWORK, INIT_PROTO_VERSION),
diff --git a/src/net.h b/src/net.h
index e2d98a90d1..e5fbf65492 100644
--- a/src/net.h
+++ b/src/net.h
@@ -82,9 +82,6 @@ static const ServiceFlags REQUIRED_SERVICES = NODE_NETWORK;
// NOTE: When adjusting this, update rpcnet:setban's help ("24h")
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24; // Default 24-hour ban
-unsigned int ReceiveFloodSize();
-unsigned int SendBufferSize();
-
typedef int NodeId;
struct AddedNodeInfo
@@ -170,6 +167,8 @@ public:
bool DisconnectNode(NodeId id);
bool DisconnectSubnet(const CSubNet& subnet);
+ unsigned int GetSendBufferSize() const;
+
void AddWhitelistedRange(const CSubNet &subnet);
//!set the max outbound target in bytes
@@ -235,6 +234,8 @@ private:
void DumpData();
void DumpBanlist();
+ unsigned int GetReceiveFloodSize() const;
+
// Network stats
void RecordBytesRecv(uint64_t bytes);
void RecordBytesSent(uint64_t bytes);
@@ -256,6 +257,9 @@ private:
std::vector<CSubNet> vWhitelistedRange;
CCriticalSection cs_vWhitelistedRange;
+ unsigned int nSendBufferMaxSize;
+ unsigned int nReceiveFloodSize;
+
std::vector<ListenSocket> vhListenSocket;
banmap_t setBanned;
CCriticalSection cs_setBanned;