don't send stats to trackers received through tracker exchange

This commit is contained in:
Arvid Norberg 2009-09-25 18:17:59 +00:00
parent 6eefa02c56
commit 9b15c11740
6 changed files with 18 additions and 6 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -3606,6 +3606,9 @@ namespace libtorrent
for (std::vector<announce_entry>::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);

View File

@ -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())