reports redundant downloads to tracker, fixed downloaded calculation to be more stable when not including redundant. Improved redundant data accounting to be more accurate

This commit is contained in:
Arvid Norberg 2010-10-18 00:10:33 +00:00
parent 973a1c45f2
commit eba657d8ad
6 changed files with 43 additions and 12 deletions

View File

@ -53,6 +53,9 @@
* added more detailed instrumentation of the disk I/O thread * added more detailed instrumentation of the disk I/O thread
* reports redundant downloads to tracker, fixed downloaded calculation to
be more stable when not including redundant. Improved redundant data accounting
to be more accurate
* fixed bugs in http seed connection and added unit test for it * fixed bugs in http seed connection and added unit test for it
* fixed error reporting when fallocate fails * fixed error reporting when fallocate fails
* deprecate support for separate proxies for separate kinds of connections * deprecate support for separate proxies for separate kinds of connections

View File

@ -79,6 +79,11 @@ namespace libtorrent
{ {
tracker_request() tracker_request()
: kind(announce_request) : kind(announce_request)
, downloaded(-1)
, uploaded(-1)
, left(-1)
, corrupt(0)
, redundant(0)
, event(none) , event(none)
, key(0) , key(0)
, num_want(0) , num_want(0)
@ -106,6 +111,7 @@ namespace libtorrent
size_type uploaded; size_type uploaded;
size_type left; size_type left;
size_type corrupt; size_type corrupt;
size_type redundant;
unsigned short listen_port; unsigned short listen_port;
event_t event; event_t event;
std::string url; std::string url;

View File

@ -138,8 +138,8 @@ namespace libtorrent
char str[1024]; char str[1024];
const bool stats = tracker_req().send_stats; const bool stats = tracker_req().send_stats;
snprintf(str, sizeof(str), "&peer_id=%s&port=%d&uploaded=%"PRId64 snprintf(str, sizeof(str), "&peer_id=%s&port=%d&uploaded=%"PRId64
"&downloaded=%"PRId64"&left=%"PRId64"&corrupt=%"PRId64"&compact=1" "&downloaded=%"PRId64"&left=%"PRId64"&corrupt=%"PRId64"&redundant=%"PRId64
"&numwant=%d&key=%x&no_peer_id=1" "&compact=1&numwant=%d&key=%x&no_peer_id=1"
, escape_string((const char*)&tracker_req().pid[0], 20).c_str() , escape_string((const char*)&tracker_req().pid[0], 20).c_str()
// the i2p tracker seems to verify that the port is not 0, // the i2p tracker seems to verify that the port is not 0,
// even though it ignores it otherwise // even though it ignores it otherwise
@ -148,6 +148,7 @@ namespace libtorrent
, stats ? tracker_req().downloaded : 0 , stats ? tracker_req().downloaded : 0
, stats ? tracker_req().left : 0 , stats ? tracker_req().left : 0
, stats ? tracker_req().corrupt : 0 , stats ? tracker_req().corrupt : 0
, stats ? tracker_req().redundant: 0
, tracker_req().num_want , tracker_req().num_want
, tracker_req().key); , tracker_req().key);
url += str; url += str;

View File

@ -3289,7 +3289,19 @@ namespace libtorrent
if (t) if (t)
{ {
// make sure we keep all the stats! // make sure we keep all the stats!
if (!m_ignore_stats) t->add_stats(statistics()); if (!m_ignore_stats)
{
t->add_stats(statistics());
// report any partially received payload as redundant
boost::optional<piece_block_progress> pbp = downloading_piece_progress();
if (pbp
&& pbp->bytes_downloaded > 0
&& pbp->bytes_downloaded < pbp->full_block_bytes)
{
t->add_redundant_bytes(pbp->bytes_downloaded);
}
}
if (t->has_picker()) if (t->has_picker())
{ {

View File

@ -1449,15 +1449,24 @@ namespace libtorrent
tracker_request req; tracker_request req;
req.info_hash = m_torrent_file->info_hash(); req.info_hash = m_torrent_file->info_hash();
req.pid = m_ses.get_peer_id(); req.pid = m_ses.get_peer_id();
req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes;
req.uploaded = m_stat.total_payload_upload(); req.uploaded = m_stat.total_payload_upload();
req.corrupt = m_total_failed_bytes; req.corrupt = m_total_failed_bytes;
req.left = bytes_left(); req.redundant = m_total_redundant_bytes;
if (settings().report_true_downloaded)
{
req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes;
req.left = bytes_left();
}
else
{
req.downloaded = quantized_bytes_done();
TORRENT_ASSERT(!valid_metadata() || req.downloaded <= m_torrent_file->total_size());
req.left = valid_metadata() ? m_torrent_file->total_size() - req.downloaded : -1;
}
if (req.left == -1) req.left = 16*1024; if (req.left == -1) req.left = 16*1024;
// exclude redundant bytes if we should TORRENT_ASSERT(req.downloaded >= 0);
if (!settings().report_true_downloaded)
req.downloaded -= m_total_redundant_bytes;
req.event = e; req.event = e;
error_code ec; error_code ec;
@ -6838,6 +6847,8 @@ namespace libtorrent
TORRENT_ASSERT(b > 0); TORRENT_ASSERT(b > 0);
m_total_redundant_bytes += b; m_total_redundant_bytes += b;
m_ses.add_redundant_bytes(b); m_ses.add_redundant_bytes(b);
TORRENT_ASSERT(m_total_redundant_bytes + m_total_failed_bytes
<= m_stat.total_payload_download());
} }
void torrent::add_failed_bytes(int b) void torrent::add_failed_bytes(int b)
@ -6845,6 +6856,8 @@ namespace libtorrent
TORRENT_ASSERT(b > 0); TORRENT_ASSERT(b > 0);
m_total_failed_bytes += b; m_total_failed_bytes += b;
m_ses.add_failed_bytes(b); m_ses.add_failed_bytes(b);
TORRENT_ASSERT(m_total_redundant_bytes + m_total_failed_bytes
<= m_stat.total_payload_download());
} }
int torrent::num_seeds() const int torrent::num_seeds() const

View File

@ -96,10 +96,6 @@ namespace libtorrent
void web_peer_connection::disconnect(error_code const& ec, int error) void web_peer_connection::disconnect(error_code const& ec, int error)
{ {
boost::shared_ptr<torrent> t = associated_torrent().lock(); boost::shared_ptr<torrent> t = associated_torrent().lock();
if (t && m_block_pos)
t->add_redundant_bytes(m_block_pos);
peer_connection::disconnect(ec, error); peer_connection::disconnect(ec, error);
if (t) t->disconnect_web_seed(this); if (t) t->disconnect_web_seed(this);
} }