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
+36 -18
View File
@@ -1,9 +1,11 @@
#include "config.h"
#include <stdexcept>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <istream>
#include <sstream>
#include <sigc++/bind.h>
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
@@ -77,16 +79,35 @@ Manager::stop(Download* d) {
}
void
Manager::create_file(const std::string& uri) {
DownloadList::iterator itr = m_downloadList.end();
Manager::set_dns(const std::string& dns) {
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 {
std::fstream f(uri.c_str(), std::ios::in);
itr = m_downloadList.insert(&f);
start(*itr);
m_downloadStore.save(*itr);
create_final(&f);
} catch (torrent::local_error& e) {
// What to do? Keep in list for now.
@@ -101,19 +122,16 @@ Manager::create_http(const std::string& uri) {
// Add the failed signal here.
}
void
Manager::receive_http_done(CurlGet* http) {
DownloadList::iterator itr = m_downloadList.end();
Manager::iterator
Manager::create_final(std::istream* s) {
iterator itr = m_downloadList.insert(s);
(*itr)->get_download().set_ip(m_dns);
try {
itr = m_downloadList.insert(http->get_stream());
start(*itr);
m_downloadStore.save(*itr);
start(*itr);
m_downloadStore.save(*itr);
} catch (torrent::local_error& e) {
// What to do? Keep in list for now.
}
}
return itr;
}
}
+28 -22
View File
@@ -17,38 +17,44 @@ public:
Manager() : m_portFirst(6890), m_portLast(6999) {}
DownloadList& get_download_list() { return m_downloadList; }
DownloadStore& get_download_store() { return m_downloadStore; }
HashQueue& get_hash_queue() { return m_hashQueue; }
HttpQueue& get_http_queue() { return m_httpQueue; }
DownloadList& get_download_list() { return m_downloadList; }
DownloadStore& get_download_store() { return m_downloadStore; }
HashQueue& get_hash_queue() { return m_hashQueue; }
HttpQueue& get_http_queue() { return m_httpQueue; }
Poll& get_poll() { return m_poll; }
Poll& get_poll() { return m_poll; }
void initialize();
void cleanup();
void initialize();
void cleanup();
void insert(std::string uri);
iterator erase(DownloadList::iterator itr);
void insert(std::string uri);
iterator erase(DownloadList::iterator itr);
void start(Download* d);
void stop(Download* d);
void start(Download* d);
void stop(Download* d);
void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; }
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; }
private:
void receive_http_done(CurlGet* http);
void receive_http_done(CurlGet* http);
void create_file(const std::string& uri);
void create_http(const std::string& uri);
void create_file(const std::string& uri);
void create_http(const std::string& uri);
DownloadList m_downloadList;
DownloadStore m_downloadStore;
HashQueue m_hashQueue;
HttpQueue m_httpQueue;
Poll m_poll;
iterator create_final(std::istream* s);
int m_portFirst;
int m_portLast;
DownloadList m_downloadList;
DownloadStore m_downloadStore;
HashQueue m_hashQueue;
HttpQueue m_httpQueue;
Poll m_poll;
std::string m_dns;
int m_portFirst;
int m_portLast;
};
}
+6 -3
View File
@@ -2,14 +2,17 @@
#include <torrent/torrent.h>
#include "core/manager.h"
#include "canvas.h"
#include "window_statusbar.h"
namespace display {
WindowStatusbar::WindowStatusbar() :
WindowStatusbar::WindowStatusbar(core::Manager* c) :
Window(new Canvas, false, 1),
m_counter(0) {
m_counter(0),
m_core(c) {
}
void
@@ -24,7 +27,7 @@ WindowStatusbar::redraw() {
m_canvas->erase();
m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i Select: %u",
(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::HANDSHAKES_TOTAL),
m_counter);
+7 -2
View File
@@ -3,16 +3,21 @@
#include "window.h"
namespace core {
class Manager;
}
namespace display {
class WindowStatusbar : public Window {
public:
WindowStatusbar();
WindowStatusbar(core::Manager* c);
virtual void redraw();
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) {
OptionParser optionParser;
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),
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));
@@ -211,6 +212,7 @@ 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 <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 << " -s <directory> Set the session directory" << 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_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_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);
+1 -1
View File
@@ -23,7 +23,7 @@ namespace ui {
DownloadList::DownloadList(Control* c) :
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_windowHttpQueue(new WHttp(&c->get_core().get_http_queue())),