From 6343fe6a6d79cd9da3da5e978ad6f9382a4427ca Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 23 Nov 2009 08:38:50 +0000 Subject: [PATCH] optimized header dependencies to lower build time --- Jamfile | 1 + docs/manual.rst | 4 +- include/libtorrent/address.hpp | 67 +++++++ include/libtorrent/alert.hpp | 5 +- include/libtorrent/alert_types.hpp | 2 +- include/libtorrent/aux_/session_impl.hpp | 1 + include/libtorrent/broadcast_socket.hpp | 4 +- include/libtorrent/bt_peer_connection.hpp | 1 - include/libtorrent/buffer.hpp | 1 - include/libtorrent/chained_buffer.hpp | 2 +- include/libtorrent/connection_queue.hpp | 5 +- include/libtorrent/create_torrent.hpp | 6 +- include/libtorrent/disk_io_thread.hpp | 8 +- include/libtorrent/entry.hpp | 31 +--- include/libtorrent/enum_net.hpp | 4 +- include/libtorrent/error_code.hpp | 16 +- include/libtorrent/escape_string.hpp | 3 +- include/libtorrent/file.hpp | 3 +- include/libtorrent/http_connection.hpp | 4 +- include/libtorrent/http_seed_connection.hpp | 19 +- include/libtorrent/http_stream.hpp | 2 + include/libtorrent/i2p_stream.hpp | 3 + .../{random_sample.hpp => io_service.hpp} | 66 ++++--- include/libtorrent/io_service_fwd.hpp | 77 ++++++++ include/libtorrent/ip_filter.hpp | 3 +- include/libtorrent/kademlia/dht_tracker.hpp | 1 - include/libtorrent/kademlia/find_data.hpp | 3 +- include/libtorrent/kademlia/node.hpp | 5 +- include/libtorrent/kademlia/node_entry.hpp | 1 + include/libtorrent/kademlia/observer.hpp | 1 + include/libtorrent/kademlia/refresh.hpp | 2 - include/libtorrent/kademlia/rpc_manager.hpp | 5 - .../kademlia/traversal_algorithm.hpp | 1 + include/libtorrent/lsd.hpp | 2 +- include/libtorrent/natpmp.hpp | 5 +- include/libtorrent/peer_connection.hpp | 12 +- include/libtorrent/piece_picker.hpp | 1 - include/libtorrent/policy.hpp | 1 + include/libtorrent/proxy_base.hpp | 17 +- include/libtorrent/session_settings.hpp | 2 +- include/libtorrent/socket.hpp | 10 -- include/libtorrent/socket_io.hpp | 1 + include/libtorrent/socket_type.hpp | 164 +++++++++++++++++- include/libtorrent/socket_type_fwd.hpp | 42 +++++ include/libtorrent/socks5_stream.hpp | 2 + include/libtorrent/ssl_stream.hpp | 1 + include/libtorrent/storage.hpp | 25 +-- include/libtorrent/storage_defs.hpp | 64 +++++++ include/libtorrent/time.hpp | 10 +- include/libtorrent/torrent.hpp | 4 +- include/libtorrent/torrent_handle.hpp | 3 +- include/libtorrent/torrent_info.hpp | 5 +- include/libtorrent/tracker_manager.hpp | 10 +- include/libtorrent/udp_socket.hpp | 3 +- include/libtorrent/upnp.hpp | 3 +- include/libtorrent/web_peer_connection.hpp | 19 +- src/alert.cpp | 2 +- src/connection_queue.cpp | 5 +- src/disk_io_thread.cpp | 8 +- src/escape_string.cpp | 6 +- src/http_tracker_connection.cpp | 6 +- src/kademlia/dht_tracker.cpp | 17 +- src/kademlia/node.cpp | 9 +- src/logger.cpp | 9 +- src/magnet_uri.cpp | 36 ++-- src/natpmp.cpp | 1 + src/peer_connection.cpp | 1 + src/policy.cpp | 5 - src/session.cpp | 1 - src/session_impl.cpp | 1 - src/smart_ban.cpp | 10 +- src/socket_io.cpp | 1 + src/socket_type.cpp | 147 ++++++++++++++++ src/storage.cpp | 1 - src/torrent.cpp | 1 - src/torrent_info.cpp | 7 +- src/tracker_manager.cpp | 5 - src/udp_tracker_connection.cpp | 13 +- test/test_primitives.cpp | 16 +- test/test_transfer.cpp | 2 + 80 files changed, 783 insertions(+), 290 deletions(-) create mode 100644 include/libtorrent/address.hpp rename include/libtorrent/{random_sample.hpp => io_service.hpp} (70%) create mode 100644 include/libtorrent/io_service_fwd.hpp create mode 100644 include/libtorrent/socket_type_fwd.hpp create mode 100644 include/libtorrent/storage_defs.hpp create mode 100644 src/socket_type.cpp diff --git a/Jamfile b/Jamfile index 169a76cdd..943e272a0 100755 --- a/Jamfile +++ b/Jamfile @@ -356,6 +356,7 @@ SOURCES = session session_impl socket_io + socket_type socks5_stream stat storage diff --git a/docs/manual.rst b/docs/manual.rst index 47294828a..85ecae58c 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3560,7 +3560,7 @@ session_settings int inactivity_timeout; int unchoke_interval; int optimistic_unchoke_interval; - address announce_ip; + std::string announce_ip; int num_want; int initial_picker_threshold; int allowed_fast_set_size; @@ -3767,7 +3767,7 @@ each *optimistic* unchoke. On this timer, the currently optimistically unchoked peer will change. ``announce_ip`` is the ip address passed along to trackers as the ``&ip=`` parameter. -If left as the default (default constructed), that parameter is ommited. +If left as the default (an empty string), that parameter is omitted. ``num_want`` is the number of peers we want from each tracker request. It defines what is sent as the ``&num_want=`` parameter to the tracker. diff --git a/include/libtorrent/address.hpp b/include/libtorrent/address.hpp new file mode 100644 index 000000000..eea74d59d --- /dev/null +++ b/include/libtorrent/address.hpp @@ -0,0 +1,67 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_ADDRESS_HPP_INCLUDED +#define TORRENT_ADDRESS_HPP_INCLUDED + +#include + +#ifdef __OBJC__ +#define Protocol Protocol_ +#endif + +#if BOOST_VERSION < 103500 +#include +#else +#include +#endif + +#ifdef __OBJC__ +#undef Protocol +#endif + +namespace libtorrent +{ + +#if BOOST_VERSION < 103500 + typedef ::asio::ip::address address; + typedef ::asio::ip::address_v4 address_v4; + typedef ::asio::ip::address_v6 address_v6; +#else + typedef boost::asio::ip::address address; + typedef boost::asio::ip::address_v4 address_v4; + typedef boost::asio::ip::address_v6 address_v6; +#endif +} + +#endif + diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index 845f31bfe..a1a1fb3a3 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -36,13 +36,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #ifdef _MSC_VER #pragma warning(push, 1) #endif -#include +#include #include #include @@ -57,7 +56,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/thread.hpp" -#include "libtorrent/socket.hpp" // for io_service +#include "libtorrent/io_service_fwd.hpp" #ifndef TORRENT_MAX_ALERT_TYPES #define TORRENT_MAX_ALERT_TYPES 15 diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 25632a6a7..2265e51e6 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -36,11 +36,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert.hpp" #include "libtorrent/torrent_handle.hpp" #include "libtorrent/socket.hpp" -#include "libtorrent/peer_connection.hpp" #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/identify_client.hpp" #include "libtorrent/socket_io.hpp" +#include "libtorrent/address.hpp" namespace libtorrent { diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 55c2e94e4..0376afab6 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -82,6 +82,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/deadline_timer.hpp" #include "libtorrent/socket_io.hpp" // for print_address #include "libtorrent/peer_connection.hpp" // for intrusive_ptr_release +#include "libtorrent/address.hpp" #ifdef TORRENT_STATS #include diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index 72635853a..e7e407db3 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -34,10 +34,12 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_BROADCAST_SOCKET_HPP_INCLUDED #include "libtorrent/config.hpp" +#include "libtorrent/io_service_fwd.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/error_code.hpp" #include -#include +#include #include namespace libtorrent diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 06c5250b3..29ca3967b 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -59,7 +59,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_connection.hpp" #include "libtorrent/socket.hpp" #include "libtorrent/peer_id.hpp" -#include "libtorrent/storage.hpp" #include "libtorrent/stat.hpp" #include "libtorrent/alert.hpp" #include "libtorrent/torrent_handle.hpp" diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index 6c7dbe87c..d6e197328 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -32,7 +32,6 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef LIBTORRENT_BUFFER_HPP #define LIBTORRENT_BUFFER_HPP -#include #include #include "libtorrent/invariant_check.hpp" #include "libtorrent/assert.hpp" diff --git a/include/libtorrent/chained_buffer.hpp b/include/libtorrent/chained_buffer.hpp index caf2e89be..02ff4db22 100644 --- a/include/libtorrent/chained_buffer.hpp +++ b/include/libtorrent/chained_buffer.hpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_CHAINED_BUFFER_HPP_INCLUDED #define TORRENT_CHAINED_BUFFER_HPP_INCLUDED -#include +#include #include #if BOOST_VERSION < 103500 #include diff --git a/include/libtorrent/connection_queue.hpp b/include/libtorrent/connection_queue.hpp index 0877e031c..7192e59f8 100644 --- a/include/libtorrent/connection_queue.hpp +++ b/include/libtorrent/connection_queue.hpp @@ -34,9 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_CONNECTION_QUEUE #include -#include +#include +#include #include -#include "libtorrent/socket.hpp" +#include "libtorrent/io_service.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/deadline_timer.hpp" diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index c5d263ea3..6740fe9d2 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -52,8 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(push, 1) #endif -#include -#include +#include #include #include @@ -63,7 +62,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - namespace pt = boost::posix_time; class torrent_info; struct TORRENT_EXPORT create_torrent @@ -118,7 +116,7 @@ namespace libtorrent // if a creation date is found in the torrent file // this will be set to that, otherwise it'll be // 1970, Jan 1 - pt::ptime m_creation_date; + boost::posix_time::ptime m_creation_date; // if a comment is found in the torrent file // this will be set to that comment diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 2c7e06ede..a03e878fa 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -39,8 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/storage.hpp" #include "libtorrent/allocator.hpp" -#include -#include +#include "libtorrent/io_service.hpp" + +#include +#include #include #include #include @@ -396,7 +398,7 @@ namespace libtorrent // disk_io_thread. If the event refers to a disk buffer // it will try to free it, but the buffer pool won't // exist anymore, and crash. This prevents that. - boost::optional m_work; + boost::optional m_work; // thread for performing blocking disk io operations thread m_disk_io_thread; diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index dff1261cb..2045c6b09 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -68,6 +68,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/error_code.hpp" +#include "libtorrent/max.hpp" #if TORRENT_USE_IOSTREAM #include @@ -81,32 +82,6 @@ namespace libtorrent type_error(const char* error): std::runtime_error(error) {} }; - namespace detail - { - template - struct max2 { enum { value = v1>v2?v1:v2 }; }; - - template - struct max3 - { - enum - { - temp = max2::value, - value = temp>v3?temp:v3 - }; - }; - - template - struct max4 - { - enum - { - temp = max3::value, - value = temp>v4?temp:v4 - }; - }; - } - class entry; class TORRENT_EXPORT entry @@ -195,7 +170,7 @@ namespace libtorrent union { char data[ - detail::max4) + max4) , sizeof(std::map) , sizeof(string_type) , sizeof(integer_type)>::value]; @@ -204,7 +179,7 @@ namespace libtorrent #else union { - char data[detail::max4::value]; diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index da3e9c319..68a7dec59 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -34,7 +34,9 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_ENUM_NET_HPP_INCLUDED #include "libtorrent/config.hpp" -#include "libtorrent/socket.hpp" +#include +#include "libtorrent/io_service_fwd.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/error_code.hpp" namespace libtorrent diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index d9d2d2c8f..737f863d6 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_ERROR_CODE_HPP_INCLUDED #include -#include #if BOOST_VERSION < 103500 #include @@ -228,17 +227,22 @@ namespace libtorrent #ifndef BOOST_NO_EXCEPTIONS struct TORRENT_EXPORT libtorrent_exception: std::exception { - libtorrent_exception(error_code const& s): m_error(s) {} + libtorrent_exception(error_code const& s): m_error(s), m_msg(0) {} virtual const char* what() const throw() { - if (!m_msg) m_msg.reset(new std::string(m_error.message())); - return m_msg->c_str(); + if (!m_msg) + { + std::string msg = m_error.message(); + m_msg = strdup(msg.c_str()); + } + + return m_msg; } - virtual ~libtorrent_exception() throw() {} + virtual ~libtorrent_exception() throw() { free(m_msg); } error_code error() const { return m_error; } private: error_code m_error; - mutable boost::shared_ptr m_msg; + mutable char* m_msg; }; #endif } diff --git a/include/libtorrent/escape_string.hpp b/include/libtorrent/escape_string.hpp index cfcdf0338..0f3084bbe 100644 --- a/include/libtorrent/escape_string.hpp +++ b/include/libtorrent/escape_string.hpp @@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include "libtorrent/config.hpp" #include "libtorrent/size_type.hpp" @@ -72,7 +71,7 @@ namespace libtorrent TORRENT_EXPORT std::string base32encode(std::string const& s); TORRENT_EXPORT std::string base32decode(std::string const& s); - TORRENT_EXPORT boost::optional url_has_argument( + TORRENT_EXPORT std::string url_has_argument( std::string const& url, std::string argument); // replaces \ with / diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 081a36f34..3eb6a696f 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include #ifdef _MSC_VER #pragma warning(push, 1) @@ -56,7 +55,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#include +#include #include #include #include diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index 601257c9c..6902f89bf 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -33,7 +33,9 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_HTTP_CONNECTION #define TORRENT_HTTP_CONNECTION -#include +#include +#include +#include #include #include #include diff --git a/include/libtorrent/http_seed_connection.hpp b/include/libtorrent/http_seed_connection.hpp index 5b4873090..330f801a9 100644 --- a/include/libtorrent/http_seed_connection.hpp +++ b/include/libtorrent/http_seed_connection.hpp @@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include @@ -56,25 +55,17 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(pop) #endif -#include "libtorrent/buffer.hpp" -#include "libtorrent/peer_connection.hpp" -#include "libtorrent/socket.hpp" -#include "libtorrent/peer_id.hpp" -#include "libtorrent/storage.hpp" -#include "libtorrent/stat.hpp" -#include "libtorrent/alert.hpp" -#include "libtorrent/torrent_handle.hpp" -#include "libtorrent/torrent.hpp" -#include "libtorrent/peer_request.hpp" -#include "libtorrent/piece_block_progress.hpp" #include "libtorrent/config.hpp" -// parse_url -#include "libtorrent/tracker_manager.hpp" +#include "libtorrent/peer_connection.hpp" +#include "libtorrent/disk_buffer_holder.hpp" +#include "libtorrent/torrent.hpp" +#include "libtorrent/piece_block_progress.hpp" #include "libtorrent/http_parser.hpp" namespace libtorrent { class torrent; + struct peer_request; namespace detail { diff --git a/include/libtorrent/http_stream.hpp b/include/libtorrent/http_stream.hpp index b564f6aae..cfe74fcae 100644 --- a/include/libtorrent/http_stream.hpp +++ b/include/libtorrent/http_stream.hpp @@ -33,7 +33,9 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_HTTP_STREAM_HPP_INCLUDED #define TORRENT_HTTP_STREAM_HPP_INCLUDED +#include #include "libtorrent/proxy_base.hpp" +#include namespace libtorrent { diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 19c8d6e31..4d54c0132 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -37,6 +37,9 @@ POSSIBILITY OF SUCH DAMAGE. #if TORRENT_USE_I2P +#include +#include +#include #include "libtorrent/proxy_base.hpp" #include "libtorrent/session_settings.hpp" diff --git a/include/libtorrent/random_sample.hpp b/include/libtorrent/io_service.hpp similarity index 70% rename from include/libtorrent/random_sample.hpp rename to include/libtorrent/io_service.hpp index 1eaaec1e3..f9c22a1a9 100644 --- a/include/libtorrent/random_sample.hpp +++ b/include/libtorrent/io_service.hpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2006, Arvid Norberg & Daniel Wallin +Copyright (c) 2009, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without @@ -30,45 +30,43 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TORRENT_RANDOM_SAMPLE_HPP -#define TORRENT_RANDOM_SAMPLE_HPP +#ifndef TORRENT_IO_SERVICE_HPP_INCLUDED +#define TORRENT_IO_SERVICE_HPP_INCLUDED -#include -#include +#ifdef __OBJC__ +#define Protocol Protocol_ +#endif -#include "libtorrent/config.hpp" +#ifdef _MSC_VER +#pragma warning(push, 1) +#endif + +#include + +#if BOOST_VERSION < 103500 +#include +#else +#include +#endif + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#ifdef __OBJC__ +#undef Protocol +#endif namespace libtorrent { - template - inline void random_sample_n(InIter start, InIter end - , OutIter out, Distance n) - { - Distance t = 0; - Distance m = 0; - Distance N = std::distance(start, end); - - TORRENT_ASSERT(N >= n); - - while (m < n) - { - if ((std::rand() / (RAND_MAX + 1.f)) * (N - t) >= n - m) - { - ++start; - ++t; - } - else - { - *out = *start; - ++out; - ++start; - ++t; - ++m; - } - } - } - +#if BOOST_VERSION < 103500 + typedef ::asio::io_service io_service; +#else + typedef boost::asio::io_service io_service; +#endif } #endif + + diff --git a/include/libtorrent/io_service_fwd.hpp b/include/libtorrent/io_service_fwd.hpp new file mode 100644 index 000000000..b69b7afde --- /dev/null +++ b/include/libtorrent/io_service_fwd.hpp @@ -0,0 +1,77 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_IO_SERVICE_FWD_HPP_INCLUDED +#define TORRENT_IO_SERVICE_FWD_HPP_INCLUDED + +#ifdef __OBJC__ +#define Protocol Protocol_ +#endif + +#ifdef _MSC_VER +#pragma warning(push, 1) +#endif + +#include + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#ifdef __OBJC__ +#undef Protocol +#endif + +#if BOOST_VERSION >= 103500 +namespace boost { +#endif +namespace asio { + +class io_service; + +} +#if BOOST_VERSION >= 103500 +} +#endif + +namespace libtorrent +{ + +#if BOOST_VERSION < 103500 + typedef ::asio::io_service io_service; +#else + typedef boost::asio::io_service io_service; +#endif +} + +#endif + diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index a69c1b2fb..25adcb9f8 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_IP_FILTER_HPP #include +#include #ifdef _MSC_VER #pragma warning(push, 1) @@ -49,7 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/assert.hpp" namespace libtorrent diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index 81c7d6543..ee417dcf8 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -40,7 +40,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include diff --git a/include/libtorrent/kademlia/find_data.hpp b/include/libtorrent/kademlia/find_data.hpp index 7c5b3fb0b..016bb875f 100644 --- a/include/libtorrent/kademlia/find_data.hpp +++ b/include/libtorrent/kademlia/find_data.hpp @@ -44,7 +44,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include +#include namespace libtorrent { namespace dht { diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 6612701a6..810b05d44 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -49,10 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include -#include #include -#include #include "libtorrent/socket.hpp" @@ -181,7 +178,7 @@ typedef std::map, search_torrent_entry> search_tab public: node_impl(libtorrent::aux::session_impl& ses , bool (*f)(void*, entry const&, udp::endpoint const&, int) - , dht_settings const& settings, boost::optional nid + , dht_settings const& settings, node_id nid , void* userdata); virtual ~node_impl() {} diff --git a/include/libtorrent/kademlia/node_entry.hpp b/include/libtorrent/kademlia/node_entry.hpp index 2d5c6f706..def471d75 100644 --- a/include/libtorrent/kademlia/node_entry.hpp +++ b/include/libtorrent/kademlia/node_entry.hpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/kademlia/node_id.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" namespace libtorrent { namespace dht { diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 9bc1e855d..3164b59af 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace libtorrent { namespace dht { diff --git a/include/libtorrent/kademlia/refresh.hpp b/include/libtorrent/kademlia/refresh.hpp index 50f651bb4..fc29f3014 100644 --- a/include/libtorrent/kademlia/refresh.hpp +++ b/include/libtorrent/kademlia/refresh.hpp @@ -37,8 +37,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include - namespace libtorrent { namespace dht { diff --git a/include/libtorrent/kademlia/rpc_manager.hpp b/include/libtorrent/kademlia/rpc_manager.hpp index 8784574c9..ce7351049 100644 --- a/include/libtorrent/kademlia/rpc_manager.hpp +++ b/include/libtorrent/kademlia/rpc_manager.hpp @@ -35,18 +35,13 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include -#include -#include #include -#include #include #include #include #include #include -#include #include #include "libtorrent/time.hpp" diff --git a/include/libtorrent/kademlia/traversal_algorithm.hpp b/include/libtorrent/kademlia/traversal_algorithm.hpp index e1dbb8048..a10f12505 100644 --- a/include/libtorrent/kademlia/traversal_algorithm.hpp +++ b/include/libtorrent/kademlia/traversal_algorithm.hpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include diff --git a/include/libtorrent/lsd.hpp b/include/libtorrent/lsd.hpp index cb701caf6..037bab675 100644 --- a/include/libtorrent/lsd.hpp +++ b/include/libtorrent/lsd.hpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/intrusive_ptr_base.hpp" #include "libtorrent/deadline_timer.hpp" -#include +#include #include #include diff --git a/include/libtorrent/natpmp.hpp b/include/libtorrent/natpmp.hpp index daf172004..35775117f 100644 --- a/include/libtorrent/natpmp.hpp +++ b/include/libtorrent/natpmp.hpp @@ -33,13 +33,16 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_NATPMP_HPP #define TORRENT_NATPMP_HPP +#include "libtorrent/io_service_fwd.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/thread.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/intrusive_ptr_base.hpp" #include "libtorrent/deadline_timer.hpp" -#include +#include +#include namespace libtorrent { diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index b371203a7..9cf5c8ab6 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -38,7 +38,9 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING #include "libtorrent/debug.hpp" +#endif #ifdef _MSC_VER #pragma warning(push, 1) @@ -46,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include #include @@ -57,26 +60,23 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include "libtorrent/buffer.hpp" -#include "libtorrent/socket.hpp" #include "libtorrent/peer_id.hpp" -#include "libtorrent/storage.hpp" #include "libtorrent/stat.hpp" #include "libtorrent/alert.hpp" -#include "libtorrent/torrent_handle.hpp" -#include "libtorrent/torrent.hpp" #include "libtorrent/peer_request.hpp" #include "libtorrent/piece_block_progress.hpp" #include "libtorrent/config.hpp" #include "libtorrent/session.hpp" #include "libtorrent/bandwidth_limit.hpp" #include "libtorrent/policy.hpp" -#include "libtorrent/socket_type.hpp" +#include "libtorrent/socket_type_fwd.hpp" #include "libtorrent/intrusive_ptr_base.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/chained_buffer.hpp" #include "libtorrent/disk_buffer_holder.hpp" #include "libtorrent/bitfield.hpp" #include "libtorrent/bandwidth_socket.hpp" +#include "libtorrent/socket_type_fwd.hpp" #ifdef TORRENT_STATS #include "libtorrent/aux_/session_impl.hpp" @@ -647,7 +647,7 @@ namespace libtorrent boost::intrusive_ptr self() { TORRENT_ASSERT(!m_in_constructor); - return intrusive_ptr(this); + return boost::intrusive_ptr(this); } private: diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index c773f3033..fb1ce9ceb 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -48,7 +48,6 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include "libtorrent/peer_id.hpp" -#include "libtorrent/socket.hpp" #include "libtorrent/session_settings.hpp" #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index 093090b80..987aedc11 100644 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer.hpp" #include "libtorrent/piece_picker.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/size_type.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/config.hpp" diff --git a/include/libtorrent/proxy_base.hpp b/include/libtorrent/proxy_base.hpp index 4cce119e7..298019cbd 100644 --- a/include/libtorrent/proxy_base.hpp +++ b/include/libtorrent/proxy_base.hpp @@ -34,18 +34,11 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_PROXY_BASE_HPP_INCLUDED #include "libtorrent/io.hpp" +#include "libtorrent/io_service_fwd.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/escape_string.hpp" #include "libtorrent/error_code.hpp" -#include -#include -#if BOOST_VERSION < 103500 -#include -#include -#else -#include -#include -#endif namespace libtorrent { @@ -80,7 +73,13 @@ public: return m_sock.read_some(buffers, ec); } + std::size_t available(error_code& ec) const + { return m_sock.available(ec); } + #ifndef BOOST_NO_EXCEPTIONS + std::size_t available() const + { return m_sock.available(); } + template std::size_t read_some(Mutable_Buffers const& buffers) { diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 710b21024..50c844258 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -324,7 +324,7 @@ namespace libtorrent // if this is set, this IP will be reported do the // tracker in the ip= parameter. - address announce_ip; + std::string announce_ip; // the num want sent to trackers int num_want; diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index e77d6e096..b6abf843d 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -50,13 +50,11 @@ POSSIBILITY OF SUCH DAMAGE. #if BOOST_VERSION < 103500 #include #include -#include #include #include #else #include #include -#include #include #include #endif @@ -79,12 +77,8 @@ namespace libtorrent using ::asio::async_read; typedef ::asio::ip::tcp::socket stream_socket; - typedef ::asio::ip::address address; - typedef ::asio::ip::address_v4 address_v4; - typedef ::asio::ip::address_v6 address_v6; typedef ::asio::ip::udp::socket datagram_socket; typedef ::asio::ip::tcp::acceptor socket_acceptor; - typedef ::asio::io_service io_service; #else using boost::asio::ip::tcp; using boost::asio::ip::udp; @@ -92,12 +86,8 @@ namespace libtorrent using boost::asio::async_read; typedef boost::asio::ip::tcp::socket stream_socket; - typedef boost::asio::ip::address address; - typedef boost::asio::ip::address_v4 address_v4; - typedef boost::asio::ip::address_v6 address_v6; typedef boost::asio::ip::udp::socket datagram_socket; typedef boost::asio::ip::tcp::acceptor socket_acceptor; - typedef boost::asio::io_service io_service; namespace asio = boost::asio; #endif diff --git a/include/libtorrent/socket_io.hpp b/include/libtorrent/socket_io.hpp index 2cbaeb0ce..6bc99f0df 100644 --- a/include/libtorrent/socket_io.hpp +++ b/include/libtorrent/socket_io.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_SOCKET_IO_HPP_INCLUDED #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/io.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/lazy_entry.hpp" diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index d4026336a..0d1b204a9 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2007, Arvid Norberg +Copyright (c) 2009, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without @@ -33,21 +33,169 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_SOCKET_TYPE #define TORRENT_SOCKET_TYPE +#include "libtorrent/socket.hpp" #include "libtorrent/socks5_stream.hpp" #include "libtorrent/http_stream.hpp" #include "libtorrent/i2p_stream.hpp" -#include "libtorrent/variant_stream.hpp" +#include "libtorrent/io_service.hpp" +#include "libtorrent/max.hpp" +#include "libtorrent/assert.hpp" + +#define TORRENT_SOCKTYPE_FORWARD(x) \ + switch (m_type) { \ + case socket_type_int_impl::value: \ + get()->x; break; \ + case socket_type_int_impl::value: \ + get()->x; break; \ + case socket_type_int_impl::value: \ + get()->x; break; \ + case socket_type_int_impl::value: \ + get()->x; break; \ + default: TORRENT_ASSERT(false); \ + } + +#define TORRENT_SOCKTYPE_FORWARD_RET(x, def) \ + switch (m_type) { \ + case socket_type_int_impl::value: \ + return get()->x; \ + case socket_type_int_impl::value: \ + return get()->x; \ + case socket_type_int_impl::value: \ + return get()->x; \ + case socket_type_int_impl::value: \ + return get()->x; \ + default: TORRENT_ASSERT(false); return def; \ + } namespace libtorrent { - typedef variant_stream< - stream_socket - , socks5_stream - , http_stream + + template + struct socket_type_int_impl + { enum { value = 0 }; }; + + template <> + struct socket_type_int_impl + { enum { value = 1 }; }; + + template <> + struct socket_type_int_impl + { enum { value = 2 }; }; + + template <> + struct socket_type_int_impl + { enum { value = 3 }; }; + #if TORRENT_USE_I2P - , i2p_stream + template <> + struct socket_type_int_impl + { enum { value = 4 }; }; #endif - > socket_type; + + struct socket_type + { + typedef stream_socket::lowest_layer_type lowest_layer_type; + typedef stream_socket::endpoint_type endpoint_type; + typedef stream_socket::protocol_type protocol_type; + + explicit socket_type(io_service& ios): m_io_service(ios), m_type(0) {} + ~socket_type(); + + lowest_layer_type& lowest_layer(); + io_service& get_io_service() const; + bool is_open() const; + + +#ifndef BOOST_NO_EXCEPTIONS + void open(protocol_type const& p); + void close(); + endpoint_type local_endpoint() const; + endpoint_type remote_endpoint() const; + void bind(endpoint_type const& endpoint); + std::size_t available() const; +#endif + + void open(protocol_type const& p, error_code& ec); + void close(error_code& ec); + endpoint_type local_endpoint(error_code& ec) const; + endpoint_type remote_endpoint(error_code& ec) const; + void bind(endpoint_type const& endpoint, error_code& ec); + std::size_t available(error_code& ec) const; + + + template + std::size_t read_some(Mutable_Buffers const& buffers, error_code& ec) + { TORRENT_SOCKTYPE_FORWARD_RET(read_some(buffers, ec), 0) } + + template + void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) + { TORRENT_SOCKTYPE_FORWARD(async_read_some(buffers, handler)) } + + template + void async_write_some(Const_Buffers const& buffers, Handler const& handler) + { TORRENT_SOCKTYPE_FORWARD(async_write_some(buffers, handler)) } + + template + void async_connect(endpoint_type const& endpoint, Handler const& handler) + { TORRENT_SOCKTYPE_FORWARD(async_connect(endpoint, handler)) } + +#ifndef BOOST_NO_EXCEPTIONS + template + void io_control(IO_Control_Command& ioc) + { TORRENT_SOCKTYPE_FORWARD(io_control(ioc)) } + + template + std::size_t read_some(Mutable_Buffers const& buffers) + { TORRENT_SOCKTYPE_FORWARD_RET(read_some(buffers), 0) } +#endif + + template + void io_control(IO_Control_Command& ioc, error_code& ec) + { TORRENT_SOCKTYPE_FORWARD(io_control(ioc, ec)) } + +#ifndef BOOST_NO_EXCEPTIONS + template + void set_option(SettableSocketOption const& opt) + { TORRENT_SOCKTYPE_FORWARD(set_option(opt)) } +#endif + + template + error_code set_option(SettableSocketOption const& opt, error_code& ec) + { TORRENT_SOCKTYPE_FORWARD_RET(set_option(opt, ec), ec) } + + template + void instantiate(io_service& ios) + { + TORRENT_ASSERT(&ios == &m_io_service); + construct(socket_type_int_impl::value); + } + + template S* get() + { + if (m_type != socket_type_int_impl::value) return 0; + return (S*)m_data; + } + + template S const* get() const + { + if (m_type != socket_type_int_impl::value) return 0; + return (S const*)m_data; + } + + private: + + void destruct(); + void construct(int type); + + io_service& m_io_service; + int m_type; +#if TORRENT_USE_I2P + enum { storage_size = max4::value }; +#else + enum { storage_size = max3::value }; +#endif + size_type m_data[(storage_size + sizeof(size_type) - 1) / sizeof(size_type)]; + }; } #endif diff --git a/include/libtorrent/socket_type_fwd.hpp b/include/libtorrent/socket_type_fwd.hpp new file mode 100644 index 000000000..26a134274 --- /dev/null +++ b/include/libtorrent/socket_type_fwd.hpp @@ -0,0 +1,42 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_SOCKET_TYPE_FWD_HPP +#define TORRENT_SOCKET_TYPE_FWD_HPP + +namespace libtorrent +{ + struct socket_type; +} + +#endif + diff --git a/include/libtorrent/socks5_stream.hpp b/include/libtorrent/socks5_stream.hpp index 3f488db6f..92d218252 100644 --- a/include/libtorrent/socks5_stream.hpp +++ b/include/libtorrent/socks5_stream.hpp @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_SOCKS5_STREAM_HPP_INCLUDED #define TORRENT_SOCKS5_STREAM_HPP_INCLUDED +#include +#include #include "libtorrent/proxy_base.hpp" namespace libtorrent { diff --git a/include/libtorrent/ssl_stream.hpp b/include/libtorrent/ssl_stream.hpp index c4deb1352..a0965903d 100644 --- a/include/libtorrent/ssl_stream.hpp +++ b/include/libtorrent/ssl_stream.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_SSL_STREAM_HPP_INCLUDED #include "libtorrent/socket.hpp" +#include #if BOOST_VERSION < 103500 #include #else diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 8c5b00003..e0a28d33d 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -41,9 +41,10 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(push, 1) #endif -#include +#include #include #include +#include #include #ifdef _MSC_VER @@ -60,26 +61,15 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/file.hpp" #include "libtorrent/disk_buffer_holder.hpp" #include "libtorrent/thread.hpp" +#include "libtorrent/storage_defs.hpp" namespace libtorrent { - namespace aux - { - struct piece_checker_data; - } - class session; struct file_pool; struct disk_io_job; struct disk_buffer_pool; - enum storage_mode_t - { - storage_mode_allocate = 0, - storage_mode_sparse, - storage_mode_compact - }; - TORRENT_EXPORT std::vector > get_filesizes( file_storage const& t , std::string const& p); @@ -190,15 +180,6 @@ namespace libtorrent session_settings* m_settings; }; - typedef storage_interface* (*storage_constructor_type)( - file_storage const&, file_storage const*, std::string const&, file_pool&); - - TORRENT_EXPORT storage_interface* default_storage_constructor( - file_storage const&, file_storage const* mapped, std::string const&, file_pool&); - - TORRENT_EXPORT storage_interface* disabled_storage_constructor( - file_storage const&, file_storage const* mapped, std::string const&, file_pool&); - struct disk_io_thread; class TORRENT_EXPORT piece_manager diff --git a/include/libtorrent/storage_defs.hpp b/include/libtorrent/storage_defs.hpp new file mode 100644 index 000000000..c18580f7f --- /dev/null +++ b/include/libtorrent/storage_defs.hpp @@ -0,0 +1,64 @@ +/* + +Copyright (c) 2003, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_STORAGE_DEFS_HPP_INCLUDE +#define TORRENT_STORAGE_DEFS_HPP_INCLUDE + +#include "libtorrent/config.hpp" +#include + +namespace libtorrent +{ + struct storage_interface; + struct file_storage; + struct file_pool; + + enum storage_mode_t + { + storage_mode_allocate = 0, + storage_mode_sparse, + storage_mode_compact + }; + + typedef storage_interface* (*storage_constructor_type)( + file_storage const&, file_storage const*, std::string const&, file_pool&); + + TORRENT_EXPORT storage_interface* default_storage_constructor( + file_storage const&, file_storage const* mapped, std::string const&, file_pool&); + + TORRENT_EXPORT storage_interface* disabled_storage_constructor( + file_storage const&, file_storage const* mapped, std::string const&, file_pool&); + +} + +#endif + diff --git a/include/libtorrent/time.hpp b/include/libtorrent/time.hpp index 48bf25296..7bacbda63 100644 --- a/include/libtorrent/time.hpp +++ b/include/libtorrent/time.hpp @@ -41,9 +41,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#include -#include - namespace libtorrent { inline char const* time_now_string() @@ -60,7 +57,9 @@ namespace libtorrent #if defined TORRENT_USE_BOOST_DATE_TIME -#include +#include +#include +#include #include "libtorrent/assert.hpp" namespace libtorrent @@ -68,7 +67,7 @@ namespace libtorrent typedef boost::posix_time::ptime ptime; typedef boost::posix_time::time_duration time_duration; inline ptime time_now_hires() - { return boost::posix_time::microsec_clock::universal_time(); } + { return boost::date_time::microsec_clock::universal_time(); } inline ptime min_time() { return boost::posix_time::ptime(boost::posix_time::min_date_time); } inline ptime max_time() @@ -90,6 +89,7 @@ namespace libtorrent #else // TORRENT_USE_BOOST_DATE_TIME +#include #include #include "libtorrent/assert.hpp" diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index b8ef0a730..0b7f8a0ef 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" #include "libtorrent/policy.hpp" #include "libtorrent/tracker_manager.hpp" #include "libtorrent/stat.hpp" @@ -65,7 +66,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/escape_string.hpp" #include "libtorrent/bandwidth_limit.hpp" #include "libtorrent/bandwidth_queue_entry.hpp" -#include "libtorrent/storage.hpp" +#include "libtorrent/storage_defs.hpp" #include "libtorrent/hasher.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/bitfield.hpp" @@ -84,6 +85,7 @@ namespace libtorrent struct announce_entry; struct tracker_request; struct add_torrent_params; + struct storage_interface; namespace aux { diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 3f150d16c..be24976af 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(push, 1) #endif -#include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/time.hpp" #include "libtorrent/config.hpp" #include "libtorrent/storage.hpp" +#include "libtorrent/address.hpp" namespace libtorrent { diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index fbee2197e..4927dda63 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -43,17 +43,17 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #ifdef _MSC_VER #pragma warning(pop) #endif +#include "libtorrent/config.hpp" #include "libtorrent/entry.hpp" #include "libtorrent/lazy_entry.hpp" -#include "libtorrent/socket.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/size_type.hpp" -#include "libtorrent/config.hpp" #include "libtorrent/time.hpp" #include "libtorrent/intrusive_ptr_base.hpp" #include "libtorrent/assert.hpp" @@ -62,7 +62,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace pt = boost::posix_time; - namespace gr = boost::gregorian; enum { diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 5f3fe9080..3adbb5562 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -52,12 +52,12 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(pop) #endif -#include "libtorrent/socket.hpp" -#include "libtorrent/entry.hpp" -#include "libtorrent/session_settings.hpp" -#include "libtorrent/peer_id.hpp" -#include "libtorrent/peer.hpp" #include "libtorrent/config.hpp" +#include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" +#include "libtorrent/peer_id.hpp" +#include "libtorrent/peer.hpp" // peer_entry +#include "libtorrent/session_settings.hpp" // proxy_settings #include "libtorrent/deadline_timer.hpp" #include "libtorrent/connection_queue.hpp" #include "libtorrent/intrusive_ptr_base.hpp" diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 9b2246eed..545d46821 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_UDP_SOCKET_HPP_INCLUDED #include "libtorrent/socket.hpp" +#include "libtorrent/io_service.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/session_settings.hpp" #include "libtorrent/buffer.hpp" @@ -41,7 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/deadline_timer.hpp" #include -#include +#include namespace libtorrent { diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 0cf82fc2d..0d818a5e4 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -42,7 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/thread.hpp" #include "libtorrent/deadline_timer.hpp" -#include +#include +#include #include #include #include diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index c4797cb53..4e3124342 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -39,8 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "libtorrent/debug.hpp" - #ifdef _MSC_VER #pragma warning(push, 1) #endif @@ -56,20 +54,11 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(pop) #endif -#include "libtorrent/buffer.hpp" -#include "libtorrent/peer_connection.hpp" -#include "libtorrent/socket.hpp" -#include "libtorrent/peer_id.hpp" -#include "libtorrent/storage.hpp" -#include "libtorrent/stat.hpp" -#include "libtorrent/alert.hpp" -#include "libtorrent/torrent_handle.hpp" -#include "libtorrent/torrent.hpp" -#include "libtorrent/peer_request.hpp" -#include "libtorrent/piece_block_progress.hpp" #include "libtorrent/config.hpp" -// parse_url -#include "libtorrent/tracker_manager.hpp" +#include "libtorrent/peer_connection.hpp" +#include "libtorrent/disk_buffer_holder.hpp" +#include "libtorrent/torrent.hpp" +#include "libtorrent/piece_block_progress.hpp" #include "libtorrent/http_parser.hpp" namespace libtorrent diff --git a/src/alert.cpp b/src/alert.cpp index 1038827c6..4e2ff9d46 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include "libtorrent/alert.hpp" -#include +#include "libtorrent/io_service.hpp" #include namespace libtorrent { diff --git a/src/connection_queue.cpp b/src/connection_queue.cpp index 1ac30d38c..6f4474b60 100644 --- a/src/connection_queue.cpp +++ b/src/connection_queue.cpp @@ -33,8 +33,9 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/invariant_check.hpp" #include "libtorrent/connection_queue.hpp" -#include "libtorrent/socket.hpp" +#include "libtorrent/io_service.hpp" #include "libtorrent/error_code.hpp" +#include "libtorrent/error.hpp" namespace libtorrent { @@ -257,7 +258,7 @@ namespace libtorrent function_guard guard_(m_in_timeout_function); #endif - TORRENT_ASSERT(!e || e == asio::error::operation_aborted); + TORRENT_ASSERT(!e || e == error::operation_aborted); if (e) return; ptime next_expire = max_time(); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 33934168b..1da5c9d00 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -40,7 +40,9 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alloca.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/error_code.hpp" +#include "libtorrent/error.hpp" #include +#include #ifdef TORRENT_DISK_STATS #include "libtorrent/time.hpp" @@ -274,7 +276,7 @@ namespace libtorrent // ------- disk_io_thread ------ - disk_io_thread::disk_io_thread(asio::io_service& ios + disk_io_thread::disk_io_thread(io_service& ios , boost::function const& queue_callback , int block_size) : disk_buffer_pool(block_size) @@ -1551,7 +1553,7 @@ namespace libtorrent j.error = error_code(boost::system::errc::not_enough_memory , get_posix_category()); #else - j.error = asio::error::no_memory; + j.error = error::no_memory; #endif j.str.clear(); break; @@ -1615,7 +1617,7 @@ namespace libtorrent j.error = error_code(boost::system::errc::not_enough_memory , get_posix_category()); #else - j.error = asio::error::no_memory; + j.error = error::no_memory; #endif j.str.clear(); break; diff --git a/src/escape_string.cpp b/src/escape_string.cpp index c68218524..195665087 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -470,11 +470,11 @@ namespace libtorrent return ret; } - boost::optional url_has_argument( + std::string url_has_argument( std::string const& url, std::string argument) { size_t i = url.find('?'); - if (i == std::string::npos) return boost::optional(); + if (i == std::string::npos) return std::string(); ++i; argument += '='; @@ -486,7 +486,7 @@ namespace libtorrent } argument.insert(0, "&"); i = url.find(argument, i); - if (i == std::string::npos) return boost::optional(); + if (i == std::string::npos) return std::string(); size_t pos = i + argument.size(); return url.substr(pos, url.find('&', pos) - pos); } diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 540a8f0e4..62e247102 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -172,11 +172,11 @@ namespace libtorrent } else #endif - if (settings.announce_ip != address()) + if (!settings.announce_ip.empty()) { error_code ec; - std::string ip = settings.announce_ip.to_string(ec); - if (!ec) url += "&ip=" + ip; + if (!ec) url += "&ip=" + escape_string( + settings.announce_ip.c_str(), settings.announce_ip.size()); } if (!tracker_req().ipv6.empty() && !i2p) diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index e913376f9..0bd7530db 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -40,7 +40,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include "libtorrent/kademlia/node.hpp" #include "libtorrent/kademlia/node_id.hpp" @@ -182,21 +181,21 @@ namespace libtorrent { namespace dht TORRENT_DEFINE_LOG(dht_tracker) #endif - boost::optional extract_node_id(lazy_entry const* e) + node_id extract_node_id(lazy_entry const* e) { - if (e == 0 || e->type() != lazy_entry::dict_t) return boost::optional(); + if (e == 0 || e->type() != lazy_entry::dict_t) return (node_id::min)(); lazy_entry const* nid = e->dict_find_string("node-id"); - if (nid == 0 || nid->string_length() != 20) return boost::optional(); - return boost::optional(node_id(nid->string_ptr())); + if (nid == 0 || nid->string_length() != 20) return (node_id::min)(); + return node_id(node_id(nid->string_ptr())); } - boost::optional extract_node_id(entry const* e) + node_id extract_node_id(entry const* e) { - if (e == 0 || e->type() != entry::dictionary_t) return boost::optional(); + if (e == 0 || e->type() != entry::dictionary_t) return (node_id::min)(); entry const* nid = e->find_key("node-id"); if (nid == 0 || nid->type() != entry::string_t || nid->string().length() != 20) - return boost::optional(); - return boost::optional(node_id(nid->string().c_str())); + return (node_id::min)(); + return node_id(node_id(nid->string().c_str())); } bool send_callback(void* userdata, entry const& e, udp::endpoint const& addr, int flags) diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 57b5e95b8..24e96338e 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -34,13 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include -#include -#include +#include #include "libtorrent/io.hpp" #include "libtorrent/hasher.hpp" -#include "libtorrent/random_sample.hpp" #include "libtorrent/alert_types.hpp" #include "libtorrent/socket.hpp" #include "libtorrent/aux_/session_impl.hpp" @@ -185,10 +182,10 @@ void nop() {} node_impl::node_impl(libtorrent::aux::session_impl& ses , bool (*f)(void*, entry const&, udp::endpoint const&, int) , dht_settings const& settings - , boost::optional nid + , node_id nid , void* userdata) : m_settings(settings) - , m_id(nid ? *nid : generate_id()) + , m_id(nid == (node_id::min)()? nid : generate_id()) , m_table(m_id, 8, settings) , m_rpc(m_id, m_table, f, userdata) , m_last_tracker_tick(time_now()) diff --git a/src/logger.cpp b/src/logger.cpp index 050f59936..f47ac7a77 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -48,12 +48,19 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/extensions.hpp" #include "libtorrent/entry.hpp" #include "libtorrent/peer_request.hpp" -#include "libtorrent/peer_connection.hpp" #if TORRENT_USE_IOSTREAM +#include +#include "libtorrent/file.hpp" +#include "libtorrent/time.hpp" +#include "libtorrent/lazy_entry.hpp" +#include "libtorrent/peer_connection.hpp" + namespace libtorrent { + struct peer_connection; + namespace { diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 6faf32547..e74f39413 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -106,19 +106,19 @@ namespace libtorrent std::string tracker; error_code ec; - boost::optional display_name = url_has_argument(uri, "dn"); - if (display_name) name = unescape_string(display_name->c_str(), ec); - boost::optional tracker_string = url_has_argument(uri, "tr"); - if (tracker_string) tracker = unescape_string(tracker_string->c_str(), ec); + std::string display_name = url_has_argument(uri, "dn"); + if (!display_name.empty()) name = unescape_string(display_name.c_str(), ec); + std::string tracker_string = url_has_argument(uri, "tr"); + if (!tracker_string.empty()) tracker = unescape_string(tracker_string.c_str(), ec); - boost::optional btih = url_has_argument(uri, "xt"); - if (!btih) return torrent_handle(); + std::string btih = url_has_argument(uri, "xt"); + if (btih.empty()) return torrent_handle(); - if (btih->compare(0, 9, "urn:btih:") != 0) return torrent_handle(); + if (btih.compare(0, 9, "urn:btih:") != 0) return torrent_handle(); sha1_hash info_hash; - if (btih->size() == 40 + 9) from_hex(&(*btih)[9], 40, (char*)&info_hash[0]); - else info_hash.assign(base32decode(btih->substr(9))); + if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&info_hash[0]); + else info_hash.assign(base32decode(btih.substr(9))); return ses.add_torrent(tracker.empty() ? 0 : tracker.c_str(), info_hash , name.empty() ? 0 : name.c_str(), save_path, entry() @@ -142,27 +142,27 @@ namespace libtorrent std::string tracker; error_code e; - boost::optional display_name = url_has_argument(uri, "dn"); - if (display_name) name = unescape_string(display_name->c_str(), e); - boost::optional tracker_string = url_has_argument(uri, "tr"); - if (tracker_string) tracker = unescape_string(tracker_string->c_str(), e); + std::string display_name = url_has_argument(uri, "dn"); + if (!display_name.empty()) name = unescape_string(display_name.c_str(), e); + std::string tracker_string = url_has_argument(uri, "tr"); + if (!tracker_string.empty()) tracker = unescape_string(tracker_string.c_str(), e); - boost::optional btih = url_has_argument(uri, "xt"); - if (!btih) + std::string btih = url_has_argument(uri, "xt"); + if (btih.empty()) { ec = error_code(errors::missing_info_hash_in_uri, libtorrent_category); return torrent_handle(); } - if (btih->compare(0, 9, "urn:btih:") != 0) + if (btih.compare(0, 9, "urn:btih:") != 0) { ec = error_code(errors::missing_info_hash_in_uri, libtorrent_category); return torrent_handle(); } sha1_hash info_hash; - if (btih->size() == 40 + 9) from_hex(&(*btih)[9], 40, (char*)&info_hash[0]); - else info_hash.assign(base32decode(btih->substr(9))); + if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&info_hash[0]); + else info_hash.assign(base32decode(btih.substr(9))); if (!tracker.empty()) p.tracker_url = tracker.c_str(); p.info_hash = info_hash; diff --git a/src/natpmp.cpp b/src/natpmp.cpp index 52b1ecc84..821ca038f 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/enum_net.hpp" #include "libtorrent/socket_io.hpp" +#include "libtorrent/io_service.hpp" using boost::bind; using namespace libtorrent; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4f80f41b2..a81c53a53 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket_type.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/broadcast_socket.hpp" +#include "libtorrent/torrent.hpp" #ifdef TORRENT_DEBUG #include diff --git a/src/policy.cpp b/src/policy.cpp index 918bb0272..6b34952cb 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -59,11 +59,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bt_peer_connection.hpp" #endif -namespace libtorrent -{ - class peer_connection; -} - using boost::bind; namespace diff --git a/src/session.cpp b/src/session.cpp index 618c5269b..0ab900706 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include -#include #include #include #include diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 1d8f5ceb9..837a18dd4 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include -#include #include #include #include diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index b43faff1d..bb65fc338 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -49,18 +49,18 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "libtorrent/peer_connection.hpp" -#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/hasher.hpp" -#include "libtorrent/bencode.hpp" #include "libtorrent/torrent.hpp" #include "libtorrent/extensions.hpp" #include "libtorrent/extensions/smart_ban.hpp" -#include "libtorrent/alert_types.hpp" #include "libtorrent/disk_io_thread.hpp" #include "libtorrent/aux_/session_impl.hpp" -namespace libtorrent { namespace +namespace libtorrent { + + struct torrent; + +namespace { struct smart_ban_plugin : torrent_plugin, boost::enable_shared_from_this diff --git a/src/socket_io.cpp b/src/socket_io.cpp index 8643d5a1b..db3e7ef56 100644 --- a/src/socket_io.cpp +++ b/src/socket_io.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/escape_string.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/address.hpp" namespace libtorrent { diff --git a/src/socket_type.cpp b/src/socket_type.cpp new file mode 100644 index 000000000..e6c4ce32c --- /dev/null +++ b/src/socket_type.cpp @@ -0,0 +1,147 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "libtorrent/socket_type.hpp" + +namespace libtorrent +{ + + void socket_type::destruct() + { + switch (m_type) + { + case 0: break; + case socket_type_int_impl::value: + get()->~stream_socket(); + break; + case socket_type_int_impl::value: + get()->~socks5_stream(); + break; + case socket_type_int_impl::value: + get()->~http_stream(); + break; +#if TORRENT_USE_I2P + case socket_type_int_impl::value: + get()->~i2p_stream(); + break; +#endif + } + m_type = 0; + } + + void socket_type::construct(int type) + { + destruct(); + switch (type) + { + case 0: break; + case socket_type_int_impl::value: + new ((stream_socket*)m_data) stream_socket(m_io_service); + break; + case socket_type_int_impl::value: + new ((socks5_stream*)m_data) socks5_stream(m_io_service); + break; + case socket_type_int_impl::value: + new ((http_stream*)m_data) http_stream(m_io_service); + break; +#if TORRENT_USE_I2P + case socket_type_int_impl::value: + new ((i2p_stream*)m_data) i2p_stream(m_io_service); + break; +#endif + } + + m_type = type; + } + + io_service& socket_type::get_io_service() const + { return m_io_service; } + + socket_type::~socket_type() + { destruct(); } + + bool socket_type::is_open() const + { + if (m_type == 0) return false; + TORRENT_SOCKTYPE_FORWARD_RET(is_open(), false) + } + + socket_type::lowest_layer_type& socket_type::lowest_layer() + { TORRENT_SOCKTYPE_FORWARD_RET(lowest_layer(), *((lowest_layer_type*)m_data)) } + + + void socket_type::open(protocol_type const& p, error_code& ec) + { TORRENT_SOCKTYPE_FORWARD(open(p, ec)) } + + void socket_type::close(error_code& ec) + { + if (m_type == 0) return; + TORRENT_SOCKTYPE_FORWARD(close(ec)) + } + + socket_type::endpoint_type socket_type::local_endpoint(error_code& ec) const + { TORRENT_SOCKTYPE_FORWARD_RET(local_endpoint(ec), socket_type::endpoint_type()) } + + socket_type::endpoint_type socket_type::remote_endpoint(error_code& ec) const + { TORRENT_SOCKTYPE_FORWARD_RET(remote_endpoint(ec), socket_type::endpoint_type()) } + + void socket_type::bind(endpoint_type const& endpoint, error_code& ec) + { TORRENT_SOCKTYPE_FORWARD(bind(endpoint, ec)) } + + std::size_t socket_type::available(error_code& ec) const + { TORRENT_SOCKTYPE_FORWARD_RET(available(ec), 0) } + +#ifndef BOOST_NO_EXCEPTIONS + void socket_type::open(protocol_type const& p) + { TORRENT_SOCKTYPE_FORWARD(open(p)) } + + void socket_type::close() + { + if (m_type == 0) return; + TORRENT_SOCKTYPE_FORWARD(close()) + } + + socket_type::endpoint_type socket_type::local_endpoint() const + { TORRENT_SOCKTYPE_FORWARD_RET(local_endpoint(), socket_type::endpoint_type()) } + + socket_type::endpoint_type socket_type::remote_endpoint() const + { TORRENT_SOCKTYPE_FORWARD_RET(remote_endpoint(), socket_type::endpoint_type()) } + + void socket_type::bind(endpoint_type const& endpoint) + { TORRENT_SOCKTYPE_FORWARD(bind(endpoint)) } + + std::size_t socket_type::available() const + { TORRENT_SOCKTYPE_FORWARD_RET(available(), 0) } +#endif + +} + diff --git a/src/storage.cpp b/src/storage.cpp index 2ca85fa69..849119717 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include -#include #include #include #include diff --git a/src/torrent.cpp b/src/torrent.cpp index f53128cf1..dda7c8c02 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include -#include #include #include #include diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 37b79d7d3..b5b414be1 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -48,6 +48,9 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include +#include +#include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -568,13 +571,15 @@ namespace libtorrent } #endif + typedef boost::date_time::second_clock second_clock; + // constructor used for creating new torrents // will not contain any hashes, comments, creation date // just the necessary to use it with piece manager // used for torrents with no metadata torrent_info::torrent_info(sha1_hash const& info_hash) : m_info_hash(info_hash) - , m_creation_date(pt::second_clock::universal_time()) + , m_creation_date(second_clock::universal_time()) , m_multifile(false) , m_private(false) , m_i2p(false) diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index ac0ebcdab..d0a3f1ff9 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -40,13 +40,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/tracker_manager.hpp" #include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/udp_tracker_connection.hpp" -#include "libtorrent/entry.hpp" -#include "libtorrent/bencode.hpp" -#include "libtorrent/torrent.hpp" -#include "libtorrent/peer_connection.hpp" #include "libtorrent/aux_/session_impl.hpp" -using namespace libtorrent; using boost::tuples::make_tuple; using boost::tuples::tuple; using boost::bind; diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 4a68f7de6..f6f04ff02 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -528,10 +528,15 @@ namespace libtorrent detail::write_int64(stats ? req.uploaded : 0, out); // uploaded detail::write_int32(req.event, out); // event // ip address - if (settings.announce_ip != address() && settings.announce_ip.is_v4()) - detail::write_uint32(settings.announce_ip.to_v4().to_ulong(), out); - else - detail::write_int32(0, out); + address_v4 announce_ip; + + if (!settings.announce_ip.empty()) + { + error_code ec; + address ip = address::from_string(settings.announce_ip.c_str(), ec); + if (!ec && ip.is_v4()) announce_ip = ip.to_v4(); + } + detail::write_uint32(announce_ip.to_ulong(), out); detail::write_int32(req.key, out); // key detail::write_int32(req.num_want, out); // num_want detail::write_uint16(req.listen_port, out); // port diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index a88bc05c3..61b51a7f6 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -634,14 +634,14 @@ int test_main() // url_has_argument - TEST_CHECK(!url_has_argument("http://127.0.0.1/test", "test")); - TEST_CHECK(!url_has_argument("http://127.0.0.1/test?foo=24", "bar")); - TEST_CHECK(*url_has_argument("http://127.0.0.1/test?foo=24", "foo") == "24"); - TEST_CHECK(*url_has_argument("http://127.0.0.1/test?foo=24&bar=23", "foo") == "24"); - TEST_CHECK(*url_has_argument("http://127.0.0.1/test?foo=24&bar=23", "bar") == "23"); - TEST_CHECK(*url_has_argument("http://127.0.0.1/test?foo=24&bar=23&a=e", "bar") == "23"); - TEST_CHECK(*url_has_argument("http://127.0.0.1/test?foo=24&bar=23&a=e", "a") == "e"); - TEST_CHECK(!url_has_argument("http://127.0.0.1/test?foo=24&bar=23&a=e", "b")); + TEST_CHECK(url_has_argument("http://127.0.0.1/test", "test") == ""); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24", "bar") == ""); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24", "foo") == "24"); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24&bar=23", "foo") == "24"); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24&bar=23", "bar") == "23"); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24&bar=23&a=e", "bar") == "23"); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24&bar=23&a=e", "a") == "e"); + TEST_CHECK(url_has_argument("http://127.0.0.1/test?foo=24&bar=23&a=e", "b") == ""); // escape_string char const* test_string = "!@#$%^&*()-_=+/,. %?"; diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 8deea133f..dda46f39c 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -37,9 +37,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bencode.hpp" #include "libtorrent/thread.hpp" #include +#include #include "test.hpp" #include "setup_transfer.hpp" +#include using namespace libtorrent; using boost::tuples::ignore;