forked from premiere/premiere-libtorrent
fix issue where peers could be disconnected while iterating over the peer list in the torrent. Specifically while marking peers as not-interesting
This commit is contained in:
parent
fc4588ad3b
commit
ddc8711dbe
|
@ -1066,9 +1066,11 @@ namespace libtorrent
|
||||||
if (share_mode()) return;
|
if (share_mode()) return;
|
||||||
if (super_seeding()) return;
|
if (super_seeding()) return;
|
||||||
|
|
||||||
int idx = 0;
|
// sending "not_interested" to a peer may cause us to disconnect it. Don't
|
||||||
|
// do that while looping over the peer list.
|
||||||
|
std::vector<bt_peer_connection*> defer;
|
||||||
for (peer_iterator i = m_connections.begin();
|
for (peer_iterator i = m_connections.begin();
|
||||||
i != m_connections.end(); ++idx)
|
i != m_connections.end(); ++i)
|
||||||
{
|
{
|
||||||
TORRENT_INCREMENT(m_iterating_connections);
|
TORRENT_INCREMENT(m_iterating_connections);
|
||||||
// since the call to disconnect_if_redundant() may
|
// since the call to disconnect_if_redundant() may
|
||||||
|
@ -1078,24 +1080,19 @@ namespace libtorrent
|
||||||
if (p->type() == peer_connection::bittorrent_connection)
|
if (p->type() == peer_connection::bittorrent_connection)
|
||||||
{
|
{
|
||||||
bt_peer_connection* btp = static_cast<bt_peer_connection*>(*i);
|
bt_peer_connection* btp = static_cast<bt_peer_connection*>(*i);
|
||||||
boost::shared_ptr<peer_connection> me(btp->self());
|
|
||||||
if (!btp->is_disconnecting())
|
if (!btp->is_disconnecting())
|
||||||
{
|
defer.push_back(btp);
|
||||||
btp->send_not_interested();
|
|
||||||
btp->write_upload_only();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::vector<bt_peer_connection*>::iterator i = defer.begin()
|
||||||
if (p->is_disconnecting())
|
, end(defer.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
i = m_connections.begin() + idx;
|
bt_peer_connection* btp = *i;
|
||||||
--idx;
|
boost::shared_ptr<peer_connection> me(btp->self());
|
||||||
}
|
btp->send_not_interested();
|
||||||
else
|
if (!btp->is_disconnecting())
|
||||||
{
|
btp->write_upload_only();
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue