trying (once more) to improve ThreadMaintainDHTNodes (dht nodes from registration network nodes)

This commit is contained in:
Miguel Freitas 2013-10-12 16:24:30 -03:00
parent 56194d1eaf
commit f1c58b9d2a

View File

@ -186,11 +186,13 @@ void ThreadMaintainDHTNodes()
MilliSleep(15000);
if( ses ) {
LOCK(cs_vNodes);
vector<CAddress> 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<std::string, int>(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<std::string, int>(addr, port));
}
}
BOOST_FOREACH(const CAddress &a, vAddr) {