diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2013-01-28 11:09:03 -0800 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2013-01-28 11:09:03 -0800 |
commit | 79bec38cb490a77e9431716245c645d2aa0c0a87 (patch) | |
tree | 00c321b65438eb02e464c0c26708e056405603d3 /src/net.cpp | |
parent | f73abdc82dd69c046f7800acd0845002cb20aec5 (diff) | |
parent | f2bd6c28e6bddd75d56d580c28f45d2a8be065ab (diff) |
Merge pull request #1549 from TheBlueMatt/addnoderpc
Addnode optimization and addnode access via RPC
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/net.cpp b/src/net.cpp index 319739429c..f89d2899fe 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -72,6 +72,9 @@ CCriticalSection cs_vOneShots; set<CNetAddr> setservAddNodeAddresses; CCriticalSection cs_setservAddNodeAddresses; +vector<std::string> vAddedNodes; +CCriticalSection cs_vAddedNodes; + static CSemaphore *semOutbound = NULL; void AddOneShot(string strDest) @@ -1523,16 +1526,26 @@ void ThreadOpenAddedConnections2(void* parg) { printf("ThreadOpenAddedConnections started\n"); - if (mapArgs.count("-addnode") == 0) - return; + { + LOCK(cs_vAddedNodes); + vAddedNodes = mapMultiArgs["-addnode"]; + } if (HaveNameProxy()) { while(!fShutdown) { - BOOST_FOREACH(string& strAddNode, mapMultiArgs["-addnode"]) { + list<string> lAddresses(0); + { + LOCK(cs_vAddedNodes); + BOOST_FOREACH(string& strAddNode, vAddedNodes) + lAddresses.push_back(strAddNode); + } + BOOST_FOREACH(string& strAddNode, lAddresses) { CAddress addr; CSemaphoreGrant grant(*semOutbound); OpenNetworkConnection(addr, &grant, strAddNode.c_str()); Sleep(500); + if (fShutdown) + return; } vnThreadsRunning[THREAD_ADDEDCONNECTIONS]--; Sleep(120000); // Retry every 2 minutes @@ -1541,41 +1554,47 @@ void ThreadOpenAddedConnections2(void* parg) return; } - vector<vector<CService> > vservAddressesToAdd(0); - BOOST_FOREACH(string& strAddNode, mapMultiArgs["-addnode"]) + for (unsigned int i = 0; true; i++) { - vector<CService> vservNode(0); - if(Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0)) + list<string> lAddresses(0); { - vservAddressesToAdd.push_back(vservNode); + LOCK(cs_vAddedNodes); + BOOST_FOREACH(string& strAddNode, vAddedNodes) + lAddresses.push_back(strAddNode); + } + + list<vector<CService> > lservAddressesToAdd(0); + BOOST_FOREACH(string& strAddNode, lAddresses) + { + vector<CService> vservNode(0); + if(Lookup(strAddNode.c_str(), vservNode, GetDefaultPort(), fNameLookup, 0)) { - LOCK(cs_setservAddNodeAddresses); - BOOST_FOREACH(CService& serv, vservNode) - setservAddNodeAddresses.insert(serv); + lservAddressesToAdd.push_back(vservNode); + { + LOCK(cs_setservAddNodeAddresses); + BOOST_FOREACH(CService& serv, vservNode) + setservAddNodeAddresses.insert(serv); + } } } - } - loop - { - vector<vector<CService> > vservConnectAddresses = vservAddressesToAdd; // Attempt to connect to each IP for each addnode entry until at least one is successful per addnode entry // (keeping in mind that addnode entries can have many IPs if fNameLookup) { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) - for (vector<vector<CService> >::iterator it = vservConnectAddresses.begin(); it != vservConnectAddresses.end(); it++) + for (list<vector<CService> >::iterator it = lservAddressesToAdd.begin(); it != lservAddressesToAdd.end(); it++) BOOST_FOREACH(CService& addrNode, *(it)) if (pnode->addr == addrNode) { - it = vservConnectAddresses.erase(it); + it = lservAddressesToAdd.erase(it); it--; break; } } - BOOST_FOREACH(vector<CService>& vserv, vservConnectAddresses) + BOOST_FOREACH(vector<CService>& vserv, lservAddressesToAdd) { CSemaphoreGrant grant(*semOutbound); - OpenNetworkConnection(CAddress(*(vserv.begin())), &grant); + OpenNetworkConnection(CAddress(vserv[i % vserv.size()]), &grant); Sleep(500); if (fShutdown) return; |