diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 70d8a597..f0411058 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -11,6 +11,7 @@ #include "init.h" #include "base58.h" #include "main.h" +#include "twister.h" using namespace std; using namespace boost; @@ -77,6 +78,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("timeoffset", (boost::int64_t)GetTimeOffset())); obj.push_back(Pair("connections", (int)vNodes.size())); + obj.push_back(Pair("dht_nodes", getDhtNodes())); obj.push_back(Pair("addrman_total", (int)addrman.size())); obj.push_back(Pair("addrman_get", (int)addrman.GetAddr().size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); diff --git a/src/twister.cpp b/src/twister.cpp index 38f651b8..3bc23e90 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -316,6 +316,14 @@ void saveTorrentResumeData() } } +int getDhtNodes() +{ + if( !ses ) + return 0; + session_status ss = ses->status(); + return ss.dht_nodes; +} + void ThreadMaintainDHTNodes() { RenameThread("maintain-dht-nodes"); @@ -325,20 +333,25 @@ void ThreadMaintainDHTNodes() } int64 lastSaveResumeTime = GetTime(); + int lastTotalNodesCandidates = 0; while(1) { session_status ss = ses->status(); int dht_nodes = ss.dht_nodes; bool nodesAdded = false; int vNodesSize = 0; - - if( ses ) { + { LOCK(cs_vNodes); vNodesSize = vNodes.size(); + } + + if( !ses->is_paused() ) { vector vAddr = addrman.GetAddr(); int totalNodesCandidates = (int)(vNodesSize + vAddr.size()); - if( (!dht_nodes && totalNodesCandidates) || - (dht_nodes < 5 && totalNodesCandidates > 10) ) { + if( ((!dht_nodes && totalNodesCandidates) || + (dht_nodes < 5 && totalNodesCandidates > 10)) && + totalNodesCandidates != lastTotalNodesCandidates ) { + lastTotalNodesCandidates = totalNodesCandidates; printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); BOOST_FOREACH(const CAddress &a, vAddr) { std::string addr = a.ToStringIP(); @@ -347,6 +360,7 @@ void ThreadMaintainDHTNodes() ses->add_dht_node(std::pair(addr, port)); nodesAdded = true; } + LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { // if !fInbound we created this connection so ip is reachable. // we can't use port number of inbound connection, so try standard port. diff --git a/src/twister.h b/src/twister.h index a2b29e58..91610cc9 100644 --- a/src/twister.h +++ b/src/twister.h @@ -37,4 +37,6 @@ void receivedSpamMessage(std::string const &message, std::string const &user); int getBestHeight(); bool shouldDhtResourceExpire(std::string resource, bool multi, int height); +int getDhtNodes(); + #endif // TWISTER_H