added invariant checks to session_impl
This commit is contained in:
@@ -493,7 +493,7 @@ namespace libtorrent
|
|||||||
// This implements a round robin.
|
// This implements a round robin.
|
||||||
int m_next_connect_torrent;
|
int m_next_connect_torrent;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void check_invariant(const char *place = 0);
|
void check_invariant() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TORRENT_STATS
|
#ifdef TORRENT_STATS
|
||||||
|
@@ -624,6 +624,9 @@ namespace detail
|
|||||||
void session_impl::set_ip_filter(ip_filter const& f)
|
void session_impl::set_ip_filter(ip_filter const& f)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
m_ip_filter = f;
|
m_ip_filter = f;
|
||||||
|
|
||||||
// Close connections whose endpoint is filtered
|
// Close connections whose endpoint is filtered
|
||||||
@@ -636,6 +639,9 @@ namespace detail
|
|||||||
void session_impl::set_settings(session_settings const& s)
|
void session_impl::set_settings(session_settings const& s)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
assert(s.connection_speed > 0);
|
assert(s.connection_speed > 0);
|
||||||
assert(s.file_pool_size > 0);
|
assert(s.file_pool_size > 0);
|
||||||
|
|
||||||
@@ -803,6 +809,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
connection_map::iterator p = m_connections.find(s);
|
connection_map::iterator p = m_connections.find(s);
|
||||||
|
|
||||||
// the connection may have been disconnected in the receive or send phase
|
// the connection may have been disconnected in the receive or send phase
|
||||||
@@ -833,6 +841,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
assert(p->is_disconnecting());
|
assert(p->is_disconnecting());
|
||||||
connection_map::iterator i = m_connections.find(p->get_socket());
|
connection_map::iterator i = m_connections.find(p->get_socket());
|
||||||
if (i != m_connections.end())
|
if (i != m_connections.end())
|
||||||
@@ -858,6 +868,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
session_impl::mutex_t::scoped_lock l(m_mutex);
|
session_impl::mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
#if defined(TORRENT_LOGGING)
|
#if defined(TORRENT_LOGGING)
|
||||||
@@ -1458,6 +1470,8 @@ namespace detail
|
|||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
mutex::scoped_lock l2(m_checker_impl.m_mutex);
|
mutex::scoped_lock l2(m_checker_impl.m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (is_aborted())
|
if (is_aborted())
|
||||||
throw std::runtime_error("session is closing");
|
throw std::runtime_error("session is closing");
|
||||||
|
|
||||||
@@ -1550,6 +1564,8 @@ namespace detail
|
|||||||
// lock the session
|
// lock the session
|
||||||
session_impl::mutex_t::scoped_lock l(m_mutex);
|
session_impl::mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
// is the torrent already active?
|
// is the torrent already active?
|
||||||
if (!find_torrent(info_hash).expired())
|
if (!find_torrent(info_hash).expired())
|
||||||
throw duplicate_torrent();
|
throw duplicate_torrent();
|
||||||
@@ -1588,6 +1604,9 @@ namespace detail
|
|||||||
assert(h.m_ses != 0);
|
assert(h.m_ses != 0);
|
||||||
|
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
session_impl::torrent_map::iterator i =
|
session_impl::torrent_map::iterator i =
|
||||||
m_torrents.find(h.m_info_hash);
|
m_torrents.find(h.m_info_hash);
|
||||||
if (i != m_torrents.end())
|
if (i != m_torrents.end())
|
||||||
@@ -1650,6 +1669,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
session_impl::mutex_t::scoped_lock l(m_mutex);
|
session_impl::mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
tcp::endpoint new_interface;
|
tcp::endpoint new_interface;
|
||||||
if (net_interface && std::strlen(net_interface) > 0)
|
if (net_interface && std::strlen(net_interface) > 0)
|
||||||
new_interface = tcp::endpoint(address::from_string(net_interface), port_range.first);
|
new_interface = tcp::endpoint(address::from_string(net_interface), port_range.first);
|
||||||
@@ -1729,6 +1750,8 @@ namespace detail
|
|||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
boost::shared_ptr<torrent> t = find_torrent(ih).lock();
|
boost::shared_ptr<torrent> t = find_torrent(ih).lock();
|
||||||
if (!t) return;
|
if (!t) return;
|
||||||
// don't add peers from lsd to private torrents
|
// don't add peers from lsd to private torrents
|
||||||
@@ -1783,6 +1806,9 @@ namespace detail
|
|||||||
session_status session_impl::status() const
|
session_status session_impl::status() const
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
session_status s;
|
session_status s;
|
||||||
s.has_incoming_connections = m_incoming_connection;
|
s.has_incoming_connections = m_incoming_connection;
|
||||||
s.num_peers = (int)m_connections.size();
|
s.num_peers = (int)m_connections.size();
|
||||||
@@ -1824,6 +1850,9 @@ namespace detail
|
|||||||
void session_impl::start_dht(entry const& startup_state)
|
void session_impl::start_dht(entry const& startup_state)
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (m_dht)
|
if (m_dht)
|
||||||
{
|
{
|
||||||
m_dht->stop();
|
m_dht->stop();
|
||||||
@@ -1983,6 +2012,9 @@ namespace detail
|
|||||||
{
|
{
|
||||||
assert(limit > 0 || limit == -1);
|
assert(limit > 0 || limit == -1);
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
||||||
m_max_uploads = limit;
|
m_max_uploads = limit;
|
||||||
}
|
}
|
||||||
@@ -1991,6 +2023,9 @@ namespace detail
|
|||||||
{
|
{
|
||||||
assert(limit > 0 || limit == -1);
|
assert(limit > 0 || limit == -1);
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
||||||
m_max_connections = limit;
|
m_max_connections = limit;
|
||||||
}
|
}
|
||||||
@@ -1999,6 +2034,9 @@ namespace detail
|
|||||||
{
|
{
|
||||||
assert(limit > 0 || limit == -1);
|
assert(limit > 0 || limit == -1);
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
||||||
m_half_open.limit(limit);
|
m_half_open.limit(limit);
|
||||||
}
|
}
|
||||||
@@ -2007,6 +2045,9 @@ namespace detail
|
|||||||
{
|
{
|
||||||
assert(bytes_per_second > 0 || bytes_per_second == -1);
|
assert(bytes_per_second > 0 || bytes_per_second == -1);
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (bytes_per_second <= 0) bytes_per_second = bandwidth_limit::inf;
|
if (bytes_per_second <= 0) bytes_per_second = bandwidth_limit::inf;
|
||||||
m_bandwidth_manager[peer_connection::download_channel]->throttle(bytes_per_second);
|
m_bandwidth_manager[peer_connection::download_channel]->throttle(bytes_per_second);
|
||||||
}
|
}
|
||||||
@@ -2015,6 +2056,9 @@ namespace detail
|
|||||||
{
|
{
|
||||||
assert(bytes_per_second > 0 || bytes_per_second == -1);
|
assert(bytes_per_second > 0 || bytes_per_second == -1);
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (bytes_per_second <= 0) bytes_per_second = bandwidth_limit::inf;
|
if (bytes_per_second <= 0) bytes_per_second = bandwidth_limit::inf;
|
||||||
m_bandwidth_manager[peer_connection::upload_channel]->throttle(bytes_per_second);
|
m_bandwidth_manager[peer_connection::upload_channel]->throttle(bytes_per_second);
|
||||||
}
|
}
|
||||||
@@ -2022,6 +2066,9 @@ namespace detail
|
|||||||
std::auto_ptr<alert> session_impl::pop_alert()
|
std::auto_ptr<alert> session_impl::pop_alert()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (m_alerts.pending())
|
if (m_alerts.pending())
|
||||||
return m_alerts.get();
|
return m_alerts.get();
|
||||||
return std::auto_ptr<alert>(0);
|
return std::auto_ptr<alert>(0);
|
||||||
@@ -2036,6 +2083,9 @@ namespace detail
|
|||||||
int session_impl::upload_rate_limit() const
|
int session_impl::upload_rate_limit() const
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
int ret = m_bandwidth_manager[peer_connection::upload_channel]->throttle();
|
int ret = m_bandwidth_manager[peer_connection::upload_channel]->throttle();
|
||||||
return ret == (std::numeric_limits<int>::max)() ? -1 : ret;
|
return ret == (std::numeric_limits<int>::max)() ? -1 : ret;
|
||||||
}
|
}
|
||||||
@@ -2050,6 +2100,9 @@ namespace detail
|
|||||||
void session_impl::start_lsd()
|
void session_impl::start_lsd()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
m_lsd.reset(new lsd(m_io_service
|
m_lsd.reset(new lsd(m_io_service
|
||||||
, m_listen_interface.address()
|
, m_listen_interface.address()
|
||||||
, bind(&session_impl::on_lsd_peer, this, _1, _2)));
|
, bind(&session_impl::on_lsd_peer, this, _1, _2)));
|
||||||
@@ -2058,6 +2111,9 @@ namespace detail
|
|||||||
void session_impl::start_natpmp()
|
void session_impl::start_natpmp()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
m_natpmp.reset(new natpmp(m_io_service
|
m_natpmp.reset(new natpmp(m_io_service
|
||||||
, m_listen_interface.address()
|
, m_listen_interface.address()
|
||||||
, bind(&session_impl::on_port_mapping
|
, bind(&session_impl::on_port_mapping
|
||||||
@@ -2073,6 +2129,9 @@ namespace detail
|
|||||||
void session_impl::start_upnp()
|
void session_impl::start_upnp()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
m_upnp.reset(new upnp(m_io_service, m_half_open
|
m_upnp.reset(new upnp(m_io_service, m_half_open
|
||||||
, m_listen_interface.address()
|
, m_listen_interface.address()
|
||||||
, m_settings.user_agent
|
, m_settings.user_agent
|
||||||
@@ -2110,14 +2169,13 @@ namespace detail
|
|||||||
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void session_impl::check_invariant(const char *place)
|
void session_impl::check_invariant() const
|
||||||
{
|
{
|
||||||
assert(m_max_connections > 0);
|
assert(m_max_connections > 0);
|
||||||
assert(m_max_uploads > 0);
|
assert(m_max_uploads > 0);
|
||||||
assert(place);
|
|
||||||
int unchokes = 0;
|
int unchokes = 0;
|
||||||
int num_optimistic = 0;
|
int num_optimistic = 0;
|
||||||
for (connection_map::iterator i = m_connections.begin();
|
for (connection_map::const_iterator i = m_connections.begin();
|
||||||
i != m_connections.end(); ++i)
|
i != m_connections.end(); ++i)
|
||||||
{
|
{
|
||||||
assert(i->second);
|
assert(i->second);
|
||||||
@@ -2130,7 +2188,7 @@ namespace detail
|
|||||||
++num_optimistic;
|
++num_optimistic;
|
||||||
assert(!i->second->is_choked());
|
assert(!i->second->is_choked());
|
||||||
}
|
}
|
||||||
if (t)
|
if (t && i->second->peer_info_struct())
|
||||||
{
|
{
|
||||||
assert(t->get_policy().has_connection(boost::get_pointer(i->second)));
|
assert(t->get_policy().has_connection(boost::get_pointer(i->second)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user