* 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
+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;
};
}