mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-25 14:04:27 +00:00
trying (once more) to improve ThreadMaintainDHTNodes (dht nodes from registration network nodes)
This commit is contained in:
parent
56194d1eaf
commit
f1c58b9d2a
@ -186,11 +186,13 @@ void ThreadMaintainDHTNodes()
|
|||||||
MilliSleep(15000);
|
MilliSleep(15000);
|
||||||
|
|
||||||
if( ses ) {
|
if( ses ) {
|
||||||
|
LOCK(cs_vNodes);
|
||||||
vector<CAddress> vAddr = addrman.GetAddr();
|
vector<CAddress> vAddr = addrman.GetAddr();
|
||||||
session_status ss = ses->status();
|
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");
|
printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n");
|
||||||
LOCK(cs_vNodes);
|
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes) {
|
BOOST_FOREACH(CNode* pnode, vNodes) {
|
||||||
|
|
||||||
// if !fInbound we created this connection so ip is reachable
|
// 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);
|
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));
|
||||||
|
} 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) {
|
BOOST_FOREACH(const CAddress &a, vAddr) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user