From 903e11e458b6cc2742470a51289c47fa3d19d04c Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 17 Jun 2006 22:04:25 +0000 Subject: [PATCH] moved the asio headers into the include directory, to have them installed when libtorrent is installed. improved the complexity of torrent_info::map_file(), It's now O(1). --- Makefile.am | 149 +--------------------------- docs/manual.html | 132 ++---------------------- docs/manual.rst | 6 ++ examples/Makefile.am | 2 +- include/Makefile.am | 142 +++++++++++++++++++++++++- include/libtorrent/torrent_info.hpp | 3 +- src/Makefile.am | 2 +- src/http_tracker_connection.cpp | 2 +- src/torrent.cpp | 2 +- src/torrent_info.cpp | 12 ++- src/udp_tracker_connection.cpp | 2 +- test/Makefile.am | 2 +- 12 files changed, 173 insertions(+), 283 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6c65160fc..92087e97d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,153 +18,7 @@ debian/libtorrent0-dev.install \ debian/libtorrent0.dirs \ debian/libtorrent0.docs \ debian/libtorrent0.install \ -debian/rules \ -asio/aclocal.m4 \ -asio/autogen.sh \ -asio/boostify.pl \ -asio/configure \ -asio/configure.ac \ -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_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 \ -asio/include/asio/buffered_read_stream_fwd.hpp \ -asio/include/asio/buffered_stream.hpp \ -asio/include/asio/buffered_stream_fwd.hpp \ -asio/include/asio/buffered_write_stream.hpp \ -asio/include/asio/buffered_write_stream_fwd.hpp \ -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/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/kqueue_reactor_fwd.hpp \ -asio/include/asio/detail/mutex.hpp \ -asio/include/asio/detail/noncopyable.hpp \ -asio/include/asio/detail/null_event.hpp \ -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 \ -asio/include/asio/detail/posix_mutex.hpp \ -asio/include/asio/detail/posix_signal_blocker.hpp \ -asio/include/asio/detail/posix_thread.hpp \ -asio/include/asio/detail/posix_tss_ptr.hpp \ -asio/include/asio/detail/push_options.hpp \ -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 \ -asio/include/asio/detail/socket_holder.hpp \ -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 \ -asio/include/asio/detail/win_mutex.hpp \ -asio/include/asio/detail/win_signal_blocker.hpp \ -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/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/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/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 +debian/rules pkgconfigdir = $(libdir)/pkgconfig @@ -176,7 +30,6 @@ check: test && test/test_ip_filter \ && test/test_piece_picker \ && test/test_storage \ - && test/test_metadata_extension \ && test/test_buffer \ && echo && echo && echo " **** all tests passed ****" && echo && echo diff --git a/docs/manual.html b/docs/manual.html index 272cb1a4c..adc346167 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -6,127 +6,7 @@ libtorrent manual - +
@@ -137,10 +17,12 @@ div.warning, div.note, div.important { Author: Arvid Norberg, arvid@rasterbar.com +Version: +0.9.2 -
-

Table of contents

+
+

Table of contents

  • introduction
  • downloading and building
      @@ -1328,10 +1210,14 @@ iterators with the type file_entr

      The path is the full (relative) path of each file. i.e. if it is a multi-file torrent, all the files starts with a directory with the same name as torrent_info::name(). The filenames are encoded with UTF-8.

      +

      size is the size of the file (in bytes) and offset is the byte offset +of the file within the torrent. i.e. the sum of all the sizes of the files +before this one in the file list this one in the file list..

       struct file_entry
       {
               boost::filesystem::path path;
      +        size_type offset;
               size_type size;
       };
       
      diff --git a/docs/manual.rst b/docs/manual.rst index 218d25f3c..7d9f415d7 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3,6 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@rasterbar.com +:Version: 0.9.2 .. contents:: Table of contents :depth: 2 @@ -1146,11 +1147,16 @@ The ``path`` is the full (relative) path of each file. i.e. if it is a multi-fil torrent, all the files starts with a directory with the same name as ``torrent_info::name()``. The filenames are encoded with UTF-8. +``size`` is the size of the file (in bytes) and ``offset`` is the byte offset +of the file within the torrent. i.e. the sum of all the sizes of the files +before this one in the file list this one in the file list.. + :: struct file_entry { boost::filesystem::path path; + size_type offset; size_type size; }; diff --git a/examples/Makefile.am b/examples/Makefile.am index 97c7081cc..373075341 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -14,5 +14,5 @@ make_torrent_LDADD = $(top_builddir)/src/libtorrent.la simple_client_SOURCES = simple_client.cpp simple_client_LDADD = $(top_builddir)/src/libtorrent.la -AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/asio/include @DEBUGFLAGS@ @PTHREAD_CFLAGS@ +AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ @PTHREAD_CFLAGS@ AM_LDFLAGS= ${LDLAGS} -L./ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@ diff --git a/include/Makefile.am b/include/Makefile.am index 8535745e5..7e0004544 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -38,4 +38,144 @@ libtorrent/torrent_info.hpp \ libtorrent/tracker_manager.hpp \ libtorrent/udp_tracker_connection.hpp \ libtorrent/utf8.hpp \ -libtorrent/version.hpp +libtorrent/version.hpp \ +\ +asio/basic_datagram_socket.hpp \ +asio/basic_deadline_timer.hpp \ +asio/basic_io_object.hpp \ +asio/basic_resolver.hpp \ +asio/basic_socket.hpp \ +asio/basic_socket_acceptor.hpp \ +asio/basic_socket_iostream.hpp \ +asio/basic_socketbuf.hpp \ +asio/basic_strand.hpp \ +asio/basic_stream_socket.hpp \ +asio/basic_streambuf.hpp \ +asio/buffer.hpp \ +asio/buffered_read_stream.hpp \ +asio/buffered_read_stream_fwd.hpp \ +asio/buffered_stream.hpp \ +asio/buffered_stream_fwd.hpp \ +asio/buffered_write_stream.hpp \ +asio/buffered_write_stream_fwd.hpp \ +asio/completion_condition.hpp \ +asio/datagram_socket_service.hpp \ +asio/deadline_timer.hpp \ +asio/deadline_timer_service.hpp \ +asio/detail/bind_handler.hpp \ +asio/detail/buffer_resize_guard.hpp \ +asio/detail/buffered_stream_storage.hpp \ +asio/detail/call_stack.hpp \ +asio/detail/const_buffers_iterator.hpp \ +asio/detail/consuming_buffers.hpp \ +asio/detail/epoll_reactor.hpp \ +asio/detail/epoll_reactor_fwd.hpp \ +asio/detail/event.hpp \ +asio/detail/fd_set_adapter.hpp \ +asio/detail/handler_alloc_helpers.hpp \ +asio/detail/hash_map.hpp \ +asio/detail/io_control.hpp \ +asio/detail/kqueue_reactor.hpp \ +asio/detail/kqueue_reactor_fwd.hpp \ +asio/detail/mutex.hpp \ +asio/detail/noncopyable.hpp \ +asio/detail/null_event.hpp \ +asio/detail/null_mutex.hpp \ +asio/detail/null_signal_blocker.hpp \ +asio/detail/null_thread.hpp \ +asio/detail/null_tss_ptr.hpp \ +asio/detail/old_win_sdk_compat.hpp \ +asio/detail/pipe_select_interrupter.hpp \ +asio/detail/pop_options.hpp \ +asio/detail/posix_event.hpp \ +asio/detail/posix_mutex.hpp \ +asio/detail/posix_signal_blocker.hpp \ +asio/detail/posix_thread.hpp \ +asio/detail/posix_tss_ptr.hpp \ +asio/detail/push_options.hpp \ +asio/detail/reactive_deadline_timer_service.hpp \ +asio/detail/reactive_socket_service.hpp \ +asio/detail/reactor_op_queue.hpp \ +asio/detail/reactor_timer_queue.hpp \ +asio/detail/resolver_service.hpp \ +asio/detail/scoped_lock.hpp \ +asio/detail/select_interrupter.hpp \ +asio/detail/select_reactor.hpp \ +asio/detail/select_reactor_fwd.hpp \ +asio/detail/service_registry.hpp \ +asio/detail/signal_blocker.hpp \ +asio/detail/signal_init.hpp \ +asio/detail/socket_holder.hpp \ +asio/detail/socket_ops.hpp \ +asio/detail/socket_option.hpp \ +asio/detail/socket_select_interrupter.hpp \ +asio/detail/socket_types.hpp \ +asio/detail/strand_service.hpp \ +asio/detail/task_io_service.hpp \ +asio/detail/task_io_service_fwd.hpp \ +asio/detail/thread.hpp \ +asio/detail/tss_ptr.hpp \ +asio/detail/win_event.hpp \ +asio/detail/win_iocp_io_service.hpp \ +asio/detail/win_iocp_io_service_fwd.hpp \ +asio/detail/win_iocp_operation.hpp \ +asio/detail/win_iocp_socket_service.hpp \ +asio/detail/win_local_free_on_block_exit.hpp \ +asio/detail/win_mutex.hpp \ +asio/detail/win_signal_blocker.hpp \ +asio/detail/win_thread.hpp \ +asio/detail/win_tss_ptr.hpp \ +asio/detail/winsock_init.hpp \ +asio/detail/wrapped_handler.hpp \ +asio/error.hpp \ +asio/error_handler.hpp \ +asio/handler_alloc_hook.hpp \ +asio/impl/io_service.ipp \ +asio/impl/read.ipp \ +asio/impl/read_until.ipp \ +asio/impl/write.ipp \ +asio/io_service.hpp \ +asio/ip/address.hpp \ +asio/ip/address_v4.hpp \ +asio/ip/address_v6.hpp \ +asio/ip/basic_endpoint.hpp \ +asio/ip/basic_resolver_entry.hpp \ +asio/ip/basic_resolver_iterator.hpp \ +asio/ip/basic_resolver_query.hpp \ +asio/ip/detail/socket_option.hpp \ +asio/ip/host_name.hpp \ +asio/ip/multicast.hpp \ +asio/ip/resolver_query_base.hpp \ +asio/ip/tcp.hpp \ +asio/ip/udp.hpp \ +asio/is_read_buffered.hpp \ +asio/is_write_buffered.hpp \ +asio/placeholders.hpp \ +asio/read.hpp \ +asio/read_until.hpp \ +asio/resolver_service.hpp \ +asio/socket_acceptor_service.hpp \ +asio/socket_base.hpp \ +asio/ssl/basic_context.hpp \ +asio/ssl/context.hpp \ +asio/ssl/context_base.hpp \ +asio/ssl/context_service.hpp \ +asio/ssl/detail/openssl_context_service.hpp \ +asio/ssl/detail/openssl_init.hpp \ +asio/ssl/detail/openssl_operation.hpp \ +asio/ssl/detail/openssl_stream_service.hpp \ +asio/ssl/detail/openssl_types.hpp \ +asio/ssl/stream.hpp \ +asio/ssl/stream_base.hpp \ +asio/ssl/stream_service.hpp \ +asio/ssl.hpp \ +asio/strand.hpp \ +asio/strand_service.hpp \ +asio/stream_socket_service.hpp \ +asio/streambuf.hpp \ +asio/system_exception.hpp \ +asio/thread.hpp \ +asio/time_traits.hpp \ +asio/write.hpp \ +asio.hpp + diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 80a24654f..8d932cb5b 100755 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -63,7 +63,8 @@ namespace libtorrent struct TORRENT_EXPORT file_entry { boost::filesystem::path path; - size_type size; + size_type offset; // the offset of this file inside the torrent + size_type size; // the size of this file }; struct TORRENT_EXPORT file_slice diff --git a/src/Makefile.am b/src/Makefile.am index c72fda8d9..ec1546450 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,5 +55,5 @@ $(top_srcdir)/include/libtorrent/version.hpp libtorrent_la_LDFLAGS = $(LDFLAGS) -version-info 1:0:1 libtorrent_la_LIBADD = @ZLIB@ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@ -AM_CXXFLAGS= -ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/asio/include @ZLIBINCL@ @DEBUGFLAGS@ @PTHREAD_CFLAGS@ +AM_CXXFLAGS= -ftemplate-depth-50 -I$(top_srcdir)/include @ZLIBINCL@ @DEBUGFLAGS@ @PTHREAD_CFLAGS@ AM_LDFLAGS= $(LDFLAGS) -L./ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@ diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index d3dd5ae5f..db28560f7 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -375,7 +375,7 @@ namespace libtorrent } #endif - tcp::resolver::query q(*connect_to_host, "https"); + tcp::resolver::query q(*connect_to_host, 0); m_name_lookup.async_resolve(q , boost::bind(&http_tracker_connection::name_lookup, self(), _1, _2)); set_timeout(m_settings.tracker_completion_timeout diff --git a/src/torrent.cpp b/src/torrent.cpp index f086b8ebb..9bc90bd72 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -955,7 +955,7 @@ namespace libtorrent = parse_url_components(url); m_resolving_web_seeds.insert(url); - tcp::resolver::query q(hostname, "http"); + tcp::resolver::query q(hostname, 0); m_host_resolver.async_resolve(q, bind(&torrent::on_name_lookup , shared_from_this(), _1, _2, port, url)); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 33a5562c0..eb54ac5ea 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -87,7 +87,7 @@ namespace i != list->end(); ++i) { if (i->string() != "..") - target.path /= i->string(); + target.path /= i->string(); } if (target.path.is_complete()) throw std::runtime_error("torrent contains " "a file with an absolute path: '" @@ -97,10 +97,13 @@ namespace void extract_files(const entry::list_type& list, std::vector& target , std::string const& root_dir) { + size_type offset = 0; for (entry::list_type::const_iterator i = list.begin(); i != list.end(); ++i) { target.push_back(file_entry()); extract_single_file(*i, target.back(), root_dir); + target.back().offset = offset; + offset += target.back().size; } } @@ -224,6 +227,7 @@ namespace libtorrent // field. file_entry e; e.path = m_name; + e.offset = 0; e.size = info["length"].integer(); m_files.push_back(e); } @@ -666,9 +670,9 @@ namespace libtorrent peer_request torrent_info::map_file(int file_index, size_type file_offset , int size) const { - size_type offset = file_offset; - for (int i = 0; i < file_index; ++i) - offset += file_at(i).size; + assert(file_index < (int)m_files.size()); + assert(file_index >= 0); + size_type offset = file_offset + m_files[file_index].offset; peer_request ret; ret.piece = offset / piece_length(); diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 3681ec10b..0ca24ae08 100755 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -90,7 +90,7 @@ namespace libtorrent , m_attempts(0) { m_socket.reset(new datagram_socket(d)); - tcp::resolver::query q(hostname, "http"); + tcp::resolver::query q(hostname, 0); m_name_lookup.async_resolve(q , boost::bind(&udp_tracker_connection::name_lookup, self(), _1, _2)); set_timeout(m_settings.tracker_completion_timeout diff --git a/test/Makefile.am b/test/Makefile.am index 885abad04..0cd4f5a11 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -24,5 +24,5 @@ test_metadata_extension_LDADD = $(top_builddir)/src/libtorrent.la noinst_HEADERS = test.hpp setup_transfer.hpp -AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/asio/include @DEBUGFLAGS@ @PTHREAD_CFLAGS@ +AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ @PTHREAD_CFLAGS@ AM_LDFLAGS= -L./ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@