Permalink
Browse files

Drop release times for CNode

Closes potential dos window
  • Loading branch information...
Tranz5 committed Jul 12, 2014
1 parent e26a4c8 commit 7530fd3212bfb1b0580b84e84a9149183984551a
Showing with 9 additions and 23 deletions.
  1. +3 −11 src/net.cpp
  2. +6 −11 src/net.h
  3. +0 −1 src/rpcnet.cpp
View
@@ -468,7 +468,7 @@ CNode* FindNode(const CService& addr)
return NULL;
}
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, int64 nTimeout)
CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
{
if (pszDest == NULL) {
if (IsLocal(addrConnect))
@@ -478,10 +478,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, int64 nTimeout)
CNode* pnode = FindNode((CService)addrConnect);
if (pnode)
{
if (nTimeout != 0)
pnode->AddRef(nTimeout);
else
pnode->AddRef();
pnode->AddRef();
return pnode;
}
}
@@ -513,10 +510,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, int64 nTimeout)
// Add node
CNode* pnode = new CNode(hSocket, addrConnect, pszDest ? pszDest : "", false);
if (nTimeout != 0)
pnode->AddRef(nTimeout);
else
pnode->AddRef();
pnode->AddRef();
{
LOCK(cs_vNodes);
@@ -626,7 +620,6 @@ void CNode::copyStats(CNodeStats &stats)
X(nVersion);
X(strSubVer);
X(fInbound);
X(nReleaseTime);
X(nStartingHeight);
X(nMisbehavior);
X(nSendBytes);
@@ -696,7 +689,6 @@ void ThreadSocketHandler2(void* parg)
pnode->Cleanup();
// hold in disconnected pool until all refs are released
pnode->nReleaseTime = max(pnode->nReleaseTime, GetTime() + 15 * 60);
if (pnode->fNetworkNode || pnode->fInbound)
pnode->Release();
vNodesDisconnected.push_back(pnode);
View
@@ -35,7 +35,7 @@ bool GetMyExternalIP(CNetAddr& ipRet);
void AddressCurrentlyConnected(const CService& addr);
CNode* FindNode(const CNetAddr& ip);
CNode* FindNode(const CService& ip);
CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL, int64 nTimeout=0);
CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL);
void MapPort();
unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
@@ -145,7 +145,6 @@ class CNodeStats
int nVersion;
std::string strSubVer;
bool fInbound;
int64 nReleaseTime;
int nStartingHeight;
int nMisbehavior;
uint64 nSendBytes;
@@ -189,8 +188,8 @@ class CNode
bool fSuccessfullyConnected;
bool fDisconnect;
CSemaphoreGrant grantOutbound;
protected:
int nRefCount;
protected:
// Denial-of-service detection/prevention
// Key is IP address, value is banned-until-time
@@ -199,7 +198,6 @@ class CNode
int nMisbehavior;
public:
int64 nReleaseTime;
std::map<uint256, CRequestTracker> mapRequests;
CCriticalSection cs_mapRequests;
uint256 hashContinue;
@@ -244,7 +242,6 @@ class CNode
fSuccessfullyConnected = false;
fDisconnect = false;
nRefCount = 0;
nReleaseTime = 0;
hashContinue = 0;
pindexLastGetBlocksBegin = 0;
hashLastGetBlocksEnd = 0;
@@ -276,15 +273,13 @@ class CNode
int GetRefCount()
{
return std::max(nRefCount, 0) + (GetTime() < nReleaseTime ? 1 : 0);
assert(nRefCount >= 0);
return nRefCount;
}
CNode* AddRef(int64 nTimeout=0)
CNode* AddRef()
{
if (nTimeout != 0)
nReleaseTime = std::max(nReleaseTime, GetTime() + nTimeout);
else
nRefCount++;
nRefCount++;
return this;
}
View
@@ -62,7 +62,6 @@ Value getpeerinfo(CWallet* pWallet, const Array& params, bool fHelp)
obj.push_back(Pair("version", stats.nVersion));
obj.push_back(Pair("subver", stats.strSubVer));
obj.push_back(Pair("inbound", stats.fInbound));
obj.push_back(Pair("releasetime", (boost::int64_t)stats.nReleaseTime));
obj.push_back(Pair("startingheight", stats.nStartingHeight));
obj.push_back(Pair("banscore", stats.nMisbehavior));

0 comments on commit 7530fd3

Please sign in to comment.