From 51ed9ec971614aebdbfbd9527aba365dd0afd437 Mon Sep 17 00:00:00 2001 From: Brandon Dahler Date: Sat, 13 Apr 2013 00:13:08 -0500 Subject: Cleanup code using forward declarations. Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files. --- src/net.h | 107 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 48 deletions(-) (limited to 'src/net.h') diff --git a/src/net.h b/src/net.h index 35ee7a06a6..b07c10610d 100644 --- a/src/net.h +++ b/src/net.h @@ -2,34 +2,45 @@ // Copyright (c) 2009-2013 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #ifndef BITCOIN_NET_H #define BITCOIN_NET_H +#include "bloom.h" +#include "compat.h" +#include "hash.h" +#include "limitedmap.h" +#include "mruset.h" +#include "netbase.h" +#include "protocol.h" +#include "sync.h" +#include "uint256.h" +#include "util.h" + #include -#include -#include -#include -#include +#include +#include #ifndef WIN32 #include #endif -#include "mruset.h" -#include "limitedmap.h" -#include "netbase.h" -#include "protocol.h" -#include "addrman.h" -#include "hash.h" -#include "bloom.h" - -/** The maximum number of entries in an 'inv' protocol message */ -static const unsigned int MAX_INV_SZ = 50000; +//#include +#include +#include +#include -class CNode; +class CAddrMan; class CBlockIndex; +class CNetAddr; +class CNode; +namespace boost { + class thread_group; +} +/** The maximum number of entries in an 'inv' protocol message */ +static const unsigned int MAX_INV_SZ = 50000; inline unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); } inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); } @@ -85,17 +96,17 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); extern bool fDiscover; -extern uint64 nLocalServices; -extern uint64 nLocalHostNonce; +extern uint64_t nLocalServices; +extern uint64_t nLocalHostNonce; extern CAddrMan addrman; extern int nMaxConnections; extern std::vector vNodes; extern CCriticalSection cs_vNodes; extern std::map mapRelay; -extern std::deque > vRelayExpiration; +extern std::deque > vRelayExpiration; extern CCriticalSection cs_mapRelay; -extern limitedmap mapAlreadyAskedFor; +extern limitedmap mapAlreadyAskedFor; extern std::vector vAddedNodes; extern CCriticalSection cs_vAddedNodes; @@ -106,18 +117,18 @@ extern CCriticalSection cs_vAddedNodes; class CNodeStats { public: - uint64 nServices; - int64 nLastSend; - int64 nLastRecv; - int64 nTimeConnected; + uint64_t nServices; + int64_t nLastSend; + int64_t nLastRecv; + int64_t nTimeConnected; std::string addrName; int nVersion; std::string strSubVer; bool fInbound; int nStartingHeight; int nMisbehavior; - uint64 nSendBytes; - uint64 nRecvBytes; + uint64_t nSendBytes; + uint64_t nRecvBytes; bool fSyncNode; double dPingTime; double dPingWait; @@ -171,25 +182,25 @@ class CNode { public: // socket - uint64 nServices; + uint64_t nServices; SOCKET hSocket; CDataStream ssSend; size_t nSendSize; // total size of all vSendMsg entries size_t nSendOffset; // offset inside the first vSendMsg already sent - uint64 nSendBytes; + uint64_t nSendBytes; std::deque vSendMsg; CCriticalSection cs_vSend; std::deque vRecvGetData; std::deque vRecvMsg; CCriticalSection cs_vRecvMsg; - uint64 nRecvBytes; + uint64_t nRecvBytes; int nRecvVersion; - int64 nLastSend; - int64 nLastRecv; - int64 nLastSendEmpty; - int64 nTimeConnected; + int64_t nLastSend; + int64_t nLastRecv; + int64_t nLastSendEmpty; + int64_t nTimeConnected; CAddress addr; std::string addrName; CService addrLocal; @@ -214,7 +225,7 @@ protected: // Denial-of-service detection/prevention // Key is IP address, value is banned-until-time - static std::map setBanned; + static std::map setBanned; static CCriticalSection cs_setBanned; int nMisbehavior; @@ -238,12 +249,12 @@ public: mruset setInventoryKnown; std::vector vInventoryToSend; CCriticalSection cs_inventory; - std::multimap mapAskFor; + std::multimap mapAskFor; // Ping time measurement - uint64 nPingNonceSent; - int64 nPingUsecStart; - int64 nPingUsecTime; + uint64_t nPingNonceSent; + int64_t nPingUsecStart; + int64_t nPingUsecTime; bool fPingQueued; CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : ssSend(SER_NETWORK, INIT_PROTO_VERSION) @@ -305,8 +316,8 @@ private: // Network usage totals static CCriticalSection cs_totalBytesRecv; static CCriticalSection cs_totalBytesSent; - static uint64 nTotalBytesRecv; - static uint64 nTotalBytesSent; + static uint64_t nTotalBytesRecv; + static uint64_t nTotalBytesSent; CNode(const CNode&); void operator=(const CNode&); @@ -389,17 +400,17 @@ public: { // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent - int64 nRequestTime; - limitedmap::const_iterator it = mapAlreadyAskedFor.find(inv); + int64_t nRequestTime; + limitedmap::const_iterator it = mapAlreadyAskedFor.find(inv); if (it != mapAlreadyAskedFor.end()) nRequestTime = it->second; else nRequestTime = 0; - LogPrint("net", "askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); + LogPrint("net", "askfor %s %"PRId64" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str()); // Make sure not to reuse time indexes to keep things in the same order - int64 nNow = (GetTime() - 1) * 1000000; - static int64 nLastTime; + int64_t nNow = (GetTime() - 1) * 1000000; + static int64_t nLastTime; ++nLastTime; nNow = std::max(nNow, nLastTime); nLastTime = nNow; @@ -664,11 +675,11 @@ public: void copyStats(CNodeStats &stats); // Network stats - static void RecordBytesRecv(uint64 bytes); - static void RecordBytesSent(uint64 bytes); + static void RecordBytesRecv(uint64_t bytes); + static void RecordBytesSent(uint64_t bytes); - static uint64 GetTotalBytesRecv(); - static uint64 GetTotalBytesSent(); + static uint64_t GetTotalBytesRecv(); + static uint64_t GetTotalBytesSent(); }; -- cgit v1.2.3