From 8fafa58c1f81bba8ec3b44f3060a316f5627837a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 11 Jun 2006 23:24:36 +0000 Subject: [PATCH] added per file progress, added patch suggested by Tianhao Qui regarding unchoking when a peer becomes uninterested. Updated documentation and removed block quotes around bullet lists. --- src/peer_connection.cpp | 2 +- src/policy.cpp | 3 +++ src/torrent.cpp | 26 ++++++++++++++++++++++++++ src/torrent_handle.cpp | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 077592c9f..4f268704a 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -315,7 +315,7 @@ namespace libtorrent peer_connection::~peer_connection() { - INVARIANT_CHECK; +// INVARIANT_CHECK; #ifdef TORRENT_VERBOSE_LOGGING using namespace boost::posix_time; diff --git a/src/policy.cpp b/src/policy.cpp index 714a36f93..be1e51187 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -1120,6 +1120,9 @@ namespace libtorrent { c.send_choke(); --m_num_unchoked; + + if (m_torrent->is_seed()) seed_unchoke_one_peer(); + else unchoke_one_peer(); } } diff --git a/src/torrent.cpp b/src/torrent.cpp index 22f9f1f09..f086b8ebb 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1645,6 +1645,32 @@ namespace libtorrent assert(!m_metadata.empty()); return m_metadata; } + + void torrent::file_progress(std::vector& fp) const + { + assert(valid_metadata()); + + fp.clear(); + fp.resize(m_torrent_file.num_files(), 0.f); + + for (int i = 0; i < m_torrent_file.num_files(); ++i) + { + peer_request ret = m_torrent_file.map_file(i, 0, m_torrent_file.file_at(i).size); + size_type done = 0; + while (ret.length > 0) + { + size_type bytes_step = std::min(m_torrent_file.piece_size(ret.piece) + - ret.start, (size_type)ret.length); + if (m_have_pieces[ret.piece]) done += bytes_step; + ++ret.piece; + ret.start = 0; + ret.length -= bytes_step; + } + assert(ret.length == 0); + + fp[i] = static_cast(done) / m_torrent_file.file_at(i).size; + } + } torrent_status torrent::status() const { diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 623540022..2ee7e5376 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -243,6 +243,39 @@ namespace libtorrent , bind(&torrent::set_tracker_login, _1, name, password)); } + void torrent_handle::file_progress(std::vector& progress) + { + INVARIANT_CHECK; + + if (m_ses == 0) throw_invalid_handle(); + + if (m_chk) + { + mutex::scoped_lock l(m_chk->m_mutex); + + detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash); + if (d != 0) + { + if (!d->processing) + { + torrent_info const& info = d->torrent_ptr->torrent_file(); + progress.clear(); + progress.resize(info.num_files(), 0.f); + return; + } + d->torrent_ptr->file_progress(progress); + return; + } + } + + { + session_impl::mutex_t::scoped_lock l(m_ses->m_mutex); + boost::shared_ptr t = m_ses->find_torrent(m_info_hash).lock(); + if (t) return t->file_progress(progress); + } + + throw_invalid_handle(); + } torrent_status torrent_handle::status() const {