Browse Source

fix dht count when using proxy (fix #231)

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
6cae25e7ab
  1. 4
      src/dhtproxy.cpp
  2. 2
      src/dhtproxy.h
  3. 17
      src/twister.cpp

4
src/dhtproxy.cpp

@ -74,7 +74,7 @@ namespace DhtProxy @@ -74,7 +74,7 @@ namespace DhtProxy
}
}
vector<CNode*> getRandomDhtProxies()
vector<CNode*> getRandomDhtProxies(int *totalProxyNodes)
{
// (cs_vNodes) lock must be held!
vector<CNode*> vNodesProxy;
@ -83,6 +83,8 @@ namespace DhtProxy @@ -83,6 +83,8 @@ namespace DhtProxy
vNodesProxy.push_back(pnode);
}
}
if( totalProxyNodes )
*totalProxyNodes = (int) vNodesProxy.size();
std::random_shuffle(vNodesProxy.begin(),vNodesProxy.end());
if(vNodesProxy.size() > numProxiesToUse) {
vNodesProxy.resize(numProxiesToUse);

2
src/dhtproxy.h

@ -86,6 +86,8 @@ namespace DhtProxy @@ -86,6 +86,8 @@ namespace DhtProxy
// Handle a dhtput request received from TCP. send request to UDP. (server side)
// return true if accepted.
bool dhtputRequestReceived(const CDHTPutRequest& req, CNode* pfrom);
vector<CNode*> getRandomDhtProxies(int *totalProxyNodes = NULL);
}
class CDHTTarget

17
src/twister.cpp

@ -459,13 +459,24 @@ void lockAndSaveUserData() @@ -459,13 +459,24 @@ void lockAndSaveUserData()
int getDhtNodes(boost::int64_t *dht_global_nodes)
{
int dhtNodes = 0;
if( dht_global_nodes )
*dht_global_nodes = 0;
if( !DhtProxy::fEnabled ) {
boost::shared_ptr<session> ses(m_ses);
if( !ses )
return 0;
if( ses ) {
session_status ss = ses->status();
if( dht_global_nodes )
*dht_global_nodes = ss.dht_global_nodes;
return ss.dht_nodes;
dhtNodes = ss.dht_nodes;
}
} else {
LOCK(cs_vNodes);
DhtProxy::getRandomDhtProxies(&dhtNodes);
}
return dhtNodes;
}
void torrentManualTrackerUpdate(const std::string &username)

Loading…
Cancel
Save