* Cleaned up torrent::ProtocolBuffer.

* Added enums to torrent::Tracker to allow the client to check
whetever the tracker is an UDP or HTTP tracker.

* Added "enable_udp_trackers" setting for disabling the use of UDP
trackers, enabled by default.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@498 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-07-13 18:51:19 +00:00
parent d02ded1d4c
commit 7a9010445b
10 changed files with 82 additions and 56 deletions
+5 -1
View File
@@ -43,6 +43,9 @@
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no
# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes
#
# Do not modify the following parameters unless you know what you're doing.
#
@@ -67,7 +70,8 @@
# Number of sockets to simultaneously keep open.
#max_open_sockets = <no default>
# Dump data received from trackers to the files "./tracker_dump.<time>".
# Dump data received from trackers to the files
# "./tracker_dump.<time>".
#tracker_dump = no
# Change the interval between each throttle tick, in milliseconds. In
+7
View File
@@ -76,6 +76,13 @@ Download::set_root_directory(const std::string& d) {
(m_download.get_entry_size() > 1 ? m_download.get_name() : ""));
}
void
Download::enable_udp_trackers(bool state) {
for (int i = 0, last = m_download.get_tracker_size(); i < last; ++i)
if (m_download.get_tracker(i).get_type() == torrent::Tracker::TRACKER_UDP)
m_download.get_tracker(i).enable(state);
}
void
Download::release_download() {
if (!m_download.is_valid())
+2
View File
@@ -68,6 +68,8 @@ public:
void set_connection_leech(const std::string& name) { m_connectionLeech = name; }
void set_connection_seed(const std::string& name) { m_connectionSeed = name; }
void enable_udp_trackers(bool state);
// Helper functions for calling functions in torrent::Download
// through sigc++.
template <typename Ret, Ret (torrent::Download::*func)()>
+2 -2
View File
@@ -50,8 +50,8 @@ public:
typedef sigc::slot1<void, Download*> SlotDownload;
typedef std::map<std::string, SlotDownload> Base;
void insert(const std::string& key, SlotDownload s) { Base::operator[](key) = s; }
void erase(const std::string& key) {}
void insert(const std::string& key, SlotDownload s) { Base::operator[](key) = s; }
void erase(const std::string& key) { Base::erase(key); }
void for_each(Download* d);
};
+17 -18
View File
@@ -72,30 +72,29 @@ Manager::initialize() {
// Register slots to be called when a download is inserted/erased,
// opened or closed.
m_downloadList.slot_map_insert().insert("0_initialize_bencode", sigc::mem_fun(*this, &Manager::initialize_bencode));
m_downloadList.slot_map_insert().insert("1_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front)));
m_downloadList.slot_map_insert().insert("1_connect_tracker_log", sigc::bind(sigc::ptr_fun(&connect_signal_tracker_log), sigc::mem_fun(m_logComplete, &Log::push_front)));
//m_downloadList.slot_map_insert().insert("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
m_downloadList.slot_map_insert()["0_initialize_bencode"] = sigc::mem_fun(*this, &Manager::initialize_bencode);
m_downloadList.slot_map_insert()["1_connect_network_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front));
m_downloadList.slot_map_insert()["1_connect_tracker_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_tracker_log), sigc::mem_fun(m_logComplete, &Log::push_front));
//m_downloadList.slot_map_insert()["1_enable_udp_trackers"] = sigc::bind(sigc::mem_fun(&core::Download::enable_udp_trackers), true);
m_downloadList.slot_map_erase().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
m_downloadList.slot_map_erase().insert("1_store_remove", sigc::mem_fun(m_downloadStore, &DownloadStore::remove));
m_downloadList.slot_map_erase()["1_hash_queue_remove"] = sigc::mem_fun(m_hashQueue, &HashQueue::remove);
m_downloadList.slot_map_erase()["1_store_remove"] = sigc::mem_fun(m_downloadStore, &DownloadStore::remove);
//m_downloadList.slot_map_open().insert("1_download_open", sigc::mem_fun(&Download::open));
m_downloadList.slot_map_open().insert("1_download_open", sigc::mem_fun(&Download::call<void, &torrent::Download::open>));
m_downloadList.slot_map_open()["1_download_open"] = sigc::mem_fun(&Download::call<void, &torrent::Download::open>);
// Currently does not call stop, might want to add a function that
// checks if we're running, and if so stop?
m_downloadList.slot_map_close().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
m_downloadList.slot_map_close().insert("2_download_close", sigc::mem_fun(&Download::call<void, &torrent::Download::close>));
m_downloadList.slot_map_close()["1_hash_queue_remove"] = sigc::mem_fun(m_hashQueue, &HashQueue::remove);
m_downloadList.slot_map_close()["2_download_close"] = sigc::mem_fun(&Download::call<void, &torrent::Download::close>);
m_downloadList.slot_map_start().insert("1_download_start", sigc::mem_fun(&Download::start));
m_downloadList.slot_map_start()["1_download_start"] = sigc::mem_fun(&Download::start);
m_downloadList.slot_map_stop().insert("1_download_stop", sigc::mem_fun(&Download::call<void, &torrent::Download::stop>));
m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::call<void, &torrent::Download::hash_resume_save>));
m_downloadList.slot_map_stop().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
m_downloadList.slot_map_stop()["1_download_stop"] = sigc::mem_fun(&Download::call<void, &torrent::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);
m_downloadList.slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(*this, &Manager::receive_download_done), true));
m_downloadList.slot_map_finished().insert("2_receive_finished", sigc::mem_fun(&Download::receive_finished));
m_downloadList.slot_map_finished()["1_download_done"] = sigc::mem_fun(*this, &Manager::receive_download_done);
m_downloadList.slot_map_finished()["2_receive_finished"] = sigc::mem_fun(&Download::receive_finished);
}
void
@@ -196,8 +195,8 @@ Manager::check_hash(Download* d) {
}
void
Manager::receive_download_done(Download* d, bool check_hash) {
if (check_hash) {
Manager::receive_download_done(Download* d) {
if (m_checkHash) {
// Start the hash checking, send completed to tracker after
// finishing.
prepare_hash_check(d);
+6 -3
View File
@@ -58,7 +58,7 @@ public:
typedef sigc::slot1<void, DownloadList::iterator> SlotReady;
typedef sigc::slot0<void> SlotFailed;
Manager() : m_portRandom(false), m_portFirst(6890), m_portLast(6999) {}
Manager() : m_portRandom(false), m_portFirst(6890), m_portLast(6999), m_checkHash(true) {}
DownloadList& get_download_list() { return m_downloadList; }
DownloadStore& get_download_store() { return m_downloadStore; }
@@ -72,6 +72,8 @@ public:
void set_port_random(bool v) { m_portRandom = v; }
void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; }
void set_check_hash(bool state) { m_checkHash = state; }
void initialize();
void cleanup();
@@ -85,8 +87,6 @@ public:
void check_hash(Download* d);
void receive_download_done(Download* d, bool check_hash);
private:
void listen_open();
@@ -100,6 +100,7 @@ private:
void receive_http_failed(std::string msg);
void receive_download_done_hash_checked(Download* d);
void receive_download_inserted(Download* d);
void receive_download_done(Download* d);
DownloadList m_downloadList;
DownloadStore m_downloadStore;
@@ -113,6 +114,8 @@ private:
bool m_portRandom;
int m_portFirst;
int m_portLast;
bool m_checkHash;
};
}
+3 -2
View File
@@ -84,10 +84,11 @@ WindowTrackerList::redraw() {
range.first == *m_focus ? '*' : ' ',
t.get_url().c_str());
m_canvas->print(0, pos++, "%c Group: %2i Id: %s",
m_canvas->print(0, pos++, "%c Group: %2i Id: %s Enabled: %s",
range.first == *m_focus ? '*' : ' ',
t.get_group(),
utils::escape_string(t.get_tracker_id()).c_str());
utils::escape_string(t.get_tracker_id()).c_str(),
t.is_enabled() ? "yes" : "no");
++range.first;
}
+22 -21
View File
@@ -113,33 +113,34 @@ parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** arg
void
initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) {
optionHandler->insert("max_peers", new OptionHandlerInt(c, &apply_download_max_peers, &validate_download_peers));
optionHandler->insert("min_peers", new OptionHandlerInt(c, &apply_download_min_peers, &validate_download_peers));
optionHandler->insert("max_uploads", new OptionHandlerInt(c, &apply_download_max_uploads, &validate_download_peers));
optionHandler->insert("max_peers", new OptionHandlerInt(c, &apply_download_max_peers, &validate_download_peers));
optionHandler->insert("min_peers", new OptionHandlerInt(c, &apply_download_min_peers, &validate_download_peers));
optionHandler->insert("max_uploads", new OptionHandlerInt(c, &apply_download_max_uploads, &validate_download_peers));
optionHandler->insert("download_rate", new OptionHandlerInt(c, &apply_global_download_rate, &validate_rate));
optionHandler->insert("upload_rate", new OptionHandlerInt(c, &apply_global_upload_rate, &validate_rate));
optionHandler->insert("download_rate", new OptionHandlerInt(c, &apply_global_download_rate, &validate_rate));
optionHandler->insert("upload_rate", new OptionHandlerInt(c, &apply_global_upload_rate, &validate_rate));
optionHandler->insert("bind", new OptionHandlerString(c, &apply_bind, &validate_ip));
optionHandler->insert("ip", new OptionHandlerString(c, &apply_ip, &validate_ip));
optionHandler->insert("port_range", new OptionHandlerString(c, &apply_port_range, &validate_port_range));
optionHandler->insert("port_random", new OptionHandlerString(c, &apply_port_random, &validate_yes_no));
optionHandler->insert("bind", new OptionHandlerString(c, &apply_bind, &validate_ip));
optionHandler->insert("ip", new OptionHandlerString(c, &apply_ip, &validate_ip));
optionHandler->insert("port_range", new OptionHandlerString(c, &apply_port_range, &validate_port_range));
optionHandler->insert("port_random", new OptionHandlerString(c, &apply_port_random, &validate_yes_no));
optionHandler->insert("check_hash", new OptionHandlerString(c, &apply_check_hash, &validate_yes_no));
optionHandler->insert("directory", new OptionHandlerString(c, &apply_download_directory, &validate_directory));
optionHandler->insert("check_hash", new OptionHandlerString(c, &apply_check_hash, &validate_yes_no));
optionHandler->insert("directory", new OptionHandlerString(c, &apply_download_directory, &validate_directory));
optionHandler->insert("hash_read_ahead", new OptionHandlerInt(c, &apply_hash_read_ahead, &validate_hash_read_ahead));
optionHandler->insert("hash_interval", new OptionHandlerInt(c, &apply_hash_interval, &validate_hash_interval));
optionHandler->insert("hash_max_tries", new OptionHandlerInt(c, &apply_hash_max_tries, &validate_hash_max_tries));
optionHandler->insert("max_open_files", new OptionHandlerInt(c, &apply_max_open_files, &validate_fd));
optionHandler->insert("max_open_sockets", new OptionHandlerInt(c, &apply_max_open_sockets, &validate_fd));
optionHandler->insert("throttle_interval", new OptionHandlerInt(c, &apply_throttle_interval, &validate_throttle_interval));
optionHandler->insert("hash_read_ahead", new OptionHandlerInt(c, &apply_hash_read_ahead, &validate_hash_read_ahead));
optionHandler->insert("hash_interval", new OptionHandlerInt(c, &apply_hash_interval, &validate_hash_interval));
optionHandler->insert("hash_max_tries", new OptionHandlerInt(c, &apply_hash_max_tries, &validate_hash_max_tries));
optionHandler->insert("max_open_files", new OptionHandlerInt(c, &apply_max_open_files, &validate_fd));
optionHandler->insert("max_open_sockets", new OptionHandlerInt(c, &apply_max_open_sockets, &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("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));
optionHandler->insert("session", new OptionHandlerString(c, &apply_session_directory, &validate_directory));
optionHandler->insert("tracker_dump", new OptionHandlerString(c, &apply_tracker_dump, &validate_yes_no));
optionHandler->insert("use_udp_trackers", new OptionHandlerString(c, &apply_use_udp_trackers, &validate_yes_no));
}
void
+17 -9
View File
@@ -116,35 +116,35 @@ validate_throttle_interval(int arg) {
void
apply_download_min_peers(ui::Control* m, int arg) {
m->get_core().get_download_list().slot_map_insert().insert("1_min_peers", sigc::bind(sigc::mem_fun(&core::Download::call<void, uint32_t, &torrent::Download::set_peers_min>), arg));
m->get_core().get_download_list().slot_map_insert()["1_min_peers"] = sigc::bind(sigc::mem_fun(&core::Download::call<void, uint32_t, &torrent::Download::set_peers_min>), arg);
}
void
apply_download_max_peers(ui::Control* m, int arg) {
m->get_core().get_download_list().slot_map_insert().insert("1_max_peers", sigc::bind(sigc::mem_fun(&core::Download::call<void, uint32_t, &torrent::Download::set_peers_max>), arg));
m->get_core().get_download_list().slot_map_insert()["1_max_peers"] = sigc::bind(sigc::mem_fun(&core::Download::call<void, uint32_t, &torrent::Download::set_peers_max>), arg);
}
void
apply_download_max_uploads(ui::Control* m, int arg) {
m->get_core().get_download_list().slot_map_insert().insert("1_max_uploads", sigc::bind(sigc::mem_fun(&core::Download::call<void, uint32_t, &torrent::Download::set_uploads_max>), arg));
m->get_core().get_download_list().slot_map_insert()["1_max_uploads"] = sigc::bind(sigc::mem_fun(&core::Download::call<void, uint32_t, &torrent::Download::set_uploads_max>), arg);
}
void
apply_download_directory(ui::Control* m, const std::string& arg) {
if (!arg.empty())
m->get_core().get_download_list().slot_map_insert().insert("1_directory", sigc::bind(sigc::mem_fun(&core::Download::set_root_directory), arg));
m->get_core().get_download_list().slot_map_insert()["1_directory"] = sigc::bind(sigc::mem_fun(&core::Download::set_root_directory), arg);
else
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));
m->get_core().get_download_list().slot_map_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));
m->get_core().get_download_list().slot_map_insert()["1_connection_seed"] = sigc::bind(sigc::mem_fun(&core::Download::set_connection_seed), arg);
}
void
@@ -216,17 +216,25 @@ apply_port_random(ui::Control* m, const std::string& arg) {
void
apply_tracker_dump(ui::Control* m, const std::string& arg) {
if (arg == "yes")
m->get_core().get_download_list().slot_map_insert().insert("1_tracker_dump", sigc::bind(sigc::mem_fun(&core::Download::call<sigc::connection, torrent::Download::SlotIStream, &torrent::Download::signal_tracker_dump>), sigc::ptr_fun(&receive_tracker_dump)));
m->get_core().get_download_list().slot_map_insert()["1_tracker_dump"] = sigc::bind(sigc::mem_fun(&core::Download::call<sigc::connection, torrent::Download::SlotIStream, &torrent::Download::signal_tracker_dump>), sigc::ptr_fun(&receive_tracker_dump));
else
m->get_core().get_download_list().slot_map_insert().erase("1_tracker_dump");
}
void
apply_use_udp_trackers(ui::Control* m, const std::string& arg) {
if (arg == "yes")
m->get_core().get_download_list().slot_map_insert().erase("1_use_udp_trackers");
else
m->get_core().get_download_list().slot_map_insert()["1_use_udp_trackers"] = sigc::bind(sigc::mem_fun(&core::Download::enable_udp_trackers), false);
}
void
apply_check_hash(ui::Control* m, const std::string& arg) {
if (arg == "yes")
m->get_core().get_download_list().slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(m->get_core(), &core::Manager::receive_download_done), true));
m->get_core().set_check_hash(true);
else
m->get_core().get_download_list().slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(m->get_core(), &core::Manager::receive_download_done), false));
m->get_core().set_check_hash(false);
}
void
+1
View File
@@ -88,6 +88,7 @@ void apply_bind(ui::Control* m, const std::string& arg);
void apply_port_range(ui::Control* m, const std::string& arg);
void apply_port_random(ui::Control* m, const std::string& arg);
void apply_tracker_dump(ui::Control* m, const std::string& arg);
void apply_use_udp_trackers(ui::Control* m, const std::string& arg);
void apply_check_hash(ui::Control* m, const std::string& arg);
void apply_session_directory(ui::Control* m, const std::string& arg);