better exception handling and more invariant checks
This commit is contained in:
@@ -396,6 +396,7 @@ namespace libtorrent
|
|||||||
peer_connection::~peer_connection()
|
peer_connection::~peer_connection()
|
||||||
{
|
{
|
||||||
// INVARIANT_CHECK;
|
// INVARIANT_CHECK;
|
||||||
|
TORRENT_ASSERT(!m_in_constructor);
|
||||||
TORRENT_ASSERT(m_disconnecting);
|
TORRENT_ASSERT(m_disconnecting);
|
||||||
|
|
||||||
#ifdef TORRENT_VERBOSE_LOGGING
|
#ifdef TORRENT_VERBOSE_LOGGING
|
||||||
@@ -627,6 +628,7 @@ namespace libtorrent
|
|||||||
// check to make sure we don't have another connection with the same
|
// check to make sure we don't have another connection with the same
|
||||||
// info_hash and peer_id. If we do. close this connection.
|
// info_hash and peer_id. If we do. close this connection.
|
||||||
t->attach_peer(this);
|
t->attach_peer(this);
|
||||||
|
if (m_disconnecting) return;
|
||||||
m_torrent = wpt;
|
m_torrent = wpt;
|
||||||
|
|
||||||
TORRENT_ASSERT(!m_torrent.expired());
|
TORRENT_ASSERT(!m_torrent.expired());
|
||||||
@@ -2048,16 +2050,19 @@ namespace libtorrent
|
|||||||
#if defined(TORRENT_VERBOSE_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING)
|
||||||
(*m_logger) << "*** CONNECTION FAILED " << message << "\n";
|
(*m_logger) << "*** CONNECTION FAILED " << message << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
// we cannot create an intrusive pointer to ourselves, since we
|
||||||
|
// might be calling disconnect from the constructor (which would
|
||||||
|
// delete ourselves before the constructor returns)
|
||||||
// boost::intrusive_ptr<peer_connection> me(this);
|
// boost::intrusive_ptr<peer_connection> me(this);
|
||||||
|
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (m_disconnecting) return;
|
if (m_disconnecting) return;
|
||||||
m_disconnecting = true;
|
if (m_connecting && m_connection_ticket >= 0)
|
||||||
if (m_connecting)
|
{
|
||||||
m_ses.m_half_open.done(m_connection_ticket);
|
m_ses.m_half_open.done(m_connection_ticket);
|
||||||
|
m_connection_ticket = -1;
|
||||||
m_ses.m_io_service.post(boost::bind(&close_socket_ignore_error, m_socket));
|
}
|
||||||
|
|
||||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||||
|
|
||||||
@@ -2092,7 +2097,11 @@ namespace libtorrent
|
|||||||
m_torrent.reset();
|
m_torrent.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::shared_ptr<socket_type> sock = m_socket;
|
||||||
|
m_disconnecting = true;
|
||||||
m_ses.close_connection(this, message);
|
m_ses.close_connection(this, message);
|
||||||
|
|
||||||
|
m_ses.m_io_service.post(boost::bind(&close_socket_ignore_error, sock));
|
||||||
}
|
}
|
||||||
|
|
||||||
void peer_connection::set_upload_limit(int limit)
|
void peer_connection::set_upload_limit(int limit)
|
||||||
@@ -3004,6 +3013,18 @@ namespace libtorrent
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void peer_connection::check_invariant() const
|
void peer_connection::check_invariant() const
|
||||||
{
|
{
|
||||||
|
if (m_disconnecting)
|
||||||
|
{
|
||||||
|
for (aux::session_impl::torrent_map::const_iterator i = m_ses.m_torrents.begin()
|
||||||
|
, end(m_ses.m_torrents.end()); i != end; ++i)
|
||||||
|
TORRENT_ASSERT(!i->second->has_peer((peer_connection*)this));
|
||||||
|
TORRENT_ASSERT(!m_torrent.lock());
|
||||||
|
}
|
||||||
|
else if (!m_in_constructor)
|
||||||
|
{
|
||||||
|
TORRENT_ASSERT(m_ses.has_peer((peer_connection*)this));
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
// this peer is in the bandwidth history iff max_assignable < limit
|
// this peer is in the bandwidth history iff max_assignable < limit
|
||||||
@@ -3253,7 +3274,6 @@ namespace libtorrent
|
|||||||
|
|
||||||
bool peer_connection::is_seed() const
|
bool peer_connection::is_seed() const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
|
||||||
// if m_num_pieces == 0, we probably don't have the
|
// if m_num_pieces == 0, we probably don't have the
|
||||||
// metadata yet.
|
// metadata yet.
|
||||||
return m_num_pieces == (int)m_have_piece.size() && m_num_pieces > 0;
|
return m_num_pieces == (int)m_have_piece.size() && m_num_pieces > 0;
|
||||||
|
@@ -2475,6 +2475,7 @@ namespace detail
|
|||||||
boost::shared_ptr<torrent> t = (*i)->associated_torrent().lock();
|
boost::shared_ptr<torrent> t = (*i)->associated_torrent().lock();
|
||||||
|
|
||||||
peer_connection* p = i->get();
|
peer_connection* p = i->get();
|
||||||
|
TORRENT_ASSERT(!p->is_disconnecting());
|
||||||
if (!p->is_choked()) ++unchokes;
|
if (!p->is_choked()) ++unchokes;
|
||||||
if (p->peer_info_struct()
|
if (p->peer_info_struct()
|
||||||
&& p->peer_info_struct()->optimistically_unchoked)
|
&& p->peer_info_struct()->optimistically_unchoked)
|
||||||
|
@@ -2195,8 +2195,6 @@ namespace libtorrent
|
|||||||
throw protocol_error("reached connection limit");
|
throw protocol_error("reached connection limit");
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_ASSERT(m_connections.find(p) == m_connections.end());
|
|
||||||
peer_iterator ci = m_connections.insert(p).first;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// if new_connection throws, we have to remove the
|
// if new_connection throws, we have to remove the
|
||||||
@@ -2210,23 +2208,19 @@ namespace libtorrent
|
|||||||
if (pp) p->add_extension(pp);
|
if (pp) p->add_extension(pp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
TORRENT_ASSERT(m_connections.find(p) == ci);
|
if (!m_policy.new_connection(*p))
|
||||||
TORRENT_ASSERT(*ci == p);
|
|
||||||
if (!m_policy.new_connection(**ci))
|
|
||||||
{
|
|
||||||
m_connections.erase(ci);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
#if defined(TORRENT_LOGGING)
|
#if defined(TORRENT_LOGGING)
|
||||||
(*m_ses.m_logger) << time_now_string() << " CLOSING CONNECTION "
|
(*m_ses.m_logger) << time_now_string() << " CLOSING CONNECTION "
|
||||||
<< p->remote() << " policy::new_connection threw: " << e.what() << "\n";
|
<< p->remote() << " policy::new_connection threw: " << e.what() << "\n";
|
||||||
#endif
|
#endif
|
||||||
m_connections.erase(ci);
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
TORRENT_ASSERT(m_connections.find(p) == m_connections.end());
|
||||||
|
peer_iterator ci = m_connections.insert(p).first;
|
||||||
TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint());
|
TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint());
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
Reference in New Issue
Block a user