From d355a42af87646360dd1ee103111f08dd90721ed Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 9 Dec 2007 18:50:22 +0000 Subject: [PATCH] bandwidth manager fix --- libtorrent/include/libtorrent/bandwidth_manager.hpp | 11 +++++++++-- libtorrent/src/kademlia/rpc_manager.cpp | 2 +- libtorrent/src/session_impl.cpp | 2 +- libtorrent/src/torrent.cpp | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libtorrent/include/libtorrent/bandwidth_manager.hpp b/libtorrent/include/libtorrent/bandwidth_manager.hpp index ef132543f..ecb065a9d 100644 --- a/libtorrent/include/libtorrent/bandwidth_manager.hpp +++ b/libtorrent/include/libtorrent/bandwidth_manager.hpp @@ -225,8 +225,14 @@ struct bandwidth_manager } #endif - TORRENT_ASSERT(peer->max_assignable_bandwidth(m_channel) > 0); boost::shared_ptr t = peer->associated_torrent().lock(); + + if (peer->max_assignable_bandwidth(m_channel) == 0) + { + t->expire_bandwidth(m_channel, blk); + peer->assign_bandwidth(m_channel, 0); + return; + } m_queue.push_back(bw_queue_entry(peer, blk, non_prioritized)); if (!non_prioritized) { @@ -389,6 +395,7 @@ private: if (max_assignable == 0) { t->expire_bandwidth(m_channel, qe.max_block_size); + qe.peer->assign_bandwidth(m_channel, 0); TORRENT_ASSERT(amount == limit - m_current_quota); continue; } @@ -430,7 +437,7 @@ private: if (block_size > qe.max_block_size) block_size = qe.max_block_size; #ifdef TORRENT_VERBOSE_BANDWIDTH_LIMIT - std::cerr << " block_size = " << block_size << " amount = " << amount << std::endl; + std::cerr << " block_size = " << block_size << " amount = " << amount << std::endl; #endif if (amount < block_size / 2) { diff --git a/libtorrent/src/kademlia/rpc_manager.cpp b/libtorrent/src/kademlia/rpc_manager.cpp index 5ae448501..5225e6942 100644 --- a/libtorrent/src/kademlia/rpc_manager.cpp +++ b/libtorrent/src/kademlia/rpc_manager.cpp @@ -217,7 +217,7 @@ bool rpc_manager::incoming(msg const& m) { #ifdef TORRENT_DHT_VERBOSE_LOGGING TORRENT_LOG(rpc) << "Reply with incorrect address and valid transaction id: " - << tid << " from " << m.addr; + << tid << " from " << m.addr << " expected: " << o->target_addr; #endif return false; } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 5c4611cf4..c1969d523 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -1836,7 +1836,7 @@ namespace detail t.abort(); if ((!t.is_paused() || t.should_request()) - && !t.torrent_file().trackers().empty()) + && !t.trackers().empty()) { tracker_request req = t.generate_tracker_request(); TORRENT_ASSERT(req.event == tracker_request::stopped); diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index d28c97d47..168042a5f 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -2760,6 +2760,8 @@ namespace libtorrent #endif disconnect_all(); + if (!m_paused) + m_just_paused = true; m_paused = true; // tell the tracker that we stopped m_event = tracker_request::stopped;