diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 09ad35dee..b82a7c954 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -444,7 +444,7 @@ namespace aux { , std::vector
const& addresses, int port); #endif -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION torrent const* find_encrypted_torrent( sha1_hash const& info_hash, sha1_hash const& xor_mask) override; @@ -876,7 +876,7 @@ namespace aux { // ordered by their queue position aux::vector m_download_queue; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // this maps obfuscated hashes to torrents. It's only // used when encryption is enabled torrent_map m_obfuscated_torrents; diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 2a62702e4..64c58ab51 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -294,7 +294,7 @@ namespace aux { virtual boost::asio::ssl::context* ssl_ctx() = 0 ; #endif -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION virtual torrent const* find_encrypted_torrent( sha1_hash const& info_hash, sha1_hash const& xor_mask) = 0; virtual void add_obfuscated_hash(sha1_hash const& obfuscated diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 23a2448cf..65a284cb5 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -108,7 +108,7 @@ namespace libtorrent { ~bt_peer_connection() override; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION bool supports_encryption() const { return m_encrypted; } bool rc4_encrypted() const @@ -171,7 +171,7 @@ namespace libtorrent { , std::size_t bytes_transferred) override; void on_receive_impl(std::size_t bytes_transferred); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // next_barrier, buffers-to-prepend std::tuple>> hit_send_barrier(span> iovec) override; @@ -181,8 +181,8 @@ namespace libtorrent { bool in_handshake() const override; bool packet_finished() const { return m_recv_buffer.packet_finished(); } -#ifndef TORRENT_DISABLE_EXTENSIONS bool supports_holepunch() const { return m_holepunch_id != 0; } +#ifndef TORRENT_DISABLE_EXTENSIONS void set_ut_pex(std::weak_ptr ut_pex) { m_ut_pex = std::move(ut_pex); } bool was_introduced_by(tcp::endpoint const& ep) const @@ -218,13 +218,11 @@ namespace libtorrent { void on_have_none(int received); void on_reject_request(int received); void on_allowed_fast(int received); -#ifndef TORRENT_DISABLE_EXTENSIONS void on_holepunch(); void on_extended(int received); void on_extended_handshake(); -#endif // the following functions appends messages // to the send buffer @@ -241,11 +239,10 @@ namespace libtorrent { void write_keepalive() override; void write_handshake(); void write_upload_only(bool enabled) override; -#ifndef TORRENT_DISABLE_EXTENSIONS void write_extensions(); void write_share_mode(); void write_holepunch_msg(int type, tcp::endpoint const& ep, int error); -#endif + // DHT extension void write_dht_port(int listen_port); @@ -298,7 +295,7 @@ namespace libtorrent { // will be invalid. piece_block_progress downloading_piece_progress() const override; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // if (is_local()), we are 'a' otherwise 'b' // @@ -327,7 +324,7 @@ namespace libtorrent { template void append_const_send_buffer(Holder holder, int size) { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION if (!m_enc_handler.is_send_plaintext()) { // if we're encrypting this buffer, we need to make a copy @@ -346,8 +343,8 @@ namespace libtorrent { enum class state_t : std::uint8_t { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) - read_pe_dhkey = 0, +#if !defined TORRENT_DISABLE_ENCRYPION + read_pe_dhkey, read_pe_syncvc, read_pe_synchash, read_pe_skey_vc, @@ -355,10 +352,8 @@ namespace libtorrent { read_pe_pad, read_pe_ia, init_bt_handshake, - read_protocol_identifier, -#else - read_protocol_identifier = 0, #endif + read_protocol_identifier, read_info_hash, read_peer_id, @@ -391,7 +386,7 @@ namespace libtorrent { // only done once per connection bool m_sent_allowed_fast:1; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // this is set to true after the encryption method has been // successfully negotiated (either plaintext or rc4), to signal // automatic encryption/decryption. @@ -441,7 +436,7 @@ namespace libtorrent { std::vector m_payloads; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // initialized during write_pe1_2_dhkey, and destroyed on // creation of m_enc_handler. Cannot reinitialize once // initialized. @@ -465,15 +460,12 @@ namespace libtorrent { // the sync hash (hash("req1",secret)). Destroyed after the // sync step. std::unique_ptr m_sync_hash; -#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) // used to disconnect peer if sync points are not found within // the maximum number of bytes int m_sync_bytes_read = 0; #endif -#ifndef TORRENT_DISABLE_EXTENSIONS // the message ID for upload only message // 0 if not supported std::uint8_t m_upload_only_id = 0; @@ -488,10 +480,11 @@ namespace libtorrent { // 0 if not supported std::uint8_t m_share_mode_id = 0; +#ifndef TORRENT_DISABLE_EXTENSIONS std::weak_ptr m_ut_pex; +#endif std::array m_reserved_bits; -#endif }; } diff --git a/include/libtorrent/extensions.hpp b/include/libtorrent/extensions.hpp index 6ee533561..5aa7f0709 100644 --- a/include/libtorrent/extensions.hpp +++ b/include/libtorrent/extensions.hpp @@ -160,9 +160,6 @@ POSSIBILITY OF SUCH DAMAGE. // // .. _`alert section`: reference-Alerts.html - -#ifndef TORRENT_DISABLE_EXTENSIONS - #include #include "libtorrent/config.hpp" @@ -175,6 +172,8 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { +#ifndef TORRENT_DISABLE_EXTENSIONS + // these are flags that can be returned by implemented_features() // indicating which callbacks this plugin is interested in using feature_flags_t = flags::bitfield_flag; @@ -469,6 +468,9 @@ namespace libtorrent { // no other plugin will have this function called. virtual bool write_request(peer_request const&) { return false; } }; +#endif // TORRENT_DISABLE_EXTENSIONS + +#if !defined TORRENT_DISABLE_ENCRYPTION struct TORRENT_EXPORT crypto_plugin { @@ -504,8 +506,8 @@ namespace libtorrent { // advance the next step of decryption. default is 0 virtual std::tuple decrypt(span> /*receive_vec*/) = 0; }; + +#endif // TORRENT_DISABLE_ENCRYPTION } -#endif - #endif // TORRENT_EXTENSIONS_HPP_INCLUDED diff --git a/include/libtorrent/pe_crypto.hpp b/include/libtorrent/pe_crypto.hpp index 34774374f..3c3b2e877 100644 --- a/include/libtorrent/pe_crypto.hpp +++ b/include/libtorrent/pe_crypto.hpp @@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION #ifndef TORRENT_PE_CRYPTO_HPP_INCLUDED #define TORRENT_PE_CRYPTO_HPP_INCLUDED diff --git a/include/libtorrent/receive_buffer.hpp b/include/libtorrent/receive_buffer.hpp index 16f327716..53c64c993 100644 --- a/include/libtorrent/receive_buffer.hpp +++ b/include/libtorrent/receive_buffer.hpp @@ -88,7 +88,7 @@ struct TORRENT_EXTRA_EXPORT receive_buffer // This is the "current" packet. span get() const; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // returns the buffer from the current packet start position to the last // received byte (possibly part of another packet) span mutable_buffer(); @@ -159,7 +159,7 @@ private: buffer m_recv_buffer; }; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // Wraps a receive_buffer to provide the ability to inject // possibly authenticated crypto beneath the bittorrent protocol. // When authenticated crypto is in use the wrapped receive_buffer diff --git a/include/libtorrent/torrent_peer.hpp b/include/libtorrent/torrent_peer.hpp index c0a035ce4..e2fec86ad 100644 --- a/include/libtorrent/torrent_peer.hpp +++ b/include/libtorrent/torrent_peer.hpp @@ -157,7 +157,7 @@ namespace libtorrent { peer_source_flags_t peer_source() const { return peer_source_flags_t(source); } -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // Hints encryption support of torrent_peer. Only effective // for and when the outgoing encryption policy // allows both encrypted and non encrypted diff --git a/simulation/test_dht_bootstrap.cpp b/simulation/test_dht_bootstrap.cpp index de650fa8f..63f4cd02c 100644 --- a/simulation/test_dht_bootstrap.cpp +++ b/simulation/test_dht_bootstrap.cpp @@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace sim; +#ifndef TORRENT_DISABLE_DHT + struct sim_config : sim::default_config { chrono::high_resolution_clock::duration hostname_lookup( @@ -104,3 +106,6 @@ TORRENT_TEST(dht_bootstrap) TEST_CHECK(a.dict_find_int_value("bs", -1) == 1); } +#else +TORRENT_TEST(disabled) {} +#endif // TORRENT_DISABLE_DHT diff --git a/simulation/test_dht_rate_limit.cpp b/simulation/test_dht_rate_limit.cpp index b32a26b06..61b126aed 100644 --- a/simulation/test_dht_rate_limit.cpp +++ b/simulation/test_dht_rate_limit.cpp @@ -218,7 +218,7 @@ TORRENT_TEST(dht_rate_limit) TEST_EQUAL(cnt[counters::dht_messages_in_dropped] + cnt[counters::dht_ping_in], num_packets); -#endif // #if !defined TORRENT_DISABLE_EXTENSIONS && !defined TORRENT_DISABLE_DHT +#endif // #if !defined TORRENT_DISABLE_DHT } // TODO: put test here to take advantage of existing code, refactor diff --git a/simulation/test_dht_storage.cpp b/simulation/test_dht_storage.cpp index 8cbc95fd7..4dc8d0d9b 100644 --- a/simulation/test_dht_storage.cpp +++ b/simulation/test_dht_storage.cpp @@ -30,9 +30,11 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TORRENT_DISABLE_DHT #include "test.hpp" + +#ifndef TORRENT_DISABLE_DHT + #include "settings.hpp" #include "setup_transfer.hpp" // for ep() #include "libtorrent/config.hpp" @@ -210,5 +212,6 @@ TORRENT_TEST(dht_storage_infohashes_sample) boost::system::error_code ec; sim.run(ec); } - +#else +TORRENT_TEST(disabled) {} #endif // TORRENT_DISABLE_DHT diff --git a/simulation/test_metadata_extension.cpp b/simulation/test_metadata_extension.cpp index 44f0a3913..6b02470cd 100644 --- a/simulation/test_metadata_extension.cpp +++ b/simulation/test_metadata_extension.cpp @@ -44,6 +44,8 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; +#ifndef TORRENT_DISABLE_EXTENSIONS + enum flags_t { // disconnect immediately after receiving the metadata (to test that @@ -210,4 +212,6 @@ TORRENT_TEST(ut_metadata_upload_only_disconnect_readd) { run_metadata_test(upload_only | disconnect | readd); } - +#else +TORRENT_TEST(disabled) {} +#endif // TORRENT_DISABLE_EXTENSIONS diff --git a/simulation/test_pe_crypto.cpp b/simulation/test_pe_crypto.cpp index b33090e4a..c81585a31 100644 --- a/simulation/test_pe_crypto.cpp +++ b/simulation/test_pe_crypto.cpp @@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "settings.hpp" #include "setup_swarm.hpp" -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION using namespace lt; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index ccc363e56..2c41452d5 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -64,14 +64,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/string_util.hpp" // for search #include "libtorrent/aux_/generate_peer_id.hpp" -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION #include "libtorrent/pe_crypto.hpp" #include "libtorrent/hasher.hpp" #endif namespace libtorrent { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION namespace { constexpr std::size_t handshake_len = 68; @@ -150,7 +150,7 @@ namespace { , m_sent_bitfield(false) , m_sent_handshake(false) , m_sent_allowed_fast(false) -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION , m_encrypted(false) , m_rc4_encrypted(false) , m_recv_buffer(peer_connection::m_recv_buffer) @@ -161,9 +161,7 @@ namespace { peer_log(peer_log_alert::info, "CONSTRUCT", "bt_peer_connection"); #endif -#ifndef TORRENT_DISABLE_EXTENSIONS m_reserved_bits.fill(0); -#endif } void bt_peer_connection::start() @@ -178,7 +176,7 @@ namespace { bt_peer_connection::~bt_peer_connection() = default; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION void bt_peer_connection::switch_send_crypto(std::shared_ptr crypto) { if (m_enc_handler.switch_send_crypto(std::move(crypto), send_buffer_size() - get_send_barrier())) @@ -211,7 +209,7 @@ namespace { // packet, or at least back-to-back packets cork c_(*this); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION std::uint8_t out_policy = std::uint8_t(m_settings.get_int(settings_pack::out_enc_policy)); @@ -304,13 +302,11 @@ namespace { // will send their bitfield when the handshake // is done std::shared_ptr t = associated_torrent().lock(); -#ifndef TORRENT_DISABLE_EXTENSIONS if (!t->share_mode()) { bool const upload_only_enabled = t->is_upload_only() && !t->super_seeding(); send_upload_only(upload_only_enabled); } -#endif if (m_sent_bitfield) return; @@ -449,7 +445,7 @@ namespace { if (is_utp(*get_socket())) p.flags |= peer_info::utp_socket; if (is_ssl(*get_socket())) p.flags |= peer_info::ssl_socket; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION if (m_encrypted) { p.flags |= m_rc4_encrypted @@ -471,7 +467,7 @@ namespace { return !m_sent_handshake; } -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION void bt_peer_connection::write_pe1_2_dhkey() { @@ -671,7 +667,7 @@ namespace { m_rc4->decrypt(buf); } -#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#endif // #if !defined TORRENT_DISABLE_ENCRYPTION void bt_peer_connection::write_handshake() { @@ -702,10 +698,8 @@ namespace { *(ptr + 7) |= 0x01; #endif -#ifndef TORRENT_DISABLE_EXTENSIONS // we support extensions *(ptr + 5) |= 0x10; -#endif if (m_settings.get_bool(settings_pack::support_merkle_torrents)) { @@ -1327,7 +1321,6 @@ namespace { // -------- RENDEZVOUS --------- // ----------------------------- -#ifndef TORRENT_DISABLE_EXTENSIONS void bt_peer_connection::on_holepunch() { INVARIANT_CHECK; @@ -1540,13 +1533,11 @@ namespace { stats_counters().inc_stats_counter(counters::num_outgoing_extended); } -#endif // TORRENT_DISABLE_EXTENSIONS // ----------------------------- // --------- EXTENDED ---------- // ----------------------------- -#ifndef TORRENT_DISABLE_EXTENSIONS void bt_peer_connection::on_extended(int received) { INVARIANT_CHECK; @@ -1652,12 +1643,14 @@ namespace { , "msg: %d size: %d", extended_id, m_recv_buffer.packet_size()); #endif +#ifndef TORRENT_DISABLE_EXTENSIONS for (auto const& e : m_extensions) { if (e->on_extended(m_recv_buffer.packet_size() - 2, extended_id , recv_buffer)) return; } +#endif disconnect(errors::invalid_message, operation_t::bittorrent, 2); } @@ -1696,6 +1689,7 @@ namespace { } #endif +#ifndef TORRENT_DISABLE_EXTENSIONS for (auto i = m_extensions.begin(); !m_extensions.empty() && i != m_extensions.end();) { @@ -1707,6 +1701,7 @@ namespace { ++i; } if (is_disconnecting()) return; +#endif // upload_only if (bdecode_node const m = root.dict_find_dict("m")) @@ -1782,7 +1777,6 @@ namespace { stats_counters().inc_stats_counter(counters::num_incoming_ext_handshake); } -#endif // TORRENT_DISABLE_EXTENSIONS bool bt_peer_connection::dispatch_message(int const received) { @@ -1833,9 +1827,7 @@ namespace { case msg_have_none: on_have_none(received); break; case msg_reject_request: on_reject_request(received); break; case msg_allowed_fast: on_allowed_fast(received); break; -#ifndef TORRENT_DISABLE_EXTENSIONS case msg_extended: on_extended(received); break; -#endif default: { #ifndef TORRENT_DISABLE_EXTENSIONS @@ -1880,7 +1872,6 @@ namespace { void bt_peer_connection::write_upload_only(bool const enabled) { -#ifndef TORRENT_DISABLE_EXTENSIONS INVARIANT_CHECK; #if TORRENT_USE_ASSERTS @@ -1902,12 +1893,8 @@ namespace { send_buffer(msg); stats_counters().inc_stats_counter(counters::num_outgoing_extended); -#else - TORRENT_UNUSED(enabled); -#endif } -#ifndef TORRENT_DISABLE_EXTENSIONS void bt_peer_connection::write_share_mode() { INVARIANT_CHECK; @@ -1923,7 +1910,6 @@ namespace { stats_counters().inc_stats_counter(counters::num_outgoing_extended); } -#endif void bt_peer_connection::write_keepalive() { @@ -2073,7 +2059,6 @@ namespace { stats_counters().inc_stats_counter(counters::num_outgoing_bitfield); } -#ifndef TORRENT_DISABLE_EXTENSIONS void bt_peer_connection::write_extensions() { INVARIANT_CHECK; @@ -2147,12 +2132,14 @@ namespace { && t->share_mode()) handshake["share_mode"] = 1; +#ifndef TORRENT_DISABLE_EXTENSIONS // loop backwards, to make the first extension be the last // to fill in the handshake (i.e. give the first extensions priority) for (auto const& e : m_extensions) { e->add_handshake(handshake); } +#endif #ifndef NDEBUG // make sure there are not conflicting extensions @@ -2191,7 +2178,6 @@ namespace { } #endif } -#endif void bt_peer_connection::write_choke() { @@ -2246,7 +2232,6 @@ namespace { void bt_peer_connection::write_dont_have(piece_index_t const index) { -#ifndef TORRENT_DISABLE_EXTENSIONS INVARIANT_CHECK; TORRENT_ASSERT(associated_torrent().lock()->valid_metadata()); TORRENT_ASSERT(index >= piece_index_t(0)); @@ -2265,9 +2250,6 @@ namespace { send_buffer(msg); stats_counters().inc_stats_counter(counters::num_outgoing_extended); -#else - TORRENT_UNUSED(index); -#endif } void bt_peer_connection::write_piece(peer_request const& r, disk_buffer_holder buffer) @@ -2370,7 +2352,7 @@ namespace { // packet, or at least back-to-back packets cork c_(*this); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION if (!m_enc_handler.is_recv_plaintext()) { int const consumed = m_enc_handler.decrypt(m_recv_buffer, bytes_transferred); @@ -2428,7 +2410,7 @@ namespace { span recv_buffer = m_recv_buffer.get(); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION // m_state is set to read_pe_dhkey in initial state // (read_protocol_identifier) for incoming, or in constructor // for outgoing @@ -2949,7 +2931,7 @@ namespace { } } -#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#endif // #if !defined TORRENT_DISABLE_ENCRYPTION if (m_state == state_t::read_protocol_identifier) { @@ -2966,7 +2948,7 @@ namespace { if (packet_size != 19 || std::memcmp(recv_buffer.begin(), protocol_string, 20) != 0) { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "ENCRYPTION" , "unrecognized protocol header"); @@ -3016,7 +2998,7 @@ namespace { } else { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION TORRENT_ASSERT(m_state != state_t::read_pe_dhkey); if (!is_outgoing() @@ -3070,11 +3052,10 @@ namespace { } #endif -#ifndef TORRENT_DISABLE_EXTENSIONS std::memcpy(m_reserved_bits.data(), recv_buffer.begin(), 8); if (recv_buffer[5] & 0x10) m_supports_extensions = true; -#endif + if (recv_buffer[7] & 0x01) m_supports_dht_port = true; @@ -3213,9 +3194,9 @@ namespace { } } if (is_disconnecting()) return; +#endif if (m_supports_extensions) write_extensions(); -#endif #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::incoming_message, "HANDSHAKE", "connection ready"); @@ -3224,7 +3205,7 @@ namespace { if (peer_info_struct()) t->clear_failcount(peer_info_struct()); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION // Toggle pe_support back to false if this is a // standard successful connection if (is_outgoing() && !m_encrypted && @@ -3351,7 +3332,7 @@ namespace { TORRENT_ASSERT(!m_recv_buffer.packet_finished()); } -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION std::tuple>> bt_peer_connection::hit_send_barrier( span> iovec) @@ -3432,7 +3413,7 @@ namespace { { std::shared_ptr t = associated_torrent().lock(); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPTION TORRENT_ASSERT( (bool(m_state != state_t::read_pe_dhkey) || m_dh_key_exchange.get()) || !is_outgoing()); diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 2161249f6..ec7da00ef 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -131,7 +131,7 @@ namespace libtorrent { , (tracker_req().event != tracker_request::none) ? event_string[tracker_req().event - 1] : "" , tracker_req().num_want); url += str; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION if (settings.get_int(settings_pack::in_enc_policy) != settings_pack::pe_disabled && settings.get_bool(settings_pack::announce_crypto_support)) url += "&supportcrypto=1"; diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index 46238fed4..8fb1e02c7 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION #include #include @@ -411,4 +411,4 @@ std::size_t rc4_encrypt(unsigned char *out, std::size_t outlen, rc4 *state) } // namespace libtorrent -#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#endif // TORRENT_DISABLE_ENCRYPION diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 61ad3b9a7..517a3a89d 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -4275,7 +4275,7 @@ namespace libtorrent { if (m_outgoing) m_counters.inc_stats_counter(counters::error_outgoing_peers); else m_counters.inc_stats_counter(counters::error_incoming_peers); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION if (type() == connection_type::bittorrent && op != operation_t::connect) { auto* bt = static_cast(this); diff --git a/src/peer_connection_handle.cpp b/src/peer_connection_handle.cpp index 7dbc1126a..4d7367528 100644 --- a/src/peer_connection_handle.cpp +++ b/src/peer_connection_handle.cpp @@ -315,7 +315,7 @@ bool bt_peer_connection_handle::support_extensions() const bool bt_peer_connection_handle::supports_encryption() const { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION std::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); return pc->supports_encryption(); @@ -326,7 +326,7 @@ bool bt_peer_connection_handle::supports_encryption() const void bt_peer_connection_handle::switch_send_crypto(std::shared_ptr crypto) { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION std::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->switch_send_crypto(std::move(crypto)); @@ -337,7 +337,7 @@ void bt_peer_connection_handle::switch_send_crypto(std::shared_ptr crypto) { -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION std::shared_ptr pc = native_handle(); TORRENT_ASSERT(pc); pc->switch_recv_crypto(std::move(crypto)); diff --git a/src/peer_list.cpp b/src/peer_list.cpp index fc014089d..50f7c378e 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -922,7 +922,7 @@ namespace libtorrent { if (m_round_robin >= iter - m_peers.begin()) ++m_round_robin; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION if (flags & pex_encryption) p->pe_support = true; #endif if (flags & pex_seed) diff --git a/src/receive_buffer.cpp b/src/receive_buffer.cpp index e15620e05..80ffbefa5 100644 --- a/src/receive_buffer.cpp +++ b/src/receive_buffer.cpp @@ -150,7 +150,7 @@ span receive_buffer::get() const return aux::typed_span(m_recv_buffer).subspan(m_recv_start, m_recv_pos); } -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION span receive_buffer::mutable_buffer() { INVARIANT_CHECK; @@ -230,7 +230,7 @@ void receive_buffer::reset(int const packet_size) m_packet_size = packet_size; } -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION bool crypto_receive_buffer::packet_finished() const { if (m_recv_pos == INT_MAX) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index a86ff3d97..dbf0280fc 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4460,7 +4460,7 @@ namespace aux { trigger_auto_manage(); } -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION torrent const* session_impl::find_encrypted_torrent(sha1_hash const& info_hash , sha1_hash const& xor_mask) { @@ -4803,7 +4803,7 @@ namespace aux { m_torrents.insert(std::make_pair(params.info_hash, torrent_ptr)); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION static char const req2[4] = {'r', 'e', 'q', '2'}; hasher h(req2); h.update(params.info_hash); @@ -5191,7 +5191,7 @@ namespace aux { m_torrents.erase(i); tptr->removed(); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION static char const req2[4] = {'r', 'e', 'q', '2'}; hasher h(req2); h.update(tptr->info_hash()); @@ -6092,13 +6092,13 @@ namespace aux { #endif -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION void session_impl::add_obfuscated_hash(sha1_hash const& obfuscated , std::weak_ptr const& t) { m_obfuscated_torrents.insert(std::make_pair(obfuscated, t.lock())); } -#endif // !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#endif // TORRENT_DISABLE_ENCRYPION bool session_impl::is_listening() const { diff --git a/src/torrent.cpp b/src/torrent.cpp index 1b5ac12b9..0f01f7d8d 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -490,7 +490,7 @@ bool is_downloading_state(int const st) aux::random_shuffle(ws.begin(), ws.end()); for (auto& w : ws) m_web_seeds.push_back(std::move(w)); -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION static char const req2[4] = {'r', 'e', 'q', '2'}; hasher h(req2); h.update(m_torrent_file->info_hash()); diff --git a/src/torrent_peer.cpp b/src/torrent_peer.cpp index f594baeab..2519011d1 100644 --- a/src/torrent_peer.cpp +++ b/src/torrent_peer.cpp @@ -151,7 +151,7 @@ namespace libtorrent { , fast_reconnects(0) , trust_points(0) , source(static_cast(src)) -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION // assume no support in order to // prefer opening non-encrypted // connections. If it fails, we'll diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 28bd6ea6e..ef2feed70 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_DISABLE_EXTENSIONS -namespace libtorrent {namespace { +namespace libtorrent { namespace { const char extension_name[] = "ut_pex"; @@ -167,7 +167,7 @@ namespace libtorrent {namespace { // used as a rendezvous point in case direct // connections to the peer fail pex_flags_t flags = p->is_seed() ? pex_seed : pex_flags_t{}; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION flags |= p->supports_encryption() ? pex_encryption : pex_flags_t{}; #endif flags |= is_utp(*p->get_socket()) ? pex_utp : pex_flags_t{}; @@ -552,7 +552,7 @@ namespace libtorrent {namespace { // used as a rendezvous point in case direct // connections to the peer fail int flags = p->is_seed() ? 2 : 0; -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION flags |= p->supports_encryption() ? 1 : 0; #endif flags |= is_utp(*p->get_socket()) ? 4 : 0; diff --git a/test/test_dht_storage.cpp b/test/test_dht_storage.cpp index 0147d8352..a7c71a9c0 100644 --- a/test/test_dht_storage.cpp +++ b/test/test_dht_storage.cpp @@ -30,8 +30,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TORRENT_DISABLE_DHT - #include "libtorrent/config.hpp" #include "libtorrent/session.hpp" #include "libtorrent/kademlia/dht_settings.hpp" @@ -54,6 +52,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "test.hpp" #include "setup_transfer.hpp" +#ifndef TORRENT_DISABLE_DHT + using namespace lt; using namespace lt::dht; @@ -505,5 +505,6 @@ TORRENT_TEST(infohashes_sample_dist) std::printf("infohashes set size: %d\n", int(infohash_set.size())); TEST_CHECK(infohash_set.size() > 500); } - +#else +TORRENT_TEST(dummy) {} #endif diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index 4ff462446..6feab4a97 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -283,11 +283,7 @@ void do_handshake(tcp::socket& s, sha1_hash const& ih, char* buffer) // check for extension protocol support bool const lt_extension_protocol = (extensions[5] & 0x10) != 0; -#ifndef TORRENT_DISABLE_EXTENSIONS TEST_CHECK(lt_extension_protocol == true); -#else - TEST_CHECK(lt_extension_protocol == false); -#endif // check for DHT support bool const dht_support = (extensions[7] & 0x1) != 0; @@ -363,6 +359,7 @@ entry read_extension_handshake(tcp::socket& s, char* recv_buffer, int size) } } +#ifndef TORRENT_DISABLE_EXTENSIONS void send_ut_metadata_msg(tcp::socket& s, int ut_metadata_msg, int type, int piece) { std::vector buf; @@ -414,6 +411,7 @@ entry read_ut_metadata_msg(tcp::socket& s, char* recv_buffer, int size) return bdecode(recv_buffer + 2, recv_buffer + len); } } +#endif // TORRENT_DISABLE_EXTENSIONS std::shared_ptr setup_peer(tcp::socket& s, sha1_hash& ih , std::shared_ptr& ses, bool incoming = true @@ -794,7 +792,6 @@ TORRENT_TEST(multiple_have_all) print_session_log(*ses); } -#ifndef TORRENT_DISABLE_EXTENSIONS // makes sure that pieces that are lost are not requested TORRENT_TEST(dont_have) { @@ -896,6 +893,43 @@ TORRENT_TEST(dont_have) print_session_log(*ses); } +TORRENT_TEST(extension_handshake) +{ + using namespace lt::detail; + + sha1_hash ih; + std::shared_ptr ses; + io_service ios; + tcp::socket s(ios); + std::shared_ptr ti = setup_peer(s, ih, ses); + + char recv_buffer[1000]; + do_handshake(s, ih, recv_buffer); + print_session_log(*ses); + send_have_all(s); + print_session_log(*ses); + + entry extensions; + send_extension_handshake(s, extensions); + + extensions = read_extension_handshake(s, recv_buffer, sizeof(recv_buffer)); + + std::cout << extensions << '\n'; + + // these extensions are built-in + TEST_CHECK(extensions["m"]["lt_donthave"].integer() != 0); + TEST_CHECK(extensions["m"]["share_mode"].integer() != 0); + TEST_CHECK(extensions["m"]["upload_only"].integer() != 0); + TEST_CHECK(extensions["m"]["ut_holepunch"].integer() != 0); + + // these require extensions to be enabled +#ifndef TORRENT_DISABLE_EXTENSIONS + TEST_CHECK(extensions["m"]["ut_metadata"].integer() != 0); + TEST_CHECK(extensions["m"]["ut_pex"].integer() != 0); +#endif +} + +#ifndef TORRENT_DISABLE_EXTENSIONS // TEST metadata extension messages and edge cases // this tests sending a request for a metadata piece that's too high. This is @@ -904,8 +938,6 @@ TORRENT_TEST(invalid_metadata_request) { using namespace lt::detail; - std::cout << "\n === test invalid metadata ===\n" << std::endl; - sha1_hash ih; std::shared_ptr ses; io_service ios; @@ -954,6 +986,8 @@ TORRENT_TEST(invalid_metadata_request) print_session_log(*ses); } +#endif // TORRENT_DISABLE_EXTENSIONS + TORRENT_TEST(invalid_request) { @@ -1030,7 +1064,5 @@ TORRENT_TEST(incoming_have_all) have_all_test(false); } -#endif // TORRENT_DISABLE_EXTENSIONS - // TODO: test sending invalid requests (out of bound piece index, offsets and // sizes) diff --git a/test/test_pe_crypto.cpp b/test/test_pe_crypto.cpp index 2a5987e39..6e5d1a82b 100644 --- a/test/test_pe_crypto.cpp +++ b/test/test_pe_crypto.cpp @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include "test.hpp" -#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#if !defined TORRENT_DISABLE_ENCRYPION namespace { diff --git a/test/test_privacy.cpp b/test/test_privacy.cpp index 468eb6139..3224293b8 100644 --- a/test/test_privacy.cpp +++ b/test/test_privacy.cpp @@ -73,7 +73,7 @@ constexpr flags_t expect_peer_connection = 6_bit; constexpr flags_t dont_proxy_peers = 10_bit; constexpr flags_t dont_proxy_trackers = 11_bit; -session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, flags_t const flags) +session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, flags_t flags) { #ifdef TORRENT_DISABLE_DHT // if DHT is disabled, we won't get any requests to it diff --git a/test/test_session.cpp b/test/test_session.cpp index 0aba7ad43..dfe5819c7 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -424,7 +424,9 @@ TORRENT_TEST(save_state_peer_id) TEST_EQUAL(ses.get_settings().get_str(settings_pack::peer_fingerprint), "foobar"); } -#ifndef TORRENT_DISABLE_LOGGING +#if !defined TORRENT_DISABLE_LOGGING + +#if !defined TORRENT_DISABLE_DHT auto const count_dht_inits = [](session& ses) { @@ -496,6 +498,8 @@ TORRENT_TEST(init_dht_empty_bootstrap) TEST_EQUAL(count, 1); } +#endif // TORRENT_DISABLE_DHT + TORRENT_TEST(reopen_network_sockets) { auto count_alerts = [](session& ses, int const listen, int const portmap) diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 28d30a968..578cf99ca 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -604,16 +604,12 @@ void test_malicious_peer() } } // anonymous namespace -#endif // TORRENT_USE_OPENSSL TORRENT_TEST(malicious_peer) { -#ifdef TORRENT_USE_OPENSSL test_malicious_peer(); -#endif } -#ifdef TORRENT_USE_OPENSSL TORRENT_TEST(utp_config0) { test_ssl(0, true); } TORRENT_TEST(utp_config1) { test_ssl(1, true); } TORRENT_TEST(utp_config2) { test_ssl(2, true); } @@ -633,5 +629,7 @@ TORRENT_TEST(tcp_config5) { test_ssl(5, false); } TORRENT_TEST(tcp_config6) { test_ssl(6, false); } TORRENT_TEST(tcp_config7) { test_ssl(7, false); } TORRENT_TEST(tcp_config8) { test_ssl(8, false); } -#endif +#else +TORRENT_TEST(disabled) {} +#endif // TORRENT_USE_OPENSSL