From 39866c230653fc20b4aebe80773aca36a7c8bcd3 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 7 Jan 2017 00:32:11 -0500 Subject: [PATCH] fix division by zero when setting tick_interval > 1000 --- ChangeLog | 1 + simulation/Jamfile | 1 + simulation/test_auto_manage.cpp | 2 +- simulation/test_session.cpp | 66 +++++++++++++++++++++++++++++++++ src/peer_connection.cpp | 6 +-- 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 simulation/test_session.cpp diff --git a/ChangeLog b/ChangeLog index b5102be47..d5db6a694 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * fix division by zero when setting tick_interval > 1000 * fix move_storage() to its own directory (would delete the files) * fix socks5 support for UDP * add setting urlseed_max_request_bytes to handle large web seed requests diff --git a/simulation/Jamfile b/simulation/Jamfile index 2daf9b873..09b85f76b 100644 --- a/simulation/Jamfile +++ b/simulation/Jamfile @@ -34,6 +34,7 @@ alias libtorrent-sims : [ run test_auto_manage.cpp ] [ run test_torrent_status.cpp ] [ run test_swarm.cpp ] + [ run test_session.cpp ] [ run test_super_seeding.cpp ] [ run test_utp.cpp ] [ run test_dht.cpp ] diff --git a/simulation/test_auto_manage.cpp b/simulation/test_auto_manage.cpp index f6607e52f..3bf25dc38 100644 --- a/simulation/test_auto_manage.cpp +++ b/simulation/test_auto_manage.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "settings.hpp" #include "create_torrent.hpp" #include "simulator/simulator.hpp" -#include "simulator/utils.hpp" +#include "simulator/utils.hpp" // for timer #include using namespace sim; diff --git a/simulation/test_session.cpp b/simulation/test_session.cpp new file mode 100644 index 000000000..7c889687c --- /dev/null +++ b/simulation/test_session.cpp @@ -0,0 +1,66 @@ +/* + +Copyright (c) 2017, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "setup_swarm.hpp" +#include "test.hpp" +#include "utils.hpp" +#include "libtorrent/session.hpp" +#include "libtorrent/socket.hpp" +#include "simulator/simulator.hpp" +#include "simulator/utils.hpp" // for timer +#include "settings.hpp" +#include "create_torrent.hpp" + +using namespace libtorrent; + +TORRENT_TEST(seed_mode) +{ + // with seed mode + setup_swarm(2, swarm_test::upload + // add session + , [](lt::settings_pack& pack) { + // make sure the session works with a tick interval of 5 seconds + pack.set_int(settings_pack::tick_interval, 5000); + } + // add torrent + , [](lt::add_torrent_params& params) { + params.flags |= add_torrent_params::flag_seed_mode; + } + // on alert + , [](lt::alert const* a, lt::session& ses) {} + // terminate + , [](int ticks, lt::session& ses) -> bool { + // we don't need to finish seeding, exit after 20 seconds + return ticks > 20; + }); +} + diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index dea740fce..32527a5bb 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -5453,14 +5453,14 @@ namespace libtorrent if (channel == download_channel) { - return (std::max)((std::max)(m_outstanding_bytes + return std::max((std::max)(m_outstanding_bytes , m_recv_buffer.packet_bytes_remaining()) + 30 , int(boost::int64_t(m_statistics.download_rate()) * 2 - / (1000 / tick_interval))); + * tick_interval / 1000)); } else { - return (std::max)((std::max)(m_reading_bytes + return std::max((std::max)(m_reading_bytes , m_send_buffer.size()) , int((boost::int64_t(m_statistics.upload_rate()) * 2 * tick_interval) / 1000));