From 67354421fbd8b4d8b2f131074cf71f16853d7a51 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 20 May 2008 07:57:44 +0000 Subject: [PATCH] introduced an error state for torrents. Torrents with an error are not restarted automatically --- docs/manual.html | 5 +++++ docs/manual.rst | 6 ++++++ examples/client_test.cpp | 7 +++++++ include/libtorrent/torrent.hpp | 5 +++++ include/libtorrent/torrent_handle.hpp | 2 ++ src/session_impl.cpp | 4 ++-- src/torrent.cpp | 8 ++++++-- 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/manual.html b/docs/manual.html index dcd3303fa..b28c62be6 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -2206,6 +2206,8 @@ struct torrent_status state_t state; bool paused; float progress; + std::string error; + boost::posix_time::time_duration next_announce; boost::posix_time::time_duration announce_interval; @@ -2319,6 +2321,9 @@ allocated.

When downloading, the progress is total_wanted_done / total_wanted.

paused is set to true if the torrent is paused and false otherwise.

+

error may be set to an error message describing why the torrent was paused, in +case it was paused by an error. If the torrent is not paused or if it's paused but +not because of an error, this string is empty.

next_announce is the time until the torrent will announce itself to the tracker. And announce_interval is the time the tracker want us to wait until we announce ourself again the next time.

diff --git a/docs/manual.rst b/docs/manual.rst index 098f9daf2..060ce453c 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2170,6 +2170,8 @@ It contains the following fields:: state_t state; bool paused; float progress; + std::string error; + boost::posix_time::time_duration next_announce; boost::posix_time::time_duration announce_interval; @@ -2273,6 +2275,10 @@ When downloading, the progress is ``total_wanted_done`` / ``total_wanted``. ``paused`` is set to true if the torrent is paused and false otherwise. +``error`` may be set to an error message describing why the torrent was paused, in +case it was paused by an error. If the torrent is not paused or if it's paused but +not because of an error, this string is empty. + ``next_announce`` is the time until the torrent will announce itself to the tracker. And ``announce_interval`` is the time the tracker want us to wait until we announce ourself again the next time. diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 539398354..f3b61e6b7 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1253,6 +1253,13 @@ int main(int ac, char* av[]) bool paused = h.is_paused(); bool auto_managed = h.is_auto_managed(); out << std::setw(13) << std::setiosflags(std::ios::left); + if (!s.error.empty()) + { + out << esc("31") << "error " << s.error; + out << esc("0") << std::endl; + continue; + } + if (paused && !auto_managed) out << "paused"; else if (paused && auto_managed) out << "queued"; else diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 39aa2fe4b..629766c11 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -181,6 +181,7 @@ namespace libtorrent void ip_filter_updated() { m_policy.ip_filter_updated(); } + bool has_error() const { return !m_error.empty(); } void pause(); void resume(); bool is_paused() const { return m_paused; } @@ -750,6 +751,10 @@ namespace libtorrent // the state of this torrent (queued, checking, downloading) torrent_status::state_t m_state; + // if there's an error on this torrent, this is the + // error message + std::string m_error; + entry m_resume_data; // if the torrent is started without metadata, it may diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index e6e7e55f4..6d0873085 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -137,6 +137,8 @@ namespace libtorrent state_t state; bool paused; float progress; + std::string error; + boost::posix_time::time_duration next_announce; boost::posix_time::time_duration announce_interval; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5e70cb6e7..2615d0211 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1043,7 +1043,7 @@ namespace aux { else ++uncongested_torrents; - if (t.is_auto_managed() && t.is_paused()) + if (t.is_auto_managed() && t.is_paused() && !t.has_error()) { ++num_paused_auto_managed; if (!least_recently_scraped->second->is_auto_managed() @@ -1308,7 +1308,7 @@ namespace aux { { torrent* t = i->second.get(); TORRENT_ASSERT(t); - if (t->is_auto_managed()) + if (t->is_auto_managed() && !t->has_error()) { // this torrent is auto managed, add it to // the list (depending on if it's a seed or not) diff --git a/src/torrent.cpp b/src/torrent.cpp index 25cb02558..d02c99304 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -449,7 +449,7 @@ namespace libtorrent } std::fill(m_have_pieces.begin(), m_have_pieces.end(), false); m_num_pieces = 0; - auto_managed(false); + m_error = j.str; pause(); return; } @@ -637,7 +637,7 @@ namespace libtorrent } std::fill(m_have_pieces.begin(), m_have_pieces.end(), false); m_num_pieces = 0; - auto_managed(false); + m_error = j.str; pause(); m_ses.done_checking(shared_from_this()); return; @@ -3564,6 +3564,7 @@ namespace libtorrent m_paused = false; m_started = time_now(); + m_error.clear(); // tell the tracker that we're back m_event = tracker_request::started; @@ -3750,6 +3751,7 @@ namespace libtorrent { alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.str)); } + m_error = j.str; pause(); } f(ret); @@ -3809,6 +3811,8 @@ namespace libtorrent torrent_status st; + st.error = m_error; + if (m_last_scrape == min_time()) { st.last_scrape = -1;