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.
This commit is contained in:
parent
e90f549f58
commit
8fafa58c1f
|
@ -315,7 +315,7 @@ namespace libtorrent
|
|||
|
||||
peer_connection::~peer_connection()
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
// INVARIANT_CHECK;
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
using namespace boost::posix_time;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1645,6 +1645,32 @@ namespace libtorrent
|
|||
assert(!m_metadata.empty());
|
||||
return m_metadata;
|
||||
}
|
||||
|
||||
void torrent::file_progress(std::vector<float>& 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<float>(done) / m_torrent_file.file_at(i).size;
|
||||
}
|
||||
}
|
||||
|
||||
torrent_status torrent::status() const
|
||||
{
|
||||
|
|
|
@ -243,6 +243,39 @@ namespace libtorrent
|
|||
, bind(&torrent::set_tracker_login, _1, name, password));
|
||||
}
|
||||
|
||||
void torrent_handle::file_progress(std::vector<float>& 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<torrent> 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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue