* Moved the resume code out of DownloadWrapper and made it use the

public API. The client can now use the various calls provided or
implement its own.

* 'U' now deletes the tied file in addition to clearing 'tied_to_file.

* Bound left arrow in chunks seen to return to peer list. Patch by
Josef Drexler.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@734 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-07-01 20:31:07 +00:00
parent 9f2f427e9d
commit 26ffe74744
9 changed files with 40 additions and 16 deletions
+8
View File
@@ -44,6 +44,7 @@
#include <torrent/object.h>
#include <torrent/exceptions.h>
#include <torrent/rate.h>
#include <torrent/resume.h>
#include "utils/variable_generic.h"
@@ -186,6 +187,13 @@ DownloadFactory::receive_success() {
if (!m_session && m_variables.get("tied_to_file").as_value())
download->variable()->set("tied_to_file", m_uri);
torrent::Object& resumeObject = root->has_key_map("libtorrent_resume")
? root->get_key("libtorrent_resume")
: root->insert_key("libtorrent_resume", torrent::Object(torrent::Object::TYPE_MAP));
torrent::resume_load_addresses(*download->download(), resumeObject);
torrent::resume_load_file_priorities(*download->download(), resumeObject);
// The action of inserting might cause the torrent to be
// opened/started or such. Figure out a nicer way of handling this.
if (m_manager->download_list()->insert(download) == m_manager->download_list()->end()) {
+7 -6
View File
@@ -42,6 +42,7 @@
#include <torrent/exceptions.h>
#include <torrent/object.h>
#include <torrent/object_stream.h>
#include <torrent/resume.h>
#include <torrent/torrent.h>
#include "rak/functional.h"
@@ -304,7 +305,7 @@ DownloadList::resume(Download* download) {
// on non-complete downloads after a crash. This shouldn't be
// needed, but for some reason linux 2.6 is very lazy about
// updating mtime.
download->download()->hash_resume_clear();
torrent::resume_clear_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
}
// Update the priority to ensure it has the correct
@@ -333,7 +334,7 @@ DownloadList::pause(Download* download) {
return;
download->download()->stop();
download->download()->hash_resume_save();
torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
std::for_each(slot_map_stop().begin(), slot_map_stop().end(), download_list_call(download));
std::for_each(slot_map_hash_removed().begin(), slot_map_hash_removed().end(), download_list_call(download));
@@ -409,7 +410,7 @@ DownloadList::hash_done(Download* download) {
// Save resume data so we update time-stamps and priorities if
// they were invalid/changed while loading/hashing.
download->variable()->set("complete", (int64_t)download->is_done());
download->download()->hash_resume_save();
torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
if (download->variable()->get_value("state") == 1)
resume(download);
@@ -443,7 +444,7 @@ DownloadList::hash_queue(Download* download, int type) {
throw torrent::client_error("DownloadList::hash_queue(...) hashing already queued.");
close_throw(download);
download->download()->hash_resume_clear();
torrent::resume_clear_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
download->set_hash_failed(false);
download->variable()->set_value("hashing", type);
@@ -482,8 +483,8 @@ DownloadList::confirm_finished(Download* download) {
// Do this before the slots are called in case one of them closes
// the download.
if (!download->is_active() && control->variable()->get_value("session_on_completion") == 1) {
download->download()->hash_resume_save();
if (!download->is_active() && control->variable()->get_value("session_on_completion") != 0) {
torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume"));
control->core()->download_store()->save(download);
}
+4
View File
@@ -48,6 +48,7 @@
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
#include <torrent/rate.h>
#include <torrent/resume.h>
#include <torrent/object_stream.h>
#include "download.h"
@@ -108,6 +109,9 @@ DownloadStore::save(Download* d) {
d->bencode()->get_key("rtorrent").insert_key("total_uploaded", d->download()->up_rate()->total());
d->bencode()->get_key("rtorrent").insert_key("chunks_done", d->download()->chunks_done());
torrent::resume_save_addresses(*d->download(), d->download()->bencode()->get_key("libtorrent_resume"));
torrent::resume_save_file_priorities(*d->download(), d->download()->bencode()->get_key("libtorrent_resume"));
f << *d->bencode();
if (!f.good())
+11 -6
View File
@@ -52,6 +52,7 @@
#include <torrent/object.h>
#include <torrent/connection_manager.h>
#include <torrent/exceptions.h>
#include <torrent/resume.h>
#include <torrent/tracker_list.h>
#include "utils/variable_map.h"
@@ -104,9 +105,9 @@ receive_tracker_dump(const std::string& url, const char* data, size_t size) {
}
// Hmm... find some better place for all this.
static void
delete_tied(Download* d) {
const std::string tie = d->variable()->get_string("tied_to_file");
void
Manager::delete_tied(Download* d) {
const std::string& tie = d->variable()->get_string("tied_to_file");
// This should be configurable, need to wait for the variable
// thingie to be implemented.
@@ -114,7 +115,9 @@ delete_tied(Download* d) {
return;
if (::unlink(rak::path_expand(tie).c_str()) == -1)
control->core()->push_log("Could not unlink tied file: " + std::string(rak::error_number::current().c_str()));
push_log("Could not unlink tied file: " + std::string(rak::error_number::current().c_str()));
d->variable()->set("tied_to_file", std::string());
}
Manager::Manager() :
@@ -173,7 +176,7 @@ Manager::initialize_second() {
m_downloadList->slot_map_insert()["1_connect_storage_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_storage_log), sigc::mem_fun(m_logComplete, &Log::push_front));
m_downloadList->slot_map_insert()["1_connect_tracker_dump"] = sigc::bind(sigc::ptr_fun(&connect_signal_tracker_dump), sigc::ptr_fun(&receive_tracker_dump));
m_downloadList->slot_map_erase()["1_delete_tied"] = sigc::ptr_fun(&delete_tied);
m_downloadList->slot_map_erase()["1_delete_tied"] = sigc::mem_fun(this, &Manager::delete_tied);
}
void
@@ -215,7 +218,7 @@ Manager::listen_open() {
int boundary = m_portFirst + random() % (m_portLast - m_portFirst + 1);
if (torrent::connection_manager()->listen_open(boundary, m_portLast) ||
torrent::connection_manager()->listen_open(m_portFirst, boundary))
torrent::connection_manager()->listen_open(m_portFirst, boundary))
return;
} else {
@@ -396,6 +399,8 @@ Manager::receive_hashing_changed() {
continue;
m_downloadList->open_throw(*itr);
torrent::resume_load_progress(*(*itr)->download(), (*itr)->download()->bencode()->get_key("libtorrent_resume"));
(*itr)->download()->hash_check();
return;
+2
View File
@@ -97,6 +97,8 @@ public:
void try_create_download(const std::string& uri, bool start, bool printLog = true, bool tied = false);
void try_create_download_expand(const std::string& uri, bool start, bool printLog = true, bool tied = false);
void delete_tied(Download* d);
private:
void create_http(const std::string& uri);
void create_final(std::istream* s);