forked from premiere/premiere-libtorrent
simplified policy and optimized case when a piece fails hash check
This commit is contained in:
parent
fa195aa2e2
commit
6db1b54304
|
@ -99,11 +99,6 @@ namespace libtorrent
|
|||
// the peer has got at least one interesting piece
|
||||
void peer_is_interesting(peer_connection& c);
|
||||
|
||||
void piece_finished(int index, bool successfully_verified);
|
||||
|
||||
// the peer choked us
|
||||
void choked(peer_connection& c);
|
||||
|
||||
int count_choked() const;
|
||||
|
||||
// the peer unchoked us
|
||||
|
|
|
@ -796,7 +796,6 @@ namespace libtorrent
|
|||
(*m_logger) << time_now_string() << " <== CHOKE\n";
|
||||
#endif
|
||||
m_peer_choked = true;
|
||||
t->get_policy().choked(*this);
|
||||
|
||||
if (peer_info_struct() == 0 || !peer_info_struct()->on_parole)
|
||||
{
|
||||
|
|
|
@ -881,35 +881,6 @@ namespace libtorrent
|
|||
return &i->second;
|
||||
}
|
||||
|
||||
// this is called when we are choked by a peer
|
||||
// i.e. a peer lets us know that we will not receive
|
||||
// anything for a while
|
||||
void policy::choked(peer_connection&)
|
||||
{
|
||||
}
|
||||
|
||||
void policy::piece_finished(int index, bool successfully_verified)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
TORRENT_ASSERT(index >= 0 && index < m_torrent->torrent_file().num_pieces());
|
||||
|
||||
if (successfully_verified)
|
||||
{
|
||||
// have all peers update their interested-flag
|
||||
for (iterator i = m_peers.begin();
|
||||
i != m_peers.end(); ++i)
|
||||
{
|
||||
if (i->second.connection == 0) continue;
|
||||
// if we're not interested, we will not become interested
|
||||
if (!i->second.connection->is_interesting()) continue;
|
||||
if (!i->second.connection->has_piece(index)) continue;
|
||||
|
||||
i->second.connection->update_interest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this is called when we are unchoked by a peer
|
||||
// i.e. a peer lets us know that we will receive
|
||||
// data from now on
|
||||
|
|
|
@ -1254,9 +1254,35 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(valid_metadata());
|
||||
// if we just became a seed, picker is now invalid, since it
|
||||
// is deallocated by the torrent once it starts seeding
|
||||
|
||||
// since this piece just passed, we might have
|
||||
// become uninterested in some peers where this
|
||||
// was the last piece we were interested in
|
||||
for (peer_iterator i = m_connections.begin()
|
||||
, end(m_connections.end()); i != end; ++i)
|
||||
{
|
||||
peer_connection* p = *i;
|
||||
// if we're not interested already, no need to check
|
||||
if (!p->is_interesting()) continue;
|
||||
// if the peer doesn't have the piece we just got, it
|
||||
// wouldn't affect our interest
|
||||
if (!p->has_piece(index)) continue;
|
||||
p->update_interest();
|
||||
}
|
||||
|
||||
if (!was_finished&& is_finished())
|
||||
{
|
||||
TORRENT_ASSERT(passed_hash_check == 0);
|
||||
// torrent finished
|
||||
// i.e. all the pieces we're interested in have
|
||||
// been downloaded. Release the files (they will open
|
||||
// in read only mode if needed)
|
||||
finished();
|
||||
}
|
||||
}
|
||||
else if (passed_hash_check == -2)
|
||||
{
|
||||
// piece_failed() will restore the piece
|
||||
piece_failed(index);
|
||||
}
|
||||
else
|
||||
|
@ -1264,21 +1290,6 @@ namespace libtorrent
|
|||
TORRENT_ASSERT(passed_hash_check == -1);
|
||||
m_picker->restore_piece(index);
|
||||
}
|
||||
|
||||
m_policy.piece_finished(index, passed_hash_check == 0);
|
||||
|
||||
if (!was_finished
|
||||
&& (is_seed()
|
||||
|| m_picker->num_filtered() + num_have()
|
||||
== torrent_file().num_pieces()))
|
||||
{
|
||||
TORRENT_ASSERT(passed_hash_check == 0);
|
||||
// torrent finished
|
||||
// i.e. all the pieces we're interested in have
|
||||
// been downloaded. Release the files (they will open
|
||||
// in read only mode if needed)
|
||||
finished();
|
||||
}
|
||||
}
|
||||
|
||||
void torrent::piece_failed(int index)
|
||||
|
@ -3271,7 +3282,8 @@ namespace libtorrent
|
|||
piece_manager& torrent::filesystem()
|
||||
{
|
||||
TORRENT_ASSERT(m_owning_storage.get());
|
||||
return *m_owning_storage;
|
||||
TORRENT_ASSERT(m_storage);
|
||||
return *m_storage;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue