forked from premiere/premiere-libtorrent
added more asserts for choke/unchoke states and a peer_info flag to indicate a peer being optimistically unchoked
This commit is contained in:
parent
89cba6df58
commit
23a20a24c1
|
@ -56,10 +56,11 @@ namespace libtorrent
|
|||
connecting = 0x80,
|
||||
queued = 0x100,
|
||||
on_parole = 0x200,
|
||||
seed = 0x400
|
||||
seed = 0x400,
|
||||
optimistic_unchoke = 0x800
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
, rc4_encrypted = 0x800,
|
||||
plaintext_encrypted = 0x1000
|
||||
, rc4_encrypted = 0x100000,
|
||||
plaintext_encrypted = 0x200000
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -1679,6 +1679,8 @@ namespace libtorrent
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
assert(!m_peer_info || !m_peer_info->optimistically_unchoked);
|
||||
|
||||
if (m_choked) return;
|
||||
write_choke();
|
||||
m_choked = true;
|
||||
|
@ -1697,14 +1699,6 @@ namespace libtorrent
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
#ifndef NDEBUG
|
||||
// TODO: once the policy lowers the interval for optimistic
|
||||
// unchoke, increase this value that interval
|
||||
// this condition cannot be guaranteed since if peers disconnect
|
||||
// a new one will be unchoked ignoring when it was last choked
|
||||
//assert(time_now() - m_last_choke > seconds(9));
|
||||
#endif
|
||||
|
||||
if (!m_choked) return;
|
||||
write_unchoke();
|
||||
m_choked = false;
|
||||
|
@ -2009,6 +2003,7 @@ namespace libtorrent
|
|||
p.failcount = peer_info_struct()->failcount;
|
||||
p.num_hashfails = peer_info_struct()->hashfails;
|
||||
p.flags |= peer_info_struct()->on_parole ? peer_info::on_parole : 0;
|
||||
p.flags |= peer_info_struct()->optimistically_unchoked ? peer_info::optimistic_unchoke : 0;
|
||||
p.remote_dl_rate = m_remote_dl_rate;
|
||||
}
|
||||
else
|
||||
|
@ -2231,20 +2226,6 @@ namespace libtorrent
|
|||
m_reading_bytes += r.length;
|
||||
|
||||
m_requests.erase(m_requests.begin());
|
||||
/*
|
||||
if (m_requests.empty()
|
||||
&& m_num_invalid_requests > 0
|
||||
&& is_peer_interested()
|
||||
&& !is_seed())
|
||||
{
|
||||
// this will make the peer clear
|
||||
// its download queue and re-request
|
||||
// pieces. Hopefully it will not
|
||||
// send invalid requests then
|
||||
send_choke();
|
||||
send_unchoke();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2785,9 +2766,14 @@ namespace libtorrent
|
|||
void peer_connection::check_invariant() const
|
||||
{
|
||||
if (m_peer_info)
|
||||
{
|
||||
assert(m_peer_info->connection == this
|
||||
|| m_peer_info->connection == 0);
|
||||
|
||||
|
||||
if (m_peer_info->optimistically_unchoked)
|
||||
assert(!is_choked());
|
||||
}
|
||||
|
||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||
if (!t)
|
||||
{
|
||||
|
|
|
@ -1320,14 +1320,16 @@ namespace libtorrent
|
|||
INVARIANT_CHECK;
|
||||
|
||||
peer* p = c.peer_info_struct();
|
||||
// if we couldn't find the connection in our list, just ignore it.
|
||||
if (p == 0) return;
|
||||
|
||||
assert(std::find_if(
|
||||
assert((std::find_if(
|
||||
m_peers.begin()
|
||||
, m_peers.end()
|
||||
, match_peer_connection(c))
|
||||
!= m_peers.end());
|
||||
!= m_peers.end()) == (p != 0));
|
||||
|
||||
// if we couldn't find the connection in our list, just ignore it.
|
||||
if (p == 0) return;
|
||||
|
||||
assert(p->connection == &c);
|
||||
|
||||
p->connection = 0;
|
||||
|
|
|
@ -1106,6 +1106,7 @@ namespace detail
|
|||
}
|
||||
else
|
||||
{
|
||||
assert(p->peer_info_struct());
|
||||
if (!p->is_choked() && !p->peer_info_struct()->optimistically_unchoked)
|
||||
t->choke_peer(*p);
|
||||
}
|
||||
|
@ -1159,8 +1160,8 @@ namespace detail
|
|||
{
|
||||
torrent* t = current_optimistic_unchoke->second->associated_torrent().lock().get();
|
||||
assert(t);
|
||||
t->choke_peer(*current_optimistic_unchoke->second);
|
||||
current_optimistic_unchoke->second->peer_info_struct()->optimistically_unchoked = false;
|
||||
t->choke_peer(*current_optimistic_unchoke->second);
|
||||
}
|
||||
|
||||
torrent* t = optimistic_unchoke_candidate->second->associated_torrent().lock().get();
|
||||
|
|
Loading…
Reference in New Issue