add asserts to try to catch crash in peer_connection::received_valid_data

This commit is contained in:
Arvid Norberg 2012-02-09 06:24:58 +00:00
parent 8b459a27bd
commit f7b5c10b2b
5 changed files with 22 additions and 9 deletions

View File

@ -1261,6 +1261,7 @@ namespace libtorrent
bool m_in_constructor:1; bool m_in_constructor:1;
bool m_disconnect_started:1; bool m_disconnect_started:1;
bool m_initialized:1; bool m_initialized:1;
int m_in_use;
int m_received_in_piece; int m_received_in_piece;
#endif #endif
}; };

View File

@ -311,7 +311,7 @@ namespace libtorrent
// we have been connected via uTP at least once // we have been connected via uTP at least once
bool confirmed_supports_utp:1; bool confirmed_supports_utp:1;
bool supports_holepunch:1; bool supports_holepunch:1;
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool in_use:1; bool in_use:1;
#endif #endif
}; };

View File

@ -198,6 +198,7 @@ namespace libtorrent
, m_in_constructor(true) , m_in_constructor(true)
, m_disconnect_started(false) , m_disconnect_started(false)
, m_initialized(false) , m_initialized(false)
, m_in_use(1337)
, m_received_in_piece(0) , m_received_in_piece(0)
#endif #endif
{ {
@ -349,6 +350,7 @@ namespace libtorrent
, m_in_constructor(true) , m_in_constructor(true)
, m_disconnect_started(false) , m_disconnect_started(false)
, m_initialized(false) , m_initialized(false)
, m_in_use(1337)
, m_received_in_piece(0) , m_received_in_piece(0)
#endif #endif
{ {
@ -915,6 +917,10 @@ namespace libtorrent
TORRENT_ASSERT(m_disconnecting); TORRENT_ASSERT(m_disconnecting);
TORRENT_ASSERT(m_disconnect_started); TORRENT_ASSERT(m_disconnect_started);
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_in_use = 0;
#endif
// defensive // defensive
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
@ -5650,6 +5656,7 @@ namespace libtorrent
void peer_connection::check_invariant() const void peer_connection::check_invariant() const
{ {
TORRENT_ASSERT(m_in_use == 1337);
TORRENT_ASSERT(m_queued_time_critical <= int(m_request_queue.size())); TORRENT_ASSERT(m_queued_time_critical <= int(m_request_queue.size()));
TORRENT_ASSERT(bool(m_disk_recv_buffer) == (m_disk_recv_buffer_size > 0)); TORRENT_ASSERT(bool(m_disk_recv_buffer) == (m_disk_recv_buffer_size > 0));

View File

@ -423,7 +423,7 @@ namespace libtorrent
if (m_round_robin > i - m_peers.begin()) --m_round_robin; if (m_round_robin > i - m_peers.begin()) --m_round_robin;
if (m_round_robin >= int(m_peers.size())) m_round_robin = 0; if (m_round_robin >= int(m_peers.size())) m_round_robin = 0;
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
TORRENT_ASSERT((*i)->in_use); TORRENT_ASSERT((*i)->in_use);
(*i)->in_use = false; (*i)->in_use = false;
#endif #endif
@ -933,7 +933,7 @@ namespace libtorrent
#endif #endif
new (p) ipv4_peer(c.remote(), false, 0); new (p) ipv4_peer(c.remote(), false, 0);
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
p->in_use = true; p->in_use = true;
#endif #endif
@ -1214,13 +1214,13 @@ namespace libtorrent
m_torrent->session().m_i2p_peer_pool.set_next_size(500); m_torrent->session().m_i2p_peer_pool.set_next_size(500);
new (p) i2p_peer(destination, true, src); new (p) i2p_peer(destination, true, src);
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
p->in_use = true; p->in_use = true;
#endif #endif
if (!insert_peer(p, iter, flags)) if (!insert_peer(p, iter, flags))
{ {
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
p->in_use = false; p->in_use = false;
#endif #endif
@ -1339,13 +1339,13 @@ namespace libtorrent
#endif #endif
new (p) ipv4_peer(remote, true, src); new (p) ipv4_peer(remote, true, src);
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
p->in_use = true; p->in_use = true;
#endif #endif
if (!insert_peer(p, iter, flags)) if (!insert_peer(p, iter, flags))
{ {
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
p->in_use = false; p->in_use = false;
#endif #endif
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
@ -1677,7 +1677,7 @@ namespace libtorrent
, supports_utp(true) // assume peers support utp , supports_utp(true) // assume peers support utp
, confirmed_supports_utp(false) , confirmed_supports_utp(false)
, supports_holepunch(false) , supports_holepunch(false)
#ifdef TORRENT_DEBUG #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
, in_use(false) , in_use(false)
#endif #endif
{ {

View File

@ -3140,12 +3140,17 @@ namespace libtorrent
{ {
policy::peer* p = static_cast<policy::peer*>(*i); policy::peer* p = static_cast<policy::peer*>(*i);
if (p == 0) continue; if (p == 0) continue;
TORRENT_ASSERT(p->in_use);
p->on_parole = false; p->on_parole = false;
int trust_points = p->trust_points; int trust_points = p->trust_points;
++trust_points; ++trust_points;
if (trust_points > 8) trust_points = 8; if (trust_points > 8) trust_points = 8;
p->trust_points = trust_points; p->trust_points = trust_points;
if (p->connection) p->connection->received_valid_data(index); if (p->connection)
{
TORRENT_ASSERT(p->connection->m_in_use == 1337);
p->connection->received_valid_data(index);
}
} }
if (settings().max_sparse_regions > 0 if (settings().max_sparse_regions > 0