diff --git a/ChangeLog b/ChangeLog index 4c9cf221b..d3e119371 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * rate limiter overflow fix (for very high limits) * non-auto-managed torrents no longer count against the torrent limits * handle DHT error responses correctly * allow force_announce to only affect a single tracker diff --git a/Jamfile b/Jamfile index bb1ee1486..a1ba6d748 100755 --- a/Jamfile +++ b/Jamfile @@ -244,6 +244,14 @@ rule building ( properties * ) result += TORRENT_EXPORT_EXTRA ; } + if ( debug in $(properties) + && ( clang in $(properties) + || gcc in $(properties) + || darwin in $(properties) ) ) + { + result += -ftrapv ; + } + if ( debug in $(properties) || on in $(properties) ) { @@ -645,8 +653,6 @@ local usage-requirements = gcc:-fno-strict-aliasing gcc:-Wno-missing-braces # assert on integer overflow - gcc,debug:-ftrapv - darwin,debug:-ftrapv clang:-Wno-invalid-offsetof clang-darwin:-Wno-invalid-offsetof system:$(CXXFLAGS) diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index 112c87eb8..dc89bd637 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -96,7 +96,7 @@ private: typedef std::vector queue_t; queue_t m_queue; // the number of bytes all the requests in queue are for - int m_queued_bytes; + boost::int64_t m_queued_bytes; // this is the channel within the consumers // that bandwidth is assigned to (upload or download) diff --git a/src/bandwidth_limit.cpp b/src/bandwidth_limit.cpp index 73827a1dd..45fbd4179 100644 --- a/src/bandwidth_limit.cpp +++ b/src/bandwidth_limit.cpp @@ -47,7 +47,7 @@ namespace libtorrent { TORRENT_ASSERT(limit >= 0); // if the throttle is more than this, we might overflow - TORRENT_ASSERT(limit < INT_MAX / 31); + TORRENT_ASSERT(limit < INT_MAX); m_limit = limit; } diff --git a/src/bandwidth_manager.cpp b/src/bandwidth_manager.cpp index 3546294da..6b36607cc 100644 --- a/src/bandwidth_manager.cpp +++ b/src/bandwidth_manager.cpp @@ -123,7 +123,7 @@ namespace libtorrent #if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS void bandwidth_manager::check_invariant() const { - int queued = 0; + boost::int64_t queued = 0; for (queue_t::const_iterator i = m_queue.begin() , end(m_queue.end()); i != end; ++i) { diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 5eb3e1904..16a2d03df 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -4676,8 +4676,9 @@ namespace libtorrent // we can only have one outstanding bandwidth request at a time if (m_channel_state[upload_channel] & peer_info::bw_limit) return 0; - int bytes = (std::max)(m_send_buffer.size(), m_statistics.upload_rate() * 2 - * m_ses.m_settings.tick_interval / 1000); + int bytes = (std::max)(m_send_buffer.size() + , int(boost::int64_t(m_statistics.upload_rate()) * 2 + * m_ses.m_settings.tick_interval / 1000)); // we already have quota for the bytes we want to send if (m_quota[upload_channel] >= bytes) return 0; @@ -4761,7 +4762,8 @@ namespace libtorrent if (m_channel_state[download_channel] & peer_info::bw_limit) return 0; int bytes = (std::max)((std::max)(m_outstanding_bytes, m_packet_size - m_recv_pos) + 30 - , m_statistics.download_rate() * 2 * m_ses.m_settings.tick_interval / 1000); + , int(boost::int64_t(m_statistics.download_rate()) * 2 + * m_ses.m_settings.tick_interval / 1000)); // we already have enough quota if (m_quota[download_channel] >= bytes) return 0; diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index bc9846d42..3dd0e8c89 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/stat.hpp" #include "libtorrent/time.hpp" +#include "libtorrent/session_settings.hpp" #include #include @@ -100,7 +101,7 @@ void peer_connection::assign_bandwidth(int channel, int amount) void peer_connection::start() { - m_bwm.request_bandwidth(self(), 150000, m_priority + m_bwm.request_bandwidth(self(), 400000000, m_priority , &m_bandwidth_channel , &m_torrent_bandwidth_channel , &global_bwc); @@ -151,9 +152,11 @@ void run_test(connections_t& v std::for_each(v.begin(), v.end() , boost::bind(&peer_connection::start, _1)); - for (int i = 0; i < int(sample_time * 10); ++i) + int tick_interval = session_settings().tick_interval; + + for (int i = 0; i < int(sample_time * 1000 / tick_interval); ++i) { - manager.update_quotas(milliseconds(100)); + manager.update_quotas(milliseconds(tick_interval)); if ((i % 15) == 0) f(); } } @@ -459,6 +462,7 @@ int test_main() test_equal_connections(7, 20000); test_equal_connections(33, 60000); test_equal_connections(33, 500000); + test_equal_connections(1, 100000000); test_connections_variable_rate(2, 20, 0); test_connections_variable_rate(5, 20000, 0); test_connections_variable_rate(3, 2000, 6000);