From 70d64327fd51f3952ec25e1957b7988d33423897 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 2 Aug 2018 02:00:01 +0200 Subject: [PATCH 1/5] bump checking_mem_usage to be higher than the default in the high_performance_seed preset --- src/session.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/session.cpp b/src/session.cpp index 7d8b4d58f..76000de52 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -302,9 +302,7 @@ namespace { // number of disk threads for low level file operations set.set_int(settings_pack::aio_threads, 8); - // keep 5 MiB outstanding when checking hashes - // of a resumed file - set.set_int(settings_pack::checking_mem_usage, 320); + set.set_int(settings_pack::checking_mem_usage, 2048); // the disk cache performs better with the pool allocator set.set_bool(settings_pack::use_disk_cache_pool, true); From 149c24e5492fe6f622051dddadffa00f86f0cff0 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 2 Aug 2018 11:42:59 +0200 Subject: [PATCH 2/5] make test_ssl less likely to fail spuriously --- test/test_ssl.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 679780b1b..998cc7e81 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -74,7 +74,7 @@ struct test_config_t int ssl_disconnects; }; -test_config_t test_config[] = +test_config_t const test_config[] = { // name sslport sd-cert dl-cert dl-port expect peer-error ssl-disconn {"nobody has a cert (connect to regular port)", false, false, false, true, false, 0, 1}, @@ -114,7 +114,7 @@ bool on_alert(alert const* a) return false; } -void test_ssl(int test_idx, bool use_utp) +void test_ssl(int const test_idx, bool const use_utp) { // these are declared before the session objects // so that they are destructed last. This enables @@ -281,10 +281,13 @@ void test_ssl(int test_idx, bool use_utp) fprintf(stderr, "peer_errors: %d expected_errors: %d\n" , peer_errors, test.peer_errors); - TEST_EQUAL(peer_errors > 0, test.peer_errors > 0); fprintf(stderr, "ssl_disconnects: %d expected: %d\n", ssl_peer_disconnects, test.ssl_disconnects); - TEST_EQUAL(ssl_peer_disconnects > 0, test.ssl_disconnects > 0); + if (!use_utp) + { + TEST_EQUAL(ssl_peer_disconnects > 0, test.ssl_disconnects > 0); + TEST_EQUAL(peer_errors > 0, test.peer_errors > 0); + } fprintf(stderr, "%s: EXPECT: %s\n", time_now_string(), test.expected_to_complete ? "SUCCEESS" : "FAILURE"); fprintf(stderr, "%s: RESULT: %s\n", time_now_string(), tor2.status().is_seeding ? "SUCCEESS" : "FAILURE"); @@ -319,7 +322,7 @@ enum attack_flags_t valid_bittorrent_hash = 16, }; -attack_t attacks[] = +attack_t const attacks[] = { // positive test { valid_certificate | valid_sni_hash | valid_bittorrent_hash, true}, From 0a5b3c1bb08017a42d2efe5ea071ad6541929dee Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 7 Aug 2018 19:36:25 +0200 Subject: [PATCH 3/5] update documentation for save_resume_data() and stop_when_ready() --- include/libtorrent/torrent_handle.hpp | 19 ++++++++++++------- src/torrent.cpp | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index ab07dd856..a23e7c6ca 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -603,6 +603,11 @@ namespace libtorrent // for the state_changed_alert and then call pause(). The download/seeding // will most likely start in between posting the alert and receiving the // call to pause. + // + // A downloading state is one where peers are being connected. Which means + // just downloading the metadata via the ``ut_metadata`` extension counts + // as a downloading state. In order to stop a torrent once the metadata + // has been downloaded, instead set all file priorities to dont_download void stop_when_ready(bool b) const; // Explicitly sets the upload mode of the torrent. In upload mode, the @@ -741,9 +746,8 @@ namespace libtorrent // extern int outstanding_resume_data; // global counter of outstanding resume data // std::vector handles = ses.get_torrents(); // ses.pause(); - // for (torrent_handle i : handles) + // for (torrent_handle const& h : handles) // { - // torrent_handle& h = *i; // if (!h.is_valid()) continue; // torrent_status s = h.status(); // if (!s.has_metadata) continue; @@ -758,7 +762,7 @@ namespace libtorrent // alert const* a = ses.wait_for_alert(seconds(10)); // // // if we don't get an alert within 10 seconds, abort - // if (a == 0) break; + // if (a == nullptr) break; // // std::vector alerts; // ses.pop_alerts(&alerts); @@ -773,7 +777,7 @@ namespace libtorrent // } // // save_resume_data_alert const* rd = alert_cast(a); - // if (rd == 0) + // if (rd == nullptr) // { // process_alert(a); // continue; @@ -807,9 +811,10 @@ namespace libtorrent // time. // //.. note:: - // A torrent's resume data is considered saved as soon as the alert is - // posted. It is important to make sure this alert is received and - // handled in order for this function to be meaningful. + // A torrent's resume data is considered saved as soon as the + // save_resume_data_alert is posted. It is important to make sure this + // alert is received and handled in order for this function to be + // meaningful. bool need_save_resume_data() const; // changes whether the torrent is auto managed or not. For more info, diff --git a/src/torrent.cpp b/src/torrent.cpp index b72939c3b..d3511b868 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -117,7 +117,7 @@ namespace libtorrent boost::uint32_t const unset = std::numeric_limits::max(); - bool is_downloading_state(int st) + bool is_downloading_state(int const st) { switch (st) { @@ -8498,7 +8498,7 @@ namespace { namespace { #ifndef TORRENT_DISABLE_LOGGING - char const* list_name(int idx) + char const* list_name(int const idx) { #define TORRENT_LIST_NAME(n) case aux::session_interface:: n: return #n; switch (idx) From 6d2541f131605fc93a53eadb4aadd543792eb56a Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 8 Aug 2018 10:43:31 +0200 Subject: [PATCH 4/5] improve connect-boost feature, to make new torrents quickly connect peers --- ChangeLog | 2 ++ include/libtorrent/settings_pack.hpp | 1 + include/libtorrent/torrent.hpp | 16 ++++++++-------- src/session_impl.cpp | 9 +++++---- src/settings_pack.cpp | 4 ++-- src/torrent.cpp | 14 ++++++++------ src/ut_pex.cpp | 7 ++++++- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index d85db05d5..16f0ae692 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * improve connect-boost feature, to make new torrents quickly connect peers + 1.1.9 release * save both file and piece priorities in resume file diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index d2eac1bf6..b08cccff4 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -1408,6 +1408,7 @@ namespace libtorrent // them starting up. The normal connect scheduler is run once every // second, this allows peers to be connected immediately instead of // waiting for the session tick to trigger connections. + // This may not be set higher than 255. torrent_connect_boost, // ``alert_queue_size`` is the maximum number of alerts queued up diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 9ee9668e9..1fdee65ec 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1580,13 +1580,6 @@ namespace libtorrent // work of refreshing the suggest pieces bool m_need_suggest_pieces_refresh:1; - // this is set to true when the torrent starts up - // The first tracker response, when this is true, - // will attempt to connect to a bunch of peers immediately - // and set this to false. We only do this once to get - // the torrent kick-started - bool m_need_connect_boost:1; - // rotating sequence number for LSD announces sent out. // used to only use IP broadcast for every 8th lsd announce boost::uint8_t m_lsd_seq:3; @@ -1610,7 +1603,14 @@ namespace libtorrent // the number of bytes of padding files boost::uint32_t m_padding:24; - // TODO: gap of 8 bits available here + // this is set to the connect boost quota for this torrent. + // After having received this many priority peer connection attempts, it + // falls back onto the steady state peer connection logic, driven by the + // session tick. Each tracker response, as long as this is non-zero, will + // attempt to connect to peers immediately and decrement the counter. + // We give torrents a connect boost when they are first added and then + // every time they resume from being paused. + boost::uint8_t m_connect_boost_counter; // ---- diff --git a/src/session_impl.cpp b/src/session_impl.cpp index b993ff19a..698468794 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4046,16 +4046,14 @@ retry: // attempt this tick int max_connections = m_settings.get_int(settings_pack::connection_speed); - // zero connections speeds are allowed, we just won't make any connections - if (max_connections <= 0) return; - // this loop will "hand out" connection_speed to the torrents, in a round // robin fashion, so that every torrent is equally likely to connect to a // peer // boost connections are connections made by torrent connection // boost, which are done immediately on a tracker response. These - // connections needs to be deducted from this second + // connections needs to be deducted from the regular connection attempt + // quota for this tick if (m_boost_connections > 0) { if (m_boost_connections > max_connections) @@ -4070,6 +4068,9 @@ retry: } } + // zero connections speeds are allowed, we just won't make any connections + if (max_connections <= 0) return; + // TODO: use a lower limit than m_settings.connections_limit // to allocate the to 10% or so of connection slots for incoming // connections diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 9a6825dbe..99ce5c8a2 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -254,7 +254,7 @@ namespace libtorrent SET(max_failcount, 3, &session_impl::update_max_failcount), SET(min_reconnect_time, 60, 0), SET(peer_connect_timeout, 15, 0), - SET(connection_speed, 10, &session_impl::update_connection_speed), + SET(connection_speed, 30, &session_impl::update_connection_speed), SET(inactivity_timeout, 600, 0), SET(unchoke_interval, 15, 0), SET(optimistic_unchoke_interval, 30, 0), @@ -334,7 +334,7 @@ namespace libtorrent SET(utp_loss_multiplier, 50, 0), SET(mixed_mode_algorithm, settings_pack::peer_proportional, 0), SET(listen_queue_size, 5, 0), - SET(torrent_connect_boost, 10, 0), + SET(torrent_connect_boost, 80, 0), SET(alert_queue_size, 1000, &session_impl::update_alert_queue_size), SET(max_metadata_size, 3 * 1024 * 10240, 0), DEPRECATED_SET(hashing_threads, 1, 0), diff --git a/src/torrent.cpp b/src/torrent.cpp index d3511b868..8c0f1f6d6 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -290,12 +290,12 @@ namespace libtorrent , m_save_resume_flags(0) , m_num_uploads(0) , m_need_suggest_pieces_refresh(false) - , m_need_connect_boost(true) , m_lsd_seq(0) , m_magnet_link(false) , m_apply_ip_filter((p.flags & add_torrent_params::flag_apply_ip_filter) != 0) , m_merge_resume_trackers((p.flags & add_torrent_params::flag_merge_resume_trackers) != 0) , m_padding(0) + , m_connect_boost_counter(static_cast(settings().get_int(settings_pack::torrent_connect_boost))) , m_incomplete(0xffffff) , m_announce_to_dht((p.flags & add_torrent_params::flag_paused) == 0) , m_is_active_download(false) @@ -3758,23 +3758,24 @@ namespace { void torrent::do_connect_boost() { - if (!m_need_connect_boost) return; + if (m_connect_boost_counter == 0) return; // this is the first tracker response for this torrent // instead of waiting one second for session_impl::on_tick() // to be called, connect to a few peers immediately - int conns = (std::min)( - settings().get_int(settings_pack::torrent_connect_boost) + int conns = (std::min)(int(m_connect_boost_counter) , settings().get_int(settings_pack::connections_limit) - m_ses.num_connections()); - if (conns > 0) m_need_connect_boost = false; + if (conns == 0) return; // if we don't know of any peers if (!m_peer_list) return; while (want_peers() && conns > 0) { + TORRENT_ASSERT(m_connect_boost_counter > 0); --conns; + --m_connect_boost_counter; torrent_state st = get_peer_list_state(); torrent_peer* p = m_peer_list->connect_one_peer(m_ses.session_time(), &st); peers_erased(st.erased); @@ -9950,7 +9951,8 @@ namespace { } #endif - m_need_connect_boost = true; + m_connect_boost_counter + = static_cast(settings().get_int(settings_pack::torrent_connect_boost)); m_inactive = false; update_state_list(); diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 655e4ef08..8b66998f5 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -337,6 +337,7 @@ namespace libtorrent { namespace p = pex_msg.dict_find_string("added"); bdecode_node pf = pex_msg.dict_find_string("added.f"); + bool peers_added = false; #ifndef TORRENT_DISABLE_LOGGING if (p) num_added += p.string_length() / 6; #endif @@ -363,6 +364,7 @@ namespace libtorrent { namespace if (j != m_peers.end() && *j == v) continue; m_peers.insert(j, v); m_torrent.add_peer(adr, peer_info::pex, flags); + peers_added = true; } } @@ -416,7 +418,8 @@ namespace libtorrent { namespace if (j != m_peers6.end() && *j == v) continue; m_peers6.insert(j, v); m_torrent.add_peer(adr, peer_info::pex, flags); - } + peers_added = true; + } } #endif #ifndef TORRENT_DISABLE_LOGGING @@ -425,6 +428,8 @@ namespace libtorrent { namespace #endif m_pc.stats_counters().inc_stats_counter(counters::num_incoming_pex); + + if (peers_added) m_torrent.do_connect_boost(); return true; } From 0bcf6cef2387484a107a77364bf9208f261fce8b Mon Sep 17 00:00:00 2001 From: d_komarov Date: Thu, 9 Aug 2018 22:49:17 +0300 Subject: [PATCH 5/5] Fix exporting files To avoid overwriting existing files, before exporting anything from a parts file, check whether it contains valid data. --- src/storage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage.cpp b/src/storage.cpp index 4a4712d15..d6bf3be13 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -463,7 +463,7 @@ namespace libtorrent return; } - if (m_part_file) + if (m_part_file && use_partfile(i)) { m_part_file->export_file(*f, fs.file_offset(i), fs.file_size(i), ec.ec); if (ec)