mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 14:49:21 +00:00
* Moved hash and torrent size checking to initialize so it will be
caught when loading a torrent. * Added VariableMap to core::Download and started moving various settings. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@624 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+29
-13
@@ -42,6 +42,8 @@
|
||||
#include <sigc++/signal.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "utils/variable_generic.h"
|
||||
|
||||
#include "download.h"
|
||||
|
||||
namespace core {
|
||||
@@ -49,15 +51,25 @@ namespace core {
|
||||
Download::Download(torrent::Download d) :
|
||||
m_download(d),
|
||||
|
||||
m_chunksFailed(0),
|
||||
m_connectionLeech(torrent::Download::CONNECTION_LEECH),
|
||||
m_connectionSeed(torrent::Download::CONNECTION_SEED) {
|
||||
m_chunksFailed(0) {
|
||||
|
||||
m_connTrackerSucceded = m_download.signal_tracker_succeded(sigc::bind(sigc::mem_fun(*this, &Download::receive_tracker_msg), ""));
|
||||
m_connTrackerFailed = m_download.signal_tracker_failed(sigc::mem_fun(*this, &Download::receive_tracker_msg));
|
||||
m_connStorageError = m_download.signal_storage_error(sigc::mem_fun(*this, &Download::receive_storage_error));
|
||||
|
||||
m_download.signal_chunk_failed(sigc::mem_fun(*this, &Download::receive_chunk_failed));
|
||||
|
||||
m_variables.insert("connection_current", new utils::VariableSlotString<const char*, const std::string&>(rak::mem_fn(this, &Download::connection_current),
|
||||
rak::mem_fn(this, &Download::set_connection_current)));
|
||||
m_variables.insert("connection_leech", new utils::VariableValue(connection_type_to_string(torrent::Download::CONNECTION_LEECH)));
|
||||
m_variables.insert("connection_seed", new utils::VariableValue(connection_type_to_string(torrent::Download::CONNECTION_SEED)));
|
||||
m_variables.insert("directory", new utils::VariableSlotString<std::string, const std::string&>(NULL,
|
||||
rak::mem_fn(this, &Download::set_root_directory)));
|
||||
m_variables.insert("tied_to_file", new utils::VariableBencode(&m_download.bencode(), "tied_to_file", torrent::Bencode::TYPE_STRING));
|
||||
|
||||
m_variables.insert("peers_min", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_min),
|
||||
rak::mem_fn(&m_download, &torrent::Download::set_peers_min),
|
||||
"%u"));
|
||||
}
|
||||
|
||||
Download::~Download() {
|
||||
@@ -74,23 +86,16 @@ Download::~Download() {
|
||||
void
|
||||
Download::start() {
|
||||
if (is_done()) {
|
||||
m_download.set_connection_type(m_connectionSeed);
|
||||
m_download.set_connection_type(string_to_connection_type(m_variables.get("connection_seed").as_string()));
|
||||
torrent::download_set_priority(m_download, 2);
|
||||
} else {
|
||||
m_download.set_connection_type(m_connectionLeech);
|
||||
m_download.set_connection_type(string_to_connection_type(m_variables.get("connection_leech").as_string()));
|
||||
torrent::download_set_priority(m_download, 4);
|
||||
}
|
||||
|
||||
m_download.start();
|
||||
}
|
||||
|
||||
void
|
||||
Download::set_root_directory(const std::string& d) {
|
||||
m_download.set_root_dir(d +
|
||||
(!d.empty() && *d.rbegin() != '/' ? "/" : "") +
|
||||
(m_download.size_file_entries() > 1 ? m_download.name() : ""));
|
||||
}
|
||||
|
||||
void
|
||||
Download::enable_udp_trackers(bool state) {
|
||||
for (int i = 0, last = m_download.size_trackers(); i < last; ++i)
|
||||
@@ -103,7 +108,7 @@ Download::enable_udp_trackers(bool state) {
|
||||
|
||||
void
|
||||
Download::receive_finished() {
|
||||
m_download.set_connection_type(m_connectionSeed);
|
||||
m_download.set_connection_type(string_to_connection_type(m_variables.get("connection_seed").as_string()));
|
||||
torrent::download_set_priority(m_download, 2);
|
||||
}
|
||||
|
||||
@@ -148,4 +153,15 @@ Download::receive_chunk_failed(uint32_t idx) {
|
||||
m_chunksFailed++;
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
void
|
||||
Download::set_root_directory(const std::string& d) {
|
||||
if (d.empty())
|
||||
m_download.set_root_dir("./" + (m_download.size_file_entries() > 1 ? m_download.name() : std::string()));
|
||||
else
|
||||
m_download.set_root_dir(d +
|
||||
(*d.rbegin() != '/' ? "/" : "") +
|
||||
(m_download.size_file_entries() > 1 ? m_download.name() : ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+15
-17
@@ -41,6 +41,8 @@
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
class Download {
|
||||
@@ -55,6 +57,9 @@ public:
|
||||
|
||||
void start();
|
||||
|
||||
utils::VariableMap* variables() { return &m_variables; }
|
||||
std::string variable_string(const std::string& key) { return m_variables.get_string(key); }
|
||||
|
||||
torrent::Download& get_download() { return m_download; }
|
||||
const torrent::Download& get_download() const { return m_download; }
|
||||
std::string get_hash() { return m_download.info_hash(); }
|
||||
@@ -64,18 +69,6 @@ public:
|
||||
|
||||
uint32_t chunks_failed() const { return m_chunksFailed; }
|
||||
|
||||
void set_root_directory(const std::string& d);
|
||||
|
||||
ConnType get_connection_current() const { return m_download.connection_type(); }
|
||||
ConnType get_connection_leech() const { return m_connectionLeech; }
|
||||
ConnType get_connection_seed() const { return m_connectionSeed; }
|
||||
|
||||
void set_connection_leech(const std::string& name) { m_connectionLeech = string_to_connection_type(name); }
|
||||
void set_connection_seed(const std::string& name) { m_connectionSeed = string_to_connection_type(name); }
|
||||
|
||||
const std::string& tied_to_file() const { return m_tiedToFile; }
|
||||
void set_tied_to_file(const std::string& str) { m_tiedToFile = str; }
|
||||
|
||||
void enable_udp_trackers(bool state);
|
||||
|
||||
// Helper functions for calling functions in torrent::Download
|
||||
@@ -94,24 +87,29 @@ public:
|
||||
static const char* connection_type_to_string(ConnType t);
|
||||
|
||||
private:
|
||||
Download(const Download&);
|
||||
void operator () (const Download&);
|
||||
|
||||
void receive_tracker_msg(std::string msg);
|
||||
void receive_storage_error(std::string msg);
|
||||
|
||||
void receive_chunk_failed(uint32_t idx);
|
||||
|
||||
const char* connection_current() const { return connection_type_to_string(m_download.connection_type()); }
|
||||
void set_connection_current(const std::string& t) { return m_download.set_connection_type(string_to_connection_type(t.c_str())); }
|
||||
|
||||
void set_root_directory(const std::string& d);
|
||||
|
||||
torrent::Download m_download;
|
||||
|
||||
std::string m_message;
|
||||
uint32_t m_chunksFailed;
|
||||
|
||||
ConnType m_connectionLeech;
|
||||
ConnType m_connectionSeed;
|
||||
|
||||
std::string m_tiedToFile;
|
||||
|
||||
sigc::connection m_connTrackerSucceded;
|
||||
sigc::connection m_connTrackerFailed;
|
||||
sigc::connection m_connStorageError;
|
||||
|
||||
utils::VariableMap m_variables;
|
||||
};
|
||||
|
||||
inline bool
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#include <torrent/bencode.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "utils/variable_generic.h"
|
||||
|
||||
#include "curl_get.h"
|
||||
#include "http_queue.h"
|
||||
#include "globals.h"
|
||||
@@ -60,12 +62,16 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) :
|
||||
m_uri(uri),
|
||||
m_session(false),
|
||||
m_start(false),
|
||||
m_printLog(true),
|
||||
m_tiedToFile(false) {
|
||||
m_printLog(true) {
|
||||
|
||||
m_taskLoad.set_slot(rak::mem_fn(this, &DownloadFactory::receive_load));
|
||||
m_taskCommit.set_slot(rak::mem_fn(this, &DownloadFactory::receive_commit));
|
||||
}
|
||||
|
||||
m_variables.insert("connection_leech", new utils::VariableValue(control->variables()->get("connection_leech")));
|
||||
m_variables.insert("connection_seed", new utils::VariableValue(control->variables()->get("connection_seed")));
|
||||
m_variables.insert("directory", new utils::VariableValue(control->variables()->get("directory")));
|
||||
m_variables.insert("tied_to_file", new utils::VariableBool(false));
|
||||
}
|
||||
|
||||
DownloadFactory::~DownloadFactory() {
|
||||
priority_queue_erase(&taskScheduler, &m_taskLoad);
|
||||
@@ -98,7 +104,7 @@ DownloadFactory::receive_load() {
|
||||
(*itr)->signal_done().slots().push_front(sigc::mem_fun(*this, &DownloadFactory::receive_loaded));
|
||||
(*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &DownloadFactory::receive_failed));
|
||||
|
||||
m_tiedToFile = false;
|
||||
m_variables.set("tied_to_file", (int64_t)false);
|
||||
|
||||
} else {
|
||||
m_stream = new std::fstream(m_uri.c_str(), std::ios::in);
|
||||
@@ -140,6 +146,14 @@ DownloadFactory::receive_success() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Move to 'rtorrent'.
|
||||
(*itr)->variables()->set("connection_leech", m_variables.get("connection_leech"));
|
||||
(*itr)->variables()->set("connection_seed", m_variables.get("connection_seed"));
|
||||
(*itr)->variables()->set("directory", m_variables.get("directory"));
|
||||
|
||||
// if (control->variables()->get("peers_min")
|
||||
// (*itr)->variables()->set("peers_min", m_variables.get("directory"));
|
||||
|
||||
torrent::Bencode& bencode = (*itr)->get_bencode();
|
||||
|
||||
if (m_session) {
|
||||
@@ -147,18 +161,16 @@ DownloadFactory::receive_success() {
|
||||
if (bencode.get_key("rtorrent").get_key("state").as_string() == "started")
|
||||
m_manager->start(*itr, m_printLog);
|
||||
|
||||
if (bencode.get_key("rtorrent").has_key("tied") &&
|
||||
bencode.get_key("rtorrent").get_key("tied").is_string())
|
||||
(*itr)->set_tied_to_file(bencode.get_key("rtorrent").get_key("tied").as_string());
|
||||
// Consider adding an empty 'tied_to_file' here if not present.
|
||||
|
||||
} else {
|
||||
// Remove the settings if this isn't a session torrent.
|
||||
//bencode.erase_key("rtorrent");
|
||||
|
||||
if (m_tiedToFile) {
|
||||
(*itr)->set_tied_to_file(m_uri);
|
||||
bencode.get_key("rtorrent").insert_key("tied", m_uri);
|
||||
}
|
||||
if (m_variables.get("tied_to_file").as_value())
|
||||
(*itr)->variables()->set("tied_to_file", m_uri);
|
||||
else
|
||||
(*itr)->variables()->set("tied_to_file", std::string());
|
||||
|
||||
if (m_start)
|
||||
m_manager->start(*itr, m_printLog);
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
#include <sigc++/slot.h>
|
||||
#include <rak/priority_queue_default.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
|
||||
#include "http_queue.h"
|
||||
|
||||
namespace core {
|
||||
@@ -65,6 +67,8 @@ public:
|
||||
void load();
|
||||
void commit();
|
||||
|
||||
utils::VariableMap* variables() { return &m_variables; }
|
||||
|
||||
bool get_session() const { return m_session; }
|
||||
void set_session(bool v) { m_session = v; }
|
||||
|
||||
@@ -74,9 +78,6 @@ public:
|
||||
bool print_log() const { return m_printLog; }
|
||||
void set_print_log(bool v) { m_printLog = v; }
|
||||
|
||||
bool tied_to_file() const { return m_tiedToFile; }
|
||||
void set_tied_to_file(bool v) { m_tiedToFile = v; }
|
||||
|
||||
void slot_finished(Slot s) { m_slotFinished = s; }
|
||||
|
||||
private:
|
||||
@@ -96,7 +97,8 @@ private:
|
||||
bool m_session;
|
||||
bool m_start;
|
||||
bool m_printLog;
|
||||
bool m_tiedToFile;
|
||||
|
||||
utils::VariableMap m_variables;
|
||||
|
||||
Slot m_slotFinished;
|
||||
rak::priority_item m_taskLoad;
|
||||
|
||||
+7
-4
@@ -80,10 +80,12 @@ connect_signal_storage_log(Download* d, torrent::Download::SlotString s) {
|
||||
// Hmm... find some better place for all this.
|
||||
static void
|
||||
delete_tied(Download* d) {
|
||||
const std::string tie = d->variables()->get("tied_to_file").as_string();
|
||||
|
||||
// This should be configurable, need to wait for the variable
|
||||
// thingie to be implemented.
|
||||
if (!d->tied_to_file().empty())
|
||||
::unlink(d->tied_to_file().c_str());
|
||||
if (!tie.empty())
|
||||
::unlink(tie.c_str());
|
||||
}
|
||||
|
||||
Manager::Manager() :
|
||||
@@ -338,9 +340,10 @@ Manager::try_create_download(const std::string& uri, bool start, bool printLog,
|
||||
// Adding download.
|
||||
DownloadFactory* f = new DownloadFactory(uri, this);
|
||||
|
||||
f->variables()->set("tied_to_file", tied ? "yes" : "no");
|
||||
|
||||
f->set_start(start);
|
||||
f->set_print_log(printLog);
|
||||
f->set_tied_to_file(tied);
|
||||
f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func<core::DownloadFactory>), f));
|
||||
f->load();
|
||||
f->commit();
|
||||
@@ -402,7 +405,7 @@ Manager::try_create_download_expand(const std::string& uri, bool start, bool pri
|
||||
if (tied)
|
||||
for (std::vector<std::string>::iterator itr = paths.begin(); itr != paths.end(); )
|
||||
if (std::find_if(m_downloadList.begin(), m_downloadList.end(),
|
||||
rak::equal(*itr, std::mem_fun(&Download::tied_to_file))) != m_downloadList.end())
|
||||
rak::equal(*itr, rak::bind2nd(std::mem_fun(&Download::variable_string), "tied_to_file"))) != m_downloadList.end())
|
||||
itr = paths.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
|
||||
Reference in New Issue
Block a user