mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-18 08:02:29 +00:00
* Encrypted (obfuscated) handshake and connection support. Patch by
Josef Drexler, public domain as per earlier agreement. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@790 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
#include <sigc++/hide.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/error.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
@@ -105,6 +106,60 @@ receive_tracker_dump(const std::string& url, const char* data, size_t size) {
|
||||
fstr << std::endl <<"---" << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
Manager::handshake_log(const sockaddr* sa, torrent::ConnectionManager::HandshakeMessage msg, int err, std::string hash) {
|
||||
if (!control->variable()->get_value("handshake_log"))
|
||||
return;
|
||||
|
||||
std::string peer;
|
||||
std::string download;
|
||||
|
||||
const rak::socket_address* socketAddress = rak::socket_address::cast_from(sa);
|
||||
if (socketAddress->is_valid()) {
|
||||
char port[6];
|
||||
snprintf(port, sizeof(port), "%d", socketAddress->port());
|
||||
peer = socketAddress->address_str() + ":" + port;
|
||||
} else {
|
||||
peer = "(unknown)";
|
||||
}
|
||||
|
||||
torrent::Download d = torrent::download_find(hash);
|
||||
if (d.is_valid())
|
||||
download = ": " + d.name();
|
||||
else
|
||||
download = "";
|
||||
|
||||
switch (msg) {
|
||||
case torrent::ConnectionManager::handshake_incoming:
|
||||
m_logComplete.push_front("Incoming connection from " + 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);
|
||||
break;
|
||||
case torrent::ConnectionManager::handshake_success:
|
||||
m_logComplete.push_front("Successful handshake: " + peer + download);
|
||||
break;
|
||||
case torrent::ConnectionManager::handshake_dropped:
|
||||
m_logComplete.push_front("Dropped handshake: " + peer + " - " + torrent::strerror(err) + download);
|
||||
break;
|
||||
case torrent::ConnectionManager::handshake_failed:
|
||||
m_logComplete.push_front("Handshake failed: " + peer + " - " + torrent::strerror(err) + download);
|
||||
break;
|
||||
case torrent::ConnectionManager::handshake_retry_plaintext:
|
||||
m_logComplete.push_front("Trying again without encryption: " + peer + download);
|
||||
break;
|
||||
case torrent::ConnectionManager::handshake_retry_encrypted:
|
||||
m_logComplete.push_front("Trying again encrypted: " + peer + download);
|
||||
break;
|
||||
default:
|
||||
m_logComplete.push_front("Unknown handshake message for " + peer + download);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Hmm... find some better place for all this.
|
||||
void
|
||||
Manager::delete_tied(Download* d) {
|
||||
@@ -183,6 +238,8 @@ Manager::initialize_second() {
|
||||
m_downloadList->slot_map_insert()["1_connect_tracker_dump"] = sigc::bind(sigc::ptr_fun(&connect_signal_tracker_dump), sigc::ptr_fun(&receive_tracker_dump));
|
||||
|
||||
m_downloadList->slot_map_erase()["1_delete_tied"] = sigc::mem_fun(this, &Manager::delete_tied);
|
||||
|
||||
torrent::connection_manager()->set_signal_handshake_log(sigc::mem_fun(this, &Manager::handshake_log));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <torrent/connection_manager.h>
|
||||
|
||||
#include "download_list.h"
|
||||
#include "poll_manager.h"
|
||||
#include "log.h"
|
||||
@@ -93,6 +95,8 @@ public:
|
||||
|
||||
void push_log(const std::string& msg) { m_logImportant.push_front(msg); m_logComplete.push_front(msg); }
|
||||
|
||||
void handshake_log(const sockaddr* sa, torrent::ConnectionManager::HandshakeMessage msg, int err, std::string hash);
|
||||
|
||||
// Temporary, find a better place for this.
|
||||
void try_create_download(const std::string& uri, bool start, bool printLog = true, bool tied = false);
|
||||
void try_create_download_expand(const std::string& uri, bool start, bool printLog = true, bool tied = false);
|
||||
|
||||
@@ -101,6 +101,43 @@ private:
|
||||
TextElement* m_branch2;
|
||||
};
|
||||
|
||||
template <typename slot_type>
|
||||
class TextElementBranch3 : public TextElement {
|
||||
public:
|
||||
typedef typename slot_type::argument_type arg1_type;
|
||||
typedef typename slot_type::result_type result_type;
|
||||
|
||||
TextElementBranch3(const slot_type& slot1, TextElement* branch1, const slot_type& slot2, TextElement* branch2, TextElement* branch3) :
|
||||
m_slot1(slot1), m_slot2(slot2), m_branch1(branch1), m_branch2(branch2), m_branch3(branch3) {}
|
||||
~TextElementBranch3() { delete m_branch1; delete m_branch2; delete m_branch3; }
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
if (object == NULL)
|
||||
return first;
|
||||
|
||||
if (m_slot1(reinterpret_cast<arg1_type>(object)))
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, object) : first;
|
||||
else if (m_slot2(reinterpret_cast<arg1_type>(object)))
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, object) : first;
|
||||
else
|
||||
return m_branch3 != NULL ? m_branch3->print(first, last, attributes, object) : first;
|
||||
}
|
||||
|
||||
virtual extent_type max_length() {
|
||||
return std::max(m_branch1 != NULL ? m_branch1->max_length() : 0,
|
||||
std::max(m_branch2 != NULL ? m_branch2->max_length() : 0,
|
||||
m_branch3 != NULL ? m_branch3->max_length() : 0));
|
||||
}
|
||||
|
||||
private:
|
||||
slot_type m_slot1;
|
||||
slot_type m_slot2;
|
||||
|
||||
TextElement* m_branch1;
|
||||
TextElement* m_branch2;
|
||||
TextElement* m_branch3;
|
||||
};
|
||||
|
||||
template <typename slot_type>
|
||||
inline TextElementBranchVoid<slot_type>*
|
||||
text_element_branch_void(const slot_type& slot, TextElement* branch1, TextElement* branch2) {
|
||||
@@ -113,6 +150,12 @@ text_element_branch(const slot_type& slot, TextElement* branch1, TextElement* br
|
||||
return new TextElementBranch<slot_type>(slot, branch1, branch2);
|
||||
}
|
||||
|
||||
template <typename slot_type>
|
||||
inline TextElementBranch3<slot_type>*
|
||||
text_element_branch3(const slot_type& slot1, TextElement* branch1, const slot_type& slot2, TextElement* branch2, TextElement* branch3) {
|
||||
return new TextElementBranch3<slot_type>(slot1, branch1, slot2, branch2, branch3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -107,6 +107,7 @@ WindowPeerList::redraw() {
|
||||
m_canvas->print(x, y, "%.1f", (double)p.peer_rate()->rate() / 1024); x += 7;
|
||||
|
||||
m_canvas->print(x, y, "%c/%c%c/%c%c",
|
||||
p.is_encrypted() ? p.is_incoming() ? 'R' : 'L' :
|
||||
p.is_incoming() ? 'r' : 'l',
|
||||
p.is_remote_choked() ? 'c' : 'u',
|
||||
p.is_remote_interested() ? 'i' : 'n',
|
||||
|
||||
@@ -228,6 +228,36 @@ apply_encoding_list(__UNUSED Control* m, const std::string& arg) {
|
||||
torrent::encoding_list()->push_back(arg);
|
||||
}
|
||||
|
||||
void
|
||||
apply_encryption_options(const std::string& arg) {
|
||||
rak::split_iterator_t<std::string> sitr = rak::split_iterator(arg, ',');
|
||||
uint32_t options_mask = torrent::ConnectionManager::encryption_none;
|
||||
|
||||
while (sitr != rak::split_iterator(arg)) {
|
||||
std::string opt = rak::trim(*sitr);
|
||||
++sitr;
|
||||
|
||||
if (opt == "none")
|
||||
options_mask = torrent::ConnectionManager::encryption_none;
|
||||
else if (opt == "allow_incoming")
|
||||
options_mask |= torrent::ConnectionManager::encryption_allow_incoming;
|
||||
else if (opt == "try_outgoing")
|
||||
options_mask |= torrent::ConnectionManager::encryption_try_outgoing;
|
||||
else if (opt == "require")
|
||||
options_mask |= torrent::ConnectionManager::encryption_require;
|
||||
else if (opt == "require_RC4")
|
||||
options_mask |= torrent::ConnectionManager::encryption_require_RC4;
|
||||
else if (opt == "enable_retry")
|
||||
options_mask |= torrent::ConnectionManager::encryption_enable_retry;
|
||||
else if (opt == "prefer_plaintext")
|
||||
options_mask |= torrent::ConnectionManager::encryption_prefer_plaintext;
|
||||
else
|
||||
throw torrent::input_error("Invalid encryption option '" + opt + "'.");
|
||||
}
|
||||
|
||||
torrent::connection_manager()->set_encryption_options(options_mask);
|
||||
}
|
||||
|
||||
void
|
||||
apply_enable_trackers(Control* m, __UNUSED const std::string& arg) {
|
||||
bool state = (arg != "no");
|
||||
@@ -503,4 +533,7 @@ initialize_option_handler(Control* c) {
|
||||
|
||||
variables->insert("enable_trackers", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::bind_ptr_fn(&apply_enable_trackers, c)));
|
||||
variables->insert("encoding_list", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::bind_ptr_fn(&apply_encoding_list, c)));
|
||||
|
||||
variables->insert("encryption_options", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::ptr_fn(&apply_encryption_options)));
|
||||
variables->insert("handshake_log", new utils::VariableBool(false));
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ ElementPeerList::create_info() {
|
||||
element->push_column("Client:", display::text_element_string_slot(rak::on(std::mem_fun(&torrent::Peer::id), rak::make_mem_fun(control->client_info(), &display::ClientInfo::str_str))));
|
||||
element->push_column("Options:", display::text_element_string_slot(std::mem_fun(&torrent::Peer::options), string_base::flag_escape_hex | string_base::flag_fixed_width, 0, 8));
|
||||
element->push_column("Connected:", display::text_element_branch(std::mem_fun(&torrent::Peer::is_incoming), te_string("incoming"), te_string("outgoing")));
|
||||
element->push_column("Encrypted:", display::text_element_branch3(std::mem_fun(&torrent::Peer::is_encrypted), te_string("yes"), std::mem_fun(&torrent::Peer::is_obfuscated), te_string("handshake"), te_string("no")));
|
||||
|
||||
element->push_back("");
|
||||
element->push_column("Snubbed:", display::text_element_branch(std::mem_fun(&torrent::Peer::is_snubbed), te_string("yes"), te_string("no")));
|
||||
|
||||
Reference in New Issue
Block a user