forked from premiere/premiere-libtorrent
made the unchoke interval configurable
This commit is contained in:
parent
e858cbc1ae
commit
a7ad108e8a
|
@ -104,6 +104,8 @@ namespace libtorrent
|
|||
// the peer choked us
|
||||
void choked(peer_connection& c);
|
||||
|
||||
int count_choked() const;
|
||||
|
||||
// the peer unchoked us
|
||||
void unchoked(peer_connection& c);
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ namespace libtorrent
|
|||
, send_redundant_have(false)
|
||||
, lazy_bitfields(true)
|
||||
, inactivity_timeout(600)
|
||||
, unchoke_interval(20)
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
, use_dht_as_fallback(true)
|
||||
#endif
|
||||
|
@ -234,6 +235,9 @@ namespace libtorrent
|
|||
// default is 10 minutes
|
||||
int inactivity_timeout;
|
||||
|
||||
// the number of seconds between chokes/unchokes
|
||||
int unchoke_interval;
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
// while this is true, the dht will note be used unless the
|
||||
// tracker is online
|
||||
|
|
|
@ -850,12 +850,13 @@ namespace libtorrent
|
|||
--m_num_unchoked;
|
||||
} while (m_num_unchoked > m_torrent->m_uploads_quota.given);
|
||||
}
|
||||
else
|
||||
// this should prevent the choke/unchoke
|
||||
// problem, since it will not unchoke unless
|
||||
// there actually are any choked peers
|
||||
else if (count_choked() > 0)
|
||||
{
|
||||
// optimistic unchoke. trade the 'worst'
|
||||
// unchoked peer with one of the choked
|
||||
// TODO: This rotation should happen
|
||||
// far less frequent than this!
|
||||
assert(m_num_unchoked <= m_torrent->num_peers());
|
||||
iterator p = find_unchoke_candidate();
|
||||
if (p != m_peers.end())
|
||||
|
@ -875,6 +876,22 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
int policy::count_choked() const
|
||||
{
|
||||
int ret = 0;
|
||||
for (const_iterator i = m_peers.begin();
|
||||
i != m_peers.end(); ++i)
|
||||
{
|
||||
if (!i->connection
|
||||
|| i->connection->is_connecting()
|
||||
|| i->connection->is_disconnecting()
|
||||
|| !i->connection->is_peer_interested())
|
||||
continue;
|
||||
if (i->connection->is_choked()) ++ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void policy::new_connection(peer_connection& c)
|
||||
{
|
||||
assert(!c.is_local());
|
||||
|
|
|
@ -623,6 +623,9 @@ namespace libtorrent { namespace detail
|
|||
mutex_t::scoped_lock l(m_mutex);
|
||||
assert(s.connection_speed > 0);
|
||||
assert(s.file_pool_size > 0);
|
||||
|
||||
// less than 5 seconds unchoke interval is insane
|
||||
assert(s.unchoke_interval >= 5);
|
||||
m_settings = s;
|
||||
m_files.resize(m_settings.file_pool_size);
|
||||
// replace all occurances of '\n' with ' '.
|
||||
|
|
|
@ -562,7 +562,6 @@ namespace libtorrent
|
|||
bind(&torrent::on_peer_name_lookup, shared_from_this(), _1, _2, i->pid)));
|
||||
}
|
||||
}
|
||||
m_policy->pulse();
|
||||
|
||||
if (m_ses.m_alerts.should_post(alert::info))
|
||||
{
|
||||
|
@ -2464,7 +2463,7 @@ namespace libtorrent
|
|||
m_time_scaler--;
|
||||
if (m_time_scaler <= 0)
|
||||
{
|
||||
m_time_scaler = 10;
|
||||
m_time_scaler = settings().unchoke_interval;
|
||||
m_policy->pulse();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue