diff --git a/src/core/manager.cc b/src/core/manager.cc index 4712d729..e287f4e5 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -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 + "\""); diff --git a/src/core/manager.h b/src/core/manager.h index a5b59bf2..c992ca4b 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -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); } diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index 7aa68f82..bd469091 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -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)));