Browse Source

avoid adding the same nodes to dht subsys all the time

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
ba0b4c8613
  1. 2
      src/rpcwallet.cpp
  2. 22
      src/twister.cpp
  3. 2
      src/twister.h

2
src/rpcwallet.cpp

@ -11,6 +11,7 @@ @@ -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) @@ -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())));

22
src/twister.cpp

@ -316,6 +316,14 @@ void saveTorrentResumeData() @@ -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() @@ -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<CAddress> 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() @@ -347,6 +360,7 @@ void ThreadMaintainDHTNodes()
ses->add_dht_node(std::pair<std::string, int>(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.

2
src/twister.h

@ -37,4 +37,6 @@ void receivedSpamMessage(std::string const &message, std::string const &user); @@ -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

Loading…
Cancel
Save