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; }