|
|
@ -56,7 +56,6 @@ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
const int MAX_OUTBOUND_CONNECTIONS = 8; |
|
|
|
const int MAX_OUTBOUND_CONNECTIONS = 8; |
|
|
@ -78,7 +77,7 @@ bool fDiscover = true; |
|
|
|
bool fListen = true; |
|
|
|
bool fListen = true; |
|
|
|
uint64_t nLocalServices = NODE_NETWORK; |
|
|
|
uint64_t nLocalServices = NODE_NETWORK; |
|
|
|
CCriticalSection cs_mapLocalHost; |
|
|
|
CCriticalSection cs_mapLocalHost; |
|
|
|
map<CNetAddr, LocalServiceInfo> mapLocalHost; |
|
|
|
std::map<CNetAddr, LocalServiceInfo> mapLocalHost; |
|
|
|
static bool vfLimited[NET_MAX] = {}; |
|
|
|
static bool vfLimited[NET_MAX] = {}; |
|
|
|
static CNode* pnodeLocalHost = NULL; |
|
|
|
static CNode* pnodeLocalHost = NULL; |
|
|
|
uint64_t nLocalHostNonce = 0; |
|
|
|
uint64_t nLocalHostNonce = 0; |
|
|
@ -88,20 +87,20 @@ int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS; |
|
|
|
bool fAddressesInitialized = false; |
|
|
|
bool fAddressesInitialized = false; |
|
|
|
std::string strSubVersion; |
|
|
|
std::string strSubVersion; |
|
|
|
|
|
|
|
|
|
|
|
vector<CNode*> vNodes; |
|
|
|
std::vector<CNode*> vNodes; |
|
|
|
CCriticalSection cs_vNodes; |
|
|
|
CCriticalSection cs_vNodes; |
|
|
|
map<uint256, CTransaction> mapRelay; |
|
|
|
std::map<uint256, CTransaction> mapRelay; |
|
|
|
deque<pair<int64_t, uint256> > vRelayExpiration; |
|
|
|
std::deque<std::pair<int64_t, uint256> > vRelayExpiration; |
|
|
|
CCriticalSection cs_mapRelay; |
|
|
|
CCriticalSection cs_mapRelay; |
|
|
|
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ); |
|
|
|
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ); |
|
|
|
|
|
|
|
|
|
|
|
static deque<string> vOneShots; |
|
|
|
static std::deque<std::string> vOneShots; |
|
|
|
CCriticalSection cs_vOneShots; |
|
|
|
CCriticalSection cs_vOneShots; |
|
|
|
|
|
|
|
|
|
|
|
set<CNetAddr> setservAddNodeAddresses; |
|
|
|
std::set<CNetAddr> setservAddNodeAddresses; |
|
|
|
CCriticalSection cs_setservAddNodeAddresses; |
|
|
|
CCriticalSection cs_setservAddNodeAddresses; |
|
|
|
|
|
|
|
|
|
|
|
vector<std::string> vAddedNodes; |
|
|
|
std::vector<std::string> vAddedNodes; |
|
|
|
CCriticalSection cs_vAddedNodes; |
|
|
|
CCriticalSection cs_vAddedNodes; |
|
|
|
|
|
|
|
|
|
|
|
NodeId nLastNodeId = 0; |
|
|
|
NodeId nLastNodeId = 0; |
|
|
@ -135,7 +134,7 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer) |
|
|
|
int nBestReachability = -1; |
|
|
|
int nBestReachability = -1; |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
LOCK(cs_mapLocalHost); |
|
|
|
for (map<CNetAddr, LocalServiceInfo>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) |
|
|
|
for (std::map<CNetAddr, LocalServiceInfo>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int nScore = (*it).second.nScore; |
|
|
|
int nScore = (*it).second.nScore; |
|
|
|
int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); |
|
|
|
int nReachability = (*it).first.GetReachabilityFrom(paddrPeer); |
|
|
@ -796,7 +795,7 @@ void SocketSendData(CNode *pnode) |
|
|
|
pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it); |
|
|
|
pnode->vSendMsg.erase(pnode->vSendMsg.begin(), it); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static list<CNode*> vNodesDisconnected; |
|
|
|
static std::list<CNode*> vNodesDisconnected; |
|
|
|
|
|
|
|
|
|
|
|
class CNodeRef { |
|
|
|
class CNodeRef { |
|
|
|
public: |
|
|
|
public: |
|
|
@ -1045,7 +1044,7 @@ void ThreadSocketHandler() |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
// Disconnect unused nodes
|
|
|
|
// Disconnect unused nodes
|
|
|
|
vector<CNode*> vNodesCopy = vNodes; |
|
|
|
std::vector<CNode*> vNodesCopy = vNodes; |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodesCopy) |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodesCopy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pnode->fDisconnect || |
|
|
|
if (pnode->fDisconnect || |
|
|
@ -1069,7 +1068,7 @@ void ThreadSocketHandler() |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Delete disconnected nodes
|
|
|
|
// Delete disconnected nodes
|
|
|
|
list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected; |
|
|
|
std::list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected; |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy) |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// wait until threads are done using it
|
|
|
|
// wait until threads are done using it
|
|
|
@ -1120,7 +1119,7 @@ void ThreadSocketHandler() |
|
|
|
|
|
|
|
|
|
|
|
BOOST_FOREACH(const ListenSocket& hListenSocket, vhListenSocket) { |
|
|
|
BOOST_FOREACH(const ListenSocket& hListenSocket, vhListenSocket) { |
|
|
|
FD_SET(hListenSocket.socket, &fdsetRecv); |
|
|
|
FD_SET(hListenSocket.socket, &fdsetRecv); |
|
|
|
hSocketMax = max(hSocketMax, hListenSocket.socket); |
|
|
|
hSocketMax = std::max(hSocketMax, hListenSocket.socket); |
|
|
|
have_fds = true; |
|
|
|
have_fds = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1131,7 +1130,7 @@ void ThreadSocketHandler() |
|
|
|
if (pnode->hSocket == INVALID_SOCKET) |
|
|
|
if (pnode->hSocket == INVALID_SOCKET) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
FD_SET(pnode->hSocket, &fdsetError); |
|
|
|
FD_SET(pnode->hSocket, &fdsetError); |
|
|
|
hSocketMax = max(hSocketMax, pnode->hSocket); |
|
|
|
hSocketMax = std::max(hSocketMax, pnode->hSocket); |
|
|
|
have_fds = true; |
|
|
|
have_fds = true; |
|
|
|
|
|
|
|
|
|
|
|
// Implement the following logic:
|
|
|
|
// Implement the following logic:
|
|
|
@ -1198,7 +1197,7 @@ void ThreadSocketHandler() |
|
|
|
//
|
|
|
|
//
|
|
|
|
// Service each socket
|
|
|
|
// Service each socket
|
|
|
|
//
|
|
|
|
//
|
|
|
|
vector<CNode*> vNodesCopy; |
|
|
|
std::vector<CNode*> vNodesCopy; |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
vNodesCopy = vNodes; |
|
|
|
vNodesCopy = vNodes; |
|
|
@ -1355,7 +1354,7 @@ void ThreadMapPort() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string strDesc = "Bitcoin " + FormatFullVersion(); |
|
|
|
std::string strDesc = "Bitcoin " + FormatFullVersion(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
@ -1441,7 +1440,7 @@ void ThreadDNSAddressSeed() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const vector<CDNSSeedData> &vSeeds = Params().DNSSeeds(); |
|
|
|
const std::vector<CDNSSeedData> &vSeeds = Params().DNSSeeds(); |
|
|
|
int found = 0; |
|
|
|
int found = 0; |
|
|
|
|
|
|
|
|
|
|
|
LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); |
|
|
|
LogPrintf("Loading addresses from DNS seeds (could take a while)\n"); |
|
|
@ -1450,8 +1449,8 @@ void ThreadDNSAddressSeed() |
|
|
|
if (HaveNameProxy()) { |
|
|
|
if (HaveNameProxy()) { |
|
|
|
AddOneShot(seed.host); |
|
|
|
AddOneShot(seed.host); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
vector<CNetAddr> vIPs; |
|
|
|
std::vector<CNetAddr> vIPs; |
|
|
|
vector<CAddress> vAdd; |
|
|
|
std::vector<CAddress> vAdd; |
|
|
|
if (LookupHost(seed.host.c_str(), vIPs, 0, true)) |
|
|
|
if (LookupHost(seed.host.c_str(), vIPs, 0, true)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH(const CNetAddr& ip, vIPs) |
|
|
|
BOOST_FOREACH(const CNetAddr& ip, vIPs) |
|
|
@ -1508,7 +1507,7 @@ void DumpData() |
|
|
|
|
|
|
|
|
|
|
|
void static ProcessOneShot() |
|
|
|
void static ProcessOneShot() |
|
|
|
{ |
|
|
|
{ |
|
|
|
string strDest; |
|
|
|
std::string strDest; |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vOneShots); |
|
|
|
LOCK(cs_vOneShots); |
|
|
|
if (vOneShots.empty()) |
|
|
|
if (vOneShots.empty()) |
|
|
@ -1574,7 +1573,7 @@ void ThreadOpenConnections() |
|
|
|
// Only connect out to one peer per network group (/16 for IPv4).
|
|
|
|
// Only connect out to one peer per network group (/16 for IPv4).
|
|
|
|
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
|
|
|
|
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
|
|
|
|
int nOutbound = 0; |
|
|
|
int nOutbound = 0; |
|
|
|
set<vector<unsigned char> > setConnected; |
|
|
|
std::set<std::vector<unsigned char> > setConnected; |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
@ -1632,7 +1631,7 @@ void ThreadOpenAddedConnections() |
|
|
|
|
|
|
|
|
|
|
|
if (HaveNameProxy()) { |
|
|
|
if (HaveNameProxy()) { |
|
|
|
while(true) { |
|
|
|
while(true) { |
|
|
|
list<string> lAddresses(0); |
|
|
|
std::list<std::string> lAddresses(0); |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vAddedNodes); |
|
|
|
LOCK(cs_vAddedNodes); |
|
|
|
BOOST_FOREACH(const std::string& strAddNode, vAddedNodes) |
|
|
|
BOOST_FOREACH(const std::string& strAddNode, vAddedNodes) |
|
|
@ -1650,16 +1649,16 @@ void ThreadOpenAddedConnections() |
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; true; i++) |
|
|
|
for (unsigned int i = 0; true; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
list<string> lAddresses(0); |
|
|
|
std::list<std::string> lAddresses(0); |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vAddedNodes); |
|
|
|
LOCK(cs_vAddedNodes); |
|
|
|
BOOST_FOREACH(const std::string& strAddNode, vAddedNodes) |
|
|
|
BOOST_FOREACH(const std::string& strAddNode, vAddedNodes) |
|
|
|
lAddresses.push_back(strAddNode); |
|
|
|
lAddresses.push_back(strAddNode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
list<vector<CService> > lservAddressesToAdd(0); |
|
|
|
std::list<std::vector<CService> > lservAddressesToAdd(0); |
|
|
|
BOOST_FOREACH(const std::string& strAddNode, lAddresses) { |
|
|
|
BOOST_FOREACH(const std::string& strAddNode, lAddresses) { |
|
|
|
vector<CService> vservNode(0); |
|
|
|
std::vector<CService> vservNode(0); |
|
|
|
if(Lookup(strAddNode.c_str(), vservNode, Params().GetDefaultPort(), fNameLookup, 0)) |
|
|
|
if(Lookup(strAddNode.c_str(), vservNode, Params().GetDefaultPort(), fNameLookup, 0)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
lservAddressesToAdd.push_back(vservNode); |
|
|
|
lservAddressesToAdd.push_back(vservNode); |
|
|
@ -1675,7 +1674,7 @@ void ThreadOpenAddedConnections() |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
|
for (list<vector<CService> >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++) |
|
|
|
for (std::list<std::vector<CService> >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++) |
|
|
|
BOOST_FOREACH(const CService& addrNode, *(it)) |
|
|
|
BOOST_FOREACH(const CService& addrNode, *(it)) |
|
|
|
if (pnode->addr == addrNode) |
|
|
|
if (pnode->addr == addrNode) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1684,7 +1683,7 @@ void ThreadOpenAddedConnections() |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
BOOST_FOREACH(vector<CService>& vserv, lservAddressesToAdd) |
|
|
|
BOOST_FOREACH(std::vector<CService>& vserv, lservAddressesToAdd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CSemaphoreGrant grant(*semOutbound); |
|
|
|
CSemaphoreGrant grant(*semOutbound); |
|
|
|
OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant); |
|
|
|
OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant); |
|
|
@ -1732,7 +1731,7 @@ void ThreadMessageHandler() |
|
|
|
SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); |
|
|
|
SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); |
|
|
|
while (true) |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
vector<CNode*> vNodesCopy; |
|
|
|
std::vector<CNode*> vNodesCopy; |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
vNodesCopy = vNodes; |
|
|
|
vNodesCopy = vNodes; |
|
|
@ -1792,7 +1791,7 @@ void ThreadMessageHandler() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BindListenPort(const CService &addrBind, string& strError, bool fWhitelisted) |
|
|
|
bool BindListenPort(const CService &addrBind, std::string& strError, bool fWhitelisted) |
|
|
|
{ |
|
|
|
{ |
|
|
|
strError = ""; |
|
|
|
strError = ""; |
|
|
|
int nOne = 1; |
|
|
|
int nOne = 1; |
|
|
@ -1900,7 +1899,7 @@ void static Discover(boost::thread_group& threadGroup) |
|
|
|
char pszHostName[256] = ""; |
|
|
|
char pszHostName[256] = ""; |
|
|
|
if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) |
|
|
|
if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) |
|
|
|
{ |
|
|
|
{ |
|
|
|
vector<CNetAddr> vaddr; |
|
|
|
std::vector<CNetAddr> vaddr; |
|
|
|
if (LookupHost(pszHostName, vaddr, 0, true)) |
|
|
|
if (LookupHost(pszHostName, vaddr, 0, true)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
BOOST_FOREACH (const CNetAddr &addr, vaddr) |
|
|
|
BOOST_FOREACH (const CNetAddr &addr, vaddr) |
|
|
@ -2300,7 +2299,7 @@ bool CAddrDB::Read(CAddrMan& addr) |
|
|
|
// Don't try to resize to a negative number if file is small
|
|
|
|
// Don't try to resize to a negative number if file is small
|
|
|
|
if (fileSize >= sizeof(uint256)) |
|
|
|
if (fileSize >= sizeof(uint256)) |
|
|
|
dataSize = fileSize - sizeof(uint256); |
|
|
|
dataSize = fileSize - sizeof(uint256); |
|
|
|
vector<unsigned char> vchData; |
|
|
|
std::vector<unsigned char> vchData; |
|
|
|
vchData.resize(dataSize); |
|
|
|
vchData.resize(dataSize); |
|
|
|
uint256 hashIn; |
|
|
|
uint256 hashIn; |
|
|
|
|
|
|
|
|
|
|
@ -2580,7 +2579,7 @@ bool CBanDB::Read(banmap_t& banSet) |
|
|
|
// Don't try to resize to a negative number if file is small
|
|
|
|
// Don't try to resize to a negative number if file is small
|
|
|
|
if (fileSize >= sizeof(uint256)) |
|
|
|
if (fileSize >= sizeof(uint256)) |
|
|
|
dataSize = fileSize - sizeof(uint256); |
|
|
|
dataSize = fileSize - sizeof(uint256); |
|
|
|
vector<unsigned char> vchData; |
|
|
|
std::vector<unsigned char> vchData; |
|
|
|
vchData.resize(dataSize); |
|
|
|
vchData.resize(dataSize); |
|
|
|
uint256 hashIn; |
|
|
|
uint256 hashIn; |
|
|
|
|
|
|
|
|
|
|
|