From 04d31cea6e96c3feada8f17abfb98d4f48371be4 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 18 Feb 2010 06:45:07 +0000 Subject: [PATCH] support option to report redundant bytes or not to tracker as well as 'corrupt' argument --- ChangeLog | 1 + bindings/python/src/session_settings.cpp | 1 + docs/manual.rst | 5 +++++ include/libtorrent/session_settings.hpp | 7 +++++++ include/libtorrent/tracker_manager.hpp | 1 + src/http_tracker_connection.cpp | 4 +++- src/torrent.cpp | 18 +++++++++++++++--- 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fbc58e4d..f492f12a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -118,6 +118,7 @@ release 0.14.9 * fixed MinGW support * fixed DHT bootstrapping issue * fixed UDP over SOCKS5 issue + * added support for "corrupt" tracker announce release 0.14.8 diff --git a/bindings/python/src/session_settings.cpp b/bindings/python/src/session_settings.cpp index c258b06b8..5a5f94043 100644 --- a/bindings/python/src/session_settings.cpp +++ b/bindings/python/src/session_settings.cpp @@ -121,6 +121,7 @@ void bind_session_settings() .def_readwrite("increase_est_reciprocation_rate", &session_settings::increase_est_reciprocation_rate) .def_readwrite("decrease_est_reciprocation_rate", &session_settings::decrease_est_reciprocation_rate) .def_readwrite("incoming_starts_queued_torrents", &session_settings::incoming_starts_queued_torrents) + .def_readwrite("report_true_downoaded", &session_settings::report_true_downloaded) ; enum_("proxy_type") diff --git a/docs/manual.rst b/docs/manual.rst index a6497263d..942ec0147 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3772,6 +3772,7 @@ session_settings int increase_est_reciprocation_rate; int decrease_est_reciprocation_rate; bool incoming_starts_queued_torrents; + bool report_true_downloaded; }; ``user_agent`` this is the client identification to the tracker. @@ -4343,6 +4344,10 @@ avoid spreading one's unchoke slots too thin. If a peer managed to find us, even though we're no in the torrent anymore, this setting can make us start the torrent and serve it. +When ``report_true_downloaded`` is true, the ``&downloaded=`` argument +sent to trackers will include redundant downloaded bytes. It defaults +to ``false``, which means redundant bytes are not reported to the tracker. + pe_settings =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 8a9ee7ced..87173de18 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -202,6 +202,7 @@ namespace libtorrent , increase_est_reciprocation_rate(20) , decrease_est_reciprocation_rate(3) , incoming_starts_queued_torrents(false) + , report_true_downloaded(false) {} // this is the user agent that will be sent to the tracker @@ -762,6 +763,12 @@ namespace libtorrent // if set to true, an incoming connection to a torrent that's // paused and auto-managed will make the torrent start. bool incoming_starts_queued_torrents; + + // when set to true, the downloaded counter sent to trackers + // will include the actual number of payload bytes donwnloaded + // including redundant bytes. If set to false, it will not include + // any redundany bytes + bool report_true_downloaded; }; #ifndef TORRENT_DISABLE_DHT diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index f3985312a..aff77bda6 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -104,6 +104,7 @@ namespace libtorrent size_type downloaded; size_type uploaded; size_type left; + size_type corrupt; unsigned short listen_port; event_t event; std::string url; diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 3a64b709c..1c441ea9d 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -139,7 +139,8 @@ namespace libtorrent char str[1024]; const bool stats = tracker_req().send_stats; snprintf(str, sizeof(str), "&peer_id=%s&port=%d&uploaded=%"PRId64 - "&downloaded=%"PRId64"&left=%"PRId64"&compact=1&numwant=%d&key=%x&no_peer_id=1" + "&downloaded=%"PRId64"&left=%"PRId64"&corrupt="PRId64"&compact=1" + "&numwant=%d&key=%x&no_peer_id=1" , escape_string((const char*)&tracker_req().pid[0], 20).c_str() // the i2p tracker seems to verify that the port is not 0, // even though it ignores it otherwise @@ -147,6 +148,7 @@ namespace libtorrent , stats ? tracker_req().uploaded : 0 , stats ? tracker_req().downloaded : 0 , stats ? tracker_req().left : 0 + , stats ? tracker_req().corrupt : 0 , tracker_req().num_want , tracker_req().key); url += str; diff --git a/src/torrent.cpp b/src/torrent.cpp index c81e7a498..7f15b83c0 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1345,10 +1345,16 @@ namespace libtorrent tracker_request req; req.info_hash = m_torrent_file->info_hash(); req.pid = m_ses.get_peer_id(); - req.downloaded = m_stat.total_payload_download(); + req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes; req.uploaded = m_stat.total_payload_upload(); + req.corrupt = m_total_failed_bytes; req.left = bytes_left(); if (req.left == -1) req.left = 16*1024; + + // exclude redundant bytes if we should + if (!settings().report_true_downloaded) + req.downloaded -= m_total_redundant_bytes; + req.event = e; error_code ec; tcp::endpoint ep; @@ -5327,10 +5333,16 @@ namespace libtorrent // tell the tracker that we're back std::for_each(m_trackers.begin(), m_trackers.end() , bind(&announce_entry::reset, _1)); - m_stat.clear(); - announce_with_tracker(); } + // reset the stats, since from the tracker's + // point of view, this is a new session + m_total_failed_bytes = 0; + m_total_redundant_bytes = 0; + m_stat.clear(); + + announce_with_tracker(); + // private torrents are never announced on LSD // or on DHT, we don't need this timer. if (!m_torrent_file->is_valid()