* Added preliminary support for tunneling peer connections through a

http proxy. Doesn't currently support error checking or such. Use the
'connection_proxy' option to enable.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@796 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-10-22 10:32:49 +00:00
parent a72054d018
commit 2781ce9698
3 changed files with 46 additions and 2 deletions
+41 -2
View File
@@ -133,11 +133,14 @@ Manager::handshake_log(const sockaddr* sa, torrent::ConnectionManager::Handshake
case torrent::ConnectionManager::handshake_incoming:
m_logComplete.push_front("Incoming connection from " + peer + download);
break;
case torrent::ConnectionManager::handshake_outgoing:
m_logComplete.push_front("Outgoing connection to " + peer + download);
break;
case torrent::ConnectionManager::handshake_outgoing_encrypted:
m_logComplete.push_front("Outgoing encrypted connection to " + peer + download);
break;
case torrent::ConnectionManager::handshake_outgoing:
m_logComplete.push_front("Outgoing connection to " + peer + download);
case torrent::ConnectionManager::handshake_outgoing_proxy:
m_logComplete.push_front("Outgoing proxy connection to " + peer + download);
break;
case torrent::ConnectionManager::handshake_success:
m_logComplete.push_front("Successful handshake: " + peer + download);
@@ -350,6 +353,42 @@ Manager::set_local_address(const std::string& addr) {
}
}
std::string
Manager::proxy_address() const {
return rak::socket_address::cast_from(torrent::connection_manager()->proxy_address())->address_str();
}
void
Manager::set_proxy_address(const std::string& addr) {
int port;
rak::address_info* ai;
char buf[addr.length() + 1];
int err = std::sscanf(addr.c_str(), "%[^:]:%i", buf, &port);
if (err <= 0)
throw torrent::input_error("Could not parse proxy address.");
if (err == 1)
port = 80;
if ((err = rak::address_info::get_address_info(buf, PF_INET, SOCK_STREAM, &ai)) != 0)
throw torrent::input_error("Could not set proxy address: " + std::string(rak::address_info::strerror(err)) + ".");
try {
ai->address()->set_port(port);
torrent::connection_manager()->set_proxy_address(ai->address()->c_sockaddr());
rak::address_info::free_address_info(ai);
} catch (torrent::input_error& e) {
rak::address_info::free_address_info(ai);
throw e;
}
}
void
Manager::receive_http_failed(std::string msg) {
m_logImportant.push_front("Http download error: \"" + msg + "\"");
+3
View File
@@ -91,6 +91,9 @@ public:
std::string local_address() const;
void set_local_address(const std::string& addr);
std::string proxy_address() const;
void set_proxy_address(const std::string& addr);
void shutdown(bool force);
void push_log(const std::string& msg) { m_logImportant.push_front(msg); m_logComplete.push_front(msg); }
+2
View File
@@ -449,6 +449,8 @@ initialize_option_handler(Control* c) {
rak::mem_fn(control->core(), &core::Manager::set_bind_address)));
variables->insert("ip", new utils::VariableStringSlot(rak::mem_fn(control->core(), &core::Manager::local_address),
rak::mem_fn(control->core(), &core::Manager::set_local_address)));
variables->insert("connection_proxy", new utils::VariableStringSlot(rak::mem_fn(control->core(), &core::Manager::proxy_address),
rak::mem_fn(control->core(), &core::Manager::set_proxy_address)));
variables->insert("http_proxy", new utils::VariableStringSlot(rak::mem_fn(c->core()->get_poll_manager()->get_http_stack(), &core::CurlStack::http_proxy),
rak::mem_fn(c->core()->get_poll_manager()->get_http_stack(), &core::CurlStack::set_http_proxy)));