start torrent on incoming connection feature

This commit is contained in:
Arvid Norberg 2010-02-11 04:39:04 +00:00
parent 0816ff69c6
commit 3d5d9eb807
6 changed files with 54 additions and 14 deletions

View File

@ -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

View File

@ -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_settings::proxy_type>("proxy_type")
@ -129,7 +130,7 @@ void bind_session_settings()
.value("largest_contiguous", session_settings::largest_contiguous)
;
enum_<session_settings::disk_cache_algo_t>("choking_algorithm_t")
enum_<session_settings::choking_algorithm_t>("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)

View File

@ -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
===========

View File

@ -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

View File

@ -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);

View File

@ -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);