diff --git a/Jamfile b/Jamfile index 145e79db0..a3e944fdc 100644 --- a/Jamfile +++ b/Jamfile @@ -45,59 +45,6 @@ else VERSION = 1.2.0 ; -# rule for linking the correct libraries depending -# on features and target-os -rule link-openssl ( properties * ) -{ - local result ; - - # openssl libraries, if enabled - # exclude gcc from a regular windows build to make mingw - # link against the regular unix library name - if pre1.1 in $(properties) - && windows in $(properties) - && ! gcc in $(properties) - { - result += ssleay32 libeay32 ; - } - else - { - # on windows the library names were changed to be in line with other - # system starting with OpenSSL 1.1 - result += crypto ssl ; - } - - if libcrypto in $(properties) - { - # exclude gcc from a regular windows build to make mingw - # link against the regular unix library name - if pre1.1 in $(properties) - && windows in $(properties) - && ! gcc in $(properties) - { - # it should be possible to cleanup this list, but this is safe for now - result += libeay32 ; - } - else - { - result += crypto ; - } - } - - # windows needs some more libraries when using openSSL - if windows in $(properties) - && ! gcc in $(properties) - { - result += advapi32 - user32 - shell32 - gdi32 - ; - } - echo "link openssl = " $(result) ; - return $(result) ; -} - rule linking ( properties * ) { local result ; @@ -419,7 +366,6 @@ rule openssl-lib-path ( properties * ) local result ; result += $(OPENSSL_LIB) ; - echo "openssl-lib-path = " $(result) ; return $(result) ; } @@ -454,7 +400,6 @@ rule openssl-include-path ( properties * ) local result ; result += $(OPENSSL_INCLUDE) ; - echo "openssl-include-path = " $(result) ; return $(result) ; } @@ -588,16 +533,51 @@ variant test_arm : debug on on ; -lib crypto : : crypto @openssl-lib-path : : @openssl-include-path ; -lib ssl : : ssl crypto @openssl-lib-path : : @openssl-include-path ; - -# required for openssl on windows -lib ssleay32 : : ssleay32 @openssl-lib-path : : @openssl-include-path ; -lib libeay32 : : libeay32 @openssl-lib-path : : @openssl-include-path ; lib advapi32 : : advapi32 ; lib user32 : : user32 ; lib shell32 : : shell32 ; lib gdi32 : : gdi32 ; +lib z : : shared z ; + +# windows variants for libssl and libcrypto (they have different names and some +# additional dependencies) +lib crypto + : # sources + : # requirements + windows + pre1.1 + libeay32 + @openssl-lib-path + : # default-build + : # usage-requirements + @openssl-include-path + advapi32 + user32 + shell32 + gdi32 + ; + +lib ssl + : # sources + : # requirements + windows + pre1.1 + ssleay32 + crypto + @openssl-lib-path + : # default-build + : # usage-requirments + @openssl-include-path + advapi32 + user32 + shell32 + gdi32 + ; + + +lib crypto : : crypto z @openssl-lib-path : : @openssl-include-path ; +lib ssl : : ssl crypto @openssl-lib-path : : @openssl-include-path ; + lib dbghelp : : dbghelp ; # required for networking on beos @@ -609,8 +589,7 @@ lib libiconv : : iconv shared /usr/local/lib ; # openssl on linux/bsd etc. lib gcrypt : : gcrypt shared /opt/local/lib ; - -alias openssl-libraries : : : : @link-openssl ; +lib dl : : shared dl ; lib libsocket : : libnsl socket shared /usr/sfw/lib shared ; lib libnsl : : nsl shared /usr/sfw/lib shared ; @@ -825,8 +804,9 @@ lib torrent shared:TORRENT_BUILDING_SHARED BOOST_NO_DEPRECATED shared:BOOST_SYSTEM_SOURCE - openssl:openssl-libraries - libcrypto:openssl-libraries + openssl:ssl + openssl:crypto + libcrypto:crypto on:src/kademlia/$(KADEMLIA_SOURCES).cpp on:ed25519/src/$(ED25519_SOURCES).cpp diff --git a/bindings/python/Jamfile b/bindings/python/Jamfile index 8701a21cd..dde0b180d 100644 --- a/bindings/python/Jamfile +++ b/bindings/python/Jamfile @@ -152,6 +152,8 @@ my-python-extension libtorrent darwin:-Wno-deprecated-declarations darwin:-Wno-unused-command-line-argument @libtorrent_linking + openssl:/torrent//ssl + openssl:/torrent//crypto : # default-build all : # usage-requirements diff --git a/bindings/python/src/error_code.cpp b/bindings/python/src/error_code.cpp index 36f34af23..bd799bd59 100644 --- a/bindings/python/src/error_code.cpp +++ b/bindings/python/src/error_code.cpp @@ -49,7 +49,10 @@ namespace boost #include #if defined TORRENT_USE_OPENSSL -#include +#include +#endif +#if TORRENT_USE_I2P +#include #endif using namespace boost::python; diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index ccc79e96d..e969eee05 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -49,9 +49,14 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifdef TORRENT_USE_OPENSSL -#include "libtorrent/aux_/disable_warnings_push.hpp" -#include -#include "libtorrent/aux_/disable_warnings_pop.hpp" +// there is no forward declaration header for asio +namespace boost { +namespace asio { +namespace ssl { + class context; +} +} +} #endif namespace libtorrent { diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index 4bd69af58..b03035e26 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -39,7 +39,14 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifdef TORRENT_USE_OPENSSL -#include +// there is no forward declaration header for asio +namespace boost { +namespace asio { +namespace ssl { + struct context; +} +} +} #endif #include "libtorrent/aux_/disable_warnings_pop.hpp" diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 02fbf14d7..9f25af61f 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -73,6 +73,18 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/vector.hpp" #include "libtorrent/aux_/deferred_handler.hpp" +#ifdef TORRENT_USE_OPENSSL +// there is no forward declaration header for asio +namespace boost { +namespace asio { +namespace ssl { + class context; + class verify_context; +} +} +} +#endif + #if TORRENT_COMPLETE_TYPES_REQUIRED #include "libtorrent/peer_connection.hpp" #endif diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 5c1e30f39..f3dc3e16b 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -46,9 +46,14 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifdef TORRENT_USE_OPENSSL -#include "libtorrent/aux_/disable_warnings_push.hpp" -#include -#include "libtorrent/aux_/disable_warnings_pop.hpp" +// there is no forward declaration header for asio +namespace boost { +namespace asio { +namespace ssl { + class context; +} +} +} #endif #include "libtorrent/socket.hpp" diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index e3b0cd71d..071a98219 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -36,11 +36,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/broadcast_socket.hpp" -#include "libtorrent/http_connection.hpp" #include "libtorrent/deadline_timer.hpp" #include "libtorrent/enum_net.hpp" #include "libtorrent/resolver.hpp" #include "libtorrent/debug.hpp" +#include "libtorrent/string_util.hpp" #include "libtorrent/aux_/portmap.hpp" #include "libtorrent/aux_/vector.hpp" @@ -49,6 +49,8 @@ POSSIBILITY OF SUCH DAMAGE. #include namespace libtorrent { + struct http_connection; + class http_parser; namespace upnp_errors { @@ -256,16 +258,12 @@ private: struct rootdevice { -#if TORRENT_USE_ASSERTS - rootdevice() {} - ~rootdevice() - { - TORRENT_ASSERT(magic == 1337); - magic = 0; - } - rootdevice(rootdevice const&) = default; - rootdevice& operator=(rootdevice const&) = default; -#endif + rootdevice(); + ~rootdevice(); + rootdevice(rootdevice const&); + rootdevice& operator=(rootdevice const&); + rootdevice(rootdevice&&); + rootdevice& operator=(rootdevice&&); // the interface url, through which the list of // supported interfaces are fetched @@ -310,13 +308,7 @@ private: #if TORRENT_USE_ASSERTS int magic = 1337; #endif - void close() const - { - TORRENT_ASSERT(magic == 1337); - if (!upnp_connection) return; - upnp_connection->close(); - upnp_connection.reset(); - } + void close() const; bool operator<(rootdevice const& rhs) const { return url < rhs.url; } diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 124947cf5..00a3b216b 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -1185,7 +1185,20 @@ void block_cache::clear(tailqueue& jobs) for (int i = 0; i < cached_piece_entry::num_lrus; ++i) m_lru[i].get_all(); - m_pieces.clear(); + // it's not ok to erase pieces with a refcount > 0 + // since we're cancelling all jobs though, it shouldn't be too bad + // to let the jobs already running complete. + for (cache_t::iterator i = m_pieces.begin(); i != m_pieces.end();) + { + if (i->refcount == 0 && i->piece_refcount == 0) + { + i = m_pieces.erase(i); + } + else + { + ++i; + } + } } void block_cache::move_to_ghost(cached_piece_entry* pe) diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 28e4630a2..3aef6186d 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -49,6 +49,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#ifdef TORRENT_USE_OPENSSL +#include +#endif + using namespace std::placeholders; namespace libtorrent { diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 05c04baec..d7ef8bc26 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -40,6 +40,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/performance_counters.hpp" #include "libtorrent/socket_io.hpp" +#ifdef TORRENT_USE_OPENSSL +#include +#endif + using namespace std::placeholders; namespace libtorrent { diff --git a/src/upnp.cpp b/src/upnp.cpp index 8c951373f..3ef5b7e32 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -40,7 +40,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/random.hpp" #include "libtorrent/aux_/time.hpp" // for aux::time_now() #include "libtorrent/aux_/escape_string.hpp" // for convert_from_native +#include "libtorrent/http_connection.hpp" + +#if defined TORRENT_ASIO_DEBUGGING #include "libtorrent/debug.hpp" +#endif #include "libtorrent/aux_/numeric_cast.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -70,6 +74,28 @@ namespace upnp_errors static error_code ignore_error; +upnp::rootdevice::rootdevice() {} +upnp::rootdevice::~rootdevice() +{ + TORRENT_ASSERT(magic == 1337); +#if TORRENT_USE_ASSERTS + magic = 0; +#endif +} + +upnp::rootdevice::rootdevice(rootdevice const&) = default; +upnp::rootdevice& upnp::rootdevice::operator=(rootdevice const&) = default; +upnp::rootdevice::rootdevice(rootdevice&&) = default; +upnp::rootdevice& upnp::rootdevice::operator=(rootdevice&&) = default; + +void upnp::rootdevice::close() const +{ + TORRENT_ASSERT(magic == 1337); + if (!upnp_connection) return; + upnp_connection->close(); + upnp_connection.reset(); +} + // TODO: 3 bind the broadcast socket. it would probably have to be changed to a vector of interfaces to // bind to, since the broadcast socket opens one socket per local // interface by default diff --git a/test/Jamfile b/test/Jamfile index de3a0132e..43e7f4dd3 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -143,17 +143,23 @@ test-suite libtorrent : test_enum_net.cpp test_linked_list.cpp test_stack_allocator.cpp - test_listen_socket.cpp test_file_progress.cpp test_alloca.cpp ] + [ run test_listen_socket.cpp + : : : openssl:/torrent//ssl + openssl:/torrent//crypto + ] + [ run test_piece_picker.cpp ] [ run test_dht.cpp test_dht_storage.cpp test_direct_dht.cpp test_hasher512.cpp - ] + : : : openssl:/torrent//ssl + openssl:/torrent//crypto + ] [ run test_string.cpp test_utf8.cpp @@ -183,7 +189,10 @@ test-suite libtorrent : [ run test_recheck.cpp ] [ run test_read_resume.cpp ] [ run test_resume.cpp ] - [ run test_ssl.cpp ] + [ run test_ssl.cpp : : + : openssl:/torrent//ssl + openssl:/torrent//crypto + ] [ run test_tracker.cpp ] [ run test_checking.cpp ] [ run test_url_seed.cpp ] @@ -202,7 +211,10 @@ test-suite libtorrent : [ run test_remap_files.cpp ] [ run test_utp.cpp ] [ run test_auto_unchoke.cpp ] - [ run test_http_connection.cpp ] + [ run test_http_connection.cpp : : + : openssl:/torrent//ssl + openssl:/torrent//crypto + ] [ run test_torrent.cpp ] [ run test_transfer.cpp ] [ run test_time_critical.cpp ] diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index d7bcd1c36..e3c7c6daa 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -43,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/create_torrent.hpp" #include "libtorrent/socket_io.hpp" // print_endpoint -#include "libtorrent/socket_type.hpp" #include "libtorrent/ip_filter.hpp" #include "libtorrent/session_stats.hpp" #include "libtorrent/random.hpp" @@ -57,11 +56,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "test_utils.hpp" #include "setup_transfer.hpp" -#ifdef TORRENT_USE_OPENSSL -#include -#include -#endif - #ifndef _WIN32 #include #include diff --git a/test/test_ip_voter.cpp b/test/test_ip_voter.cpp index 93aba3c0e..158d74703 100644 --- a/test/test_ip_voter.cpp +++ b/test/test_ip_voter.cpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/random.hpp" #include "libtorrent/socket_io.hpp" -#include "libtorrent/aux_/session_impl.hpp" +#include "libtorrent/aux_/session_interface.hpp" #include "libtorrent/broadcast_socket.hpp" // for supports_ipv6() #include "setup_transfer.hpp" // for rand_v4 @@ -165,8 +165,8 @@ TORRENT_TEST(ip_voter_1) TEST_CHECK(!ec); for (int i = 0; i < 50; ++i) { - ipv1.cast_vote(real_external, aux::session_impl::source_dht, rand_v4()); - ipv1.cast_vote(rand_v4(), aux::session_impl::source_dht, malicious); + ipv1.cast_vote(real_external, aux::session_interface::source_dht, rand_v4()); + ipv1.cast_vote(rand_v4(), aux::session_interface::source_dht, malicious); } TEST_CHECK(ipv1.external_address() == real_external); } @@ -205,13 +205,13 @@ TORRENT_TEST(ip_voter_2) for (int i = 0; i < 50; ++i) { - ipv2.cast_vote(real_external1, aux::session_impl::source_dht, rand_v4()); - ipv2.cast_vote(malicious_external, aux::session_impl::source_dht, malicious); + ipv2.cast_vote(real_external1, aux::session_interface::source_dht, rand_v4()); + ipv2.cast_vote(malicious_external, aux::session_interface::source_dht, malicious); #if TORRENT_USE_IPV6 if (supports_ipv6()) { - ipv6.cast_vote(real_external2, aux::session_impl::source_dht, rand_v6()); - ipv6.cast_vote(malicious_external2, aux::session_impl::source_dht, malicious2); + ipv6.cast_vote(real_external2, aux::session_interface::source_dht, rand_v6()); + ipv6.cast_vote(malicious_external2, aux::session_interface::source_dht, malicious2); } #endif } diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 7aa4ffaff..c74a275b9 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -40,7 +40,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/session.hpp" #include "libtorrent/alert_types.hpp" -#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/create_torrent.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/read_resume_data.hpp" @@ -48,6 +47,9 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/path.hpp" #include "libtorrent/aux_/storage_utils.hpp" +#include +#include // for bind + #include #include diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index cbfd7dabc..7a73116b3 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/upnp.hpp" #include "libtorrent/socket.hpp" #include "libtorrent/socket_io.hpp" // print_endpoint +#include "libtorrent/http_parser.hpp" #include "test.hpp" #include "setup_transfer.hpp" #include "libtorrent/aux_/path.hpp" diff --git a/test/test_xml.cpp b/test/test_xml.cpp index 4f1a5d27f..0047cf4b2 100644 --- a/test/test_xml.cpp +++ b/test/test_xml.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/upnp.hpp" #include "test.hpp" #include +#include char upnp_xml[] = ""