|
|
@ -189,18 +189,28 @@ void ThreadMaintainDHTNodes() |
|
|
|
MilliSleep(15000); |
|
|
|
MilliSleep(15000); |
|
|
|
|
|
|
|
|
|
|
|
if( ses ) { |
|
|
|
if( ses ) { |
|
|
|
|
|
|
|
vector<CAddress> vAddr = addrman.GetAddr(); |
|
|
|
session_status ss = ses->status(); |
|
|
|
session_status ss = ses->status(); |
|
|
|
if( ss.dht_nodes < (int)vNodes.size() ) { |
|
|
|
if( ss.dht_nodes < (int)(vNodes.size() + vAddr.size()) / 2 ) { |
|
|
|
printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); |
|
|
|
printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
|
BOOST_FOREACH(CAddress const &knownAddr, pnode->setAddrKnown) { |
|
|
|
|
|
|
|
std::string addr = knownAddr.ToStringIP(); |
|
|
|
// if !fInbound we created this connection so ip is reachable
|
|
|
|
int port = knownAddr.GetPort() + LIBTORRENT_PORT_OFFSET; |
|
|
|
if( !pnode->fInbound ) { |
|
|
|
printf("Adding dht node %s:%d\n", addr.c_str(), port); |
|
|
|
std::string addr = pnode->addr.ToStringIP(); |
|
|
|
|
|
|
|
int port = pnode->addr.GetPort() + LIBTORRENT_PORT_OFFSET; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Adding dht node (outbound) %s:%d\n", addr.c_str(), port); |
|
|
|
ses->add_dht_node(std::pair<std::string, int>(addr, port)); |
|
|
|
ses->add_dht_node(std::pair<std::string, int>(addr, port)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_FOREACH(const CAddress &a, vAddr) { |
|
|
|
|
|
|
|
std::string addr = a.ToStringIP(); |
|
|
|
|
|
|
|
int port = a.GetPort() + LIBTORRENT_PORT_OFFSET; |
|
|
|
|
|
|
|
printf("Adding dht node (addrman) %s:%d\n", addr.c_str(), port); |
|
|
|
|
|
|
|
ses->add_dht_node(std::pair<std::string, int>(addr, port)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|