From f1c58b9d2aa1aa216fced31d3b5740b85787b77e Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sat, 12 Oct 2013 16:24:30 -0300 Subject: [PATCH] trying (once more) to improve ThreadMaintainDHTNodes (dht nodes from registration network nodes) --- src/twister.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/twister.cpp b/src/twister.cpp index a821190e..f11efd31 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -186,11 +186,13 @@ void ThreadMaintainDHTNodes() MilliSleep(15000); if( ses ) { + LOCK(cs_vNodes); vector vAddr = addrman.GetAddr(); session_status ss = ses->status(); - if( ss.dht_nodes < (int)(vNodes.size() + vAddr.size()) / 2 ) { + int totalNodesCandidates = (int)(vNodes.size() + vAddr.size()); + if( (!ss.dht_nodes && totalNodesCandidates) || + ss.dht_nodes < totalNodesCandidates / 2 ) { printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); - LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { // if !fInbound we created this connection so ip is reachable @@ -200,6 +202,13 @@ void ThreadMaintainDHTNodes() printf("Adding dht node (outbound) %s:%d\n", addr.c_str(), port); ses->add_dht_node(std::pair(addr, port)); + } else if( !ss.dht_nodes /* last resort! */ ) { + // can't use port number of inbound connectio, try standard port + std::string addr = pnode->addr.ToStringIP(); + int port = Params().GetDefaultPort() + LIBTORRENT_PORT_OFFSET; + + printf("Adding dht node (inbound) %s:%d\n", addr.c_str(), port); + ses->add_dht_node(std::pair(addr, port)); } } BOOST_FOREACH(const CAddress &a, vAddr) {