made end-game mode less aggressive

This commit is contained in:
Arvid Norberg 2010-02-18 17:26:21 +00:00
parent d892198a40
commit f31e670fc2
4 changed files with 40 additions and 2 deletions

View File

@ -119,6 +119,7 @@ release 0.14.9
* fixed DHT bootstrapping issue
* fixed UDP over SOCKS5 issue
* added support for "corrupt" tracker announce
* made end-game mode less aggressive
release 0.14.8

View File

@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session_settings.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/time.hpp"
namespace libtorrent
{
@ -139,8 +140,9 @@ namespace libtorrent
struct downloading_piece
{
downloading_piece(): finished(0), writing(0), requested(0) {}
downloading_piece(): last_request(min_time()), finished(0), writing(0), requested(0) {}
piece_state_t state;
ptime last_request;
// the index of the piece
int index;
@ -278,6 +280,7 @@ namespace libtorrent
void mark_as_finished(piece_block block, void* peer);
void write_failed(piece_block block);
int num_peers(piece_block block) const;
ptime last_request(int piece) const;
// returns information about the given piece
void piece_info(int index, piece_picker::downloading_piece& st) const;

View File

@ -2012,6 +2012,7 @@ namespace libtorrent
info.peer = peer;
info.num_peers = 1;
++dp.requested;
dp.last_request = time_now();
}
else
{
@ -2036,6 +2037,7 @@ namespace libtorrent
}
++info.num_peers;
if (i->state == none) i->state = state;
i->last_request = time_now();
}
return true;
}
@ -2058,6 +2060,23 @@ namespace libtorrent
return info.num_peers;
}
ptime piece_picker::last_request(int piece) const
{
TORRENT_ASSERT(piece >= 0);
TORRENT_ASSERT(piece < (int)m_piece_map.size());
piece_pos const& p = m_piece_map[piece];
if (!p.downloading) return min_time();
std::vector<downloading_piece>::const_iterator i
= std::find_if(m_downloads.begin(), m_downloads.end(), has_index(piece));
TORRENT_ASSERT(i != m_downloads.end());
// just to play it safe
if (i == m_downloads.end()) return min_time();
return i->last_request;
}
void piece_picker::get_availability(std::vector<int>& avail) const
{
TORRENT_ASSERT(m_seeds >= 0);

View File

@ -264,7 +264,13 @@ namespace libtorrent
num_requests--;
}
if (busy_pieces.empty() || num_requests <= 0)
// if we don't have any potential busy blocks to request
// or if we have picked as many blocks as we should
// or if we already have outstanding requests, don't
// pick a busy piece
if (busy_pieces.empty()
|| num_requests <= 0
|| dq.size() + rq.size() > 0)
{
return;
}
@ -285,6 +291,15 @@ namespace libtorrent
#endif
TORRENT_ASSERT(p.is_requested(*i));
TORRENT_ASSERT(p.num_peers(*i) > 0);
ptime last_request = p.last_request(i->piece_index);
ptime now = time_now();
// don't re-request from a piece more often than once every 20 seconds
// TODO: make configurable
if (now - last_request < seconds(20))
return;
c.add_request(*i, peer_connection::req_busy);
}