mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 15:19:20 +00:00
* Added slot map's for insert/erase, open/close, start/stop and
finished downloads in DownloadList, moved stuff from core::Manager to the slot maps. * Added check hash key ^r, though triggering check hash on finished signals currently borks. * Made tracker dump into an option. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@470 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+69
-61
@@ -27,9 +27,8 @@
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <sigc++/bind.h>
|
||||
#include <sigc++/hide.h>
|
||||
#include <torrent/bencode.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
@@ -40,6 +39,11 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
static void
|
||||
connect_signal_network_log(Download* d, torrent::Download::SlotString s) {
|
||||
d->get_download().signal_network_log(s);
|
||||
}
|
||||
|
||||
void
|
||||
Manager::initialize() {
|
||||
torrent::Http::set_factory(m_poll.get_http_factory());
|
||||
@@ -47,12 +51,32 @@ Manager::initialize() {
|
||||
|
||||
CurlStack::init();
|
||||
|
||||
//torrent::initialize();
|
||||
|
||||
if (!torrent::listen_open(m_portFirst, m_portLast))
|
||||
throw std::runtime_error("Could not open port for listening.");
|
||||
|
||||
// Register log signals.
|
||||
// Register slots to be called when a download is inserted/erased,
|
||||
// opened or closed.
|
||||
m_downloadList.slot_map_insert().insert("1_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front)));
|
||||
m_downloadList.slot_map_insert().insert("2_manager_start", sigc::mem_fun(*this, &Manager::start));
|
||||
m_downloadList.slot_map_insert().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
|
||||
|
||||
m_downloadList.slot_map_erase().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
|
||||
m_downloadList.slot_map_erase().insert("1_store_remove", sigc::mem_fun(m_downloadStore, &DownloadStore::remove));
|
||||
|
||||
m_downloadList.slot_map_open().insert("1_download_open", sigc::mem_fun(&Download::open));
|
||||
|
||||
// Currently does not call stop, might want to add a function that
|
||||
// checks if we're running, and if so stop?
|
||||
m_downloadList.slot_map_close().insert("1_download_close", sigc::mem_fun(&Download::close));
|
||||
m_downloadList.slot_map_close().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
|
||||
|
||||
m_downloadList.slot_map_start().insert("1_download_start", sigc::mem_fun(&Download::start));
|
||||
|
||||
m_downloadList.slot_map_stop().insert("1_download_stop", sigc::mem_fun(&Download::stop));
|
||||
m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::hash_resume_save));
|
||||
m_downloadList.slot_map_stop().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
|
||||
|
||||
//m_downloadList.slot_map_finished().insert("1_check_hash", sigc::mem_fun(*this, &Manager::check_hash));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -66,10 +90,12 @@ Manager::cleanup() {
|
||||
|
||||
void
|
||||
Manager::insert(std::string uri) {
|
||||
if (std::strncmp(uri.c_str(), "http://", 7))
|
||||
create_file(uri);
|
||||
else
|
||||
if (std::strncmp(uri.c_str(), "http://", 7) == 0) {
|
||||
create_http(uri);
|
||||
} else {
|
||||
std::fstream f(uri.c_str(), std::ios::in);
|
||||
create_final(&f);
|
||||
}
|
||||
}
|
||||
|
||||
Manager::iterator
|
||||
@@ -80,9 +106,6 @@ Manager::erase(DownloadList::iterator itr) {
|
||||
if (!(*itr)->get_download().is_open())
|
||||
throw std::logic_error("core::Manager::erase(...) called on an closed download");
|
||||
|
||||
m_hashQueue.remove(*itr);
|
||||
m_downloadStore.remove(*itr);
|
||||
|
||||
return m_downloadList.erase(itr);
|
||||
}
|
||||
|
||||
@@ -93,13 +116,13 @@ Manager::start(Download* d) {
|
||||
return;
|
||||
|
||||
if (!d->get_download().is_open())
|
||||
d->open();
|
||||
m_downloadList.open(d);
|
||||
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->start();
|
||||
m_downloadList.start(d);
|
||||
else
|
||||
// This can cause infinit loops.
|
||||
m_hashQueue.insert(d, sigc::mem_fun(d, &Download::start));
|
||||
m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
m_logImportant.push_front(e.what());
|
||||
@@ -110,13 +133,7 @@ Manager::start(Download* d) {
|
||||
void
|
||||
Manager::stop(Download* d) {
|
||||
try {
|
||||
m_hashQueue.remove(d);
|
||||
d->stop();
|
||||
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->get_download().hash_save();
|
||||
|
||||
m_downloadStore.save(d);
|
||||
m_downloadList.stop(d);
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
m_logImportant.push_front(e.what());
|
||||
@@ -125,17 +142,34 @@ Manager::stop(Download* d) {
|
||||
}
|
||||
|
||||
void
|
||||
Manager::receive_http_failed(std::string msg) {
|
||||
m_logImportant.push_front("Http download error: \"" + msg + "\"");
|
||||
m_logComplete.push_front("Http download error: \"" + msg + "\"");
|
||||
}
|
||||
Manager::check_hash(Download* d) {
|
||||
bool restart = d->get_download().is_active();
|
||||
|
||||
void
|
||||
Manager::create_file(const std::string& uri) {
|
||||
std::fstream f(uri.c_str(), std::ios::in);
|
||||
|
||||
create_final(&f);
|
||||
}
|
||||
try {
|
||||
if (d->get_download().is_active())
|
||||
m_downloadList.stop(d);
|
||||
|
||||
m_downloadList.close(d);
|
||||
d->get_download().hash_resume_clear();
|
||||
m_downloadList.open(d);
|
||||
|
||||
if (d->get_download().is_hash_checking() ||
|
||||
d->get_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())
|
||||
throw std::logic_error("Manager::check_hash(...) closed the torrent but it was found in m_hashQueue");
|
||||
|
||||
if (restart)
|
||||
m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d));
|
||||
else
|
||||
m_hashQueue.insert(d, sigc::slot0<void>());
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
m_logImportant.push_front(e.what());
|
||||
m_logComplete.push_front(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::create_http(const std::string& uri) {
|
||||
@@ -149,12 +183,7 @@ Manager::create_http(const std::string& uri) {
|
||||
void
|
||||
Manager::create_final(std::istream* s) {
|
||||
try {
|
||||
iterator itr = m_downloadList.insert(s);
|
||||
|
||||
setup_download(*itr);
|
||||
start(*itr);
|
||||
|
||||
m_downloadStore.save(*itr);
|
||||
m_downloadList.insert(s);
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
@@ -164,30 +193,9 @@ Manager::create_final(std::istream* s) {
|
||||
}
|
||||
|
||||
void
|
||||
Manager::setup_download(Download* d) {
|
||||
m_defaultSettings.for_each(d);
|
||||
|
||||
if (m_debugTracker >= 0)
|
||||
d->get_download().signal_tracker_dump(sigc::mem_fun(*this, &Manager::receive_debug_tracker));
|
||||
|
||||
// If we want to monitor network stuff.
|
||||
d->get_download().signal_network_log(sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
}
|
||||
|
||||
void
|
||||
Manager::receive_debug_tracker(std::istream* s) {
|
||||
std::stringstream filename;
|
||||
filename << "./tracker_dump." << m_debugTracker++;
|
||||
|
||||
std::fstream out(filename.str().c_str(), std::ios::out | std::ios::trunc);
|
||||
|
||||
if (!out.is_open())
|
||||
return;
|
||||
|
||||
s->seekg(0);
|
||||
|
||||
std::copy(std::istream_iterator<char>(*s), std::istream_iterator<char>(),
|
||||
std::ostream_iterator<char>(out));
|
||||
Manager::receive_http_failed(std::string msg) {
|
||||
m_logImportant.push_front("Http download error: \"" + msg + "\"");
|
||||
m_logComplete.push_front("Http download error: \"" + msg + "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user