From bc774ff491c9907f4a983399f0e7260582e5eccb Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 30 Nov 2004 11:17:32 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/debug.hpp | 6 +++--- include/libtorrent/piece_picker.hpp | 2 +- include/libtorrent/session.hpp | 2 +- include/libtorrent/torrent_handle.hpp | 9 +++++---- src/peer_connection.cpp | 9 +++++---- src/policy.cpp | 17 ++++++++++------- src/session.cpp | 7 +++---- src/torrent.cpp | 8 +++++--- src/tracker_manager.cpp | 8 ++++++-- 9 files changed, 39 insertions(+), 29 deletions(-) diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp index 65678e958..0f4d04d16 100755 --- a/include/libtorrent/debug.hpp +++ b/include/libtorrent/debug.hpp @@ -103,9 +103,9 @@ namespace libtorrent struct file_logger: libtorrent::logger { public: - file_logger(const char* filename) - : m_file(boost::filesystem::complete(filename)) - { assert(filename); } + file_logger(boost::filesystem::path const& filename) + : m_file(boost::filesystem::complete("libtorrent_logs" / filename)) + {} virtual void log(const char* text) { assert(text); m_file << text; } boost::filesystem::ofstream m_file; diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index ac1999339..248a4e7f8 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -150,7 +150,7 @@ namespace libtorrent // marked as being downloaded. If the user of this function // decides to download a piece, it must mark it as being downloaded // itself, by using the mark_as_downloading() member function. - // THIS IS DONE BY THE peer_connection::request_piece() MEMBER FUNCTION! + // THIS IS DONE BY THE peer_connection::send_request() MEMBER FUNCTION! void pick_pieces(const std::vector& pieces, std::vector& interesting_blocks, int num_pieces) const; diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 899a10959..b0b2e0e33 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -256,7 +256,7 @@ namespace libtorrent #ifndef NDEBUG void check_invariant(const char *place = 0); - boost::shared_ptr create_log(std::string name); + boost::shared_ptr create_log(std::string const& name); boost::shared_ptr m_logger; #endif }; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 7b7714796..c6574c044 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -82,6 +82,8 @@ namespace libtorrent , total_payload_upload(0) , download_rate(0) , upload_rate(0) + , download_payload_rate(0) + , upload_payload_rate(0) , num_peers(0) , pieces(0) , total_done(0) @@ -203,10 +205,9 @@ namespace libtorrent // kind of similar to get_torrent_info() but this // is low level, returning the exact info-part of - // the .torrent file. This when hashed, this buffer - // will produce the same hash as the info hash. - // the reference is valid only as long as the torrent - // is running. + // the .torrent file. When hashed, this buffer + // will produce the info hash. The reference is valid + // only as long as the torrent is running. std::vector const& metadata() const; // forces this torrent to reannounce diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 196d9fd9b..fd5589b66 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -30,9 +30,9 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include -#include #include #include "libtorrent/peer_connection.hpp" @@ -783,7 +783,7 @@ namespace libtorrent return; } - if (m_requests.size() > 40) + if (m_requests.size() > 100) { // don't allow clients to abuse our // memory consumption. @@ -804,7 +804,7 @@ namespace libtorrent } // make sure this request - // is legal and taht the peer + // is legal and that the peer // is not choked if (r.piece >= 0 && r.piece < m_torrent->torrent_file().num_pieces() @@ -2154,8 +2154,9 @@ namespace libtorrent // only add new piece-chunks if the send buffer is small enough // otherwise there will be no end to how large it will be! + // TODO: the buffer size should probably be dependent on the transfer speed while (!m_requests.empty() - && ((int)m_send_buffer.size() < m_torrent->block_size()) + && ((int)m_send_buffer.size() < m_torrent->block_size() * 6) && !m_choked) { assert(m_torrent->valid_metadata()); diff --git a/src/policy.cpp b/src/policy.cpp index 11f6ba64e..b62c5b8f4 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -64,7 +64,7 @@ namespace enum { // the limits of the download queue size - max_request_queue = 16, + max_request_queue = 100, min_request_queue = 2, // the amount of free upload allowed before @@ -84,13 +84,14 @@ namespace , std::vector ignore = std::vector()) { // this will make the number of requests linearly dependent - // on the rate in which we download from the peer. 2.5kB/s and - // less will make the desired queue size 2 and at about 70 kB/s - // it will reach the maximum of 16 requests. - // matlab expression to plot: - // x = 1:100:100000; plot(x, round(min(max(x ./ 5000 + 1.5, 4), 16))); + // on the rate in which we download from the peer. + // we want the queue to represent: + const int queue_time = 5; // seconds + // (if the latency is more than this, the download will stall) + // so, the queue size is 5 * down_rate / 16 kiB (16 kB is the size of each request) + // the minimum request size is 2 and the maximum is 100 - int desired_queue_size = static_cast(c.statistics().download_rate() / 5000.f + 1.5f); + int desired_queue_size = static_cast(5.f * c.statistics().download_rate() / (16 * 1024)); if (desired_queue_size > max_request_queue) desired_queue_size = max_request_queue; if (desired_queue_size < min_request_queue) desired_queue_size = min_request_queue; @@ -571,6 +572,8 @@ namespace libtorrent void policy::pulse() { + if (m_torrent->is_paused()) return; + using namespace boost::posix_time; // TODO: we must also remove peers that diff --git a/src/session.cpp b/src/session.cpp index b28118b6d..c0060648b 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -778,12 +778,11 @@ namespace libtorrent { namespace detail } #ifndef NDEBUG - boost::shared_ptr session_impl::create_log(std::string name) + boost::shared_ptr session_impl::create_log(std::string const& name) { - name = "libtorrent_log_" + name + ".log"; - // current options are file_logger and cout_logger + // current options are file_logger, cout_logger and null_logger #if defined(TORRENT_VERBOSE_LOGGING) - return boost::shared_ptr(new file_logger(name.c_str())); + return boost::shared_ptr(new file_logger(name + ".log")); #else return boost::shared_ptr(new null_logger()); #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 28a1a9f08..20bd2cf4b 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -598,7 +598,6 @@ namespace libtorrent m_policy->connection_closed(*p); m_connections.erase(i); - } peer_connection& torrent::connect_to_peer(const address& a) @@ -1098,7 +1097,10 @@ namespace libtorrent if (m_have_metadata.empty()) m_have_metadata.resize(256, false); - std::pair req = offset_to_req(std::make_pair(offset, size), total_size); + std::pair req = offset_to_req(std::make_pair(offset, size) + , total_size); + + assert(req.first + req.second <= m_have_metadata.size()); std::fill( m_have_metadata.begin() + req.first @@ -1120,7 +1122,7 @@ namespace libtorrent { std::fill( m_have_metadata.begin() - , m_have_metadata.end() + req.first + req.second + , m_have_metadata.begin() + req.first + req.second , false); return false; } diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index baad832c2..c9bcbf88b 100755 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -336,12 +336,16 @@ namespace libtorrent void tracker_manager::tick() { tracker_connections_t::iterator i; - for (i = m_connections.begin(); i != m_connections.end(); ++i) + for (i = m_connections.begin(); i != m_connections.end();) { boost::shared_ptr& c = *i; try { - if (!c->tick()) continue; + if (!c->tick()) + { + ++i; + continue; + } } catch (const std::exception& e) {