added flags to torrent::status() that can filter which values are calculated

This commit is contained in:
Arvid Norberg 2010-03-04 19:15:23 +00:00
parent 281b6368f7
commit d4854024db
4 changed files with 24 additions and 9 deletions

View File

@ -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 * support 'explicit read cache' which keeps a specific set of pieces
in the read cache, without implicitly caching other pieces in the read cache, without implicitly caching other pieces
* support sending suggest messages based on what's in the read cache * support sending suggest messages based on what's in the read cache

View File

@ -239,7 +239,7 @@ namespace libtorrent
void add_stats(stat const& s); void add_stats(stat const& s);
size_type bytes_left() const; size_type bytes_left() const;
int block_bytes_wanted(piece_block const& p) 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; size_type quantized_bytes_done() const;
void ip_filter_updated() { m_policy.ip_filter_updated(); } 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 set_piece_deadline(int piece, int t, int flags);
void update_piece_priorities(); void update_piece_priorities();
torrent_status status() const; torrent_status status(boost::uint32_t flags) const;
void file_progress(std::vector<size_type>& fp, int flags = 0) const; void file_progress(std::vector<size_type>& fp, int flags = 0) const;

View File

@ -390,7 +390,15 @@ namespace libtorrent
void get_full_peer_list(std::vector<peer_list_entry>& v) const; void get_full_peer_list(std::vector<peer_list_entry>& v) const;
void get_peer_info(std::vector<peer_info>& v) const; void get_peer_info(std::vector<peer_info>& 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<partial_piece_info>& queue) const; void get_download_queue(std::vector<partial_piece_info>& queue) const;
enum deadline_flags { alert_when_available = 1 }; enum deadline_flags { alert_when_available = 1 };

View File

@ -1806,7 +1806,7 @@ namespace libtorrent
} }
// fills in total_wanted, total_wanted_done and total_done // 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; INVARIANT_CHECK;
@ -1898,6 +1898,9 @@ namespace libtorrent
TORRENT_ASSERT(st.total_wanted_done >= 0); TORRENT_ASSERT(st.total_wanted_done >= 0);
TORRENT_ASSERT(st.total_done >= st.total_wanted_done); 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<piece_picker::downloading_piece>& dl_queue const std::vector<piece_picker::downloading_piece>& dl_queue
= m_picker->get_download_queue(); = m_picker->get_download_queue();
@ -6086,7 +6089,7 @@ namespace libtorrent
m_state = s; m_state = s;
} }
torrent_status torrent::status() const torrent_status torrent::status(boost::uint32_t flags) const
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
@ -6124,7 +6127,7 @@ namespace libtorrent
st.num_complete = m_complete; st.num_complete = m_complete;
st.num_incomplete = m_incomplete; st.num_incomplete = m_incomplete;
st.paused = m_paused; 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_wanted_done >= 0);
TORRENT_ASSERT(st.total_done >= st.total_wanted_done); TORRENT_ASSERT(st.total_done >= st.total_wanted_done);
@ -6168,8 +6171,11 @@ namespace libtorrent
{ {
std::vector<announce_entry>::const_iterator i; std::vector<announce_entry>::const_iterator i;
for (i = m_trackers.begin(); i != m_trackers.end(); ++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; st.num_uploads = m_num_uploads;
@ -6224,7 +6230,7 @@ namespace libtorrent
} }
st.num_pieces = num_have(); st.num_pieces = num_have();
st.num_seeds = num_seeds(); 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) = boost::tie(st.distributed_full_copies, st.distributed_fraction) =
m_picker->distributed_copies(); m_picker->distributed_copies();