forked from premiere/premiere-libtorrent
added more invariant checks to policy
This commit is contained in:
parent
aaf6f0f19a
commit
8cfc98b976
|
@ -824,6 +824,8 @@ namespace libtorrent
|
||||||
|
|
||||||
void policy::ban_peer(const peer_connection& c)
|
void policy::ban_peer(const peer_connection& c)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
std::vector<peer>::iterator i = std::find_if(
|
std::vector<peer>::iterator i = std::find_if(
|
||||||
m_peers.begin()
|
m_peers.begin()
|
||||||
, m_peers.end()
|
, m_peers.end()
|
||||||
|
@ -839,6 +841,7 @@ namespace libtorrent
|
||||||
void policy::new_connection(peer_connection& c)
|
void policy::new_connection(peer_connection& c)
|
||||||
{
|
{
|
||||||
assert(!c.is_local());
|
assert(!c.is_local());
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
// if the connection comes from the tracker,
|
// if the connection comes from the tracker,
|
||||||
// it's probably just a NAT-check. Ignore the
|
// it's probably just a NAT-check. Ignore the
|
||||||
|
@ -895,6 +898,8 @@ namespace libtorrent
|
||||||
|
|
||||||
void policy::peer_from_tracker(const address& remote, const peer_id& id)
|
void policy::peer_from_tracker(const address& remote, const peer_id& id)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
// just ignore the obviously invalid entries from the tracker
|
// just ignore the obviously invalid entries from the tracker
|
||||||
if(remote.ip() == 0 || remote.port == 0)
|
if(remote.ip() == 0 || remote.port == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -980,6 +985,8 @@ namespace libtorrent
|
||||||
|
|
||||||
void policy::piece_finished(int index, bool successfully_verified)
|
void policy::piece_finished(int index, bool successfully_verified)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
assert(index >= 0 && index < m_torrent->torrent_file().num_pieces());
|
assert(index >= 0 && index < m_torrent->torrent_file().num_pieces());
|
||||||
|
|
||||||
if (successfully_verified)
|
if (successfully_verified)
|
||||||
|
@ -1017,6 +1024,8 @@ namespace libtorrent
|
||||||
// this peer has.
|
// this peer has.
|
||||||
void policy::block_finished(peer_connection& c, piece_block)
|
void policy::block_finished(peer_connection& c, piece_block)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
// if the peer hasn't choked us, ask for another piece
|
// if the peer hasn't choked us, ask for another piece
|
||||||
if (!c.has_peer_choked())
|
if (!c.has_peer_choked())
|
||||||
request_a_block(*m_torrent, c);
|
request_a_block(*m_torrent, c);
|
||||||
|
@ -1027,6 +1036,7 @@ namespace libtorrent
|
||||||
// data from now on
|
// data from now on
|
||||||
void policy::unchoked(peer_connection& c)
|
void policy::unchoked(peer_connection& c)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
if (c.is_interesting())
|
if (c.is_interesting())
|
||||||
{
|
{
|
||||||
request_a_block(*m_torrent, c);
|
request_a_block(*m_torrent, c);
|
||||||
|
@ -1036,6 +1046,8 @@ namespace libtorrent
|
||||||
// called when a peer is interested in us
|
// called when a peer is interested in us
|
||||||
void policy::interested(peer_connection& c)
|
void policy::interested(peer_connection& c)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
// if the peer is choked and we have upload slots left,
|
// if the peer is choked and we have upload slots left,
|
||||||
// then unchoke it. Another condition that has to be met
|
// then unchoke it. Another condition that has to be met
|
||||||
// is that the torrent doesn't keep track of the individual
|
// is that the torrent doesn't keep track of the individual
|
||||||
|
@ -1060,6 +1072,8 @@ namespace libtorrent
|
||||||
// called when a peer is no longer interested in us
|
// called when a peer is no longer interested in us
|
||||||
void policy::not_interested(peer_connection& c)
|
void policy::not_interested(peer_connection& c)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (m_torrent->ratio() != 0.f)
|
if (m_torrent->ratio() != 0.f)
|
||||||
{
|
{
|
||||||
assert(c.share_diff() < std::numeric_limits<size_type>::max());
|
assert(c.share_diff() < std::numeric_limits<size_type>::max());
|
||||||
|
@ -1155,6 +1169,8 @@ namespace libtorrent
|
||||||
// this is called whenever a peer connection is closed
|
// this is called whenever a peer connection is closed
|
||||||
void policy::connection_closed(const peer_connection& c)
|
void policy::connection_closed(const peer_connection& c)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
bool unchoked = false;
|
bool unchoked = false;
|
||||||
|
|
||||||
std::vector<peer>::iterator i = std::find_if(
|
std::vector<peer>::iterator i = std::find_if(
|
||||||
|
@ -1203,6 +1219,8 @@ namespace libtorrent
|
||||||
|
|
||||||
void policy::peer_is_interesting(peer_connection& c)
|
void policy::peer_is_interesting(peer_connection& c)
|
||||||
{
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
c.send_interested();
|
c.send_interested();
|
||||||
if (c.has_peer_choked()) return;
|
if (c.has_peer_choked()) return;
|
||||||
request_a_block(*m_torrent, c);
|
request_a_block(*m_torrent, c);
|
||||||
|
|
|
@ -821,8 +821,7 @@ namespace libtorrent
|
||||||
// if the peer_connection was downloading any pieces
|
// if the peer_connection was downloading any pieces
|
||||||
// abort them
|
// abort them
|
||||||
for (std::deque<piece_block>::const_iterator i = p->download_queue().begin();
|
for (std::deque<piece_block>::const_iterator i = p->download_queue().begin();
|
||||||
i != p->download_queue().end();
|
i != p->download_queue().end(); ++i)
|
||||||
++i)
|
|
||||||
{
|
{
|
||||||
m_picker->abort_download(*i);
|
m_picker->abort_download(*i);
|
||||||
}
|
}
|
||||||
|
@ -833,8 +832,7 @@ namespace libtorrent
|
||||||
const std::vector<bool>& pieces = p->get_bitfield();
|
const std::vector<bool>& pieces = p->get_bitfield();
|
||||||
|
|
||||||
for (std::vector<bool>::const_iterator i = pieces.begin();
|
for (std::vector<bool>::const_iterator i = pieces.begin();
|
||||||
i != pieces.end();
|
i != pieces.end(); ++i)
|
||||||
++i)
|
|
||||||
{
|
{
|
||||||
if (*i) piece_list.push_back(static_cast<int>(i - pieces.begin()));
|
if (*i) piece_list.push_back(static_cast<int>(i - pieces.begin()));
|
||||||
}
|
}
|
||||||
|
@ -842,8 +840,7 @@ namespace libtorrent
|
||||||
std::random_shuffle(piece_list.begin(), piece_list.end());
|
std::random_shuffle(piece_list.begin(), piece_list.end());
|
||||||
|
|
||||||
for (std::vector<int>::iterator i = piece_list.begin();
|
for (std::vector<int>::iterator i = piece_list.begin();
|
||||||
i != piece_list.end();
|
i != piece_list.end(); ++i)
|
||||||
++i)
|
|
||||||
{
|
{
|
||||||
peer_lost(*i);
|
peer_lost(*i);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue