From 9b15c117408bb126bed543da87d4d62ade3e01ba Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 25 Sep 2009 18:17:59 +0000 Subject: [PATCH] don't send stats to trackers received through tracker exchange --- include/libtorrent/torrent_info.hpp | 4 ++++ include/libtorrent/tracker_manager.hpp | 2 ++ src/http_tracker_connection.cpp | 7 ++++--- src/lt_trackers.cpp | 1 + src/torrent.cpp | 3 +++ src/udp_tracker_connection.cpp | 7 ++++--- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 9fbfcb790..4a1b7247e 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -87,6 +87,7 @@ namespace libtorrent , updating(false) , start_sent(false) , complete_sent(false) + , send_stats(true) {} std::string url; @@ -126,6 +127,9 @@ namespace libtorrent // this is true if event completed has been sent to the tracker bool complete_sent:1; + // this is false the stats sent to this tracker will be 0 + bool send_stats:1; + void reset() { start_sent = false; diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 586d3989f..8d978d49c 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -82,6 +82,7 @@ namespace libtorrent , event(none) , key(0) , num_want(0) + , send_stats(true) {} enum @@ -111,6 +112,7 @@ namespace libtorrent std::string ipv6; std::string ipv4; address bind_ip; + bool send_stats; }; struct TORRENT_EXPORT request_callback diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index f97a8aee2..540a8f0e4 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -137,15 +137,16 @@ namespace libtorrent if (tracker_req().kind == tracker_request::announce_request) { 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" , 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 , i2p ? 1 : tracker_req().listen_port - , tracker_req().uploaded - , tracker_req().downloaded - , tracker_req().left + , stats ? tracker_req().uploaded : 0 + , stats ? tracker_req().downloaded : 0 + , stats ? tracker_req().left : 0 , tracker_req().num_want , tracker_req().key); url += str; diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index 68f66efc8..e8fb7c92f 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -220,6 +220,7 @@ namespace libtorrent { namespace announce_entry e(added->list_string_value_at(i)); if (e.url.empty()) continue; e.fail_limit = 3; + e.send_stats = false; e.source = announce_entry::source_tex; m_torrent.add_tracker(e); #ifdef TORRENT_VERBOSE_LOGGING diff --git a/src/torrent.cpp b/src/torrent.cpp index 0146e893c..8ee0e3330 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3606,6 +3606,9 @@ namespace libtorrent for (std::vector::const_iterator i = m_trackers.begin() , end(m_trackers.end()); i != end; ++i) { + // don't save trackers we can't trust + // TODO: save the send_stats state instead + if (i->send_stats == false) continue; if (i->tier == tier) { tr_list.back().list().push_back(i->url); diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 87fb16c5d..4a68f7de6 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -513,6 +513,7 @@ namespace libtorrent char* out = buf; tracker_request const& req = tracker_req(); + const bool stats = req.send_stats; session_settings const& settings = m_ses.settings(); detail::write_int64(m_connection_id, out); // connection_id @@ -522,9 +523,9 @@ namespace libtorrent out += 20; std::copy(req.pid.begin(), req.pid.end(), out); // peer_id out += 20; - detail::write_int64(req.downloaded, out); // downloaded - detail::write_int64(req.left, out); // left - detail::write_int64(req.uploaded, out); // uploaded + detail::write_int64(stats ? req.downloaded : 0, out); // downloaded + detail::write_int64(stats ? req.left : 0, out); // left + detail::write_int64(stats ? req.uploaded : 0, out); // uploaded detail::write_int32(req.event, out); // event // ip address if (settings.announce_ip != address() && settings.announce_ip.is_v4())