* Added "send_buffer_size" and "receive_buffer_size" options that set

the socket SND/RCBBUF sizes.

* Added slot for connection filtering.

* Added closing torrents with ^K and did some cleanup of the torrent
state code.

* Moved various socket setup to HandshakeManager.

* Added a baseline for the uploaded amount that resets every time the
torrent restarts, thereby sending only the amount uploaded since the
last restart.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@652 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-03-18 00:55:50 +00:00
parent 1c55348d45
commit 86a3f868df
13 changed files with 134 additions and 119 deletions
+6
View File
@@ -106,9 +106,15 @@ Download::start() {
// Update the priority to ensure it has the correct
// seeding/unfinished modifiers.
set_priority(priority());
m_download.start();
}
void
Download::stop() {
m_download.stop();
}
void
Download::enable_udp_trackers(bool state) {
for (int i = 0, last = m_download.size_trackers(); i < last; ++i)
+3
View File
@@ -56,6 +56,9 @@ public:
inline bool is_done();
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); }
+4 -7
View File
@@ -140,7 +140,7 @@ DownloadFactory::receive_success() {
if (m_stream == NULL)
throw torrent::client_error("DownloadFactory::receive_success() called on an object with m_stream == NULL");
Manager::DListItr itr = m_manager->insert(m_stream, m_printLog);
DownloadList::iterator itr = m_manager->download_list().insert(m_stream, m_printLog);
if (itr == m_manager->download_list().end()) {
// core::Manager should already have added the error message to
@@ -190,10 +190,7 @@ DownloadFactory::receive_success() {
if (control->variables()->get_string("use_udp_trackers") == "no")
(*itr)->enable_udp_trackers(false);
if (control->variables()->get_string("upload_total_clear") == "yes")
rtorrent.erase_key("total_uploaded");
else if (rtorrent.has_key("total_uploaded") && rtorrent.get_key("total_uploaded").is_value())
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 (m_session) {
@@ -204,7 +201,7 @@ DownloadFactory::receive_success() {
(*itr)->variables()->set("directory", rtorrent.get_key("directory"));
if ((*itr)->variables()->get_string("state") == "started")
m_manager->start(*itr, m_printLog);
m_manager->download_list().resume(*itr);
} else {
(*itr)->variables()->set("directory", m_variables.get("directory"));
@@ -213,7 +210,7 @@ DownloadFactory::receive_success() {
(*itr)->variables()->set("tied_to_file", m_uri);
if (m_start)
m_manager->start(*itr, m_printLog);
m_manager->download_list().start(*itr);
m_manager->download_store().save(*itr);
}
+74 -21
View File
@@ -38,10 +38,14 @@
#include <algorithm>
#include <sigc++/bind.h>
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
#include "rak/functional.h"
#include "globals.h"
#include "manager.h"
#include "download.h"
#include "download_list.h"
@@ -58,19 +62,33 @@ struct download_list_call {
};
DownloadList::iterator
DownloadList::insert(std::istream* str) {
torrent::Download d = torrent::download_add(str);
DownloadList::insert(std::istream* str, bool printLog) {
try {
iterator itr = Base::insert(end(), new Download(d));
(*itr)->get_download().signal_download_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::finished), *itr));
torrent::Download d = torrent::download_add(str);
std::for_each(m_slotMapInsert.begin(), m_slotMapInsert.end(), download_list_call(*itr));
iterator itr = Base::insert(end(), new Download(d));
return itr;
(*itr)->get_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;
} catch (torrent::local_error& e) {
if (printLog)
control->core()->push_log(e.what());
return end();
}
}
DownloadList::iterator
DownloadList::erase(iterator itr) {
// Make safe to erase active downloads.
if ((*itr)->get_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());
@@ -81,37 +99,72 @@ DownloadList::erase(iterator itr) {
void
DownloadList::open(Download* d) {
if (d->get_download().is_open())
return;
try {
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(d));
if (!d->get_download().is_open())
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(d));
} catch (torrent::local_error& e) {
control->core()->push_log(e.what());
}
}
void
DownloadList::close(Download* d) {
if (!d->get_download().is_open())
return;
try {
stop(d);
std::for_each(m_slotMapClose.begin(), m_slotMapClose.end(), download_list_call(d));
if (d->get_download().is_active())
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(d));
if (d->get_download().is_open())
std::for_each(m_slotMapClose.begin(), m_slotMapClose.end(), download_list_call(d));
} catch (torrent::local_error& e) {
control->core()->push_log(e.what());
}
}
void
DownloadList::start(Download* d) {
if (d->get_download().is_active() ||
!d->get_download().is_hash_checked())
return;
d->variables()->set("state", "started");
open(d);
std::for_each(m_slotMapStart.begin(), m_slotMapStart.end(), download_list_call(d));
resume(d);
}
void
DownloadList::stop(Download* d) {
if (!d->get_download().is_active())
return;
d->variables()->set("state", "stopped");
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(d));
pause(d);
}
void
DownloadList::resume(Download* d) {
try {
if (!d->get_download().is_open())
std::for_each(m_slotMapOpen.begin(), m_slotMapOpen.end(), download_list_call(d));
if (d->get_download().is_hash_checked())
std::for_each(m_slotMapStart.begin(), m_slotMapStart.end(), download_list_call(d));
else
// TODO: This can cause infinit looping?
control->core()->hash_queue().insert(d, sigc::bind(sigc::mem_fun(*this, &DownloadList::resume), d));
} catch (torrent::local_error& e) {
control->core()->push_log(e.what());
}
}
void
DownloadList::pause(Download* d) {
try {
if (d->get_download().is_active())
std::for_each(m_slotMapStop.begin(), m_slotMapStop.end(), download_list_call(d));
} catch (torrent::local_error& e) {
control->core()->push_log(e.what());
}
}
void
+5 -1
View File
@@ -73,7 +73,7 @@ public:
~DownloadList() { clear(); }
iterator insert(std::istream* str);
iterator insert(std::istream* str, bool printLog);
iterator erase(iterator itr);
void open(Download* d);
@@ -82,6 +82,10 @@ public:
void start(Download* d);
void stop(Download* d);
// These do not change the rtorrent:state.
void resume(Download* d);
void pause(Download* d);
SlotMap& slot_map_insert() { return m_slotMapInsert; }
SlotMap& slot_map_erase() { return m_slotMapErase; }
SlotMap& slot_map_open() { return m_slotMapOpen; }
+5 -72
View File
@@ -130,7 +130,7 @@ Manager::initialize_second() {
m_downloadList.slot_map_start()["1_download_start"] = sigc::mem_fun(&Download::start);
m_downloadList.slot_map_stop()["1_download_stop"] = sigc::mem_fun(&Download::call<void, &torrent::Download::stop>);
m_downloadList.slot_map_stop()["1_download_stop"] = sigc::mem_fun(&Download::stop);
m_downloadList.slot_map_stop()["2_hash_resume_save"] = sigc::mem_fun(&Download::call<void, &torrent::Download::hash_resume_save>);
m_downloadList.slot_map_stop()["3_store_save"] = sigc::mem_fun(m_downloadStore, &DownloadStore::save);
@@ -152,75 +152,9 @@ Manager::cleanup() {
void
Manager::shutdown(bool force) {
if (!force)
std::for_each(m_downloadList.begin(), m_downloadList.end(),
std::bind1st(std::mem_fun(&DownloadList::stop), &m_downloadList));
std::for_each(m_downloadList.begin(), m_downloadList.end(), std::bind1st(std::mem_fun(&DownloadList::pause), &m_downloadList));
else
std::for_each(m_downloadList.begin(), m_downloadList.end(),
std::bind1st(std::mem_fun(&DownloadList::close), &m_downloadList));
}
Manager::DListItr
Manager::insert(std::istream* s, bool printLog) {
try {
return m_downloadList.insert(s);
} catch (torrent::local_error& e) {
if (printLog) {
m_logImportant.push_front(e.what());
m_logComplete.push_front(e.what());
}
return m_downloadList.end();
}
}
Manager::DListItr
Manager::erase(DListItr itr) {
if ((*itr)->get_download().is_active())
throw std::logic_error("core::Manager::erase(...) called on an active download");
// if (!(*itr)->get_download().is_open())
// throw std::logic_error("core::Manager::erase(...) called on an closed download");
return m_downloadList.erase(itr);
}
void
Manager::start(Download* d, bool printLog) {
try {
d->variables()->set("state", "started");
if (d->get_download().is_active())
return;
if (!d->get_download().is_open())
m_downloadList.open(d);
if (d->get_download().is_hash_checked())
m_downloadList.start(d);
else
// This can cause infinit loops?
m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d));
} catch (torrent::local_error& e) {
if (printLog) {
m_logImportant.push_front(e.what());
m_logComplete.push_front(e.what());
}
}
}
void
Manager::stop(Download* d) {
try {
d->variables()->set("state", "stopped");
m_downloadList.stop(d);
} catch (torrent::local_error& e) {
m_logImportant.push_front(e.what());
m_logComplete.push_front(e.what());
}
std::for_each(m_downloadList.begin(), m_downloadList.end(), std::bind1st(std::mem_fun(&DownloadList::close), &m_downloadList));
}
void
@@ -231,7 +165,7 @@ Manager::check_hash(Download* d) {
prepare_hash_check(d);
if (restart)
m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d));
m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::resume), d));
else
m_hashQueue.insert(d, sigc::slot0<void>());
@@ -350,8 +284,7 @@ Manager::receive_http_failed(std::string msg) {
void
Manager::receive_download_done_hash_checked(Download* d) {
if (!d->get_download().is_active())
m_downloadList.start(d);
m_downloadList.resume(d);
if (control->variables()->get_string("session_on_completion") == "yes")
m_downloadStore.save(d);
-6
View File
@@ -83,12 +83,6 @@ public:
void shutdown(bool force);
DListItr insert(std::istream* s, bool printLog = true);
DListItr erase(DListItr itr);
void start(Download* d, bool printLog = true);
void stop(Download* d);
void check_hash(Download* d);
void push_log(const std::string& msg) { m_logImportant.push_front(msg); m_logComplete.push_front(msg); }