diff --git a/libtorrent/include/libtorrent/stat.hpp b/libtorrent/include/libtorrent/stat.hpp index ef9b7780b..04f097fcd 100755 --- a/libtorrent/include/libtorrent/stat.hpp +++ b/libtorrent/include/libtorrent/stat.hpp @@ -138,6 +138,9 @@ namespace libtorrent m_total_upload_payload += uploaded; } + size_type last_payload_downloaded() const { return m_downloaded_payload; } + size_type last_payload_uploaded() const { return m_uploaded_payload; } + private: #ifndef NDEBUG diff --git a/libtorrent/include/libtorrent/time.hpp b/libtorrent/include/libtorrent/time.hpp index 983e9fa4d..a03d728bf 100644 --- a/libtorrent/include/libtorrent/time.hpp +++ b/libtorrent/include/libtorrent/time.hpp @@ -99,6 +99,7 @@ namespace libtorrent time_duration operator/(int rhs) const { return time_duration(diff / rhs); } explicit time_duration(boost::int64_t d) : diff(d) {} time_duration& operator-=(time_duration const& c) { diff -= c.diff; return *this; } + time_duration& operator+=(time_duration const& c) { diff += c.diff; return *this; } time_duration operator+(time_duration const& c) { return time_duration(diff + c.diff); } boost::int64_t diff; }; diff --git a/libtorrent/include/libtorrent/torrent.hpp b/libtorrent/include/libtorrent/torrent.hpp index bfec8bb53..801d99598 100755 --- a/libtorrent/include/libtorrent/torrent.hpp +++ b/libtorrent/include/libtorrent/torrent.hpp @@ -518,6 +518,7 @@ namespace libtorrent torrent_handle get_handle(); void write_resume_data(entry& rd) const; + void read_resume_data(entry const& rd); // LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING @@ -838,6 +839,23 @@ namespace libtorrent int m_deficit_counter; policy m_policy; + + // the sequence number for this torrent, this is a + // monotonically increasing number for each added torrent + int m_sequence_number; + + // total time we've been available on this torrent + // does not count when the torrent is stopped or paused + time_duration m_active_time; + + // total time we've been available as a seed on this torrent + // does not count when the torrent is stopped or paused + time_duration m_seeding_time; + + // all time totals of uploaded and downloaded payload + // stored in resume data + size_type m_total_uploaded; + size_type m_total_downloaded; }; inline ptime torrent::next_announce() const diff --git a/libtorrent/include/libtorrent/torrent_handle.hpp b/libtorrent/include/libtorrent/torrent_handle.hpp index e389fe8d0..4d0a1b3ac 100755 --- a/libtorrent/include/libtorrent/torrent_handle.hpp +++ b/libtorrent/include/libtorrent/torrent_handle.hpp @@ -114,6 +114,10 @@ namespace libtorrent , storage_mode(storage_mode_sparse) , up_bandwidth_queue(0) , down_bandwidth_queue(0) + , all_time_upload(0) + , all_time_download(0) + , active_time(0) + , seeding_time(0) {} enum state_t @@ -240,6 +244,17 @@ namespace libtorrent int up_bandwidth_queue; int down_bandwidth_queue; + + // number of bytes downloaded since torrent was started + // saved and restored from resume data + size_type all_time_upload; + size_type all_time_download; + + // the number of seconds of being active + // and as being a seed, saved and restored + // from resume data + int active_time; + int seeding_time; }; struct TORRENT_EXPORT block_info diff --git a/libtorrent/src/kademlia/routing_table.cpp b/libtorrent/src/kademlia/routing_table.cpp index 1a55126f3..1deb00a71 100644 --- a/libtorrent/src/kademlia/routing_table.cpp +++ b/libtorrent/src/kademlia/routing_table.cpp @@ -229,8 +229,8 @@ void routing_table::node_failed(node_id const& id) { b.erase(i); TORRENT_ASSERT(m_lowest_active_bucket <= bucket_index); - while (m_buckets[m_lowest_active_bucket].first.empty() - && m_lowest_active_bucket < 160) + while (m_lowest_active_bucket < 160 + && m_buckets[m_lowest_active_bucket].first.empty()) { ++m_lowest_active_bucket; } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index edb5a4f03..419dccf85 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -1565,6 +1565,13 @@ namespace aux { m_queued_for_checking.pop_front(); if (!m_queued_for_checking.empty()) m_queued_for_checking.front()->start_checking(); + + if (m_alerts.should_post(alert::info)) + { + m_alerts.post_alert(torrent_checked_alert( + t->get_handle() + , "torrent finished checking")); + } } torrent_handle session_impl::add_torrent( diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 8afc9e990..f1b7048a1 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -420,6 +420,8 @@ namespace libtorrent m_state = torrent_status::queued_for_checking; + read_resume_data(m_resume_data); + m_storage->async_check_fastresume(&m_resume_data , bind(&torrent::on_resume_data_checked , shared_from_this(), _1, _2)); @@ -2257,11 +2259,31 @@ namespace libtorrent } #endif + void torrent::read_resume_data(entry const& rd) + { + entry const* e = 0; + e = rd.find_key("total_uploaded"); + m_total_uploaded = (e != 0 && e->type() == entry::int_t)?e->integer():0; + e = rd.find_key("total_downloaded"); + m_total_downloaded = (e != 0 && e->type() == entry::int_t)?e->integer():0; + + e = rd.find_key("active_time"); + m_active_time = seconds((e != 0 && e->type() == entry::int_t)?e->integer():0); + e = rd.find_key("seeding_time"); + m_seeding_time = seconds((e != 0 && e->type() == entry::int_t)?e->integer():0); + } + void torrent::write_resume_data(entry& ret) const { ret["file-format"] = "libtorrent resume file"; ret["file-version"] = 1; + ret["total_uploaded"] = m_total_uploaded; + ret["total_downloaded"] = m_total_downloaded; + + ret["active_time"] = total_seconds(m_active_time); + ret["seeding_time"] = total_seconds(m_seeding_time); + ret["allocation"] = m_storage_mode == storage_mode_sparse?"sparse" :m_storage_mode == storage_mode_allocate?"full":"compact"; @@ -3354,6 +3376,10 @@ namespace libtorrent return; } + time_duration since_last_tick = microsec(tick_interval * 1000000L); + if (is_seed()) m_seeding_time += since_last_tick; + m_active_time += since_last_tick; + // ---- WEB SEEDS ---- // re-insert urls that are to be retries into the m_web_seeds @@ -3424,6 +3450,8 @@ namespace libtorrent #endif } accumulator += m_stat; + m_total_uploaded += m_stat.last_payload_uploaded(); + m_total_downloaded += m_stat.last_payload_downloaded(); m_stat.second_tick(tick_interval); m_time_scaler--; @@ -3567,6 +3595,12 @@ namespace libtorrent st.list_seeds = m_policy.num_seeds(); st.connect_candidates = m_policy.num_connect_candidates(); + st.all_time_upload = m_total_uploaded; + st.all_time_download = m_total_downloaded; + + st.active_time = total_seconds(m_active_time); + st.seeding_time = total_seconds(m_seeding_time); + st.storage_mode = m_storage_mode; st.num_complete = m_complete;