From 9c9c13c7bba3b893b2bd326e450fc1deb67849dd Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 11 Jul 2008 10:29:26 +0000 Subject: [PATCH] exposed read cache info as well as write cache --- docs/manual.html | 9 +++++++++ docs/manual.rst | 4 ++++ examples/client_test.cpp | 20 +++++++++++++++++++- include/libtorrent/disk_io_thread.hpp | 2 ++ src/disk_io_thread.cpp | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/manual.html b/docs/manual.html index 7961af322..20b7422a3 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -793,6 +793,8 @@ struct cached_piece_info int piece; std::vector<bool> blocks; ptime last_use; + enum kind_t { read_cache = 0, write_cache = 1 }; + kind_t kind; }; @@ -801,6 +803,7 @@ struct cached_piece_info the data for that block being in the disk cache and false means it's not.

last_use is the time when a block was last written to this piece. The older a piece is, the more likely it is to be flushed to disk.

+

kind specifies if this piece is part of the read cache or the write cache.

is_listening() listen_port() listen_on()

@@ -2852,6 +2855,7 @@ struct session_settings bool upnp_ignore_nonrouters; int send_buffer_watermark; bool auto_upload_slots; + bool use_parole_mode; int cache_size; int cache_expiry; std::pair<int, int> outgoing_ports; @@ -3018,6 +3022,11 @@ slot is opened. If the upload rate has been saturated for an extended period of time, on upload slot is closed. The number of upload slots will never be less than what has been set by session::set_max_uploads(). To query the current number of upload slots, see session_status::allowed_upload_slots.

+

use_parole_mode specifies if parole mode should be used. Parole mode means +that peers that participate in pieces that fail the hash check are put in a mode +where they are only allowed to download whole pieces. If the whole piece a peer +in parole mode fails the hash check, it is banned. If a peer participates in a +piece that passes the hash check, it is taken out of parole mode.

cache_size is the disk write cache. It is specified in units of 16 KiB blocks. It defaults to 512 (= 8 MB).

cache_expiry is the number of seconds from the last cached write to a piece diff --git a/docs/manual.rst b/docs/manual.rst index 915ee8523..df4cfecbb 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -625,6 +625,8 @@ specified info-hash (``ih``). int piece; std::vector blocks; ptime last_use; + enum kind_t { read_cache = 0, write_cache = 1 }; + kind_t kind; }; ``piece`` is the piece index for this cache entry. @@ -635,6 +637,8 @@ the data for that block being in the disk cache and ``false`` means it's not. ``last_use`` is the time when a block was last written to this piece. The older a piece is, the more likely it is to be flushed to disk. +``kind`` specifies if this piece is part of the read cache or the write cache. + is_listening() listen_port() listen_on() ---------------------------------------- diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 50af5a29b..202f74abb 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1344,7 +1344,7 @@ int main(int ac, char* av[]) if (print_peers && !peers.empty()) print_peer_info(out, peers); - if (print_downloads && s.state != torrent_status::seeding) + if (print_downloads) { h.get_download_queue(queue); std::sort(queue.begin(), queue.end(), bind(&partial_piece_info::piece_index, _1) @@ -1398,6 +1398,24 @@ int main(int ac, char* av[]) out << "\n"; } + for (std::vector::iterator i = pieces.begin() + , end(pieces.end()); i != end; ++i) + { + if (i->kind != cached_piece_info::read_cache) continue; + out << to_string(i->piece, 4) << ": ["; + for (std::vector::iterator k = i->blocks.begin() + , end(i->blocks.end()); k != end; ++k) + { +#ifdef ANSI_TERMINAL_COLORS + if (*k) out << esc("33;7") << " " << esc("0"); + else out << " "; +#else + if (*k) out << "#"; + else out << " "; +#endif + } + out << "]\n"; + } out << "___________________________________\n"; } diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 3556c3cf6..d0d574411 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -58,6 +58,8 @@ namespace libtorrent int piece; std::vector blocks; ptime last_use; + enum kind_t { read_cache = 0, write_cache = 1 }; + kind_t kind; }; struct disk_io_job diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index adebdcf13..b1b49880f 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -101,6 +101,22 @@ namespace libtorrent cached_piece_info info; info.piece = i->piece; info.last_use = i->last_use; + info.kind = cached_piece_info::write_cache; + int blocks_in_piece = (ti.piece_size(i->piece) + (m_block_size) - 1) / m_block_size; + info.blocks.resize(blocks_in_piece); + for (int b = 0; b < blocks_in_piece; ++b) + if (i->blocks[b]) info.blocks[b] = true; + ret.push_back(info); + } + for (cache_t::const_iterator i = m_read_pieces.begin() + , end(m_read_pieces.end()); i != end; ++i) + { + torrent_info const& ti = *i->storage->info(); + if (ti.info_hash() != ih) continue; + cached_piece_info info; + info.piece = i->piece; + info.last_use = i->last_use; + info.kind = cached_piece_info::read_cache; int blocks_in_piece = (ti.piece_size(i->piece) + (m_block_size) - 1) / m_block_size; info.blocks.resize(blocks_in_piece); for (int b = 0; b < blocks_in_piece; ++b)