Added the -i switch.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@306 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-25 16:23:45 +00:00
parent 5ef6be4912
commit f66424f642
7 changed files with 81 additions and 47 deletions
+32 -14
View File
@@ -1,9 +1,11 @@
#include "config.h" #include "config.h"
#include <stdexcept> #include <stdexcept>
#include <cstdio>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <istream> #include <istream>
#include <sstream>
#include <sigc++/bind.h> #include <sigc++/bind.h>
#include <torrent/exceptions.h> #include <torrent/exceptions.h>
#include <torrent/torrent.h> #include <torrent/torrent.h>
@@ -77,16 +79,35 @@ Manager::stop(Download* d) {
} }
void void
Manager::create_file(const std::string& uri) { Manager::set_dns(const std::string& dns) {
DownloadList::iterator itr = m_downloadList.end(); unsigned int a, b, c, d;
if (std::sscanf(dns.c_str(), "%i.%i.%i.%i", &a, &b, &c, &d) != 4 ||
(a >= 256 || b >= 256 || c >= 256 || d >= 256))
throw std::runtime_error("Tried to set invalid ip address.");
std::stringstream str;
str << a << '.' << b << '.' << c << '.' << d;
m_dns = str.str();
}
void
Manager::receive_http_done(CurlGet* http) {
try {
create_final(http->get_stream());
} catch (torrent::local_error& e) {
// What to do? Keep in list for now.
}
}
void
Manager::create_file(const std::string& uri) {
try { try {
std::fstream f(uri.c_str(), std::ios::in); std::fstream f(uri.c_str(), std::ios::in);
itr = m_downloadList.insert(&f); create_final(&f);
start(*itr);
m_downloadStore.save(*itr);
} catch (torrent::local_error& e) { } catch (torrent::local_error& e) {
// What to do? Keep in list for now. // What to do? Keep in list for now.
@@ -101,19 +122,16 @@ Manager::create_http(const std::string& uri) {
// Add the failed signal here. // Add the failed signal here.
} }
void Manager::iterator
Manager::receive_http_done(CurlGet* http) { Manager::create_final(std::istream* s) {
DownloadList::iterator itr = m_downloadList.end(); iterator itr = m_downloadList.insert(s);
try { (*itr)->get_download().set_ip(m_dns);
itr = m_downloadList.insert(http->get_stream());
start(*itr); start(*itr);
m_downloadStore.save(*itr); m_downloadStore.save(*itr);
} catch (torrent::local_error& e) { return itr;
// What to do? Keep in list for now.
}
} }
} }
+6
View File
@@ -33,6 +33,9 @@ public:
void start(Download* d); void start(Download* d);
void stop(Download* d); void stop(Download* d);
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; }
private: private:
@@ -41,12 +44,15 @@ private:
void create_file(const std::string& uri); void create_file(const std::string& uri);
void create_http(const std::string& uri); void create_http(const std::string& uri);
iterator create_final(std::istream* s);
DownloadList m_downloadList; DownloadList m_downloadList;
DownloadStore m_downloadStore; DownloadStore m_downloadStore;
HashQueue m_hashQueue; HashQueue m_hashQueue;
HttpQueue m_httpQueue; HttpQueue m_httpQueue;
Poll m_poll; Poll m_poll;
std::string m_dns;
int m_portFirst; int m_portFirst;
int m_portLast; int m_portLast;
}; };
+6 -3
View File
@@ -2,14 +2,17 @@
#include <torrent/torrent.h> #include <torrent/torrent.h>
#include "core/manager.h"
#include "canvas.h" #include "canvas.h"
#include "window_statusbar.h" #include "window_statusbar.h"
namespace display { namespace display {
WindowStatusbar::WindowStatusbar() : WindowStatusbar::WindowStatusbar(core::Manager* c) :
Window(new Canvas, false, 1), Window(new Canvas, false, 1),
m_counter(0) { m_counter(0),
m_core(c) {
} }
void void
@@ -24,7 +27,7 @@ WindowStatusbar::redraw() {
m_canvas->erase(); m_canvas->erase();
m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i Select: %u", m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i Select: %u",
(int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024, (int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024,
"", m_core->get_dns().empty() ? "<default>" : m_core->get_dns().c_str(),
(int)torrent::get(torrent::LISTEN_PORT), (int)torrent::get(torrent::LISTEN_PORT),
(int)torrent::get(torrent::HANDSHAKES_TOTAL), (int)torrent::get(torrent::HANDSHAKES_TOTAL),
m_counter); m_counter);
+6 -1
View File
@@ -3,16 +3,21 @@
#include "window.h" #include "window.h"
namespace core {
class Manager;
}
namespace display { namespace display {
class WindowStatusbar : public Window { class WindowStatusbar : public Window {
public: public:
WindowStatusbar(); WindowStatusbar(core::Manager* c);
virtual void redraw(); virtual void redraw();
private: private:
int m_counter; int m_counter;
core::Manager* m_core;
}; };
} }
+2
View File
@@ -89,6 +89,7 @@ int
parse_options(ui::Control* c, int argc, char** argv) { parse_options(ui::Control* c, int argc, char** argv) {
OptionParser optionParser; OptionParser optionParser;
optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); optionParser.insert_flag('h', sigc::ptr_fun(&print_help));
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), optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair),
sigc::mem_fun(c->get_core(), &core::Manager::set_port_range))); 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)); optionParser.insert_option('s', sigc::mem_fun(c->get_core().get_download_store(), &core::DownloadStore::activate));
@@ -211,6 +212,7 @@ print_help() {
std::cout << std::endl; std::cout << std::endl;
std::cout << "Usage: rtorrent [OPTIONS]... [FILE]... [URL]..." << std::endl; std::cout << "Usage: rtorrent [OPTIONS]... [FILE]... [URL]..." << std::endl;
std::cout << " -h Display this very helpful text" << std::endl; std::cout << " -h Display this very helpful text" << std::endl;
std::cout << " -i <a.b.c.d> Set the IP address that is sent to the tracker" << std::endl;
std::cout << " -p <int>-<int> Set port range for incoming connections" << std::endl; std::cout << " -p <int>-<int> Set port range for incoming connections" << std::endl;
std::cout << " -s <directory> Set the session directory" << std::endl; std::cout << " -s <directory> Set the session directory" << std::endl;
std::cout << std::endl; std::cout << std::endl;
+1 -1
View File
@@ -55,7 +55,7 @@ Download::activate() {
m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL); m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL);
m_title = m_control->get_display().insert(m_control->get_display().begin(), new WTitle(m_download->get_download().get_name())); m_title = m_control->get_display().insert(m_control->get_display().begin(), new WTitle(m_download->get_download().get_name()));
m_downloadStatus = m_control->get_display().insert(m_control->get_display().end(), new WDownloadStatus(m_download)); m_downloadStatus = m_control->get_display().insert(m_control->get_display().end(), new WDownloadStatus(m_download));
m_mainStatus = m_control->get_display().insert(m_control->get_display().end(), new WMainStatus); m_mainStatus = m_control->get_display().insert(m_control->get_display().end(), new WMainStatus(&m_control->get_core()));
m_control->get_input().push_front(m_bindings); m_control->get_input().push_front(m_bindings);
+1 -1
View File
@@ -23,7 +23,7 @@ namespace ui {
DownloadList::DownloadList(Control* c) : DownloadList::DownloadList(Control* c) :
m_title(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))), m_title(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))),
m_status(new WStatus), m_status(new WStatus(&c->get_core())),
m_textInput(new WInput(new input::TextInput)), m_textInput(new WInput(new input::TextInput)),
m_windowHttpQueue(new WHttp(&c->get_core().get_http_queue())), m_windowHttpQueue(new WHttp(&c->get_core().get_http_queue())),