From cedaa714462871213472019545b8e862dacdac91 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 29 Mar 2013 00:43:31 +0100 Subject: Drop release times for CNode It seems there were two mechanisms for assessing whether a CNode was still in use: a refcount and a release timestamp. The latter seems to have been there for a long time, as a safety mechanism. However, this timer also keeps CNode objects alive for far longer than necessary after disconnects, potentially opening up a DoS window. This commit removes the timestamp-based mechanism, and replaces it with an assert(nRefCount >= 0), to verify that the refcounting is indeed correctly working. --- src/net.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/net.h') diff --git a/src/net.h b/src/net.h index 30b9ac8663..80773e3f19 100644 --- a/src/net.h +++ b/src/net.h @@ -37,7 +37,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(bool fUseUPnP); unsigned short GetListenPort(); bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string())); @@ -99,7 +99,6 @@ public: int nVersion; std::string strSubVer; bool fInbound; - int64 nReleaseTime; int nStartingHeight; int nMisbehavior; }; @@ -187,8 +186,8 @@ public: CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; CBloomFilter* pfilter; -protected: int nRefCount; +protected: // Denial-of-service detection/prevention // Key is IP address, value is banned-until-time @@ -197,7 +196,6 @@ protected: int nMisbehavior; public: - int64 nReleaseTime; uint256 hashContinue; CBlockIndex* pindexLastGetBlocksBegin; uint256 hashLastGetBlocksEnd; @@ -235,7 +233,6 @@ public: fSuccessfullyConnected = false; fDisconnect = false; nRefCount = 0; - nReleaseTime = 0; nSendSize = 0; nSendOffset = 0; hashContinue = 0; @@ -272,7 +269,8 @@ public: int GetRefCount() { - return std::max(nRefCount, 0) + (GetTime() < nReleaseTime ? 1 : 0); + assert(nRefCount >= 0); + return nRefCount; } // requires LOCK(cs_vRecvMsg) @@ -295,12 +293,9 @@ public: msg.SetVersion(nVersionIn); } - CNode* AddRef(int64 nTimeout=0) + CNode* AddRef() { - if (nTimeout != 0) - nReleaseTime = std::max(nReleaseTime, GetTime() + nTimeout); - else - nRefCount++; + nRefCount++; return this; } -- cgit v1.2.3