From 8bf6a42048867a1b0dc52aa72a35dc15db17a014 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 9 Apr 2005 18:19:14 +0000 Subject: [PATCH] Added "-b" for binding the listening ip addresse. Throw an error if no listening port is opened. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@386 e378c898-3ddf-0310-93e7-cc216c733640 --- README | 2 +- TODO | 9 ++++++++- src/core/download.cc | 2 ++ src/core/download.h | 1 + src/core/manager.cc | 4 +++- src/core/manager.h | 8 +++++--- src/display/window_statusbar.cc | 17 ++++++++++++----- src/main.cc | 6 +++++- 8 files changed, 37 insertions(+), 12 deletions(-) diff --git a/README b/README index c0080edd..3e1c9056 100644 --- a/README +++ b/README @@ -5,10 +5,10 @@ LICENSE Options and flags: + -b Bind the listening socket to this IP. -i Set the IP address sent to the tracker. -p Open a port in the range a to b. - -s Use as the session directory. The torrents will be saved with the info-hash in hex as the filename. diff --git a/TODO b/TODO index 537ababd..76a849a1 100644 --- a/TODO +++ b/TODO @@ -26,4 +26,11 @@ Make accumulate return the value, no refs please... Make sure it gracefully handles torrents that fail to open files. -Make throttle show off on 0 and up/down. +Bug: Add the same torrent while it is hash checking. + + +RELEASE: + +Enable change of default download path. + +Make sure we show better messages for signal_storage_error. diff --git a/src/core/download.cc b/src/core/download.cc index 5c8f2abe..9b3fb8df 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -36,12 +36,14 @@ Download::set_download(torrent::Download d) { 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_tracker_msg)); } void Download::release_download() { m_connTrackerSucceded.disconnect(); m_connTrackerFailed.disconnect(); + m_connStorageError.disconnect(); } void diff --git a/src/core/download.h b/src/core/download.h index 6bcac53e..4c861ff1 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -58,6 +58,7 @@ private: sigc::connection m_connTrackerSucceded; sigc::connection m_connTrackerFailed; + sigc::connection m_connStorageError; }; } diff --git a/src/core/manager.cc b/src/core/manager.cc index 97197241..4c595cc9 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -48,7 +48,9 @@ Manager::initialize() { CurlStack::init(); torrent::initialize(); - torrent::listen_open(m_portFirst, m_portLast); + + if (!torrent::listen_open(m_portFirst, m_portLast, m_listenIp)) + throw std::runtime_error("Could not open port for listening."); // Register log signals. } diff --git a/src/core/manager.h b/src/core/manager.h index 4793e1af..6444ae20 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -62,12 +62,13 @@ public: void start(Download* d); void stop(Download* d); - const std::string& get_dns() { return m_dns; } + const std::string& get_dns() { return m_dns; } void set_dns(const std::string& dns); - void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; } + void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; } + void set_listen_ip(const std::string& ip) { m_listenIp = ip; } - void debug_tracker() { m_debugTracker = 0; } + void debug_tracker() { m_debugTracker = 0; } private: void receive_http_done(CurlGet* http); @@ -92,6 +93,7 @@ private: std::string m_dns; int m_portFirst; int m_portLast; + std::string m_listenIp; int m_debugTracker; }; diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 51721bb5..5dd4e8e4 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -42,11 +42,18 @@ WindowStatusbar::redraw() { m_nextDraw = utils::Timer::cache().round_seconds() + 1000000; m_canvas->erase(); - m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i", - (int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024, - m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), - (int)torrent::get(torrent::LISTEN_PORT), - (int)torrent::get(torrent::HANDSHAKES_TOTAL)); + + if (torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) == 0) + m_canvas->print(0, 0, "Throttle: off Listen: %s:%i Handshakes: %i", + m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), + (int)torrent::get(torrent::LISTEN_PORT), + (int)torrent::get(torrent::HANDSHAKES_TOTAL)); + else + m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i", + (int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024, + m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), + (int)torrent::get(torrent::LISTEN_PORT), + (int)torrent::get(torrent::HANDSHAKES_TOTAL)); } } diff --git a/src/main.cc b/src/main.cc index 1f6841d9..14a0728c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -92,7 +92,10 @@ int parse_options(ui::Control* c, int argc, char** argv) { OptionParser optionParser; optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); + + optionParser.insert_option('b', sigc::mem_fun(c->get_core(), &core::Manager::set_listen_ip)); optionParser.insert_option('i', sigc::mem_fun(c->get_core(), &core::Manager::set_dns)); + optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair), sigc::mem_fun(c->get_core(), &core::Manager::set_port_range))); optionParser.insert_option('s', sigc::mem_fun(c->get_core().get_download_store(), &core::DownloadStore::activate)); @@ -224,7 +227,8 @@ print_help() { std::cout << std::endl; std::cout << "Usage: rtorrent [OPTIONS]... [FILE]... [URL]..." << std::endl; std::cout << " -h Display this very helpful text" << std::endl; - std::cout << " -i Set the IP address that is sent to the tracker" << std::endl; + std::cout << " -b Bind the listening socket to this IP" << std::endl; + std::cout << " -i Change the IP that is sent to the tracker" << std::endl; std::cout << " -p - Set port range for incoming connections" << std::endl; std::cout << " -s Set the session directory" << std::endl; std::cout << std::endl;