From 08c93978a61ae79d7c7d0e8ad2dd30fff0b4e0d7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 28 Feb 2011 00:35:58 +0000 Subject: [PATCH] clean up some dead code and fix windows build --- include/libtorrent/policy.hpp | 40 +++++------------------------------ src/file.cpp | 7 +++--- src/kademlia/node.cpp | 3 ++- src/pe_crypto.cpp | 1 + src/session_impl.cpp | 2 +- src/ut_metadata.cpp | 2 +- 6 files changed, 14 insertions(+), 41 deletions(-) diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index ab5d9d1bd..ae57c44e7 100644 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -170,7 +170,7 @@ namespace libtorrent // 48 struct TORRENT_EXPORT peer { - peer(); +// peer(); peer(boost::uint16_t port, bool connectable, int src); size_type total_download() const; @@ -325,7 +325,6 @@ namespace libtorrent struct TORRENT_EXPORT ipv4_peer : peer { ipv4_peer(tcp::endpoint const& ip, bool connectable, int src); - ipv4_peer(libtorrent::address const& a); address_v4 addr; }; @@ -334,7 +333,6 @@ namespace libtorrent struct TORRENT_EXPORT i2p_peer : peer { i2p_peer(char const* destination, bool connectable, int src); - i2p_peer(char const* destination); ~i2p_peer(); char* destination; @@ -345,7 +343,6 @@ namespace libtorrent struct TORRENT_EXPORT ipv6_peer : peer { ipv6_peer(tcp::endpoint const& ip, bool connectable, int src); - ipv6_peer(libtorrent::address const& a); address_v6::bytes_type addr; }; @@ -475,19 +472,8 @@ namespace libtorrent inline policy::ipv4_peer::ipv4_peer( tcp::endpoint const& ep, bool c, int src ) - : peer(ep.port(), c, src) - , addr(ep.address().to_v4()) - { -#if TORRENT_USE_IPV6 - is_v6_addr = false; -#endif -#if TORRENT_USE_I2P - is_i2p_addr = false; -#endif - } - - inline policy::ipv4_peer::ipv4_peer(libtorrent::address const& a) - : addr(a.to_v4()) + : peer(ep.port(), c, src) + , addr(ep.address().to_v4()) { #if TORRENT_USE_IPV6 is_v6_addr = false; @@ -506,14 +492,6 @@ namespace libtorrent #endif is_i2p_addr = true; } - inline policy::i2p_peer::i2p_peer(char const* dest) - : destination(strdup(dest)) - { -#if TORRENT_USE_IPV6 - is_v6_addr = false; -#endif - is_i2p_addr = true; - } inline policy::i2p_peer::~i2p_peer() { free(destination); } @@ -523,8 +501,8 @@ namespace libtorrent inline policy::ipv6_peer::ipv6_peer( tcp::endpoint const& ep, bool c, int src ) - : peer(ep.port(), c, src) - , addr(ep.address().to_v6().to_bytes()) + : peer(ep.port(), c, src) + , addr(ep.address().to_v6().to_bytes()) { is_v6_addr = true; #if TORRENT_USE_I2P @@ -532,14 +510,6 @@ namespace libtorrent #endif } - inline policy::ipv6_peer::ipv6_peer(libtorrent::address const& a) - : addr(a.to_v6().to_bytes()) - { - is_v6_addr = true; -#if TORRENT_USE_I2P - is_i2p_addr = false; -#endif - } #endif // TORRENT_USE_IPV6 #if TORRENT_USE_I2P diff --git a/src/file.cpp b/src/file.cpp index 96b1ac975..629e11751 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -623,9 +623,6 @@ namespace libtorrent : m_done(false) { ec.clear(); - memset(&m_dirent, 0, sizeof(dirent)); - m_name[0] = 0; - #ifdef TORRENT_WINDOWS // the path passed to FindFirstFile() must be // a pattern @@ -647,6 +644,10 @@ namespace libtorrent return; } #else + + memset(&m_dirent, 0, sizeof(dirent)); + m_name[0] = 0; + // the path passed to opendir() may not // end with a / std::string p = path; diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 84534bade..4e163aa7f 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/alert.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/random.hpp" #include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/kademlia/node_id.hpp" #include "libtorrent/kademlia/rpc_manager.hpp" @@ -555,7 +556,7 @@ bool node_impl::lookup_peers(sha1_hash const& info_hash, int prefix, entry& repl while (m < num) { - if ((std::rand() / (RAND_MAX + 1.f)) * (num - t) >= num - m) + if ((random() / float(UINT_MAX + 1.f)) * (num - t) >= num - m) { ++iter; ++t; diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index 98e16bf14..35139f99b 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. extern "C" { #include "libtorrent/tommath.h" } +#include "libtorrent/random.hpp" #endif #include "libtorrent/pe_crypto.hpp" diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 10b56af15..364430be2 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4890,7 +4890,7 @@ namespace aux { if (m_external_addresses.size() > 20) { - if (random() < RAND_MAX / 2) + if (random() < UINT_MAX / 2) { #if defined TORRENT_VERBOSE_LOGGING (*m_logger) << time_now_string() << ": More than 20 slots, dopped\n"; diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 144a654fa..9c06deac3 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -391,7 +391,7 @@ namespace libtorrent { namespace void failed_hash_check(ptime const& now) { - m_request_limit = now + seconds(20 + (random() * 50) / RAND_MAX); + m_request_limit = now + seconds(20 + (boost::int64_t(random()) * 50) / UINT_MAX); } private: