mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 07:17:53 +00:00
force dht_announce on every torrent after adding dht nodes
This commit is contained in:
parent
f1c58b9d2a
commit
eab70b0466
@ -185,6 +185,7 @@ void ThreadMaintainDHTNodes()
|
|||||||
while(1) {
|
while(1) {
|
||||||
MilliSleep(15000);
|
MilliSleep(15000);
|
||||||
|
|
||||||
|
bool nodesAdded = false;
|
||||||
if( ses ) {
|
if( ses ) {
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
vector<CAddress> vAddr = addrman.GetAddr();
|
vector<CAddress> vAddr = addrman.GetAddr();
|
||||||
@ -193,30 +194,34 @@ void ThreadMaintainDHTNodes()
|
|||||||
if( (!ss.dht_nodes && totalNodesCandidates) ||
|
if( (!ss.dht_nodes && totalNodesCandidates) ||
|
||||||
ss.dht_nodes < totalNodesCandidates / 2 ) {
|
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");
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes) {
|
|
||||||
|
|
||||||
// if !fInbound we created this connection so ip is reachable
|
|
||||||
if( !pnode->fInbound ) {
|
|
||||||
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));
|
|
||||||
} 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) {
|
||||||
std::string addr = a.ToStringIP();
|
std::string addr = a.ToStringIP();
|
||||||
int port = a.GetPort() + LIBTORRENT_PORT_OFFSET;
|
int port = a.GetPort() + LIBTORRENT_PORT_OFFSET;
|
||||||
printf("Adding dht node (addrman) %s:%d\n", addr.c_str(), port);
|
printf("Adding dht node (addrman) %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));
|
||||||
|
nodesAdded = true;
|
||||||
}
|
}
|
||||||
|
BOOST_FOREACH(CNode* pnode, vNodes) {
|
||||||
|
// if !fInbound we created this connection so ip is reachable.
|
||||||
|
// we can't use port number of inbound connection, so try standard port.
|
||||||
|
// only use inbound as last resort (if dht_nodes empty)
|
||||||
|
if( !pnode->fInbound || !ss.dht_nodes ) {
|
||||||
|
std::string addr = pnode->addr.ToStringIP();
|
||||||
|
int port = (!pnode->fInbound) ? pnode->addr.GetPort() : Params().GetDefaultPort();
|
||||||
|
port += LIBTORRENT_PORT_OFFSET;
|
||||||
|
|
||||||
|
printf("Adding dht node (%sbound) %s:%d\n", (!pnode->fInbound) ? "out" : "in",
|
||||||
|
addr.c_str(), port);
|
||||||
|
ses->add_dht_node(std::pair<std::string, int>(addr, port));
|
||||||
|
nodesAdded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( nodesAdded ) {
|
||||||
|
LOCK(cs_twister);
|
||||||
|
BOOST_FOREACH(const PAIRTYPE(std::string, torrent_handle)& item, m_userTorrent) {
|
||||||
|
item.second.force_dht_announce();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user