diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-05-15 09:11:04 +0200 |
---|---|---|
committer | Witchspace <witchspace81@gmail.com> | 2011-05-15 12:04:20 +0200 |
commit | 223b6f1ba4819e9a146e7aa451d546726d0bc714 (patch) | |
tree | 8d52eaba84ba2817d2227cf9fda0c71af75246cd /src/net.cpp | |
parent | c22feee634ade7f887d7e29635a8e5dc44675273 (diff) |
make bitcoin include files more modular
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/net.cpp b/src/net.cpp index 018afc47c7..1320781cb2 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -11,6 +11,9 @@ #include <miniupnpc/upnperrors.h> #endif +using namespace std; +using namespace boost; + static const int MAX_OUTBOUND_CONNECTIONS = 8; void ThreadMessageHandler2(void* parg); @@ -330,7 +333,7 @@ void ThreadGetMyExternalIP(void* parg) CAddress addr(addrLocalHost); addr.nTime = GetAdjustedTime(); CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) pnode->PushAddress(addr); } } @@ -414,7 +417,7 @@ void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1) // call this in the destructor so it doesn't get called after it's deleted. CRITICAL_BLOCK(cs_vNodes) { - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) { CRITICAL_BLOCK(pnode->cs_mapRequests) { @@ -451,7 +454,7 @@ bool AnySubscribed(unsigned int nChannel) if (pnodeLocalHost->IsSubscribed(nChannel)) return true; CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->IsSubscribed(nChannel)) return true; return false; @@ -473,7 +476,7 @@ void CNode::Subscribe(unsigned int nChannel, unsigned int nHops) { // Relay subscribe CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode != this) pnode->PushMessage("subscribe", nChannel, nHops); } @@ -495,7 +498,7 @@ void CNode::CancelSubscribe(unsigned int nChannel) { // Relay subscription cancel CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode != this) pnode->PushMessage("sub-cancel", nChannel); } @@ -513,7 +516,7 @@ CNode* FindNode(unsigned int ip) { CRITICAL_BLOCK(cs_vNodes) { - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->addr.ip == ip) return (pnode); } @@ -524,7 +527,7 @@ CNode* FindNode(CAddress addr) { CRITICAL_BLOCK(cs_vNodes) { - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->addr == addr) return (pnode); } @@ -661,7 +664,7 @@ void ThreadSocketHandler2(void* parg) { // Disconnect unused nodes vector<CNode*> vNodesCopy = vNodes; - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) { if (pnode->fDisconnect || (pnode->GetRefCount() <= 0 && pnode->vRecv.empty() && pnode->vSend.empty())) @@ -683,7 +686,7 @@ void ThreadSocketHandler2(void* parg) // Delete disconnected nodes list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected; - foreach(CNode* pnode, vNodesDisconnectedCopy) + BOOST_FOREACH(CNode* pnode, vNodesDisconnectedCopy) { // wait until threads are done using it if (pnode->GetRefCount() <= 0) @@ -729,7 +732,7 @@ void ThreadSocketHandler2(void* parg) hSocketMax = max(hSocketMax, hListenSocket); CRITICAL_BLOCK(cs_vNodes) { - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) { if (pnode->hSocket == INVALID_SOCKET || pnode->hSocket < 0) continue; @@ -771,7 +774,7 @@ void ThreadSocketHandler2(void* parg) int nInbound = 0; CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->fInbound) nInbound++; if (hSocket == INVALID_SOCKET) @@ -801,10 +804,10 @@ void ThreadSocketHandler2(void* parg) CRITICAL_BLOCK(cs_vNodes) { vNodesCopy = vNodes; - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->AddRef(); } - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) { if (fShutdown) return; @@ -921,7 +924,7 @@ void ThreadSocketHandler2(void* parg) } CRITICAL_BLOCK(cs_vNodes) { - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->Release(); } @@ -1057,7 +1060,7 @@ void DNSAddressSeed() vector<CAddress> vaddr; if (Lookup(strDNSSeed[seed_idx], vaddr, NODE_NETWORK, true)) { - foreach (CAddress& addr, vaddr) + BOOST_FOREACH (CAddress& addr, vaddr) { if (addr.GetByte(3) != 127) { @@ -1148,7 +1151,7 @@ void ThreadOpenConnections2(void* parg) { for (int64 nLoop = 0;; nLoop++) { - foreach(string strAddr, mapMultiArgs["-connect"]) + BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"]) { CAddress addr(strAddr, fAllowDNS); if (addr.IsValid()) @@ -1166,7 +1169,7 @@ void ThreadOpenConnections2(void* parg) // Connect to manually added nodes first if (mapArgs.count("-addnode")) { - foreach(string strAddr, mapMultiArgs["-addnode"]) + BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"]) { CAddress addr(strAddr, fAllowDNS); if (addr.IsValid()) @@ -1190,7 +1193,7 @@ void ThreadOpenConnections2(void* parg) { int nOutbound = 0; CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (!pnode->fInbound) nOutbound++; int nMaxOutboundConnections = MAX_OUTBOUND_CONNECTIONS; @@ -1233,7 +1236,7 @@ void ThreadOpenConnections2(void* parg) { nSeedDisconnected = GetTime(); CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (setSeed.count(pnode->addr.ip)) pnode->fDisconnect = true; } @@ -1241,7 +1244,7 @@ void ThreadOpenConnections2(void* parg) // Keep setting timestamps to 0 so they won't reconnect if (GetTime() - nSeedDisconnected < 60 * 60) { - foreach(PAIRTYPE(const vector<unsigned char>, CAddress)& item, mapAddresses) + BOOST_FOREACH(PAIRTYPE(const vector<unsigned char>, CAddress)& item, mapAddresses) { if (setSeed.count(item.second.ip) && item.second.nTime != 0) { @@ -1264,12 +1267,12 @@ void ThreadOpenConnections2(void* parg) // Do this here so we don't have to critsect vNodes inside mapAddresses critsect. set<unsigned int> setConnected; CRITICAL_BLOCK(cs_vNodes) - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) setConnected.insert(pnode->addr.ip & 0x0000ffff); CRITICAL_BLOCK(cs_mapAddresses) { - foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses) + BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses) { const CAddress& addr = item.second; if (!addr.IsIPv4() || !addr.IsValid() || setConnected.count(addr.ip & 0x0000ffff)) @@ -1385,7 +1388,7 @@ void ThreadMessageHandler2(void* parg) CRITICAL_BLOCK(cs_vNodes) { vNodesCopy = vNodes; - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->AddRef(); } @@ -1393,7 +1396,7 @@ void ThreadMessageHandler2(void* parg) CNode* pnodeTrickle = NULL; if (!vNodesCopy.empty()) pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())]; - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) { // Receive messages TRY_CRITICAL_BLOCK(pnode->cs_vRecv) @@ -1410,7 +1413,7 @@ void ThreadMessageHandler2(void* parg) CRITICAL_BLOCK(cs_vNodes) { - foreach(CNode* pnode, vNodesCopy) + BOOST_FOREACH(CNode* pnode, vNodesCopy) pnode->Release(); } @@ -1527,7 +1530,7 @@ void StartNode(void* parg) { vector<CAddress> vaddr; if (Lookup(pszHostName, vaddr, nLocalServices, -1, true)) - foreach (const CAddress &addr, vaddr) + BOOST_FOREACH (const CAddress &addr, vaddr) if (addr.GetByte(3) != 127) { addrLocalHost = addr; @@ -1648,7 +1651,7 @@ public: ~CNetCleanup() { // Close sockets - foreach(CNode* pnode, vNodes) + BOOST_FOREACH(CNode* pnode, vNodes) if (pnode->hSocket != INVALID_SOCKET) closesocket(pnode->hSocket); if (hListenSocket != INVALID_SOCKET) |