From 262e97f21d2b8112c65318dac00e6767c5291600 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 20 May 2006 15:30:40 +0000 Subject: [PATCH] updated to latest version of asio. fixed a problem with low resolution timers in the second_tick code found by Massaroddel. --- AUTHORS | 2 +- Makefile.am | 107 +++++++++--------- docs/manual.rst | 7 +- .../libtorrent/http_tracker_connection.hpp | 5 +- include/libtorrent/session.hpp | 7 +- include/libtorrent/socket.hpp | 14 +-- include/libtorrent/torrent.hpp | 12 +- include/libtorrent/udp_tracker_connection.hpp | 5 +- src/bt_peer_connection.cpp | 4 +- src/http_tracker_connection.cpp | 46 ++++---- src/peer_connection.cpp | 2 +- src/policy.cpp | 4 +- src/session.cpp | 26 ++--- src/torrent.cpp | 39 +++---- src/udp_tracker_connection.cpp | 26 +++-- 15 files changed, 156 insertions(+), 150 deletions(-) diff --git a/AUTHORS b/AUTHORS index 46f096584..ace087242 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,7 +3,7 @@ Written by Arvid Norberg. Copyright (c) 2003-2006 Contributions by Magnus Jonsson, Daniel Wallin and Cory Nelson -Lots of testing, suggestions and contributions by Massaroddel. +Lots of testing, suggestions and contributions by Massaroddel and Tianhao Qiu. Big thanks to Michael Wojciechowski and Peter Koeleman for making the autotools scripts. diff --git a/Makefile.am b/Makefile.am index e047faf89..0c28de75b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,25 +5,20 @@ docs/udp_tracker_protocol.html docs/client_test.rst docs/client_test.html \ docs/unicode_support.png docs/client_test.png docs/style.css Jamfile project-root.jam \ m4/ac_cxx_namespaces.m4 m4/acx_pthread.m4 m4/ax_boost_date-time.m4 \ m4/ax_boost_filesystem.m4 m4/ax_boost_thread.m4 src/file_win.cpp libtorrent.pc \ -asio/COPYING \ -asio/INSTALL \ -asio/LICENSE_1_0.txt \ -asio/Makefile.am \ -asio/README \ -asio/THANKS \ -asio/TODO \ +asio/aclocal.m4 \ asio/autogen.sh \ asio/boostify.pl \ +asio/configure \ asio/configure.ac \ -asio/include/Makefile.am \ -asio/include/asio.hpp \ +asio/COPYING \ +asio/depcomp \ asio/include/asio/basic_datagram_socket.hpp \ asio/include/asio/basic_deadline_timer.hpp \ asio/include/asio/basic_io_object.hpp \ -asio/include/asio/basic_io_service.hpp \ -asio/include/asio/basic_locking_dispatcher.hpp \ +asio/include/asio/basic_resolver.hpp \ asio/include/asio/basic_socket.hpp \ asio/include/asio/basic_socket_acceptor.hpp \ +asio/include/asio/basic_strand.hpp \ asio/include/asio/basic_stream_socket.hpp \ asio/include/asio/buffer.hpp \ asio/include/asio/buffered_read_stream.hpp \ @@ -36,37 +31,20 @@ asio/include/asio/completion_condition.hpp \ asio/include/asio/datagram_socket_service.hpp \ asio/include/asio/deadline_timer.hpp \ asio/include/asio/deadline_timer_service.hpp \ -asio/include/asio/error.hpp \ -asio/include/asio/error_handler.hpp \ -asio/include/asio/handler_alloc_hook.hpp \ -asio/include/asio/io_service.hpp \ -asio/include/asio/is_read_buffered.hpp \ -asio/include/asio/is_write_buffered.hpp \ -asio/include/asio/locking_dispatcher.hpp \ -asio/include/asio/placeholders.hpp \ -asio/include/asio/read.hpp \ -asio/include/asio/service_factory.hpp \ -asio/include/asio/socket_acceptor_service.hpp \ -asio/include/asio/socket_base.hpp \ -asio/include/asio/ssl.hpp \ -asio/include/asio/stream_socket_service.hpp \ -asio/include/asio/system_exception.hpp \ -asio/include/asio/thread.hpp \ -asio/include/asio/time_traits.hpp \ -asio/include/asio/write.hpp \ asio/include/asio/detail/bind_handler.hpp \ asio/include/asio/detail/buffer_resize_guard.hpp \ asio/include/asio/detail/buffered_stream_storage.hpp \ asio/include/asio/detail/call_stack.hpp \ asio/include/asio/detail/consuming_buffers.hpp \ asio/include/asio/detail/epoll_reactor.hpp \ +asio/include/asio/detail/epoll_reactor_fwd.hpp \ asio/include/asio/detail/event.hpp \ asio/include/asio/detail/fd_set_adapter.hpp \ asio/include/asio/detail/handler_alloc_helpers.hpp \ asio/include/asio/detail/hash_map.hpp \ asio/include/asio/detail/io_control.hpp \ asio/include/asio/detail/kqueue_reactor.hpp \ -asio/include/asio/detail/locking_dispatcher.hpp \ +asio/include/asio/detail/kqueue_reactor_fwd.hpp \ asio/include/asio/detail/mutex.hpp \ asio/include/asio/detail/noncopyable.hpp \ asio/include/asio/detail/null_event.hpp \ @@ -74,6 +52,7 @@ asio/include/asio/detail/null_mutex.hpp \ asio/include/asio/detail/null_signal_blocker.hpp \ asio/include/asio/detail/null_thread.hpp \ asio/include/asio/detail/null_tss_ptr.hpp \ +asio/include/asio/detail/old_win_sdk_compat.hpp \ asio/include/asio/detail/pipe_select_interrupter.hpp \ asio/include/asio/detail/pop_options.hpp \ asio/include/asio/detail/posix_event.hpp \ @@ -86,9 +65,11 @@ asio/include/asio/detail/reactive_deadline_timer_service.hpp \ asio/include/asio/detail/reactive_socket_service.hpp \ asio/include/asio/detail/reactor_op_queue.hpp \ asio/include/asio/detail/reactor_timer_queue.hpp \ +asio/include/asio/detail/resolver_service.hpp \ asio/include/asio/detail/scoped_lock.hpp \ asio/include/asio/detail/select_interrupter.hpp \ asio/include/asio/detail/select_reactor.hpp \ +asio/include/asio/detail/select_reactor_fwd.hpp \ asio/include/asio/detail/service_registry.hpp \ asio/include/asio/detail/signal_blocker.hpp \ asio/include/asio/detail/signal_init.hpp \ @@ -97,11 +78,14 @@ asio/include/asio/detail/socket_ops.hpp \ asio/include/asio/detail/socket_option.hpp \ asio/include/asio/detail/socket_select_interrupter.hpp \ asio/include/asio/detail/socket_types.hpp \ +asio/include/asio/detail/strand_service.hpp \ asio/include/asio/detail/task_io_service.hpp \ +asio/include/asio/detail/task_io_service_fwd.hpp \ asio/include/asio/detail/thread.hpp \ asio/include/asio/detail/tss_ptr.hpp \ asio/include/asio/detail/win_event.hpp \ asio/include/asio/detail/win_iocp_io_service.hpp \ +asio/include/asio/detail/win_iocp_io_service_fwd.hpp \ asio/include/asio/detail/win_iocp_operation.hpp \ asio/include/asio/detail/win_iocp_socket_service.hpp \ asio/include/asio/detail/win_local_free_on_block_exit.hpp \ @@ -111,41 +95,62 @@ asio/include/asio/detail/win_thread.hpp \ asio/include/asio/detail/win_tss_ptr.hpp \ asio/include/asio/detail/winsock_init.hpp \ asio/include/asio/detail/wrapped_handler.hpp \ +asio/include/asio/error.hpp \ +asio/include/asio/error_handler.hpp \ +asio/include/asio/handler_alloc_hook.hpp \ +asio/include/asio/impl/basic_datagram_socket.ipp \ +asio/include/asio/impl/io_service.ipp \ asio/include/asio/impl/read.ipp \ asio/include/asio/impl/write.ipp \ +asio/include/asio/io_service.hpp \ asio/include/asio/ip/address.hpp \ +asio/include/asio/ip/address_v4.hpp \ +asio/include/asio/ip/address_v6.hpp \ asio/include/asio/ip/basic_endpoint.hpp \ +asio/include/asio/ip/basic_resolver_entry.hpp \ +asio/include/asio/ip/basic_resolver_iterator.hpp \ +asio/include/asio/ip/basic_resolver_query.hpp \ +asio/include/asio/ip/detail/socket_option.hpp \ +asio/include/asio/ip/host_name.hpp \ +asio/include/asio/ip/multicast.hpp \ +asio/include/asio/ip/resolver_query_base.hpp \ asio/include/asio/ip/tcp.hpp \ asio/include/asio/ip/udp.hpp \ -asio/include/asio/ipv4/address.hpp \ -asio/include/asio/ipv4/basic_endpoint.hpp \ -asio/include/asio/ipv4/basic_host_resolver.hpp \ -asio/include/asio/ipv4/host.hpp \ -asio/include/asio/ipv4/host_resolver.hpp \ -asio/include/asio/ipv4/host_resolver_service.hpp \ -asio/include/asio/ipv4/multicast.hpp \ -asio/include/asio/ipv4/tcp.hpp \ -asio/include/asio/ipv4/udp.hpp \ -asio/include/asio/ipv4/detail/host_resolver_service.hpp \ -asio/include/asio/ipv4/detail/socket_option.hpp \ -asio/include/asio/ipv6/address.hpp \ -asio/include/asio/ipv6/basic_endpoint.hpp \ -asio/include/asio/ipv6/multicast.hpp \ -asio/include/asio/ipv6/tcp.hpp \ -asio/include/asio/ipv6/udp.hpp \ -asio/include/asio/ipv6/detail/socket_option.hpp \ +asio/include/asio/is_read_buffered.hpp \ +asio/include/asio/is_write_buffered.hpp \ +asio/include/asio/placeholders.hpp \ +asio/include/asio/read.hpp \ +asio/include/asio/resolver_service.hpp \ +asio/include/asio/socket_acceptor_service.hpp \ +asio/include/asio/socket_base.hpp \ asio/include/asio/ssl/basic_context.hpp \ asio/include/asio/ssl/context.hpp \ asio/include/asio/ssl/context_base.hpp \ asio/include/asio/ssl/context_service.hpp \ -asio/include/asio/ssl/stream.hpp \ -asio/include/asio/ssl/stream_base.hpp \ -asio/include/asio/ssl/stream_service.hpp \ asio/include/asio/ssl/detail/openssl_context_service.hpp \ asio/include/asio/ssl/detail/openssl_init.hpp \ asio/include/asio/ssl/detail/openssl_operation.hpp \ asio/include/asio/ssl/detail/openssl_stream_service.hpp \ -asio/include/asio/ssl/detail/openssl_types.hpp +asio/include/asio/ssl/detail/openssl_types.hpp \ +asio/include/asio/ssl/stream.hpp \ +asio/include/asio/ssl/stream_base.hpp \ +asio/include/asio/ssl/stream_service.hpp \ +asio/include/asio/ssl.hpp \ +asio/include/asio/strand.hpp \ +asio/include/asio/strand_service.hpp \ +asio/include/asio/stream_socket_service.hpp \ +asio/include/asio/system_exception.hpp \ +asio/include/asio/thread.hpp \ +asio/include/asio/time_traits.hpp \ +asio/include/asio/write.hpp \ +asio/include/asio.hpp \ +asio/include/Makefile.am \ +asio/INSTALL \ +asio/install-sh \ +asio/LICENSE_1_0.txt \ +asio/Makefile.am \ +asio/missing \ +asio/README pkgconfigdir = $(libdir)/pkgconfig diff --git a/docs/manual.rst b/docs/manual.rst index de30d925c..ffcef25da 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -82,15 +82,16 @@ boost libraries as well as zlib_ (shipped) and asio_ (shipped). At least version libtorrent has been successfully compiled and tested on: * Windows 2000 vc7.1 - * Linux x86 GCC 3.0.4, GCC 3.2.3, GCC 3.4.2 - * MacOS X (darwin), (Apple's) GCC 3.3, (Apple's) GCC 4.0 + * Linux x86 GCC 3.3, GCC 3.4.2 + * MacOS X (darwin), (Apple's) GCC 4.0 * SunOS 5.8 GCC 3.1 * Cygwin GCC 3.3.3 Fails on: * GCC 2.95.4 - * msvc6 sp5 + * msvc6 + * (Apple's) GCC 3.3 (compiler crashes with the latest version of asio) libtorrent is released under the BSD-license_. diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index 7bcb553b6..dd9fea09e 100755 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -132,7 +132,7 @@ namespace libtorrent std::string const& hostname , std::string const& request); - void name_lookup(asio::error const& error); + void name_lookup(asio::error const& error, tcp::resolver::iterator i); void connected(asio::error const& error); void sent(asio::error const& error); void receive(asio::error const& error @@ -150,8 +150,7 @@ namespace libtorrent int m_content_length; std::string m_location; - host_resolver m_name_lookup; - host m_host; + tcp::resolver m_name_lookup; int m_port; boost::shared_ptr m_socket; int m_recv_pos; diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 41f008a39..be4ca7d99 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -180,7 +180,8 @@ namespace libtorrent struct session_impl: boost::noncopyable { friend class invariant_access; - typedef std::map, boost::intrusive_ptr > + typedef std::map + , boost::intrusive_ptr > connection_map; typedef std::map > torrent_map; typedef std::deque > @@ -189,7 +190,7 @@ namespace libtorrent session_impl( std::pair listen_port_range , fingerprint const& cl_fprint - , const char* listen_interface); + , char const* listen_interface = "0.0.0.0"); void operator()(); @@ -347,7 +348,7 @@ namespace libtorrent session( fingerprint const& print , std::pair listen_port_range - , const char* listen_interface = 0); + , char const* listen_interface = "0.0.0.0"); ~session(); diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index 6a0d2b7ec..5372b3650 100755 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -73,15 +73,13 @@ namespace libtorrent */ namespace asio = ::asio; - using asio::ipv4::tcp; - using asio::ipv4::udp; - typedef asio::ipv4::tcp::socket stream_socket; - using asio::ipv4::address; - typedef asio::ipv4::udp::socket datagram_socket; - typedef asio::ipv4::tcp::acceptor socket_acceptor; + using asio::ip::tcp; + using asio::ip::udp; + typedef asio::ip::tcp::socket stream_socket; + typedef asio::ip::address_v4 address; + typedef asio::ip::udp::socket datagram_socket; + typedef asio::ip::tcp::acceptor socket_acceptor; typedef asio::io_service demuxer; - using asio::ipv4::host_resolver; - using asio::ipv4::host; using asio::async_write; using asio::deadline_timer; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index c72f9b5fd..40f24eb9b 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -320,7 +320,8 @@ namespace libtorrent // this is the asio callback that is called when a name // lookup for a web seed is completed. - void on_name_lookup(asio::error const& e, int port, std::string url, host h); + void on_name_lookup(asio::error const& e, tcp::resolver::iterator i + , int port, std::string url); // this is called when the torrent has finished. i.e. // all the pieces we have not filtered have been downloaded. @@ -479,12 +480,13 @@ namespace libtorrent // The list of web seeds in this torrent. Seeds // with fatal errors are removed from the set std::set m_web_seeds; - // The set of url seeds that are currently having - // their hostnames resolved. - std::map m_resolving_web_seeds; + + // urls of the web seeds that we are currently + // resolving the address for + std::set m_resolving_web_seeds; // used to resolve the names of web seeds - host_resolver m_host_resolver; + tcp::resolver m_host_resolver; // this is the upload and download statistics for the whole torrent. // it's updated from all its peers once every second. diff --git a/include/libtorrent/udp_tracker_connection.hpp b/include/libtorrent/udp_tracker_connection.hpp index a3f6828aa..184f4dc95 100755 --- a/include/libtorrent/udp_tracker_connection.hpp +++ b/include/libtorrent/udp_tracker_connection.hpp @@ -87,7 +87,7 @@ namespace libtorrent boost::intrusive_ptr self() { return boost::intrusive_ptr(this); } - void name_lookup(asio::error const& error); + void name_lookup(asio::error const& error, tcp::resolver::iterator i); void timeout(asio::error const& error); void send_udp_connect(); @@ -103,8 +103,7 @@ namespace libtorrent tracker_manager& m_man; - host_resolver m_name_lookup; - host m_host; + tcp::resolver m_name_lookup; int m_port; boost::shared_ptr m_socket; udp::endpoint m_target; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 4b4cc2a31..ea4d7db66 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -711,8 +711,8 @@ namespace libtorrent { if (listen_port->type() == entry::int_t) { - tcp::endpoint adr((unsigned short)listen_port->integer() - , remote().address()); + tcp::endpoint adr(remote().address() + , (unsigned short)listen_port->integer()); t->get_policy().peer_from_tracker(adr, pid()); } } diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 85b1771e2..fa52806e9 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -375,8 +375,9 @@ namespace libtorrent } #endif - m_name_lookup.async_by_name(m_host, *connect_to_host - , bind(&http_tracker_connection::name_lookup, self(), _1)); + tcp::resolver::query q(*connect_to_host); + m_name_lookup.async_resolve(q + , boost::bind(&http_tracker_connection::name_lookup, self(), _1, _2)); set_timeout(m_settings.tracker_completion_timeout , m_settings.tracker_receive_timeout); } @@ -389,12 +390,13 @@ namespace libtorrent fail_timeout(); } - void http_tracker_connection::name_lookup(asio::error const& error) try + void http_tracker_connection::name_lookup(asio::error const& error + , tcp::resolver::iterator i) try { if (error == asio::error::operation_aborted) return; if (m_timed_out) return; - if (error) + if (error || i == tcp::resolver::iterator()) { fail(-1, error.what()); return; @@ -405,7 +407,7 @@ namespace libtorrent #endif restart_read_timeout(); m_socket.reset(new stream_socket(m_name_lookup.io_service())); - tcp::endpoint a(m_port, m_host.address(0)); + tcp::endpoint a(i->endpoint().address(), m_port); if (has_requester()) requester().m_tracker_address = a; m_socket->async_connect(a, bind(&http_tracker_connection::connected, self(), _1)); } @@ -515,28 +517,30 @@ namespace libtorrent std::vector::iterator end = m_buffer.begin()+m_recv_pos; std::vector::iterator newline = std::find(m_buffer.begin(), end, '\n'); // if we don't have a full line yet, wait. - if (newline == end) return; + if (newline != end) + { #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) - if (has_requester()) requester().debug_log(std::string(m_buffer.begin(), newline)); + if (has_requester()) requester().debug_log(std::string(m_buffer.begin(), newline)); #endif - std::istringstream line(std::string(m_buffer.begin(), newline)); - ++newline; - m_recv_pos -= (int)std::distance(m_buffer.begin(), newline); - m_buffer.erase(m_buffer.begin(), newline); + std::istringstream line(std::string(m_buffer.begin(), newline)); + ++newline; + m_recv_pos -= (int)std::distance(m_buffer.begin(), newline); + m_buffer.erase(m_buffer.begin(), newline); - std::string protocol; - line >> m_server_protocol; - if (m_server_protocol.substr(0, 5) != "HTTP/") - { - std::string error_msg = "unknown protocol in response: " + m_server_protocol; - fail(-1, error_msg.c_str()); - return; + std::string protocol; + line >> m_server_protocol; + if (m_server_protocol.substr(0, 5) != "HTTP/") + { + std::string error_msg = "unknown protocol in response: " + m_server_protocol; + fail(-1, error_msg.c_str()); + return; + } + line >> m_code; + std::getline(line, m_server_message); + m_state = read_header; } - line >> m_code; - std::getline(line, m_server_message); - m_state = read_header; } if (m_state == read_header) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index eb5b39dba..f362f5d3b 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1803,7 +1803,7 @@ namespace libtorrent m_queued = false; assert(m_connecting); - m_socket->open(asio::ipv4::tcp()); + m_socket->open(asio::ip::tcp::v4()); m_socket->bind(t->get_interface()); m_socket->async_connect(m_remote , bind(&peer_connection::on_connection_complete, self(), _1)); diff --git a/src/policy.cpp b/src/policy.cpp index 5afc60aec..6bc65416d 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -906,7 +906,7 @@ namespace libtorrent if (i->connection != 0) throw protocol_error("duplicate connection, closing"); if (i->banned) - throw protocol_error("ip tcp::endpoint banned, closing"); + throw protocol_error("ip address banned, closing"); } assert(i->connection == 0); @@ -924,7 +924,7 @@ namespace libtorrent INVARIANT_CHECK; // just ignore the obviously invalid entries from the tracker - if(remote.address().to_ulong() == 0 || remote.port() == 0) + if(remote.address() == address(0) || remote.port() == 0) return; try diff --git a/src/session.cpp b/src/session.cpp index f01240dca..25ee3b936 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -408,10 +408,10 @@ namespace libtorrent { namespace detail session_impl::session_impl( std::pair listen_port_range , const fingerprint& cl_fprint - , const char* listen_interface = 0) + , char const* listen_interface) : m_tracker_manager(m_http_settings) , m_listen_port_range(listen_port_range) - , m_listen_interface(listen_port_range.first) + , m_listen_interface(address::from_string(listen_interface), listen_port_range.first) , m_abort(false) , m_upload_rate(-1) , m_download_rate(-1) @@ -419,11 +419,9 @@ namespace libtorrent { namespace detail , m_max_connections(-1) , m_half_open_limit(-1) , m_incoming_connection(false) - , m_last_tick(second_clock::universal_time()) + , m_last_tick(microsec_clock::universal_time()) , m_timer(m_selector) { - if (listen_interface != 0) m_listen_interface.address( - address(listen_interface)); #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) m_logger = create_log("main_session", false); @@ -481,7 +479,7 @@ namespace libtorrent { namespace detail { try { - m_listen_socket->open(asio::ipv4::tcp()); + m_listen_socket->open(asio::ip::tcp::v4()); m_listen_socket->bind(m_listen_interface); m_listen_socket->listen(); break; @@ -608,7 +606,7 @@ namespace libtorrent { namespace detail #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << endp << " <== INCOMING CONNECTION\n"; #endif - if (m_ip_filter.access(endp.address()) & ip_filter::blocked) + if (m_ip_filter.access(endp.address().to_v4()) & ip_filter::blocked) { #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << "filtered blocked ip\n"; @@ -742,9 +740,9 @@ namespace libtorrent { namespace detail session_impl::mutex_t::scoped_lock l(m_mutex); if (m_abort) return; - float tick_interval = (second_clock::universal_time() + float tick_interval = (microsec_clock::universal_time() - m_last_tick).total_milliseconds() / 1000.f; - m_last_tick = second_clock::universal_time(); + m_last_tick = microsec_clock::universal_time(); m_timer.expires_from_now(seconds(1)); m_timer.async_wait(bind(&session_impl::second_tick, this, _1)); @@ -1080,7 +1078,7 @@ namespace libtorrent = m_impl.m_connections.begin(); i != m_impl.m_connections.end();) { tcp::endpoint sender = i->first->remote_endpoint(); - if (m_impl.m_ip_filter.access(sender.address()) + if (m_impl.m_ip_filter.access(sender.address().to_v4()) & ip_filter::blocked) { #if defined(TORRENT_VERBOSE_LOGGING) @@ -1329,9 +1327,9 @@ namespace libtorrent m_impl.m_listen_port_range = port_range; if (net_interface && std::strlen(net_interface) > 0) - m_impl.m_listen_interface = tcp::endpoint(port_range.first, net_interface); + m_impl.m_listen_interface = tcp::endpoint(address::from_string(net_interface), port_range.first); else - m_impl.m_listen_interface = tcp::endpoint(port_range.first); + m_impl.m_listen_interface = tcp::endpoint(address(), port_range.first); m_impl.open_listen_port(); return m_impl.m_listen_socket; @@ -1499,8 +1497,8 @@ namespace libtorrent i != peer_list.end(); ++i) { tcp::endpoint a( - (unsigned short)(*i)["port"].integer() - , (*i)["ip"].string().c_str()); + address::from_string((*i)["ip"].string()) + , (unsigned short)(*i)["port"].integer()); tmp_peers.push_back(a); } diff --git a/src/torrent.cpp b/src/torrent.cpp index d305fcc7e..ae6a32417 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -226,7 +226,7 @@ namespace libtorrent , m_ratio(0.f) , m_total_failed_bytes(0) , m_total_redundant_bytes(0) - , m_net_interface(0, net_interface.address()) + , m_net_interface(net_interface.address(), 0) , m_upload_bandwidth_limit(std::numeric_limits::max()) , m_download_bandwidth_limit(std::numeric_limits::max()) , m_save_path(complete(save_path)) @@ -314,7 +314,7 @@ namespace libtorrent , m_ratio(0.f) , m_total_failed_bytes(0) , m_total_redundant_bytes(0) - , m_net_interface(0, net_interface.address()) + , m_net_interface(net_interface.address(), 0) , m_upload_bandwidth_limit(std::numeric_limits::max()) , m_download_bandwidth_limit(std::numeric_limits::max()) , m_save_path(complete(save_path)) @@ -405,7 +405,7 @@ namespace libtorrent { INVARIANT_CHECK; - m_net_interface = tcp::endpoint(0, net_interface); + m_net_interface = tcp::endpoint(address::from_string(net_interface), 0); } // returns true if it is time for this torrent to make another @@ -485,9 +485,9 @@ namespace libtorrent if (i->pid == m_ses.get_peer_id()) continue; - tcp::endpoint a(i->port, i->ip.c_str()); + tcp::endpoint a(address::from_string(i->ip), i->port); - if (m_ses.m_ip_filter.access(a.address()) == ip_filter::blocked) + if (m_ses.m_ip_filter.access(a.address().to_v4()) == ip_filter::blocked) { #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) debug_log("blocked ip from tracker: " + i->ip); @@ -937,26 +937,24 @@ namespace libtorrent boost::tie(protocol, hostname, port, path) = parse_url_components(url); - typedef std::map resolving; + m_resolving_web_seeds.insert(url); + tcp::resolver::query q(hostname); - resolving::iterator i = m_resolving_web_seeds.insert(std::pair(url, host())).first; - m_host_resolver.async_by_name(i->second, hostname - , bind(&torrent::on_name_lookup, shared_from_this(), _1, port - , boost::ref(i->first), boost::ref(i->second))); + m_host_resolver.async_resolve(q, bind(&torrent::on_name_lookup + , shared_from_this(), _1, _2, port, url)); } - void torrent::on_name_lookup(asio::error const& e, int port, std::string url - , host h) try + void torrent::on_name_lookup(asio::error const& e, tcp::resolver::iterator host + , int port, std::string url) try { detail::session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); INVARIANT_CHECK; - - typedef std::map resolving; - resolving::iterator i = m_resolving_web_seeds.find(url); + + std::set::iterator i = m_resolving_web_seeds.find(url); if (i != m_resolving_web_seeds.end()) m_resolving_web_seeds.erase(i); - if (e) + if (e || host == tcp::resolver::iterator()) { if (m_ses.m_alerts.should_post(alert::warning)) { @@ -972,7 +970,7 @@ namespace libtorrent return; } - tcp::endpoint a(port, h.address(0)); + tcp::endpoint a(host->endpoint().address(), port); boost::shared_ptr s(new stream_socket(m_ses.m_selector)); boost::intrusive_ptr c(new web_peer_connection( @@ -1460,10 +1458,9 @@ namespace libtorrent web_seeds.insert(p->url()); } - for (std::map::iterator i - = m_resolving_web_seeds.begin(), end(m_resolving_web_seeds.end()); - i != end; ++i) - web_seeds.insert(web_seeds.begin(), i->first); + for (std::set::iterator i = m_resolving_web_seeds.begin() + , end(m_resolving_web_seeds.end()); i != end; ++i) + web_seeds.insert(web_seeds.begin(), *i); // from the list of available web seeds, subtract the ones we are // already connected to. diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index cff4ae1a4..cbfbdd8f1 100755 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -90,16 +90,18 @@ namespace libtorrent , m_attempts(0) { m_socket.reset(new datagram_socket(d)); - m_name_lookup.async_by_name(m_host, hostname.c_str() - , bind(&udp_tracker_connection::name_lookup, self(), _1)); + tcp::resolver::query q(hostname.c_str()); + m_name_lookup.async_resolve(q + , boost::bind(&udp_tracker_connection::name_lookup, self(), _1, _2)); set_timeout(m_settings.tracker_completion_timeout , m_settings.tracker_receive_timeout); } - void udp_tracker_connection::name_lookup(asio::error const& error) try + void udp_tracker_connection::name_lookup(asio::error const& error + , tcp::resolver::iterator i) try { if (error == asio::error::operation_aborted) return; - if (error) + if (error || i == tcp::resolver::iterator()) { fail(-1, error.what()); return; @@ -109,9 +111,9 @@ namespace libtorrent if (has_requester()) requester().debug_log("udp tracker name lookup successful"); #endif restart_read_timeout(); - m_target = udp::endpoint(m_port, m_host.address(0)); + m_target = udp::endpoint(i->endpoint().address(), m_port); if (has_requester()) requester().m_tracker_address - = tcp::endpoint(m_port, m_host.address(0)); + = tcp::endpoint(i->endpoint().address(), m_port); m_socket->connect(m_target); send_udp_connect(); } @@ -155,7 +157,7 @@ namespace libtorrent m_socket->send(asio::buffer((void*)send_buf, 16), 0); ++m_attempts; m_buffer.resize(udp_buffer_size); - m_socket->async_receive_from(asio::buffer(m_buffer), 0, m_sender + m_socket->async_receive_from(asio::buffer(m_buffer), m_sender , boost::bind(&udp_tracker_connection::connect_response, self(), _1, _2)); } @@ -172,7 +174,7 @@ namespace libtorrent if (m_target != m_sender) { // this packet was not received from the tracker - m_socket->async_receive_from(asio::buffer(m_buffer), 0, m_sender + m_socket->async_receive_from(asio::buffer(m_buffer), m_sender , boost::bind(&udp_tracker_connection::connect_response, self(), _1, _2)); return; } @@ -293,7 +295,7 @@ namespace libtorrent m_socket->send(asio::buffer(buf), 0); ++m_attempts; - m_socket->async_receive_from(asio::buffer(m_buffer), 0, m_sender + m_socket->async_receive_from(asio::buffer(m_buffer), m_sender , bind(&udp_tracker_connection::announce_response, self(), _1, _2)); } @@ -317,7 +319,7 @@ namespace libtorrent m_socket->send(asio::buffer(&buf[0], buf.size()), 0); ++m_attempts; - m_socket->async_receive_from(asio::buffer(m_buffer), 0, m_sender + m_socket->async_receive_from(asio::buffer(m_buffer), m_sender , bind(&udp_tracker_connection::scrape_response, self(), _1, _2)); } @@ -334,7 +336,7 @@ namespace libtorrent if (m_target != m_sender) { // this packet was not received from the tracker - m_socket->async_receive_from(asio::buffer(m_buffer), 0, m_sender + m_socket->async_receive_from(asio::buffer(m_buffer), m_sender , bind(&udp_tracker_connection::connect_response, self(), _1, _2)); return; } @@ -443,7 +445,7 @@ namespace libtorrent if (m_target != m_sender) { // this packet was not received from the tracker - m_socket->async_receive_from(asio::buffer(m_buffer), 0, m_sender + m_socket->async_receive_from(asio::buffer(m_buffer), m_sender , bind(&udp_tracker_connection::connect_response, self(), _1, _2)); return; }