diff --git a/bindings/python/src/session_settings.cpp b/bindings/python/src/session_settings.cpp index d52c89289..f9a43ae76 100644 --- a/bindings/python/src/session_settings.cpp +++ b/bindings/python/src/session_settings.cpp @@ -180,6 +180,10 @@ void bind_session_settings() .def_readwrite("tracker_backoff", &session_settings::tracker_backoff) .def_readwrite("ban_web_seeds", &session_settings::ban_web_seeds) .def_readwrite("max_http_recv_buffer_size", &session_settings::max_http_recv_buffer_size) + .def_readwrite("support_share_mode", &session_settings::support_share_mode) + .def_readwrite("support_merkle_torrents", &session_settings::support_merkle_torrents) + .def_readwrite("handshake_client_version", &session_settings::handshake_client_version) + .def_readwrite("report_redundant_bytes", &session_settings::report_redundant_bytes) ; enum_("proxy_type") diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 1ef1268c1..68680c903 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -949,6 +949,22 @@ namespace libtorrent // http_connection maximum receive buffer size // limits torrent file size for URL torrents int max_http_recv_buffer_size; + + // enables/disables the share-mode extension + bool support_share_mode; + + // if this is false, don't advertise support for + // the Tribler merkle tree piece message + bool support_merkle_torrents; + + // if this is true, the number of redundant bytes + // is sent to the tracker + bool report_redundant_bytes; + + // the version string to advertise for this client + // in the peer protocol handshake. If this is empty + // the user_agent is used + std::string handshake_client_version; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index e9c6daa64..ae624ad1d 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -729,8 +729,11 @@ namespace libtorrent *(ptr + 5) |= 0x10; #endif - // we support merkle torrents - *(ptr + 5) |= 0x08; + if (m_ses.m_settings.support_merkle_torrents) + { + // we support merkle torrents + *(ptr + 5) |= 0x08; + } // we support FAST extension *(ptr + 7) |= 0x04; @@ -745,7 +748,7 @@ namespace libtorrent else bitmask += '0'; } } - peer_log(">>> EXTENSION_BITS [ %s ]", bitmask.c_str()); + peer_log("==> EXTENSION [ %s ]", bitmask.c_str()); #endif ptr += 8; @@ -1746,7 +1749,8 @@ namespace libtorrent if (root.dict_find_int_value("upload_only", 0)) set_upload_only(true); - if (root.dict_find_int_value("share_mode", 0)) + if (m_ses.m_settings.support_share_mode + && root.dict_find_int_value("share_mode", 0)) set_share_mode(true); std::string myip = root.dict_find_string_value("yourip"); @@ -1801,7 +1805,10 @@ namespace libtorrent TORRENT_ASSERT(recv_buffer.left() >= 1); int packet_type = (unsigned char)recv_buffer[0]; - if (packet_type == 250) packet_type = msg_piece; + + if (m_ses.m_settings.support_merkle_torrents + && packet_type == 250) packet_type = msg_piece; + if (packet_type < 0 || packet_type >= num_supported_messages || m_message_handler[packet_type] == 0) @@ -2095,7 +2102,8 @@ namespace libtorrent if (!m_ses.m_settings.anonymous_mode) { if (is_outgoing()) handshake["p"] = m_ses.listen_port(); - handshake["v"] = m_ses.settings().user_agent; + handshake["v"] = m_ses.settings().handshake_client_version.empty() + ? m_ses.settings().user_agent : m_ses.settings().handshake_client_version; } std::string remote_address; @@ -2108,7 +2116,8 @@ namespace libtorrent m["upload_only"] = upload_only_msg; m["ut_holepunch"] = holepunch_msg; - m["share_mode"] = share_mode_msg; + if (m_ses.m_settings.support_share_mode) + m["share_mode"] = share_mode_msg; m["lt_donthave"] = dont_have_msg; int complete_ago = -1; @@ -2134,7 +2143,8 @@ namespace libtorrent )) handshake["upload_only"] = 1; - if (t->share_mode()) + if (m_ses.m_settings.support_share_mode + && t->share_mode()) handshake["share_mode"] = 1; if (!m_ses.m_settings.anonymous_mode) @@ -2268,7 +2278,7 @@ namespace libtorrent char* ptr = msg; TORRENT_ASSERT(r.length <= 16 * 1024); detail::write_int32(r.length + 1 + 4 + 4, ptr); - if (merkle) + if (m_ses.m_settings.support_merkle_torrents && merkle) detail::write_uint8(250, ptr); else detail::write_uint8(msg_piece, ptr); diff --git a/src/http_connection.cpp b/src/http_connection.cpp index ab1e39953..f68f1b22a 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -183,15 +183,15 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri // APPEND_FMT("Accept: */*\r\n"); - if (!auth.empty()) - APPEND_FMT1("Authorization: Basic %s\r\n", base64encode(auth).c_str()); - if (!m_user_agent.empty()) APPEND_FMT1("User-Agent: %s\r\n", m_user_agent.c_str()); if (m_bottled) APPEND_FMT("Accept-Encoding: gzip\r\n"); + if (!auth.empty()) + APPEND_FMT1("Authorization: Basic %s\r\n", base64encode(auth).c_str()); + APPEND_FMT("Connection: close\r\n\r\n"); sendbuffer.assign(request); diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 03beec528..bd2ef1e35 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -130,17 +130,27 @@ namespace libtorrent url += "&"; else url += "?"; - - url += "info_hash="; - url += escape_string((const char*)&tracker_req().info_hash[0], 20); if (tracker_req().kind == tracker_request::announce_request) { + const char* event_string[] = {"completed", "started", "stopped", "paused"}; + char str[1024]; const bool stats = tracker_req().send_stats; - snprintf(str, sizeof(str), "&peer_id=%s&port=%d&uploaded=%"PRId64 - "&downloaded=%"PRId64"&left=%"PRId64"&corrupt=%"PRId64"&redundant=%"PRId64 - "&compact=1&numwant=%d&key=%x&no_peer_id=1" + snprintf(str, sizeof(str) + , "info_hash=%s" + "&peer_id=%s" + "&port=%d" + "&uploaded=%"PRId64 + "&downloaded=%"PRId64 + "&left=%"PRId64 + "&corrupt=%"PRId64 + "&key=%x" + "%s%s" // event + "&numwant=%d" + "&compact=1" + "&no_peer_id=1" + , escape_string((const char*)&tracker_req().info_hash[0], 20).c_str() , escape_string((const char*)&tracker_req().pid[0], 20).c_str() // the i2p tracker seems to verify that the port is not 0, // even though it ignores it otherwise @@ -149,14 +159,20 @@ namespace libtorrent , stats ? tracker_req().downloaded : 0 , stats ? tracker_req().left : 0 , stats ? tracker_req().corrupt : 0 - , stats ? tracker_req().redundant: 0 - , tracker_req().num_want - , tracker_req().key); + , tracker_req().key + , (tracker_req().event != tracker_request::none) ? "&event=" : "" + , (tracker_req().event != tracker_request::none) ? event_string[tracker_req().event - 1] : "" + , tracker_req().num_want); url += str; #ifndef TORRENT_DISABLE_ENCRYPTION if (m_ses.get_pe_settings().in_enc_policy != pe_settings::disabled) url += "&supportcrypto=1"; #endif + if (stats && m_ses.settings().report_redundant_bytes) + { + url += "&redundant="; + url += to_string(tracker_req().redundant).elems; + } if (!tracker_req().trackerid.empty()) { std::string id = tracker_req().trackerid; @@ -164,13 +180,6 @@ namespace libtorrent url += escape_string(id.c_str(), id.length()); } - if (tracker_req().event != tracker_request::none) - { - const char* event_string[] = {"completed", "started", "stopped", "paused"}; - url += "&event="; - url += event_string[tracker_req().event - 1]; - } - #if TORRENT_USE_I2P if (i2p) { diff --git a/src/session.cpp b/src/session.cpp index 2fc66d3ea..d7263d3be 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1292,6 +1292,9 @@ namespace libtorrent , tracker_backoff(250) , ban_web_seeds(true) , max_http_recv_buffer_size(2*1024*1024) + , support_share_mode(true) + , support_merkle_torrents(false) + , report_redundant_bytes(true) {} session_settings::~session_settings() {}