fixes to remote peer download rate etimation

This commit is contained in:
Arvid Norberg 2007-06-14 21:47:00 +00:00
parent 5efe12dde6
commit 46bf2970fb
4 changed files with 32 additions and 18 deletions

View File

@ -25,5 +25,6 @@ python-extension libtorrent
/torrent//torrent
/boost/python//boost_python
: <include>src
: <link>static
;

View File

@ -336,7 +336,7 @@ void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const
out << " " << i->country[0] << i->country[1];
}
#endif
out << (i->remote_dl_rate > 0 ? add_suffix(i->remote_dl_rate) + "/s ": " ") << " ";
out << " " << (i->remote_dl_rate > 0 ? add_suffix(i->remote_dl_rate) + "/s ": " ") << " ";
if (i->flags & peer_info::handshake)
{

View File

@ -690,6 +690,10 @@ namespace libtorrent
// approximate peer download rate
int m_remote_dl_rate;
// a timestamp when the remote download rate
// was last updated
ptime m_remote_dl_update;
#ifndef NDEBUG
public:

View File

@ -115,6 +115,7 @@ namespace libtorrent
, m_connection_ticket(-1)
, m_remote_bytes_dled(0)
, m_remote_dl_rate(0)
, m_remote_dl_update(time_now())
#ifndef NDEBUG
, m_in_constructor(true)
#endif
@ -187,6 +188,7 @@ namespace libtorrent
, m_speed(slow)
, m_remote_bytes_dled(0)
, m_remote_dl_rate(0)
, m_remote_dl_update(time_now())
#ifndef NDEBUG
, m_in_constructor(true)
#endif
@ -732,8 +734,15 @@ namespace libtorrent
&& t->picker().piece_priority(index) != 0)
t->get_policy().peer_is_interesting(*this);
// update bytes downloaded since last timer
m_remote_bytes_dled += t->torrent_file().piece_size(index);
// this will disregard all have messages we get within
// the first two seconds. Since some clients implements
// lazy bitfields, these will not be reliable to use
// for an estimated peer download rate.
if (!peer_info_struct() || time_now() - peer_info_struct()->connected > seconds(2))
{
// update bytes downloaded since last timer
m_remote_bytes_dled += t->torrent_file().piece_size(index);
}
}
if (is_seed())
@ -1891,24 +1900,24 @@ namespace libtorrent
, m_upload_limit));
}
// note the 1/60 multiplication here - this is per second of the
// minute; but since timers are not exact this makes this
// calculation REALLY approximate.
float factor = 0.6666666666667f;
// update once every minute
if (now - m_remote_dl_update >= seconds(60))
{
float factor = 0.6666666666667f;
if(m_remote_dl_rate == 0) {
factor = 0.0f;
if (m_remote_dl_rate == 0)
{
factor = 0.0f;
}
m_remote_dl_rate =
(m_remote_dl_rate * factor) +
((m_remote_bytes_dled * (1.0f-factor)) / 60.f);
m_remote_bytes_dled = 0;
m_remote_dl_update = now;
}
m_remote_dl_rate =
(m_remote_dl_rate * factor) +
((m_remote_bytes_dled * (1.0f-factor)) * (1.f/60.f));
m_remote_bytes_dled = 0;
//
fill_send_buffer();
/*
size_type diff = share_diff();