X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fnet.h;h=6bbcd64e4201995c3318311e118921437f5a71d4;hb=223b6f1ba4819e9a146e7aa451d546726d0bc714;hp=ea12b983e4faaa8104eb9ce61b8de9e7338a5bb7;hpb=c22feee634ade7f887d7e29635a8e5dc44675273;p=novacoin.git diff --git a/src/net.h b/src/net.h index ea12b98..6bbcd64 100644 --- a/src/net.h +++ b/src/net.h @@ -1,6 +1,16 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. +#ifndef BITCOIN_NET_H +#define BITCOIN_NET_H + +#include +#include +#include + +#ifndef __WXMSW__ +#include +#endif class CMessageHeader; class CAddress; @@ -23,7 +33,7 @@ enum bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet); -bool Lookup(const char *pszName, vector& vaddr, int nServices, int nMaxSolutions, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); +bool Lookup(const char *pszName, std::vector& vaddr, int nServices, int nMaxSolutions, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); bool Lookup(const char *pszName, CAddress& addr, int nServices, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); bool GetMyExternalIP(unsigned int& ipRet); bool AddAddress(CAddress addr, int64 nTimePenalty=0); @@ -34,7 +44,7 @@ void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1); bool AnySubscribed(unsigned int nChannel); void MapPort(bool fMapPort); void DNSAddressSeed(); -bool BindListenPort(string& strError=REF(string())); +bool BindListenPort(std::string& strError=REF(std::string())); void StartNode(void* parg); bool StopNode(); @@ -89,12 +99,12 @@ public: READWRITE(nChecksum); ) - string GetCommand() + std::string GetCommand() { if (pchCommand[COMMAND_SIZE-1] == 0) - return string(pchCommand, pchCommand + strlen(pchCommand)); + return std::string(pchCommand, pchCommand + strlen(pchCommand)); else - return string(pchCommand, pchCommand + COMMAND_SIZE); + return std::string(pchCommand, pchCommand + COMMAND_SIZE); } bool IsValid() @@ -182,13 +192,13 @@ public: Lookup(pszIn, *this, nServicesIn, fNameLookup, 0, true); } - explicit CAddress(string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) + explicit CAddress(std::string strIn, int portIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) { Init(); Lookup(strIn.c_str(), *this, nServicesIn, fNameLookup, portIn); } - explicit CAddress(string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) + explicit CAddress(std::string strIn, bool fNameLookup = false, uint64 nServicesIn=NODE_NETWORK) { Init(); Lookup(strIn.c_str(), *this, nServicesIn, fNameLookup, 0, true); @@ -245,16 +255,16 @@ public: return false; } - vector GetKey() const + std::vector GetKey() const { CDataStream ss; ss.reserve(18); ss << FLATDATA(pchReserved) << ip << port; #if defined(_MSC_VER) && _MSC_VER < 1300 - return vector((unsigned char*)&ss.begin()[0], (unsigned char*)&ss.end()[0]); + return std::vector((unsigned char*)&ss.begin()[0], (unsigned char*)&ss.end()[0]); #else - return vector(ss.begin(), ss.end()); + return std::vector(ss.begin(), ss.end()); #endif } @@ -301,22 +311,22 @@ public: return ((unsigned char*)&ip)[3-n]; } - string ToStringIPPort() const + std::string ToStringIPPort() const { return strprintf("%u.%u.%u.%u:%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0), ntohs(port)); } - string ToStringIP() const + std::string ToStringIP() const { return strprintf("%u.%u.%u.%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0)); } - string ToStringPort() const + std::string ToStringPort() const { return strprintf("%u", ntohs(port)); } - string ToString() const + std::string ToString() const { return strprintf("%u.%u.%u.%u:%u", GetByte(3), GetByte(2), GetByte(1), GetByte(0), ntohs(port)); } @@ -364,7 +374,7 @@ public: hash = hashIn; } - CInv(const string& strType, const uint256& hashIn) + CInv(const std::string& strType, const uint256& hashIn) { int i; for (i = 1; i < ARRAYLEN(ppszTypeName); i++) @@ -403,7 +413,7 @@ public: return ppszTypeName[type]; } - string ToString() const + std::string ToString() const { return strprintf("%s %s", GetCommand(), hash.ToString().substr(0,20).c_str()); } @@ -446,17 +456,17 @@ extern uint64 nLocalServices; extern CAddress addrLocalHost; extern CNode* pnodeLocalHost; extern uint64 nLocalHostNonce; -extern array vnThreadsRunning; +extern boost::array vnThreadsRunning; extern SOCKET hListenSocket; -extern vector vNodes; +extern std::vector vNodes; extern CCriticalSection cs_vNodes; -extern map, CAddress> mapAddresses; +extern std::map, CAddress> mapAddresses; extern CCriticalSection cs_mapAddresses; -extern map mapRelay; -extern deque > vRelayExpiration; +extern std::map mapRelay; +extern std::deque > vRelayExpiration; extern CCriticalSection cs_mapRelay; -extern map mapAlreadyAskedFor; +extern std::map mapAlreadyAskedFor; // Settings extern int fUseProxy; @@ -485,7 +495,7 @@ public: unsigned int nMessageStart; CAddress addr; int nVersion; - string strSubVer; + std::string strSubVer; bool fClient; bool fInbound; bool fNetworkNode; @@ -495,7 +505,7 @@ protected: int nRefCount; public: int64 nReleaseTime; - map mapRequests; + std::map mapRequests; CCriticalSection cs_mapRequests; uint256 hashContinue; CBlockIndex* pindexLastGetBlocksBegin; @@ -503,19 +513,19 @@ public: int nStartingHeight; // flood relay - vector vAddrToSend; - set setAddrKnown; + std::vector vAddrToSend; + std::set setAddrKnown; bool fGetAddr; - set setKnown; + std::set setKnown; // inventory based relay - set setInventoryKnown; - vector vInventoryToSend; + std::set setInventoryKnown; + std::vector vInventoryToSend; CCriticalSection cs_inventory; - multimap mapAskFor; + std::multimap mapAskFor; // publish and subscription - vector vfSubscribe; + std::vector vfSubscribe; CNode(SOCKET hSocketIn, CAddress addrIn, bool fInboundIn=false) @@ -577,13 +587,13 @@ public: int GetRefCount() { - return max(nRefCount, 0) + (GetTime() < nReleaseTime ? 1 : 0); + return std::max(nRefCount, 0) + (GetTime() < nReleaseTime ? 1 : 0); } CNode* AddRef(int64 nTimeout=0) { if (nTimeout != 0) - nReleaseTime = max(nReleaseTime, GetTime() + nTimeout); + nReleaseTime = std::max(nReleaseTime, GetTime() + nTimeout); else nRefCount++; return this; @@ -634,11 +644,11 @@ public: // Make sure not to reuse time indexes to keep things in the same order int64 nNow = (GetTime() - 1) * 1000000; static int64 nLastTime; - nLastTime = nNow = max(nNow, ++nLastTime); + nLastTime = nNow = std::max(nNow, ++nLastTime); // Each retry is 2 minutes after the last - nRequestTime = max(nRequestTime + 2 * 60 * 1000000, nNow); - mapAskFor.insert(make_pair(nRequestTime, inv)); + nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow); + mapAskFor.insert(std::make_pair(nRequestTime, inv)); } @@ -722,7 +732,7 @@ public: CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost); RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe, - nLocalHostNonce, string(pszSubVer), nBestHeight); + nLocalHostNonce, std::string(pszSubVer), nBestHeight); } @@ -948,7 +958,7 @@ inline void RelayInventory(const CInv& inv) { // Put on lists to offer to the other nodes CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) pnode->PushInventory(inv); } @@ -975,7 +985,7 @@ inline void RelayMessage<>(const CInv& inv, const CDataStream& ss) // Save original serialized message so newer versions are preserved mapRelay[inv] = ss; - vRelayExpiration.push_back(make_pair(GetTime() + 15 * 60, inv)); + vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv)); } RelayInventory(inv); @@ -1007,7 +1017,7 @@ void AdvertStartPublish(CNode* pfrom, unsigned int nChannel, unsigned int nHops, // Relay CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode != pfrom && (nHops < PUBLISH_HOPS || pnode->IsSubscribed(nChannel))) pnode->PushMessage("publish", nChannel, nHops, obj); } @@ -1018,7 +1028,7 @@ void AdvertStopPublish(CNode* pfrom, unsigned int nChannel, unsigned int nHops, uint256 hash = obj.GetHash(); CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode != pfrom && (nHops < PUBLISH_HOPS || pnode->IsSubscribed(nChannel))) pnode->PushMessage("pub-cancel", nChannel, nHops, hash); @@ -1035,3 +1045,5 @@ void AdvertRemoveSource(CNode* pfrom, unsigned int nChannel, unsigned int nHops, if (obj.setSources.empty()) AdvertStopPublish(pfrom, nChannel, nHops, obj); } + +#endif