From f6554bad08dc477c65242805e09aea5139182cd3 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 7 Aug 2011 07:19:18 +0000 Subject: [PATCH] back ported feature to expose which pieces have been verified in seed_mode and exposes it in client_test (initially implemented in the libtorrent_aio branch) --- docs/manual.rst | 16 +++++++++++++++- examples/client_test.cpp | 13 +++++++++++-- include/libtorrent/session_settings.hpp | 2 +- include/libtorrent/torrent_handle.hpp | 5 ++++- src/torrent.cpp | 5 +++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 88a6b1fcd..e711802ef 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2193,7 +2193,9 @@ Its declaration looks like this:: { query_distributed_copies = 1, query_accurate_download_counters = 2, - query_last_seen_complete = 4 + query_last_seen_complete = 4, + query_pieces = 8, + query_verified_pieces = 16 }; torrent_status status(boost::uint32_t flags = 0xffffffff); @@ -3177,6 +3179,12 @@ By default everything is included. The flags you can use to decide what to *incl * ``query_last_seen_complete`` includes ``last_seen_complete``. +* ``query_pieces`` + includes ``pieces``. + +* ``query_verified_pieces`` + includes ``verified_pieces`` (only applies to torrents in *seed mode*). + get_download_queue() -------------------- @@ -3350,6 +3358,8 @@ It contains the following fields:: int connect_candidates; bitfield pieces; + bitfield verified_pieces; + int num_pieces; size_type total_done; @@ -3520,6 +3530,10 @@ order block). This is supposed to be as low as possible. the pieces we don't have. It's a pointer and may be set to 0 if the torrent isn't downloading or seeding. +``verified_pieces`` is a bitmask representing which pieces has had their hash +checked. This only applies to torrents in *seed mode*. If the torrent is not +in seed mode, this bitmask may be empty. + ``num_pieces`` is the number of pieces that has been downloaded. It is equivalent to: ``std::accumulate(pieces->begin(), pieces->end())``. So you don't have to count yourself. This can be used to see if anything has updated since last time diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 9d3a0178b..c4bed03c6 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1414,7 +1414,9 @@ int main(int argc, char* argv[]) // is a somewhat expensive operation, don't do it by default for // all torrents handles[active_torrent] = handles[active_torrent].handle.status( - torrent_handle::query_distributed_copies); + torrent_handle::query_distributed_copies + | torrent_handle::query_pieces + | torrent_handle::query_verified_pieces); } std::vector feeds; @@ -1853,12 +1855,19 @@ int main(int argc, char* argv[]) out += str; ++lines_printed; - if (print_piece_bar && s.state != torrent_status::seeding) + if (print_piece_bar && (s.state != torrent_status::seeding || s.seed_mode)) { out += " "; out += piece_bar(s.pieces, terminal_width - 7); out += "\n"; ++lines_printed; + if (s.seed_mode) + { + out += " "; + out += piece_bar(s.verified_pieces, terminal_width - 7); + out += "\n"; + ++lines_printed; + } } if (s.state != torrent_status::queued_for_checking && s.state != torrent_status::checking_files) diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 9c79ab435..83fd8d3fc 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -214,7 +214,7 @@ namespace libtorrent , dht_announce_interval(15 * 60) , udp_tracker_token_expiry(60) , volatile_read_cache(false) - , guided_read_cache(true) + , guided_read_cache(false) , default_cache_min_age(1) , num_optimistic_unchoke_slots(0) , no_atime_storage(true) diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 171598d83..1a1bd613d 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -169,7 +169,9 @@ namespace libtorrent { query_distributed_copies = 1, query_accurate_download_counters = 2, - query_last_seen_complete = 4 + query_last_seen_complete = 4, + query_pieces = 8, + query_verified_pieces = 16 }; // the flags specify which fields are calculated. By default everything @@ -574,6 +576,7 @@ namespace libtorrent int connect_candidates; bitfield pieces; + bitfield verified_pieces; // this is the number of pieces the client has // downloaded. it is equal to: diff --git a/src/torrent.cpp b/src/torrent.cpp index ef0a39a80..32de3a23f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -7567,6 +7567,11 @@ namespace libtorrent } } + if ((flags & torrent_handle::query_verified_pieces)) + { + st->verified_pieces = m_verified; + } + st->num_uploads = m_num_uploads; st->uploads_limit = m_max_uploads; st->num_connections = int(m_connections.size());