From 4c6be42b746ff3c5ad1be3f0b8318bee00d37c36 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 15 Jul 2010 06:27:44 +0000 Subject: [PATCH] added feature to not count downloaded bytes from web seeds in stats --- ChangeLog | 1 + include/libtorrent/peer_connection.hpp | 7 +++++++ include/libtorrent/session_settings.hpp | 5 +++++ src/http_seed_connection.cpp | 3 +++ src/peer_connection.cpp | 4 +++- src/session_impl.cpp | 13 +++++++++++++ src/torrent.cpp | 5 ++++- src/web_peer_connection.cpp | 3 +++ 8 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 447d21dc4..705718480 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * added feature to not count downloaded bytes from web seeds in stats * added alert for incoming local service discovery messages * added option to set file priorities when adding torrents * removed the session mutex for improved performance diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 227a8e497..993c3a161 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -245,6 +245,9 @@ namespace libtorrent bool no_download() const { return m_no_download; } void no_download(bool b) { m_no_download = b; } + bool ignore_stats() const { return m_ignore_stats; } + void ignore_stats(bool b) { m_ignore_stats = b; } + void set_priority(int p) { TORRENT_ASSERT(p > 0); @@ -1054,6 +1057,10 @@ namespace libtorrent // set to true when we've sent the first round of suggests bool m_sent_suggests:1; + + // when this is set, the transfer stats for this connection + // is not included in the torrent or session stats + bool m_ignore_stats:1; template struct handler_storage diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index d59dfe34f..d2977138b 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -216,6 +216,7 @@ namespace libtorrent , ignore_resume_timestamps(false) , anonymous_mode(false) , tick_interval(100) + , report_web_seed_downloads(true) {} // libtorrent version. Used for forward binary compatibility @@ -834,6 +835,10 @@ namespace libtorrent // the number of milliseconds between internal ticks. Should be no // more than one second (i.e. 1000). int tick_interval; + + // specifies whether downloads from web seeds is reported to the + // tracker or not. Defaults to on + bool report_web_seed_downloads; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index ad4069fab..f984b0931 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -69,6 +69,9 @@ namespace libtorrent { INVARIANT_CHECK; + if (!ses.settings().report_web_seed_downloads) + ignore_stats(true); + // we want large blocks as well, so // we can request more bytes at once request_large_blocks(true); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 982c549fa..52e705469 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -148,6 +148,7 @@ namespace libtorrent , m_bitfield_received(false) , m_no_download(false) , m_sent_suggests(false) + , m_ignore_stats(false) #ifdef TORRENT_DEBUG , m_in_constructor(true) , m_disconnect_started(false) @@ -283,6 +284,7 @@ namespace libtorrent , m_bitfield_received(false) , m_no_download(false) , m_sent_suggests(false) + , m_ignore_stats(false) #ifdef TORRENT_DEBUG , m_in_constructor(true) , m_disconnect_started(false) @@ -3237,7 +3239,7 @@ namespace libtorrent if (t) { // make sure we keep all the stats! - t->add_stats(statistics()); + if (!m_ignore_stats) t->add_stats(statistics()); if (t->has_picker()) { diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 831919dc8..c182610a7 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1253,6 +1253,19 @@ namespace aux { // if anonymous mode was enabled, clear out the peer ID bool anonymous = (m_settings.anonymous_mode != s.anonymous_mode && s.anonymous_mode); + if (m_settings.report_web_seed_downloads != s.report_web_seed_downloads) + { + // if this flag changed, update all web seed connections + for (connection_map::iterator i = m_connections.begin() + , end(m_connections.end()); i != end; ++i) + { + int type = (*i)->type(); + if (type == peer_connection::url_seed_connection + || type == peer_connection::http_seed_connection) + (*i)->ignore_stats(!s.report_web_seed_downloads); + } + } + m_settings = s; // enable anonymous mode. We don't want to accept any incoming diff --git a/src/torrent.cpp b/src/torrent.cpp index 6888ceca7..c96ccb6f6 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5770,7 +5770,10 @@ namespace libtorrent { peer_connection* p = *i; ++i; - m_stat += p->statistics(); + + if (!p->ignore_stats()) + m_stat += p->statistics(); + // updates the peer connection's ul/dl bandwidth // resource requests #ifndef BOOST_NO_EXCEPTIONS diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 658f5e137..1849b4af5 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -70,6 +70,9 @@ namespace libtorrent { INVARIANT_CHECK; + if (!ses.settings().report_web_seed_downloads) + ignore_stats(true); + // we want large blocks as well, so // we can request more bytes at once request_large_blocks(true);