diff --git a/libtorrent/include/libtorrent/hasher.hpp b/libtorrent/include/libtorrent/hasher.hpp index 84b009844..d1743527a 100755 --- a/libtorrent/include/libtorrent/hasher.hpp +++ b/libtorrent/include/libtorrent/hasher.hpp @@ -40,11 +40,26 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "zlib.h" +#ifdef TORRENT_USE_OPENSSL extern "C" { -#include "openssl/sha.h" -#include "openssl/bn.h" +#include } +#else +// from sha1.cpp +struct TORRENT_EXPORT SHA_CTX +{ + boost::uint32_t state[5]; + boost::uint32_t count[2]; + boost::uint8_t buffer[64]; +}; + +TORRENT_EXPORT void SHA1_Init(SHA_CTX* context); +TORRENT_EXPORT void SHA1_Update(SHA_CTX* context, boost::uint8_t const* data, boost::uint32_t len); +TORRENT_EXPORT void SHA1_Final(boost::uint8_t* digest, SHA_CTX* context); + +#endif + namespace libtorrent { diff --git a/libtorrent/include/libtorrent/http_stream.hpp b/libtorrent/include/libtorrent/http_stream.hpp index 75c7bf57b..2bd124b43 100644 --- a/libtorrent/include/libtorrent/http_stream.hpp +++ b/libtorrent/include/libtorrent/http_stream.hpp @@ -1,9 +1,15 @@ -#ifndef TORRENT_HTTP_STREAM_HPP_INCLUDED -#define TORRENT_HTTP_STREAM_HPP_INCLUDED -#include "libtorrent/proxy_base.hpp" +#include "libtorrent/io.hpp" +#include "libtorrent/socket.hpp" +#include +#include +#include +#include +#include + namespace libtorrent { -class http_stream : public proxy_base + +class http_stream : boost::noncopyable { public: @@ -12,12 +18,19 @@ public: typedef stream_socket::protocol_type protocol_type; explicit http_stream(asio::io_service& io_service) - : proxy_base(io_service) + : m_sock(io_service) + , m_resolver(io_service) , m_no_connect(false) {} void set_no_connect(bool c) { m_no_connect = c; } + void set_proxy(std::string hostname, int port) + { + m_hostname = hostname; + m_port = port; + } + void set_username(std::string const& user , std::string const& password) { @@ -25,6 +38,108 @@ public: m_password = password; } + template + void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) + { + m_sock.async_read_some(buffers, handler); + } + + template + std::size_t read_some(Mutable_Buffers const& buffers, asio::error_code& ec) + { + return m_sock.read_some(buffers, ec); + } + + template + std::size_t read_some(Mutable_Buffers const& buffers) + { + return m_sock.read_some(buffers); + } + + template + void io_control(IO_Control_Command& ioc) + { + m_sock.io_control(ioc); + } + + template + void io_control(IO_Control_Command& ioc, asio::error_code& ec) + { + m_sock.io_control(ioc, ec); + } + + template + void async_write_some(Const_Buffers const& buffers, Handler const& handler) + { + m_sock.async_write_some(buffers, handler); + } + + void bind(endpoint_type const& endpoint) + { + m_sock.bind(endpoint); + } + + template + void bind(endpoint_type const& endpoint, Error_Handler const& error_handler) + { + m_sock.bind(endpoint, error_handler); + } + + void open(protocol_type const& p) + { + m_sock.open(p); + } + + template + void open(protocol_type const& p, Error_Handler const& error_handler) + { + m_sock.open(p, error_handler); + } + + void close() + { + m_remote_endpoint = endpoint_type(); + m_sock.close(); + } + + template + void close(Error_Handler const& error_handler) + { + m_sock.close(error_handler); + } + + endpoint_type remote_endpoint() + { + return m_remote_endpoint; + } + + template + endpoint_type remote_endpoint(Error_Handler const& error_handler) + { + return m_remote_endpoint; + } + + endpoint_type local_endpoint() + { + return m_sock.local_endpoint(); + } + + template + endpoint_type local_endpoint(Error_Handler const& error_handler) + { + return m_sock.local_endpoint(error_handler); + } + + asio::io_service& io_service() + { + return m_sock.io_service(); + } + + lowest_layer_type& lowest_layer() + { + return m_sock.lowest_layer(); + } + typedef boost::function handler_type; template @@ -56,12 +171,19 @@ private: void handshake1(asio::error_code const& e, boost::shared_ptr h); void handshake2(asio::error_code const& e, boost::shared_ptr h); + stream_socket m_sock; + // the http proxy + std::string m_hostname; + int m_port; // send and receive buffer std::vector m_buffer; // proxy authentication std::string m_user; std::string m_password; + endpoint_type m_remote_endpoint; + + tcp::resolver m_resolver; // this is true if the connection is HTTP based and // want to talk directly to the proxy bool m_no_connect; @@ -69,4 +191,3 @@ private: } -#endif diff --git a/libtorrent/include/libtorrent/piece_picker.hpp b/libtorrent/include/libtorrent/piece_picker.hpp index ecbe2df4b..7b8612909 100755 --- a/libtorrent/include/libtorrent/piece_picker.hpp +++ b/libtorrent/include/libtorrent/piece_picker.hpp @@ -125,8 +125,6 @@ namespace libtorrent piece_picker(int blocks_per_piece , int total_num_blocks); - void get_availability(std::vector& avail) const; - void set_sequenced_download_threshold(int sequenced_download_threshold); // the vector tells which pieces we already have diff --git a/libtorrent/include/libtorrent/session.hpp b/libtorrent/include/libtorrent/session.hpp index f0127e22a..98424690a 100755 --- a/libtorrent/include/libtorrent/session.hpp +++ b/libtorrent/include/libtorrent/session.hpp @@ -179,6 +179,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_ENCRYPTION void set_pe_settings(pe_settings const& settings); + pe_settings const& get_pe_settings() const; #endif #ifndef TORRENT_DISABLE_EXTENSIONS diff --git a/libtorrent/include/libtorrent/socks5_stream.hpp b/libtorrent/include/libtorrent/socks5_stream.hpp index 60873742f..9e8a0d04b 100644 --- a/libtorrent/include/libtorrent/socks5_stream.hpp +++ b/libtorrent/include/libtorrent/socks5_stream.hpp @@ -1,18 +1,33 @@ -#ifndef TORRENT_SOCKS5_STREAM_HPP_INCLUDED -#define TORRENT_SOCKS5_STREAM_HPP_INCLUDED -#include "libtorrent/proxy_base.hpp" +#include "libtorrent/io.hpp" +#include "libtorrent/socket.hpp" +#include +#include +#include +#include +#include + namespace libtorrent { -class socks5_stream : public proxy_base +class socks5_stream : boost::noncopyable { public: - explicit socks5_stream(asio::io_service& io_service) - : proxy_base(io_service) + typedef stream_socket::lowest_layer_type lowest_layer_type; + typedef stream_socket::endpoint_type endpoint_type; + typedef stream_socket::protocol_type protocol_type; + explicit socks5_stream(asio::io_service& io_service) + : m_sock(io_service) + , m_resolver(io_service) {} + void set_proxy(std::string hostname, int port) + { + m_hostname = hostname; + m_port = port; + } + void set_username(std::string const& user , std::string const& password) { @@ -20,6 +35,107 @@ public: m_password = password; } + template + void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) + { + m_sock.async_read_some(buffers, handler); + } + + template + std::size_t read_some(Mutable_Buffers const& buffers, asio::error_code& ec) + { + return m_sock.read_some(buffers, ec); + } + + template + std::size_t read_some(Mutable_Buffers const& buffers) + { + return m_sock.read_some(buffers); + } + + template + void io_control(IO_Control_Command& ioc) + { + m_sock.io_control(ioc); + } + + template + void io_control(IO_Control_Command& ioc, asio::error_code& ec) + { + m_sock.io_control(ioc, ec); + } + + template + void async_write_some(Const_Buffers const& buffers, Handler const& handler) + { + m_sock.async_write_some(buffers, handler); + } + + void bind(endpoint_type const& endpoint) + { + m_sock.bind(endpoint); + } + + template + void bind(endpoint_type const& endpoint, Error_Handler const& error_handler) + { + m_sock.bind(endpoint, error_handler); + } + + void open(protocol_type const& p) + { + m_sock.open(p); + } + + template + void open(protocol_type const& p, Error_Handler const& error_handler) + { + m_sock.open(p, error_handler); + } + + void close() + { + m_remote_endpoint = endpoint_type(); + m_sock.close(); + } + + template + void close(Error_Handler const& error_handler) + { + m_sock.close(error_handler); + } + + endpoint_type remote_endpoint() + { + return m_remote_endpoint; + } + + template + endpoint_type remote_endpoint(Error_Handler const& error_handler) + { + return m_remote_endpoint; + } + + endpoint_type local_endpoint() + { + return m_sock.local_endpoint(); + } + + template + endpoint_type local_endpoint(Error_Handler const& error_handler) + { + return m_sock.local_endpoint(error_handler); + } + + asio::io_service& io_service() + { + return m_sock.io_service(); + } + + lowest_layer_type& lowest_layer() + { + return m_sock.lowest_layer(); + } typedef boost::function handler_type; @@ -60,14 +176,20 @@ private: void connect2(asio::error_code const& e, boost::shared_ptr h); void connect3(asio::error_code const& e, boost::shared_ptr h); + stream_socket m_sock; + // the socks5 proxy + std::string m_hostname; + int m_port; // send and receive buffer std::vector m_buffer; // proxy authentication std::string m_user; std::string m_password; + endpoint_type m_remote_endpoint; + + tcp::resolver m_resolver; }; } -#endif diff --git a/libtorrent/include/libtorrent/torrent.hpp b/libtorrent/include/libtorrent/torrent.hpp index 1fd14ae26..8943b0db9 100755 --- a/libtorrent/include/libtorrent/torrent.hpp +++ b/libtorrent/include/libtorrent/torrent.hpp @@ -184,8 +184,6 @@ namespace libtorrent void filter_files(std::vector const& files); // ============ end deprecation ============= - void piece_availability(std::vector& avail) const; - void set_piece_priority(int index, int priority); int piece_priority(int index) const; diff --git a/libtorrent/include/libtorrent/torrent_handle.hpp b/libtorrent/include/libtorrent/torrent_handle.hpp index 3713729d6..cb4b892d2 100755 --- a/libtorrent/include/libtorrent/torrent_handle.hpp +++ b/libtorrent/include/libtorrent/torrent_handle.hpp @@ -269,8 +269,6 @@ namespace libtorrent // ================ end deprecation ============ - void piece_availability(std::vector& avail) const; - // priority must be within the range [0, 7] void piece_priority(int index, int priority) const; int piece_priority(int index) const; diff --git a/libtorrent/src/file.cpp b/libtorrent/src/file.cpp index a1352ae03..71bc795a4 100755 --- a/libtorrent/src/file.cpp +++ b/libtorrent/src/file.cpp @@ -248,15 +248,15 @@ namespace libtorrent void set_size(size_type s) { size_type pos = tell(); - seek(s - 1); + seek(1, 0); char dummy = 0; read(&dummy, 1); - seek(s - 1); + seek(1, 0); write(&dummy, 1); - seek(pos); + seek(pos, 1); } - size_type seek(size_type offset, int m = 1) + size_type seek(size_type offset, int m) { assert(m_open_mode); assert(m_fd != -1); diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index 6ec697755..cf6eb4a0e 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -1292,17 +1292,6 @@ namespace libtorrent } } - void piece_picker::get_availability(std::vector& avail) const - { - TORRENT_PIECE_PICKER_INVARIANT_CHECK; - - avail.resize(m_piece_map.size()); - std::vector::iterator j = avail.begin(); - for (std::vector::const_iterator i = m_piece_map.begin() - , end(m_piece_map.end()); i != end; ++i, ++j) - *j = i->peer_count; - } - void piece_picker::mark_as_finished(piece_block block, const tcp::endpoint& peer) { TORRENT_PIECE_PICKER_INVARIANT_CHECK; diff --git a/libtorrent/src/session.cpp b/libtorrent/src/session.cpp index e1ac044c6..45711b122 100755 --- a/libtorrent/src/session.cpp +++ b/libtorrent/src/session.cpp @@ -252,6 +252,11 @@ namespace libtorrent { m_impl->set_pe_settings(settings); } + + pe_settings const& session::get_pe_settings() const + { + return m_impl->get_pe_settings(); + } #endif bool session::is_listening() const diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 9a8165af2..0623dfeb6 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -309,7 +309,7 @@ namespace libtorrent #endif } catch (std::exception&) {} - if ((compact_mode && size != s->first) + if (size != s->first || (!compact_mode && size < s->first)) { if (error) *error = "filesize mismatch for file '" @@ -319,7 +319,7 @@ namespace libtorrent + " bytes"; return false; } - if ((compact_mode && time != s->second) + if (time != s->second || (!compact_mode && time < s->second)) { if (error) *error = "timestamp mismatch for file '" @@ -412,7 +412,6 @@ namespace libtorrent void storage::initialize(bool allocate_files) { - std::cerr << "storage initialize" << std::endl; // first, create all missing directories path last_path; for (torrent_info::file_iterator file_iter = m_info.begin_files(), @@ -437,7 +436,6 @@ namespace libtorrent // the directory exits. if (file_iter->size == 0) { - std::cerr << "creating empty file: " << file_iter->path.string() << std::endl; file(m_save_path / file_iter->path, file::out); continue; } @@ -886,13 +884,13 @@ namespace libtorrent if (left_to_write > 0) { -#ifndef NDEBUG + #ifndef NDEBUG if (write_bytes > 0) ++counter; -#endif + #endif ++file_iter; assert(file_iter != m_info.end_files()); - path p = m_save_path / file_iter->path; + path p = m_save_path / file_iter->path; file_offset = 0; out = m_files.open_file( this, p, file::out | file::in); @@ -1614,44 +1612,23 @@ namespace libtorrent { m_unallocated_slots.push_back(i); } - if (m_compact_mode || m_unallocated_slots.empty()) + + if (!m_compact_mode && !m_unallocated_slots.empty()) { - m_state = state_create_files; - std::cerr << "storage: -> create_files" << std::endl; + m_state = state_allocating; return false; } + else + { + m_state = state_finished; + return true; + } } - m_current_slot = 0; - m_state = state_full_check; - std::cerr << "storage: -> full_check" << std::endl; + m_state = state_create_files; return false; } -/* - state chart: - - check_fastresume() - - | | - | v - | +------------+ - | | full_check | - | +------------+ - | | - | v - | +------------+ +--------------+ - | | allocating |-->| create_files | - | +------------+ +--------------+ - | | | - | v | - | +----------+ | - +---->| finished |<--------+ - +----------+ - -*/ - - // performs the full check and full allocation // (if necessary). returns true if finished and // false if it should be called again @@ -1665,19 +1642,16 @@ namespace libtorrent if (m_state == state_allocating) { - if (m_compact_mode || m_unallocated_slots.empty()) + if (m_compact_mode) { - m_state = state_create_files; - return std::make_pair(false, 1.f); + m_state = state_finished; + return std::make_pair(true, 1.f); } - - if (int(m_unallocated_slots.size()) == m_info.num_pieces() - && !m_fill_mode) + + if (m_unallocated_slots.empty()) { - // if there is not a single file on disk, just - // create the files - m_state = state_create_files; - return std::make_pair(false, 1.f); + m_state = state_finished; + return std::make_pair(true, 1.f); } // if we're not in compact mode, make sure the @@ -1708,19 +1682,10 @@ namespace libtorrent { m_storage->initialize(!m_fill_mode && !m_compact_mode); - if (!m_unallocated_slots.empty() && !m_compact_mode) - { - assert(!m_fill_mode); - assert(!m_compact_mode); - std::vector().swap(m_unallocated_slots); - std::fill(m_slot_to_piece.begin(), m_slot_to_piece.end(), int(unassigned)); - m_free_slots.resize(m_info.num_pieces()); - for (int i = 0; i < m_info.num_pieces(); ++i) - m_free_slots[i] = i; - } - - m_state = state_finished; - return std::make_pair(true, 1.f); + m_current_slot = 0; + m_state = state_full_check; + m_piece_data.resize(int(m_info.piece_length())); + return std::make_pair(false, 0.f); } assert(m_state == state_full_check); @@ -1732,7 +1697,6 @@ namespace libtorrent try { - m_piece_data.resize(int(m_info.piece_length())); int piece_size = int(m_info.piece_size(m_current_slot)); int num_read = m_storage->read(&m_piece_data[0] , m_current_slot, 0, piece_size); diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 135108540..6678a756e 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -981,20 +981,7 @@ namespace libtorrent return m_username + ":" + m_password; } - void torrent::piece_availability(std::vector& avail) const - { - INVARIANT_CHECK; - assert(valid_metadata()); - if (is_seed()) - { - avail.clear(); - return; - } - - m_picker->get_availability(avail); - } - void torrent::set_piece_priority(int index, int priority) { @@ -1819,8 +1806,7 @@ namespace libtorrent bool torrent::want_more_peers() const { return int(m_connections.size()) < m_connections_quota.given - && m_ses.m_half_open.free_slots() - && !m_paused;; + && m_ses.m_half_open.free_slots(); } void torrent::disconnect_all() diff --git a/libtorrent/src/torrent_handle.cpp b/libtorrent/src/torrent_handle.cpp index de6f8d170..da571ab63 100755 --- a/libtorrent/src/torrent_handle.cpp +++ b/libtorrent/src/torrent_handle.cpp @@ -351,13 +351,6 @@ namespace libtorrent , bind(&torrent::name, _1)); } - void torrent_handle::piece_availability(std::vector& avail) const - { - INVARIANT_CHECK; - - call_member(m_ses, m_chk, m_info_hash - , bind(&torrent::piece_availability, _1, boost::ref(avail))); - } void torrent_handle::piece_priority(int index, int priority) const { @@ -563,11 +556,9 @@ namespace libtorrent for (int j = 0; j < num_bitmask_bytes; ++j) { unsigned char v = 0; - int bits = std::min(num_blocks_per_piece - j*8, 8); for (int k = 0; k < 8; ++k) v |= i->info[j*8+k].finished?(1 << k):0; bitmask.insert(bitmask.end(), v); - assert(bits == 8 || j == num_bitmask_bytes - 1); } piece_struct["bitmask"] = bitmask; diff --git a/setup.py b/setup.py index b6a08980e..68bb90e9c 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ if platform.machine() == "i386" or platform.machine() == "i686": elif platform.machine() == "x86_64" or platform.machine() == "amd64": print "64bit x86_64 system detected" ARCH = "x64" -elif platform.machine() == "powerpc": +elif platform.machine() == "ppc": print "PowerPC system detected" ARCH = "ppc" else: