mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-14 22:22:31 +00:00
* Fixed an overflow in rak::partial_queue, and added some exceptions.
* Changed to configure script so --disable-mincore must be called explicitly to disable it. * API and core::Download cleanup. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@660 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+22
-21
@@ -52,9 +52,10 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
Download::Download(torrent::Download d) :
|
||||
Download::Download(download_type d) :
|
||||
m_download(d),
|
||||
m_fileList(d.file_list()),
|
||||
m_trackerList(d.tracker_list()),
|
||||
|
||||
m_chunksFailed(0) {
|
||||
|
||||
@@ -66,22 +67,22 @@ Download::Download(torrent::Download d) :
|
||||
|
||||
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::VariableAny(connection_type_to_string(torrent::Download::CONNECTION_LEECH)));
|
||||
m_variables.insert("connection_seed", new utils::VariableAny(connection_type_to_string(torrent::Download::CONNECTION_SEED)));
|
||||
m_variables.insert("state", new utils::VariableObject(&m_download.bencode(), "rtorrent", "state", torrent::Object::TYPE_STRING));
|
||||
m_variables.insert("tied_to_file", new utils::VariableObject(&m_download.bencode(), "rtorrent", "tied_to_file", torrent::Object::TYPE_STRING));
|
||||
m_variables.insert("connection_leech", new utils::VariableAny(connection_type_to_string(download_type::CONNECTION_LEECH)));
|
||||
m_variables.insert("connection_seed", new utils::VariableAny(connection_type_to_string(download_type::CONNECTION_SEED)));
|
||||
m_variables.insert("state", new utils::VariableObject(bencode(), "rtorrent", "state", torrent::Object::TYPE_STRING));
|
||||
m_variables.insert("tied_to_file", new utils::VariableObject(bencode(), "rtorrent", "tied_to_file", torrent::Object::TYPE_STRING));
|
||||
|
||||
m_variables.insert("directory", new utils::VariableSlotString<const std::string&>(rak::mem_fn(&m_fileList, &torrent::FileList::root_dir),
|
||||
rak::mem_fn(this, &Download::set_root_directory)));
|
||||
|
||||
m_variables.insert("min_peers", 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),
|
||||
m_variables.insert("min_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &download_type::peers_min),
|
||||
rak::mem_fn(&m_download, &download_type::set_peers_min),
|
||||
"%u"));
|
||||
m_variables.insert("max_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_max),
|
||||
rak::mem_fn(&m_download, &torrent::Download::set_peers_max),
|
||||
m_variables.insert("max_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &download_type::peers_max),
|
||||
rak::mem_fn(&m_download, &download_type::set_peers_max),
|
||||
"%u"));
|
||||
m_variables.insert("max_uploads", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::uploads_max),
|
||||
rak::mem_fn(&m_download, &torrent::Download::set_uploads_max),
|
||||
m_variables.insert("max_uploads", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &download_type::uploads_max),
|
||||
rak::mem_fn(&m_download, &download_type::set_uploads_max),
|
||||
"%u"));
|
||||
m_variables.insert("priority", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(this, &Download::priority),
|
||||
rak::mem_fn(this, &Download::set_priority),
|
||||
@@ -96,7 +97,7 @@ Download::~Download() {
|
||||
m_connTrackerFailed.disconnect();
|
||||
m_connStorageError.disconnect();
|
||||
|
||||
m_download = torrent::Download();
|
||||
m_download = download_type();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -132,7 +133,7 @@ Download::enable_udp_trackers(bool state) {
|
||||
|
||||
uint32_t
|
||||
Download::priority() {
|
||||
return get_bencode().get_key("rtorrent").get_key("priority").as_value();
|
||||
return bencode()->get_key("rtorrent").get_key("priority").as_value();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -146,7 +147,7 @@ Download::set_priority(uint32_t p) {
|
||||
else
|
||||
torrent::download_set_priority(m_download, p * p);
|
||||
|
||||
get_bencode().get_key("rtorrent").insert_key("priority", (int64_t)p);
|
||||
bencode()->get_key("rtorrent").insert_key("priority", (int64_t)p);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -169,23 +170,23 @@ Download::receive_storage_error(std::string msg) {
|
||||
m_message = "Storage error: [" + msg + "]";
|
||||
}
|
||||
|
||||
torrent::Download::ConnectionType
|
||||
Download::download_type::ConnectionType
|
||||
Download::string_to_connection_type(const std::string& name) {
|
||||
// Return default if the name isn't found.
|
||||
if (name == "leech")
|
||||
return torrent::Download::CONNECTION_LEECH;
|
||||
return download_type::CONNECTION_LEECH;
|
||||
else if (name == "seed")
|
||||
return torrent::Download::CONNECTION_SEED;
|
||||
return download_type::CONNECTION_SEED;
|
||||
else
|
||||
throw torrent::input_error("Unknown peer connection type selected: \"" + name + "\"");
|
||||
}
|
||||
|
||||
const char*
|
||||
Download::connection_type_to_string(torrent::Download::ConnectionType t) {
|
||||
Download::connection_type_to_string(download_type::ConnectionType t) {
|
||||
switch (t) {
|
||||
case torrent::Download::CONNECTION_LEECH:
|
||||
case download_type::CONNECTION_LEECH:
|
||||
return "leech";
|
||||
case torrent::Download::CONNECTION_SEED:
|
||||
case download_type::CONNECTION_SEED:
|
||||
return "seed";
|
||||
default:
|
||||
return "unknown";
|
||||
@@ -263,7 +264,7 @@ Download::set_root_directory(const std::string& path) {
|
||||
(m_fileList.size() > 1 ? m_download.name() : ""));
|
||||
}
|
||||
|
||||
m_download.bencode().get_key("rtorrent").insert_key("directory", path);
|
||||
bencode()->get_key("rtorrent").insert_key("directory", path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+51
-49
@@ -40,6 +40,7 @@
|
||||
#include <sigc++/connection.h>
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
@@ -48,91 +49,92 @@ namespace core {
|
||||
|
||||
class Download {
|
||||
public:
|
||||
typedef torrent::Download::ConnectionType ConnType;
|
||||
typedef torrent::Download download_type;
|
||||
typedef torrent::FileList file_list_type;
|
||||
typedef torrent::TrackerList tracker_list_type;
|
||||
typedef download_type::ConnectionType connection_type;
|
||||
typedef utils::VariableMap variable_map_type;
|
||||
|
||||
Download(torrent::Download d);
|
||||
Download(download_type d);
|
||||
~Download();
|
||||
|
||||
bool is_open() { return m_download.is_open(); }
|
||||
inline bool is_done();
|
||||
bool is_open() const { return m_download.is_open(); }
|
||||
inline bool is_done() const { return m_download.chunks_done() == m_download.chunks_total(); }
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
// Add functions like pause/etc.
|
||||
|
||||
utils::VariableMap* variables() { return &m_variables; }
|
||||
std::string variable_string(const std::string& key) { return m_variables.get_string(key); }
|
||||
variable_map_type* variable() { return &m_variables; }
|
||||
std::string variable_string(const std::string& key) { return m_variables.get_string(key); }
|
||||
|
||||
torrent::FileList* file_list() { return &m_fileList; }
|
||||
download_type* download() { return &m_download; }
|
||||
const download_type* download() const { return &m_download; }
|
||||
|
||||
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(); }
|
||||
torrent::Object& get_bencode() { return m_download.bencode(); }
|
||||
|
||||
const std::string& get_message() { return m_message; }
|
||||
torrent::Object* bencode() { return m_download.bencode(); }
|
||||
file_list_type* file_list() { return &m_fileList; }
|
||||
tracker_list_type* tracker_list() { return &m_trackerList; }
|
||||
|
||||
uint32_t chunks_failed() const { return m_chunksFailed; }
|
||||
const std::string& info_hash() const { return m_download.info_hash(); }
|
||||
const std::string& message() const { return m_message; }
|
||||
|
||||
void enable_udp_trackers(bool state);
|
||||
uint32_t chunks_failed() const { return m_chunksFailed; }
|
||||
|
||||
uint32_t priority();
|
||||
void set_priority(uint32_t p);
|
||||
void enable_udp_trackers(bool state);
|
||||
|
||||
// Helper functions for calling functions in torrent::Download
|
||||
uint32_t priority();
|
||||
void set_priority(uint32_t p);
|
||||
|
||||
// Helper functions for calling functions in download_type
|
||||
// through sigc++.
|
||||
template <typename Ret, Ret (torrent::Download::*func)()>
|
||||
void call() { (m_download.*func)(); }
|
||||
template <typename Ret, Ret (download_type::*func)()>
|
||||
void call() { (m_download.*func)(); }
|
||||
|
||||
template <typename Ret, typename Arg1, Ret (torrent::Download::*func)(Arg1)>
|
||||
void call(Arg1 a1) { (m_download.*func)(a1); }
|
||||
template <typename Ret, typename Arg1, Ret (download_type::*func)(Arg1)>
|
||||
void call(Arg1 a1) { (m_download.*func)(a1); }
|
||||
|
||||
bool operator == (const std::string& str) { return str == m_download.info_hash(); }
|
||||
|
||||
void receive_finished();
|
||||
void receive_finished();
|
||||
|
||||
static ConnType string_to_connection_type(const std::string& name);
|
||||
static const char* connection_type_to_string(ConnType t);
|
||||
static connection_type string_to_connection_type(const std::string& name);
|
||||
static const char* connection_type_to_string(connection_type t);
|
||||
|
||||
static uint32_t string_to_priority(const std::string& name);
|
||||
static const char* priority_to_string(uint32_t p);
|
||||
static uint32_t string_to_priority(const std::string& name);
|
||||
static const char* priority_to_string(uint32_t p);
|
||||
|
||||
float distributed_copies() const;
|
||||
float distributed_copies() const;
|
||||
|
||||
private:
|
||||
Download(const Download&);
|
||||
void operator () (const Download&);
|
||||
|
||||
void receive_tracker_msg(std::string msg);
|
||||
void receive_storage_error(std::string msg);
|
||||
void receive_tracker_msg(std::string msg);
|
||||
void receive_storage_error(std::string msg);
|
||||
|
||||
void receive_chunk_failed(uint32_t idx);
|
||||
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())); }
|
||||
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& path);
|
||||
void set_root_directory(const std::string& path);
|
||||
|
||||
// Store the FileList instance so we can use slots etc on it.
|
||||
torrent::Download m_download;
|
||||
torrent::FileList m_fileList;
|
||||
download_type m_download;
|
||||
file_list_type m_fileList;
|
||||
tracker_list_type m_trackerList;
|
||||
|
||||
std::string m_message;
|
||||
uint32_t m_chunksFailed;
|
||||
std::string m_message;
|
||||
uint32_t m_chunksFailed;
|
||||
|
||||
sigc::connection m_connTrackerSucceded;
|
||||
sigc::connection m_connTrackerFailed;
|
||||
sigc::connection m_connStorageError;
|
||||
variable_map_type m_variables;
|
||||
|
||||
utils::VariableMap m_variables;
|
||||
sigc::connection m_connTrackerSucceded;
|
||||
sigc::connection m_connTrackerFailed;
|
||||
sigc::connection m_connStorageError;
|
||||
};
|
||||
|
||||
inline bool
|
||||
Download::is_done() {
|
||||
return m_download.chunks_done() == m_download.chunks_total();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -70,9 +70,9 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) :
|
||||
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::VariableAny(control->variables()->get("connection_leech")));
|
||||
m_variables.insert("connection_seed", new utils::VariableAny(control->variables()->get("connection_seed")));
|
||||
m_variables.insert("directory", new utils::VariableAny(control->variables()->get("directory")));
|
||||
m_variables.insert("connection_leech", new utils::VariableAny(control->variable()->get("connection_leech")));
|
||||
m_variables.insert("connection_seed", new utils::VariableAny(control->variable()->get("connection_seed")));
|
||||
m_variables.insert("directory", new utils::VariableAny(control->variable()->get("directory")));
|
||||
m_variables.insert("tied_to_file", new utils::VariableBool(false));
|
||||
}
|
||||
|
||||
@@ -149,65 +149,65 @@ DownloadFactory::receive_success() {
|
||||
return;
|
||||
}
|
||||
|
||||
torrent::Object& root = (*itr)->get_bencode();
|
||||
torrent::Object* root = (*itr)->bencode();
|
||||
|
||||
if (!m_session) {
|
||||
// We only allow session torrents to keep their
|
||||
// 'rtorrent/libtorrent' sections.
|
||||
root.erase_key("rtorrent");
|
||||
root.erase_key("libtorrent");
|
||||
root->erase_key("rtorrent");
|
||||
root->erase_key("libtorrent");
|
||||
}
|
||||
|
||||
if (!root.has_key("rtorrent") ||
|
||||
!root.get_key("rtorrent").is_map())
|
||||
root.insert_key("rtorrent", torrent::Object(torrent::Object::TYPE_MAP));
|
||||
if (!root->has_key("rtorrent") ||
|
||||
!root->get_key("rtorrent").is_map())
|
||||
root->insert_key("rtorrent", torrent::Object(torrent::Object::TYPE_MAP));
|
||||
|
||||
torrent::Object& rtorrent = root.get_key("rtorrent");
|
||||
torrent::Object* rtorrent = &root->get_key("rtorrent");
|
||||
|
||||
if (!rtorrent.has_key("state") ||
|
||||
!rtorrent.get_key("state").is_string() ||
|
||||
(rtorrent.get_key("state").as_string() != "stopped" &&
|
||||
rtorrent.get_key("state").as_string() != "started"))
|
||||
rtorrent.insert_key("state", "stopped");
|
||||
if (!rtorrent->has_key("state") ||
|
||||
!rtorrent->get_key("state").is_string() ||
|
||||
(rtorrent->get_key("state").as_string() != "stopped" &&
|
||||
rtorrent->get_key("state").as_string() != "started"))
|
||||
rtorrent->insert_key("state", "stopped");
|
||||
|
||||
if (!rtorrent.has_key("tied_to_file") ||
|
||||
!rtorrent.get_key("tied_to_file").is_string())
|
||||
rtorrent.insert_key("tied_to_file", std::string());
|
||||
if (!rtorrent->has_key("tied_to_file") ||
|
||||
!rtorrent->get_key("tied_to_file").is_string())
|
||||
rtorrent->insert_key("tied_to_file", std::string());
|
||||
|
||||
if (rtorrent.has_key("priority") &&
|
||||
rtorrent.get_key("priority").is_value())
|
||||
(*itr)->variables()->set("priority", rtorrent.get_key("priority").as_value() % 4);
|
||||
if (rtorrent->has_key("priority") &&
|
||||
rtorrent->get_key("priority").is_value())
|
||||
(*itr)->variable()->set("priority", rtorrent->get_key("priority").as_value() % 4);
|
||||
else
|
||||
(*itr)->variables()->set("priority", (int64_t)2);
|
||||
(*itr)->variable()->set("priority", (int64_t)2);
|
||||
|
||||
// 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("min_peers", control->variables()->get("min_peers"));
|
||||
(*itr)->variables()->set("max_peers", control->variables()->get("max_peers"));
|
||||
(*itr)->variables()->set("max_uploads", control->variables()->get("max_uploads"));
|
||||
(*itr)->variable()->set("connection_leech", m_variables.get("connection_leech"));
|
||||
(*itr)->variable()->set("connection_seed", m_variables.get("connection_seed"));
|
||||
(*itr)->variable()->set("min_peers", control->variable()->get("min_peers"));
|
||||
(*itr)->variable()->set("max_peers", control->variable()->get("max_peers"));
|
||||
(*itr)->variable()->set("max_uploads", control->variable()->get("max_uploads"));
|
||||
|
||||
if (control->variables()->get_string("use_udp_trackers") == "no")
|
||||
if (control->variable()->get_string("use_udp_trackers") == "no")
|
||||
(*itr)->enable_udp_trackers(false);
|
||||
|
||||
if (rtorrent.has_key("total_uploaded") && rtorrent.get_key("total_uploaded").is_value())
|
||||
(*itr)->get_download().up_rate()->set_total(rtorrent.get_key("total_uploaded").as_value());
|
||||
if (rtorrent->has_key("total_uploaded") && rtorrent->get_key("total_uploaded").is_value())
|
||||
(*itr)->download()->up_rate()->set_total(rtorrent->get_key("total_uploaded").as_value());
|
||||
|
||||
if (m_session) {
|
||||
if (!rtorrent.has_key("directory") ||
|
||||
!rtorrent.get_key("directory").is_string())
|
||||
(*itr)->variables()->set("directory", m_variables.get("directory"));
|
||||
if (!rtorrent->has_key("directory") ||
|
||||
!rtorrent->get_key("directory").is_string())
|
||||
(*itr)->variable()->set("directory", m_variables.get("directory"));
|
||||
else
|
||||
(*itr)->variables()->set("directory", rtorrent.get_key("directory"));
|
||||
(*itr)->variable()->set("directory", rtorrent->get_key("directory"));
|
||||
|
||||
if ((*itr)->variables()->get_string("state") == "started")
|
||||
if ((*itr)->variable()->get_string("state") == "started")
|
||||
m_manager->download_list().resume(*itr);
|
||||
|
||||
} else {
|
||||
(*itr)->variables()->set("directory", m_variables.get("directory"));
|
||||
(*itr)->variable()->set("directory", m_variables.get("directory"));
|
||||
|
||||
if (m_variables.get("tied_to_file").as_value())
|
||||
(*itr)->variables()->set("tied_to_file", m_uri);
|
||||
(*itr)->variable()->set("tied_to_file", m_uri);
|
||||
|
||||
if (m_start)
|
||||
m_manager->download_list().start(*itr);
|
||||
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
void load();
|
||||
void commit();
|
||||
|
||||
utils::VariableMap* variables() { return &m_variables; }
|
||||
utils::VariableMap* variable() { return &m_variables; }
|
||||
|
||||
bool get_session() const { return m_session; }
|
||||
void set_session(bool v) { m_session = v; }
|
||||
@@ -75,8 +75,8 @@ public:
|
||||
bool get_start() const { return m_start; }
|
||||
void set_start(bool v) { m_start = v; }
|
||||
|
||||
bool print_log() const { return m_printLog; }
|
||||
void set_print_log(bool v) { m_printLog = v; }
|
||||
bool print_log() const { return m_printLog; }
|
||||
void set_print_log(bool v) { m_printLog = v; }
|
||||
|
||||
void slot_finished(Slot s) { m_slotFinished = s; }
|
||||
|
||||
|
||||
+11
-11
@@ -80,7 +80,7 @@ DownloadList::insert(std::istream* str, bool printLog) {
|
||||
|
||||
iterator itr = Base::insert(end(), new Download(d));
|
||||
|
||||
(*itr)->get_download().signal_download_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::finished), *itr));
|
||||
(*itr)->download()->signal_download_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::finished), *itr));
|
||||
std::for_each(m_slotMapInsert.begin(), m_slotMapInsert.end(), download_list_call(*itr));
|
||||
|
||||
return itr;
|
||||
@@ -99,12 +99,12 @@ DownloadList::iterator
|
||||
DownloadList::erase(iterator itr) {
|
||||
// Make safe to erase active downloads.
|
||||
|
||||
if ((*itr)->get_download().is_active())
|
||||
if ((*itr)->download()->is_active())
|
||||
throw std::logic_error("DownloadList::erase(...) called on an active download.");
|
||||
|
||||
std::for_each(m_slotMapErase.begin(), m_slotMapErase.end(), download_list_call(*itr));
|
||||
|
||||
torrent::download_remove((*itr)->get_download());
|
||||
torrent::download_remove(*(*itr)->download());
|
||||
delete *itr;
|
||||
|
||||
return Base::erase(itr);
|
||||
@@ -114,7 +114,7 @@ void
|
||||
DownloadList::open(Download* d) {
|
||||
try {
|
||||
|
||||
if (!d->get_download().is_open())
|
||||
if (!d->download()->is_open())
|
||||
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(d));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
@@ -126,10 +126,10 @@ void
|
||||
DownloadList::close(Download* d) {
|
||||
try {
|
||||
|
||||
if (d->get_download().is_active())
|
||||
if (d->download()->is_active())
|
||||
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(d));
|
||||
|
||||
if (d->get_download().is_open())
|
||||
if (d->download()->is_open())
|
||||
std::for_each(m_slotMapClose.begin(), m_slotMapClose.end(), download_list_call(d));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
@@ -139,14 +139,14 @@ DownloadList::close(Download* d) {
|
||||
|
||||
void
|
||||
DownloadList::start(Download* d) {
|
||||
d->variables()->set("state", "started");
|
||||
d->variable()->set("state", "started");
|
||||
|
||||
resume(d);
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::stop(Download* d) {
|
||||
d->variables()->set("state", "stopped");
|
||||
d->variable()->set("state", "stopped");
|
||||
|
||||
pause(d);
|
||||
}
|
||||
@@ -154,10 +154,10 @@ DownloadList::stop(Download* d) {
|
||||
void
|
||||
DownloadList::resume(Download* d) {
|
||||
try {
|
||||
if (!d->get_download().is_open())
|
||||
if (!d->download()->is_open())
|
||||
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(d));
|
||||
|
||||
if (d->get_download().is_hash_checked())
|
||||
if (d->download()->is_hash_checked())
|
||||
std::for_each(m_slotMapStart.begin(), m_slotMapStart.end(), download_list_call(d));
|
||||
else
|
||||
// TODO: This can cause infinit looping?
|
||||
@@ -172,7 +172,7 @@ void
|
||||
DownloadList::pause(Download* d) {
|
||||
try {
|
||||
|
||||
if (d->get_download().is_active())
|
||||
if (d->download()->is_active())
|
||||
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(d));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
|
||||
@@ -101,9 +101,9 @@ DownloadStore::save(Download* d) {
|
||||
return;
|
||||
|
||||
// Move this somewhere else.
|
||||
d->get_bencode().get_key("rtorrent").insert_key("total_uploaded", d->get_download().up_rate()->total());
|
||||
d->bencode()->get_key("rtorrent").insert_key("total_uploaded", d->download()->up_rate()->total());
|
||||
|
||||
f << d->get_bencode();
|
||||
f << *d->bencode();
|
||||
|
||||
if (!f.good())
|
||||
return;
|
||||
@@ -162,7 +162,7 @@ DownloadStore::is_correct_format(std::string f) {
|
||||
|
||||
std::string
|
||||
DownloadStore::create_filename(Download* d) {
|
||||
return m_path + rak::transform_hex(d->get_hash()) + ".torrent";
|
||||
return m_path + rak::transform_hex(d->info_hash()) + ".torrent";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ namespace core {
|
||||
|
||||
void
|
||||
HashQueue::insert(Download* d, Slot s) {
|
||||
if (d->get_download().is_hash_checking() ||
|
||||
if (d->download()->is_hash_checking() ||
|
||||
find(d) != end())
|
||||
return;
|
||||
|
||||
if (d->get_download().is_hash_checked()) {
|
||||
if (d->download()->is_hash_checked()) {
|
||||
s();
|
||||
return;
|
||||
}
|
||||
|
||||
iterator itr = Base::insert(end(), new HashQueueNode(d, s));
|
||||
|
||||
(*itr)->set_connection(d->get_download().signal_hash_done(sigc::bind(sigc::mem_fun(*this, &HashQueue::receive_hash_done),
|
||||
(*itr)->get_download())));
|
||||
(*itr)->set_connection(d->download()->signal_hash_done(sigc::bind(sigc::mem_fun(*this, &HashQueue::receive_hash_done),
|
||||
(*itr)->download())));
|
||||
|
||||
fill_queue();
|
||||
}
|
||||
@@ -73,7 +73,7 @@ HashQueue::remove(Download* d) {
|
||||
return;
|
||||
|
||||
// We don't do anything if we're already checking, just disconnect.
|
||||
// if ((*itr)->get_download()->get_download().is_hash_checking()) {
|
||||
// if ((*itr)->download()->download()->is_hash_checking()) {
|
||||
// // What do we do if we're already checking?
|
||||
// }
|
||||
|
||||
@@ -85,7 +85,7 @@ HashQueue::remove(Download* d) {
|
||||
|
||||
HashQueue::iterator
|
||||
HashQueue::find(Download* d) {
|
||||
return std::find_if(begin(), end(), rak::equal(d, std::mem_fun(&HashQueueNode::get_download)));
|
||||
return std::find_if(begin(), end(), rak::equal(d, std::mem_fun(&HashQueueNode::download)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -107,13 +107,13 @@ HashQueue::receive_hash_done(Download* d) {
|
||||
|
||||
void
|
||||
HashQueue::fill_queue() {
|
||||
if (empty() || front()->get_download()->get_download().is_hash_checking())
|
||||
if (empty() || front()->download()->download()->is_hash_checking())
|
||||
return;
|
||||
|
||||
if (front()->get_download()->get_download().is_hash_checked())
|
||||
if (front()->download()->download()->is_hash_checked())
|
||||
throw std::logic_error("core::HashQueue::fill_queue() encountered a checked hash");
|
||||
|
||||
front()->get_download()->get_download().hash_check();
|
||||
front()->download()->download()->hash_check();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
|
||||
void disconnect() { m_connection.disconnect(); }
|
||||
|
||||
Download* get_download() { return m_download; }
|
||||
Download* download() { return m_download; }
|
||||
HashQueue::Slot get_slot() { return m_slot; }
|
||||
|
||||
void set_connection(sigc::connection c) { m_connection = c; }
|
||||
|
||||
+13
-13
@@ -65,18 +65,18 @@ namespace core {
|
||||
|
||||
static void
|
||||
connect_signal_network_log(Download* d, torrent::Download::slot_string_type s) {
|
||||
d->get_download().signal_network_log(s);
|
||||
d->download()->signal_network_log(s);
|
||||
}
|
||||
|
||||
static void
|
||||
connect_signal_storage_log(Download* d, torrent::Download::slot_string_type s) {
|
||||
d->get_download().signal_storage_error(s);
|
||||
d->download()->signal_storage_error(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();
|
||||
const std::string tie = d->variable()->get("tied_to_file").as_string();
|
||||
|
||||
// This should be configurable, need to wait for the variable
|
||||
// thingie to be implemented.
|
||||
@@ -158,7 +158,7 @@ Manager::shutdown(bool force) {
|
||||
|
||||
void
|
||||
Manager::check_hash(Download* d) {
|
||||
bool restart = d->get_download().is_active();
|
||||
bool restart = d->download()->is_active();
|
||||
|
||||
try {
|
||||
prepare_hash_check(d);
|
||||
@@ -176,7 +176,7 @@ Manager::check_hash(Download* d) {
|
||||
|
||||
void
|
||||
Manager::receive_download_done(Download* d) {
|
||||
if (control->variables()->get("check_hash").as_string() == "yes") {
|
||||
if (control->variable()->get("check_hash").as_string() == "yes") {
|
||||
// Start the hash checking, send completed to tracker after
|
||||
// finishing.
|
||||
prepare_hash_check(d);
|
||||
@@ -191,13 +191,13 @@ Manager::receive_download_done(Download* d) {
|
||||
|
||||
void
|
||||
Manager::listen_open() {
|
||||
if (control->variables()->get_string("port_open") != "yes")
|
||||
if (control->variable()->get_string("port_open") != "yes")
|
||||
return;
|
||||
|
||||
if (m_portFirst > m_portLast)
|
||||
throw torrent::input_error("Invalid port range for listening");
|
||||
|
||||
if (control->variables()->get("port_random").as_string() == "yes") {
|
||||
if (control->variable()->get("port_random").as_string() == "yes") {
|
||||
int boundary = m_portFirst + random() % (m_portLast - m_portFirst + 1);
|
||||
|
||||
if (!torrent::connection_manager()->listen_open(boundary, m_portLast) &&
|
||||
@@ -264,11 +264,11 @@ Manager::set_local_address(const std::string& addr) {
|
||||
void
|
||||
Manager::prepare_hash_check(Download* d) {
|
||||
m_downloadList.close(d);
|
||||
d->get_download().hash_resume_clear();
|
||||
d->download()->hash_resume_clear();
|
||||
m_downloadList.open(d);
|
||||
|
||||
if (d->get_download().is_hash_checking() ||
|
||||
d->get_download().is_hash_checked())
|
||||
if (d->download()->is_hash_checking() ||
|
||||
d->download()->is_hash_checked())
|
||||
throw std::logic_error("Manager::check_hash(...) closed the torrent but is_hash_check{ing,ed}() == true");
|
||||
|
||||
if (m_hashQueue.find(d) != m_hashQueue.end())
|
||||
@@ -285,12 +285,12 @@ void
|
||||
Manager::receive_download_done_hash_checked(Download* d) {
|
||||
m_downloadList.resume(d);
|
||||
|
||||
if (control->variables()->get_string("session_on_completion") == "yes")
|
||||
if (control->variable()->get_string("session_on_completion") == "yes")
|
||||
m_downloadStore.save(d);
|
||||
|
||||
// Don't send if we did a hash check and found incompelete chunks.
|
||||
if (d->is_done())
|
||||
d->get_download().tracker_list().send_completed();
|
||||
d->download()->tracker_list().send_completed();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -298,7 +298,7 @@ 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->variable()->set("tied_to_file", tied ? "yes" : "no");
|
||||
|
||||
f->set_start(start);
|
||||
f->set_print_log(printLog);
|
||||
|
||||
Reference in New Issue
Block a user