From 758bbc9faf046678e0cd195f1859f2139318333e Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 1 Jul 2005 15:38:39 +0000 Subject: [PATCH] Fixed memory leak of PeerConnection::m_read and PeerConnection::m_write. Moved src/net/protocol_* to src/peer/. Moved over to using PeerConnectionBase and created factory class and setting for seeder/leecher. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@483 e378c898-3ddf-0310-93e7-cc216c733640 --- README | 94 ++++++++----------------------------- src/core/download.cc | 25 ++++++++++ src/core/download.h | 13 +++++ src/core/http_queue.h | 3 ++ src/core/manager.cc | 11 +++-- src/main.cc | 7 ++- src/option_handler.h | 3 ++ src/option_handler_rules.cc | 15 ++++++ src/option_handler_rules.h | 5 +- src/option_parser.h | 3 ++ 10 files changed, 97 insertions(+), 82 deletions(-) diff --git a/README b/README index 8711a3c5..01e8c8c3 100644 --- a/README +++ b/README @@ -1,81 +1,27 @@ +BUILDING + + Run "./autogen.sh" to generate the configure scripts if +nessesary. The man page "doc/rtorrent.1" must be generated with +"docbook2man rtorrent.1.xml" if it is missing. + + Note that rtorrent follows the development of libtorrent closely, and +thus the versions must be in sync. This should not be nessesary in the +future, when the library API stabilizes. + +USAGE + + See the man page or website for instructions. + LICENSE GNU GPL, see COPYING. +DEPENDENCIES -Options and flags: + libcurl >= 7.12.0 + ncurses - -b Bind the listening socket to this IP. - -i Set the IP address sent to the tracker. +CONTACT - -p Open a port in the range a to b. - - -d Sets the default path where the files in the - torrent are found/saved. By default it is "./". - - -s The session directory, all the torrents you add - will be saved there with the info hash as a file - name. When you shutdown rtorrent it will store - fast-resume data in those torrents. Restarting - rtorrent with the sesssion directory will restart - all the torrents you had when you last quit. - - -All: - - Ctrl-Q - Quit - - a/A - Increase upload/download throttle by 1 KiB - z/Z - Decrease upload/download throttle by 1 KiB - - s/S - Increase upload/download throttle by 5 KiB - x/X - Decrease upload/download throttle by 5 KiB - - d/D - Increase upload/download throttle by 50 KiB - c/C - Decrease upload/download throttle by 50 KiB - - -In main window: - - Backspace - Activate text input for inserting urls/file - paths. Arrows/C^f/C^b for navigation, enter/C^m. - - Up/Down - Select torrent - - Right - View torrent - - ^s - Start torrent - ^d - Stop/delete torrent - - ^r - Manually start a hash check of the torrent - - -In torrent view: - - Up/Down - Select peer - - Left - Back to main - - Right - View files - P - View peer - O - View trackers - - 1 - Decrease max uploads - 2 - Increase max uploads - - 3 - Decrease min peers connected - 4 - Increase min peers connected - - 5 - Decrease max peers connected - 6 - Increase max peers connected - - t - Query tracker - T - Force query tracker, ignores min reconnect time sendt by the tracker - -In file view: - - Up/Down - Select file - - Left - Back to torrent view - - SpaceBar - Change file priority + Send bug reports, suggestions and patches to or +to the mailinglist. diff --git a/src/core/download.cc b/src/core/download.cc index 4ddf7eb6..08708131 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -31,6 +31,21 @@ namespace core { +Download::Download() : + m_connectionLeech("default"), + m_connectionSeed("default") { +} + +void +Download::start() { + if (is_done()) + m_download.set_connection_type(m_connectionSeed); + else + m_download.set_connection_type(m_connectionLeech); + + m_download.start(); +} + void Download::set_download(torrent::Download d) { m_download = d; @@ -49,9 +64,19 @@ Download::set_root_directory(const std::string& d) { void Download::release_download() { + if (!m_download.is_valid()) + return; + m_connTrackerSucceded.disconnect(); m_connTrackerFailed.disconnect(); m_connStorageError.disconnect(); + + m_download = torrent::Download(); +} + +void +Download::receive_finished() { + m_download.set_connection_type(m_connectionSeed); } void diff --git a/src/core/download.h b/src/core/download.h index 65811658..9b172c81 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -31,9 +31,14 @@ namespace core { class Download { public: + Download(); + ~Download() { release_download(); } + bool is_open() { return m_download.is_open(); } inline bool is_done(); + void start(); + void set_download(torrent::Download d); void release_download(); @@ -45,6 +50,9 @@ public: void set_root_directory(const std::string& d); + void set_connection_leech(const std::string& name) { m_connectionLeech = name; } + void set_connection_seed(const std::string& name) { m_connectionSeed = name; } + // Helper functions for calling functions in torrent::Download // through sigc++. template @@ -55,6 +63,8 @@ public: bool operator == (const std::string& str) { return str == m_download.get_hash(); } + void receive_finished(); + private: void receive_tracker_msg(std::string msg); void receive_storage_error(std::string msg); @@ -63,6 +73,9 @@ private: std::string m_message; + std::string m_connectionLeech; + std::string m_connectionSeed; + sigc::connection m_connTrackerSucceded; sigc::connection m_connTrackerFailed; sigc::connection m_connStorageError; diff --git a/src/core/http_queue.h b/src/core/http_queue.h index d9768dfc..6204f5ad 100644 --- a/src/core/http_queue.h +++ b/src/core/http_queue.h @@ -50,6 +50,9 @@ public: using Base::empty; using Base::size; + HttpQueue() {} + ~HttpQueue() { clear(); } + // Note that any slots connected to the CurlGet signals must be // pushed in front of the erase slot added by HttpQueue::insert. iterator insert(const std::string& url); diff --git a/src/core/manager.cc b/src/core/manager.cc index 03ddbcda..6ec5c12a 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -69,13 +69,14 @@ Manager::initialize() { m_downloadList.slot_map_close().insert("1_download_close", sigc::mem_fun(&Download::call)); 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::call)); + 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::call)); m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::call)); m_downloadList.slot_map_stop().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save)); m_downloadList.slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(*this, &Manager::receive_download_done), false)); + m_downloadList.slot_map_finished().insert("2_receive_finished", sigc::mem_fun(&Download::receive_finished)); } void @@ -84,7 +85,7 @@ Manager::cleanup() { // any more. torrent::cleanup(); - core::CurlStack::cleanup(); + CurlStack::cleanup(); } void @@ -207,11 +208,11 @@ Manager::listen_open() { void Manager::create_http(const std::string& uri) { - core::HttpQueue::iterator itr = m_httpQueue.insert(uri); + HttpQueue::iterator itr = m_httpQueue.insert(uri); - (*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &core::Manager::create_final), + (*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &Manager::create_final), (*itr)->get_stream())); - (*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &core::Manager::receive_http_failed)); + (*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &Manager::receive_http_failed)); } void diff --git a/src/main.cc b/src/main.cc index 55da4e48..62b61bc2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -135,6 +135,9 @@ initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) { optionHandler->insert("max_open_files", new OptionHandlerInt(c, &apply_max_open_files, &validate_fd)); optionHandler->insert("throttle_interval", new OptionHandlerInt(c, &apply_throttle_interval, &validate_throttle_interval)); + optionHandler->insert("connection_leech", new OptionHandlerString(c, &apply_connection_leech, &validate_non_empty)); + optionHandler->insert("connection_seed", new OptionHandlerString(c, &apply_connection_seed, &validate_non_empty)); + optionHandler->insert("session", new OptionHandlerString(c, &apply_session_directory, &validate_directory)); optionHandler->insert("tracker_dump", new OptionHandlerString(c, &apply_tracker_dump, &validate_yes_no)); } @@ -183,11 +186,11 @@ initialize_core(ui::Control* c) { int main(int argc, char** argv) { + utils::Timer::update(); + OptionHandler optionHandler; ui::Control uiControl; - utils::Timer::update(); - srandom(utils::Timer::cache().usec()); srand48(utils::Timer::cache().usec()); diff --git a/src/option_handler.h b/src/option_handler.h index 06ecae06..595e7bf9 100644 --- a/src/option_handler.h +++ b/src/option_handler.h @@ -54,6 +54,9 @@ public: using Base::find; + OptionHandler() {} + ~OptionHandler() { clear(); } + // We take over ownership of opt. void insert(const std::string& key, OptionHandlerBase* opt); void erase(const std::string& key); diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index e0e84e8d..92d21d0d 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -60,6 +60,11 @@ validate_yes_no(const std::string& arg) { return arg == "yes" || arg == "no"; } +bool +validate_non_empty(const std::string& arg) { + return !arg.empty(); +} + bool validate_download_peers(int arg) { return arg > 0 && arg < (1 << 16); @@ -118,6 +123,16 @@ apply_download_directory(ui::Control* m, const std::string& arg) { m->get_core().get_download_list().slot_map_insert().erase("1_directory"); } +void +apply_connection_leech(ui::Control* m, const std::string& arg) { + m->get_core().get_download_list().slot_map_insert().insert("1_connection_leech", sigc::bind(sigc::mem_fun(&core::Download::set_connection_leech), arg)); +} + +void +apply_connection_seed(ui::Control* m, const std::string& arg) { + m->get_core().get_download_list().slot_map_insert().insert("1_connection_seed", sigc::bind(sigc::mem_fun(&core::Download::set_connection_seed), arg)); +} + void apply_global_download_rate(ui::Control* m, int arg) { torrent::set_read_throttle(arg * 1024); diff --git a/src/option_handler_rules.h b/src/option_handler_rules.h index 67f16365..851b1b18 100644 --- a/src/option_handler_rules.h +++ b/src/option_handler_rules.h @@ -38,6 +38,7 @@ bool validate_ip(const std::string& arg); bool validate_directory(const std::string& arg); bool validate_port_range(const std::string& arg); bool validate_yes_no(const std::string& arg); +bool validate_non_empty(const std::string& arg); bool validate_download_peers(int arg); bool validate_rate(int arg); @@ -51,9 +52,11 @@ bool validate_throttle_interval(int arg); void apply_download_min_peers(ui::Control* m, int arg); void apply_download_max_peers(ui::Control* m, int arg); void apply_download_max_uploads(ui::Control* m, int arg); - void apply_download_directory(ui::Control* m, const std::string& arg); +void apply_connection_leech(ui::Control* m, const std::string& arg); +void apply_connection_seed(ui::Control* m, const std::string& arg); + void apply_global_download_rate(ui::Control* m, int arg); void apply_global_upload_rate(ui::Control* m, int arg); diff --git a/src/option_parser.h b/src/option_parser.h index 8d7b5e72..987a84e5 100644 --- a/src/option_parser.h +++ b/src/option_parser.h @@ -36,6 +36,9 @@ public: typedef sigc::slot2 SlotStringPair; typedef sigc::slot2 SlotIntPair; + OptionParser() {} + ~OptionParser() { m_container.clear(); } + void insert_flag(char c, Slot s); void insert_option(char c, SlotString s); void insert_option_list(char c, SlotStringPair s);