From 3d5d9eb807159283e8cedd0efe1b0354f07bdc7d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 11 Feb 2010 04:39:04 +0000 Subject: [PATCH] start torrent on incoming connection feature --- ChangeLog | 2 ++ bindings/python/src/session_settings.cpp | 3 ++- docs/manual.rst | 12 ++++++++++ include/libtorrent/session_settings.hpp | 5 ++++ src/peer_connection.cpp | 16 +++++++++++-- src/session_impl.cpp | 30 +++++++++++++++--------- 6 files changed, 54 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2984ddac6..ce42d9f18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,8 @@ * support variable number of optimistic unchoke slots and to dynamically adjust based on the total number of unchoke slots * support for BitTyrant choker algorithm + * support for automatically start torrents when they receive an + incoming connection 0.15 release diff --git a/bindings/python/src/session_settings.cpp b/bindings/python/src/session_settings.cpp index c5d7bf983..2ff7e1c97 100644 --- a/bindings/python/src/session_settings.cpp +++ b/bindings/python/src/session_settings.cpp @@ -113,6 +113,7 @@ void bind_session_settings() .def_readwrite("udp_tracker_token_expiry", &session_settings::udp_tracker_token_expiry) .def_readwrite("volatile_read_cache", &session_settings::volatile_read_cache) .def_readwrite("guided_read_cache", &session_settings::guided_read_cache) + .def_readwrite("incoming_starts_queued_torrents", &session_settings::incoming_starts_queued_torrents) ; enum_("proxy_type") @@ -129,7 +130,7 @@ void bind_session_settings() .value("largest_contiguous", session_settings::largest_contiguous) ; - enum_("choking_algorithm_t") + enum_("choking_algorithm_t") .value("fixed_slots_choker", session_settings::fixed_slots_choker) .value("auto_expand_choker", session_settings::auto_expand_choker) .value("rate_based_choker", session_settings::rate_based_choker) diff --git a/docs/manual.rst b/docs/manual.rst index a4eecdae7..5896c6d3a 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3764,6 +3764,8 @@ session_settings bool volatile_read_cache; bool guided_read_cache; bool default_min_cache_age; + + bool incoming_starts_queued_torrents; }; ``user_agent`` this is the client identification to the tracker. @@ -4294,6 +4296,16 @@ fewer packets have to be sent to the UDP tracker. In order for higher values to work, the tracker needs to be configured to match the expiration time for tokens. +``incoming_starts_queued_torrents`` defaults to false. If a torrent +has been paused by the auto managed feature in libtorrent, i.e. +the torrent is paused and auto managed, this feature affects whether +or not it is automatically started on an incoming connection. The +main reason to queue torrents, is not to make them unavailable, but +to save on the overhead of announcing to the trackers, the DHT and to +avoid spreading one's unchoke slots too thin. If a peer managed to +find us, even though we're no in the torrent anymore, this setting +can make us start the torrent and serve it. + pe_settings =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index dc55ccdc7..e4803e286 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -200,6 +200,7 @@ namespace libtorrent , default_est_reciprocation_rate(16000) , increase_est_reciprocation_rate(20) , decrease_est_reciprocation_rate(3) + , incoming_starts_queued_torrents(false) {} // this is the user agent that will be sent to the tracker @@ -752,6 +753,10 @@ namespace libtorrent // our estimate of the reciprocation rate, since we might have // over-estimated it int decrease_est_reciprocation_rate; + + // if set to true, an incoming connection to a torrent that's + // paused and auto-managed will make the torrent start. + bool incoming_starts_queued_torrents; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index c21e868ef..6d4e2680c 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1071,10 +1071,15 @@ namespace libtorrent return; } - if (t->is_paused()) + if (t->is_paused() && (!t->is_auto_managed() + || !m_ses.m_settings.incoming_starts_queued_torrents + || t->has_error())) { // paused torrents will not accept - // incoming connections + // incoming connections unless they are auto managed + // and inconing_starts_queued_torrents is true + // torrents that have errors should always reject + // incoming peers #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING (*m_logger) << " rejected connection to paused torrent\n"; #endif @@ -1097,6 +1102,13 @@ namespace libtorrent #endif // TORRENT_USE_I2P TORRENT_ASSERT(m_torrent.expired()); + + if (t->is_paused()) + { + TORRENT_ASSERT(m_ses.m_settings.incoming_starts_queued_torrents); + t->resume(); + } + // check to make sure we don't have another connection with the same // info_hash and peer_id. If we do. close this connection. t->attach_peer(this); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index abc329503..090e97eee 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1524,22 +1524,30 @@ namespace aux { return; } - bool has_active_torrent = false; - for (torrent_map::iterator i = m_torrents.begin() + // if we don't have any active torrents, there's no + // point in accepting this connection. If, however, + // the setting to start up queued torrents when they + // get an incoming connection is enabled, we cannot + // perform this check. + if (!m_settings.incoming_starts_queued_torrents) + { + bool has_active_torrent = false; + for (torrent_map::iterator i = m_torrents.begin() , end(m_torrents.end()); i != end; ++i) - { - if (!i->second->is_paused()) { - has_active_torrent = true; - break; + if (!i->second->is_paused()) + { + has_active_torrent = true; + break; + } } - } - if (!has_active_torrent) - { + if (!has_active_torrent) + { #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) - (*m_logger) << " There are no _active_ torrents, disconnect\n"; + (*m_logger) << " There are no _active_ torrents, disconnect\n"; #endif - return; + return; + } } setup_socket_buffers(*s);