mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
make bitcoin include files more modular
This commit is contained in:
committed by
Witchspace
parent
c22feee634
commit
223b6f1ba4
94
src/net.h
94
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 <deque>
|
||||
#include <boost/array.hpp>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#ifndef __WXMSW__
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
class CMessageHeader;
|
||||
class CAddress;
|
||||
@@ -23,7 +33,7 @@ enum
|
||||
|
||||
|
||||
bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet);
|
||||
bool Lookup(const char *pszName, vector<CAddress>& vaddr, int nServices, int nMaxSolutions, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false);
|
||||
bool Lookup(const char *pszName, std::vector<CAddress>& 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<unsigned char> GetKey() const
|
||||
std::vector<unsigned char> GetKey() const
|
||||
{
|
||||
CDataStream ss;
|
||||
ss.reserve(18);
|
||||
ss << FLATDATA(pchReserved) << ip << port;
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1300
|
||||
return vector<unsigned char>((unsigned char*)&ss.begin()[0], (unsigned char*)&ss.end()[0]);
|
||||
return std::vector<unsigned char>((unsigned char*)&ss.begin()[0], (unsigned char*)&ss.end()[0]);
|
||||
#else
|
||||
return vector<unsigned char>(ss.begin(), ss.end());
|
||||
return std::vector<unsigned char>(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<int, 10> vnThreadsRunning;
|
||||
extern boost::array<int, 10> vnThreadsRunning;
|
||||
extern SOCKET hListenSocket;
|
||||
|
||||
extern vector<CNode*> vNodes;
|
||||
extern std::vector<CNode*> vNodes;
|
||||
extern CCriticalSection cs_vNodes;
|
||||
extern map<vector<unsigned char>, CAddress> mapAddresses;
|
||||
extern std::map<std::vector<unsigned char>, CAddress> mapAddresses;
|
||||
extern CCriticalSection cs_mapAddresses;
|
||||
extern map<CInv, CDataStream> mapRelay;
|
||||
extern deque<pair<int64, CInv> > vRelayExpiration;
|
||||
extern std::map<CInv, CDataStream> mapRelay;
|
||||
extern std::deque<std::pair<int64, CInv> > vRelayExpiration;
|
||||
extern CCriticalSection cs_mapRelay;
|
||||
extern map<CInv, int64> mapAlreadyAskedFor;
|
||||
extern std::map<CInv, int64> 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<uint256, CRequestTracker> mapRequests;
|
||||
std::map<uint256, CRequestTracker> mapRequests;
|
||||
CCriticalSection cs_mapRequests;
|
||||
uint256 hashContinue;
|
||||
CBlockIndex* pindexLastGetBlocksBegin;
|
||||
@@ -503,19 +513,19 @@ public:
|
||||
int nStartingHeight;
|
||||
|
||||
// flood relay
|
||||
vector<CAddress> vAddrToSend;
|
||||
set<CAddress> setAddrKnown;
|
||||
std::vector<CAddress> vAddrToSend;
|
||||
std::set<CAddress> setAddrKnown;
|
||||
bool fGetAddr;
|
||||
set<uint256> setKnown;
|
||||
std::set<uint256> setKnown;
|
||||
|
||||
// inventory based relay
|
||||
set<CInv> setInventoryKnown;
|
||||
vector<CInv> vInventoryToSend;
|
||||
std::set<CInv> setInventoryKnown;
|
||||
std::vector<CInv> vInventoryToSend;
|
||||
CCriticalSection cs_inventory;
|
||||
multimap<int64, CInv> mapAskFor;
|
||||
std::multimap<int64, CInv> mapAskFor;
|
||||
|
||||
// publish and subscription
|
||||
vector<char> vfSubscribe;
|
||||
std::vector<char> 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
|
||||
|
||||
Reference in New Issue
Block a user