fixed DHT bug where requests that timed out would be treated as transaction_id overflows and would slow down DHT lookups considerably.

This commit is contained in:
Arvid Norberg 2008-09-15 05:05:26 +00:00
parent 027952f69d
commit 166f761df3
2 changed files with 15 additions and 5 deletions

View File

@ -115,7 +115,7 @@ namespace libtorrent
, max_outstanding_disk_bytes_per_connection(64 * 1024) , max_outstanding_disk_bytes_per_connection(64 * 1024)
, handshake_timeout(10) , handshake_timeout(10)
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
, use_dht_as_fallback(true) , use_dht_as_fallback(false)
#endif #endif
, free_torrent_hashes(true) , free_torrent_hashes(true)
, upnp_ignore_nonrouters(true) , upnp_ignore_nonrouters(true)

View File

@ -307,7 +307,9 @@ time_duration rpc_manager::tick()
if (m_next_transaction_id == m_oldest_transaction_id) return milliseconds(timeout_ms); if (m_next_transaction_id == m_oldest_transaction_id) return milliseconds(timeout_ms);
std::vector<observer_ptr > timeouts; std::vector<observer_ptr> timeouts;
time_duration ret = milliseconds(timeout_ms);
for (;m_next_transaction_id != m_oldest_transaction_id; for (;m_next_transaction_id != m_oldest_transaction_id;
m_oldest_transaction_id = (m_oldest_transaction_id + 1) % max_transactions) m_oldest_transaction_id = (m_oldest_transaction_id + 1) % max_transactions)
@ -321,8 +323,16 @@ time_duration rpc_manager::tick()
time_duration diff = o->sent + milliseconds(timeout_ms) - time_now(); time_duration diff = o->sent + milliseconds(timeout_ms) - time_now();
if (diff > seconds(0)) if (diff > seconds(0))
{ {
if (diff < seconds(1)) return seconds(1); if (diff < seconds(1))
return diff; {
ret = seconds(1);
break;
}
else
{
ret = diff;
break;
}
} }
try try
@ -343,7 +353,7 @@ time_duration rpc_manager::tick()
// generate new requests. We need to swap, since the // generate new requests. We need to swap, since the
// destrutors may add more observers to the m_aborted_transactions // destrutors may add more observers to the m_aborted_transactions
std::vector<observer_ptr>().swap(m_aborted_transactions); std::vector<observer_ptr>().swap(m_aborted_transactions);
return milliseconds(timeout_ms); return ret;
} }
unsigned int rpc_manager::new_transaction_id(observer_ptr o) unsigned int rpc_manager::new_transaction_id(observer_ptr o)