Limit number of warning messages logged by CNode's (#1273)

This commit is contained in:
Tim Flynn 2017-01-19 14:06:32 -05:00 committed by UdjinM6
parent 0233d87739
commit 70b2f3e083
2 changed files with 16 additions and 2 deletions

View File

@ -2386,6 +2386,8 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
addr = addrIn;
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
nVersion = 0;
nNumWarningsSkipped = 0;
nLastWarningTime = 0;
strSubVer = "";
fWhitelisted = false;
fOneShot = false;
@ -2446,8 +2448,16 @@ CNode::~CNode()
void CNode::AskFor(const CInv& inv)
{
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || setAskFor.size() > SETASKFOR_MAX_SZ) {
LogPrintf("CNode::AskFor -- WARNING: inventory message dropped: mapAskFor.size = %d, setAskFor.size = %d, MAPASKFOR_MAX_SZ = %d, SETASKFOR_MAX_SZ = %d, peer=%d\n",
mapAskFor.size(), setAskFor.size(), MAPASKFOR_MAX_SZ, SETASKFOR_MAX_SZ, id);
int64_t nNow = GetTime();
if(nNow - nLastWarningTime > WARNING_INTERVAL) {
LogPrintf("CNode::AskFor -- WARNING: inventory message dropped: mapAskFor.size = %d, setAskFor.size = %d, MAPASKFOR_MAX_SZ = %d, SETASKFOR_MAX_SZ = %d, nSkipped = %d, peer=%d\n",
mapAskFor.size(), setAskFor.size(), MAPASKFOR_MAX_SZ, SETASKFOR_MAX_SZ, nNumWarningsSkipped, id);
nLastWarningTime = nNow;
nNumWarningsSkipped = 0;
}
else {
++nNumWarningsSkipped;
}
return;
}
// a peer may not have multiple non-responded queue positions for a single inv item

View File

@ -40,6 +40,8 @@ namespace boost {
static const int PING_INTERVAL = 2 * 60;
/** Time after which to disconnect, after waiting for a ping response (or inactivity). */
static const int TIMEOUT_INTERVAL = 20 * 60;
/** Minimum time between warnings printed to log. */
static const int WARNING_INTERVAL = 10 * 60;
/** The maximum number of entries in an 'inv' protocol message */
static const unsigned int MAX_INV_SZ = 50000;
/** The maximum number of new addresses to accumulate before announcing. */
@ -336,9 +338,11 @@ public:
int64_t nLastRecv;
int64_t nTimeConnected;
int64_t nTimeOffset;
int64_t nLastWarningTime;
CAddress addr;
std::string addrName;
CService addrLocal;
int nNumWarningsSkipped;
int nVersion;
// strSubVer is whatever byte array we read from the wire. However, this field is intended
// to be printed out, displayed to humans in various forms and so on. So we sanitize it and