From 6cae25e7abf7acd5bfde120aa3285dd5a681ed9e Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 4 Jul 2014 08:44:26 -0300 Subject: [PATCH] fix dht count when using proxy (fix #231) --- src/dhtproxy.cpp | 4 +++- src/dhtproxy.h | 2 ++ src/twister.cpp | 23 +++++++++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/dhtproxy.cpp b/src/dhtproxy.cpp index 6e45729c..f3dc863f 100644 --- a/src/dhtproxy.cpp +++ b/src/dhtproxy.cpp @@ -74,7 +74,7 @@ namespace DhtProxy } } - vector getRandomDhtProxies() + vector getRandomDhtProxies(int *totalProxyNodes) { // (cs_vNodes) lock must be held! vector vNodesProxy; @@ -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); diff --git a/src/dhtproxy.h b/src/dhtproxy.h index 55d2e36e..0ec5f148 100644 --- a/src/dhtproxy.h +++ b/src/dhtproxy.h @@ -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 getRandomDhtProxies(int *totalProxyNodes = NULL); } class CDHTTarget diff --git a/src/twister.cpp b/src/twister.cpp index 07cc28b9..24a19f21 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -459,13 +459,24 @@ void lockAndSaveUserData() int getDhtNodes(boost::int64_t *dht_global_nodes) { - boost::shared_ptr ses(m_ses); - if( !ses ) - return 0; - session_status ss = ses->status(); + int dhtNodes = 0; + if( dht_global_nodes ) - *dht_global_nodes = ss.dht_global_nodes; - return ss.dht_nodes; + *dht_global_nodes = 0; + + if( !DhtProxy::fEnabled ) { + boost::shared_ptr ses(m_ses); + if( ses ) { + session_status ss = ses->status(); + if( dht_global_nodes ) + *dht_global_nodes = ss.dht_global_nodes; + dhtNodes = ss.dht_nodes; + } + } else { + LOCK(cs_vNodes); + DhtProxy::getRandomDhtProxies(&dhtNodes); + } + return dhtNodes; } void torrentManualTrackerUpdate(const std::string &username)