diff --git a/ChangeLog b/ChangeLog index 79989d748..2c05ab326 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * added flags to torrent::status() that can filter which values are calculated * support 'explicit read cache' which keeps a specific set of pieces in the read cache, without implicitly caching other pieces * support sending suggest messages based on what's in the read cache diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 8b34176c4..3097139d2 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -239,7 +239,7 @@ namespace libtorrent void add_stats(stat const& s); size_type bytes_left() const; int block_bytes_wanted(piece_block const& p) const; - void bytes_done(torrent_status& st) const; + void bytes_done(torrent_status& st, bool accurate) const; size_type quantized_bytes_done() const; void ip_filter_updated() { m_policy.ip_filter_updated(); } @@ -297,7 +297,7 @@ namespace libtorrent void set_piece_deadline(int piece, int t, int flags); void update_piece_priorities(); - torrent_status status() const; + torrent_status status(boost::uint32_t flags) const; void file_progress(std::vector& fp, int flags = 0) const; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index b2c68e3b1..15e2264e1 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -390,7 +390,15 @@ namespace libtorrent void get_full_peer_list(std::vector& v) const; void get_peer_info(std::vector& v) const; - torrent_status status() const; + + enum status_flags_t + { + query_distributed_copies = 1, + query_accurate_download_counters = 2 + }; + // the flags specify which fields are calculated. By default everything + // is included, you may save CPU by not querying fields you don't need + torrent_status status(boost::uint32_t flags = 0xffffffff) const; void get_download_queue(std::vector& queue) const; enum deadline_flags { alert_when_available = 1 }; diff --git a/src/torrent.cpp b/src/torrent.cpp index e834fa08d..b0eb86832 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1806,7 +1806,7 @@ namespace libtorrent } // fills in total_wanted, total_wanted_done and total_done - void torrent::bytes_done(torrent_status& st) const + void torrent::bytes_done(torrent_status& st, bool accurate) const { INVARIANT_CHECK; @@ -1898,6 +1898,9 @@ namespace libtorrent TORRENT_ASSERT(st.total_wanted_done >= 0); TORRENT_ASSERT(st.total_done >= st.total_wanted_done); + // this is expensive, we might not want to do it all the time + if (!accurate) return; + const std::vector& dl_queue = m_picker->get_download_queue(); @@ -6086,7 +6089,7 @@ namespace libtorrent m_state = s; } - torrent_status torrent::status() const + torrent_status torrent::status(boost::uint32_t flags) const { INVARIANT_CHECK; @@ -6124,7 +6127,7 @@ namespace libtorrent st.num_complete = m_complete; st.num_incomplete = m_incomplete; st.paused = m_paused; - bytes_done(st); + bytes_done(st, flags & torrent_handle::query_accurate_download_counters); TORRENT_ASSERT(st.total_wanted_done >= 0); TORRENT_ASSERT(st.total_done >= st.total_wanted_done); @@ -6168,8 +6171,11 @@ namespace libtorrent { std::vector::const_iterator i; for (i = m_trackers.begin(); i != m_trackers.end(); ++i) - if (i->updating) break; - if (i != m_trackers.end()) st.current_tracker = i->url; + { + if (!i->updating) continue; + st.current_tracker = i->url; + break; + } } st.num_uploads = m_num_uploads; @@ -6224,7 +6230,7 @@ namespace libtorrent } st.num_pieces = num_have(); st.num_seeds = num_seeds(); - if (m_picker.get()) + if ((flags & torrent_handle::query_distributed_copies) && m_picker.get()) { boost::tie(st.distributed_full_copies, st.distributed_fraction) = m_picker->distributed_copies();