From a3bff512e1bfb0bce0b8ee60aae1ad90a3a2d3df Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 9 Mar 2010 03:21:35 +0000 Subject: [PATCH] added 'added' and 'completed' time to torrent_status --- docs/manual.rst | 9 +++++++++ include/libtorrent/torrent.hpp | 6 ++++++ include/libtorrent/torrent_handle.hpp | 6 ++++++ src/torrent.cpp | 17 +++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/docs/manual.rst b/docs/manual.rst index a9997c695..bfa7a16b5 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3055,6 +3055,9 @@ It contains the following fields:: bool upload_mode; int priority; + + time_t added_time; + time_t completed_time; }; ``progress`` is a value in the range [0, 1], that represents the progress of the @@ -3277,6 +3280,12 @@ been resolved. If the torrent is not auto-managed, you have to explicitly take it out of the upload mode by calling `set_upload_mode()`_ on the torrent_handle_. +``added_time`` is the posix-time when this torrent was added. i.e. what +``time(NULL)`` returned at the time. + +``completed_time`` is the posix-time when this torrent was finished. If +the torrent is not yet finished, this is 0. + peer_info ========= diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 025fbd3b7..3008fcdda 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -969,6 +969,12 @@ namespace libtorrent boost::uint32_t m_total_failed_bytes; boost::uint32_t m_total_redundant_bytes; + // the posix time this torrent was added and when + // it was completed. If the torrent isn't yet + // completed, m_completed_time is 0 + time_t m_added_time; + time_t m_completed_time; + // ============================== // The following members are specifically // ordered to make the 24 bit members diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 87f68d1d1..87299e0a2 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -124,6 +124,8 @@ namespace libtorrent , seed_mode(false) , upload_mode(false) , priority(0) + , added_time(0) + , completed_time(0) {} enum state_t @@ -303,6 +305,10 @@ namespace libtorrent // the priority of this torrent int priority; + + // the time this torrent was added and completed + time_t added_time; + time_t completed_time; }; struct TORRENT_EXPORT block_info diff --git a/src/torrent.cpp b/src/torrent.cpp index e26f8feed..cd3383944 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -326,6 +326,8 @@ namespace libtorrent , m_piece_time_deviation(0) , m_total_failed_bytes(0) , m_total_redundant_bytes(0) + , m_added_time(time(0)) + , m_completed_time(0) , m_upload_mode_time(0) , m_state(torrent_status::checking_resume_data) , m_storage_mode(p.storage_mode) @@ -3600,6 +3602,11 @@ namespace libtorrent if (m_seed_mode) m_verified.resize(m_torrent_file->num_pieces(), false); super_seeding(rd.dict_find_int_value("super_seeding", 0)); + m_added_time = rd.dict_find_int_value("added_time", m_added_time); + m_completed_time = rd.dict_find_int_value("completed_time", m_completed_time); + if (m_completed_time != 0 && m_completed_time < m_added_time) + m_completed_time = m_added_time; + lazy_entry const* file_priority = rd.dict_find_list("file_priority"); if (file_priority && file_priority->list_size() == m_torrent_file->num_files()) @@ -3747,6 +3754,9 @@ namespace libtorrent ret["seed_mode"] = m_seed_mode; ret["super_seeding"] = m_super_seeding; + + ret["added_time"] = m_added_time; + ret["completed_time"] = m_completed_time; const sha1_hash& info_hash = torrent_file().info_hash(); ret["info-hash"] = std::string((char*)info_hash.begin(), (char*)info_hash.end()); @@ -4463,6 +4473,8 @@ namespace libtorrent send_upload_only(); + m_completed_time = time(0); + // disconnect all seeds // TODO: should disconnect all peers that have the pieces we have // not just seeds @@ -4504,6 +4516,8 @@ namespace libtorrent set_queue_position((std::numeric_limits::max)()); m_policy.recalculate_connect_candidates(); + m_completed_time = 0; + send_upload_only(); } @@ -6106,6 +6120,9 @@ namespace libtorrent if (m_error) st.error = m_error.message() + ": " + m_error_file; st.seed_mode = m_seed_mode; + st.added_time = m_added_time; + st.completed_time - m_completed_time; + st.last_scrape = m_last_scrape; st.upload_mode = m_upload_mode; st.up_bandwidth_queue = 0;