* Bind udp and http tracker requests to the bind address.

* Allow the torrent's priority to be changed with '+'.

* More work on the variables thing.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@625 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-01-23 19:24:45 +00:00
parent 52636178d1
commit 825985b8ef
28 changed files with 282 additions and 96 deletions
+5
View File
@@ -137,6 +137,11 @@ CurlGet::set_http_proxy(const char* s) {
curl_easy_setopt(m_handle, CURLOPT_PROXY, s);
}
void
CurlGet::set_bind_address(const char* s) {
curl_easy_setopt(m_handle, CURLOPT_INTERFACE, s);
}
void
CurlGet::perform(CURLMsg* msg) {
if (msg->msg != CURLMSG_DONE)
+1
View File
@@ -68,6 +68,7 @@ class CurlGet : public torrent::Http {
void set_user_agent(const char* s);
void set_http_proxy(const char* s);
void set_bind_address(const char* s);
protected:
CURL* handle() { return m_handle; }
+3
View File
@@ -109,6 +109,9 @@ CurlStack::add_get(CurlGet* get) {
if (!m_httpProxy.empty())
get->set_http_proxy(m_httpProxy.c_str());
if (!m_bindAddress.empty())
get->set_bind_address(m_bindAddress.c_str());
CURLMcode code;
if ((code = curl_multi_add_handle((CURLM*)m_handle, get->handle())) > 0)
+4
View File
@@ -71,6 +71,9 @@ class CurlStack {
const std::string& http_proxy() const { return m_httpProxy; }
void set_http_proxy(const std::string& s) { m_httpProxy = s; }
const std::string& bind_address() const { return m_bindAddress; }
void set_bind_address(const std::string& s) { m_bindAddress = s; }
static void global_init();
static void global_cleanup();
@@ -89,6 +92,7 @@ class CurlStack {
std::string m_userAgent;
std::string m_httpProxy;
std::string m_bindAddress;
};
}
+59 -4
View File
@@ -41,6 +41,7 @@
#include <sigc++/hide.h>
#include <sigc++/signal.h>
#include <torrent/exceptions.h>
#include <torrent/torrent.h>
#include "utils/variable_generic.h"
@@ -61,15 +62,24 @@ Download::Download(torrent::Download d) :
m_variables.insert("connection_current", new utils::VariableSlotString<const char*, const std::string&>(rak::mem_fn(this, &Download::connection_current),
rak::mem_fn(this, &Download::set_connection_current)));
m_variables.insert("connection_leech", new utils::VariableValue(connection_type_to_string(torrent::Download::CONNECTION_LEECH)));
m_variables.insert("connection_seed", new utils::VariableValue(connection_type_to_string(torrent::Download::CONNECTION_SEED)));
m_variables.insert("connection_leech", new utils::VariableAny(connection_type_to_string(torrent::Download::CONNECTION_LEECH)));
m_variables.insert("connection_seed", new utils::VariableAny(connection_type_to_string(torrent::Download::CONNECTION_SEED)));
m_variables.insert("directory", new utils::VariableSlotString<std::string, const std::string&>(NULL,
rak::mem_fn(this, &Download::set_root_directory)));
m_variables.insert("tied_to_file", new utils::VariableBencode(&m_download.bencode(), "tied_to_file", torrent::Bencode::TYPE_STRING));
m_variables.insert("peers_min", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_min),
m_variables.insert("min_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_min),
rak::mem_fn(&m_download, &torrent::Download::set_peers_min),
"%u"));
m_variables.insert("max_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_max),
rak::mem_fn(&m_download, &torrent::Download::set_peers_max),
"%u"));
m_variables.insert("max_uploads", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::uploads_max),
rak::mem_fn(&m_download, &torrent::Download::set_uploads_max),
"%u"));
m_variables.insert("priority", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(this, &Download::priority),
rak::mem_fn(this, &Download::set_priority),
"%u"));
}
Download::~Download() {
@@ -106,10 +116,25 @@ Download::enable_udp_trackers(bool state) {
m_download.tracker(i).disable();
}
uint32_t
Download::priority() {
return get_bencode().get_key("rtorrent").get_key("priority").as_value();
}
void
Download::set_priority(uint32_t p) {
if (p >= 4)
throw torrent::input_error("Priority out of range.");
torrent::download_set_priority(m_download, p * 2);
get_bencode().get_key("rtorrent").insert_key("priority", (int64_t)p);
}
void
Download::receive_finished() {
m_download.set_connection_type(string_to_connection_type(m_variables.get("connection_seed").as_string()));
torrent::download_set_priority(m_download, 2);
// FIXME
//torrent::download_set_priority(m_download, 2);
}
void
@@ -148,6 +173,36 @@ Download::connection_type_to_string(torrent::Download::ConnectionType t) {
}
}
uint32_t
Download::string_to_priority(const std::string& name) {
if (name == "off")
return 0;
else if (name == "low")
return 1;
else if (name == "normal")
return 2;
else if (name == "high")
return 3;
else
throw torrent::input_error("Could not convert string to priority.");
}
const char*
Download::priority_to_string(uint32_t p) {
switch (p) {
case 0:
return "off";
case 1:
return "low";
case 2:
return "normal";
case 3:
return "high";
default:
throw torrent::input_error("Priority out of range.");
}
}
void
Download::receive_chunk_failed(uint32_t idx) {
m_chunksFailed++;
+6
View File
@@ -71,6 +71,9 @@ public:
void enable_udp_trackers(bool state);
uint32_t priority();
void set_priority(uint32_t p);
// Helper functions for calling functions in torrent::Download
// through sigc++.
template <typename Ret, Ret (torrent::Download::*func)()>
@@ -86,6 +89,9 @@ public:
static ConnType string_to_connection_type(const std::string& name);
static const char* connection_type_to_string(ConnType t);
static uint32_t string_to_priority(const std::string& name);
static const char* priority_to_string(uint32_t p);
private:
Download(const Download&);
void operator () (const Download&);
+12 -5
View File
@@ -67,9 +67,9 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) :
m_taskLoad.set_slot(rak::mem_fn(this, &DownloadFactory::receive_load));
m_taskCommit.set_slot(rak::mem_fn(this, &DownloadFactory::receive_commit));
m_variables.insert("connection_leech", new utils::VariableValue(control->variables()->get("connection_leech")));
m_variables.insert("connection_seed", new utils::VariableValue(control->variables()->get("connection_seed")));
m_variables.insert("directory", new utils::VariableValue(control->variables()->get("directory")));
m_variables.insert("connection_leech", new utils::VariableAny(control->variables()->get("connection_leech")));
m_variables.insert("connection_seed", new utils::VariableAny(control->variables()->get("connection_seed")));
m_variables.insert("directory", new utils::VariableAny(control->variables()->get("directory")));
m_variables.insert("tied_to_file", new utils::VariableBool(false));
}
@@ -150,9 +150,16 @@ DownloadFactory::receive_success() {
(*itr)->variables()->set("connection_leech", m_variables.get("connection_leech"));
(*itr)->variables()->set("connection_seed", m_variables.get("connection_seed"));
(*itr)->variables()->set("directory", m_variables.get("directory"));
(*itr)->variables()->set("min_peers", control->variables()->get("min_peers"));
(*itr)->variables()->set("max_peers", control->variables()->get("max_peers"));
(*itr)->variables()->set("max_uploads", control->variables()->get("max_uploads"));
// if (control->variables()->get("peers_min")
// (*itr)->variables()->set("peers_min", m_variables.get("directory"));
if ((*itr)->get_bencode().get_key("rtorrent").has_key("priority") &&
(*itr)->get_bencode().get_key("rtorrent").get_key("priority").is_value())
(*itr)->variables()->set("priority", (*itr)->get_bencode().get_key("rtorrent").get_key("priority").as_value() % 4);
else
(*itr)->variables()->set("priority", (int64_t)2);
torrent::Bencode& bencode = (*itr)->get_bencode();
+2
View File
@@ -290,6 +290,8 @@ Manager::bind(const std::string& addr) {
} else {
torrent::set_bind_address(addr);
}
m_pollManager->get_http_stack()->set_bind_address(torrent::bind_address());
}
void
-2
View File
@@ -95,8 +95,6 @@ void
PollManager::check_error() {
if (errno != EINTR)
throw std::runtime_error("Poll::work(): select error");
m_signalInterrupted.emit();
}
}
-5
View File
@@ -63,9 +63,6 @@ public:
virtual void poll(rak::timer timeout) = 0;
// Use a signal, connect checking for input and updating the display.
Signal& signal_interrupted() { return m_signalInterrupted; }
protected:
PollManager(const PollManager&);
void operator = (const PollManager&);
@@ -79,8 +76,6 @@ protected:
fd_set* m_readSet;
fd_set* m_writeSet;
fd_set* m_errorSet;
Signal m_signalInterrupted;
};
}