forked from premiere/premiere-libtorrent
fixed race condition in dht
This commit is contained in:
parent
e1eadab1b4
commit
1d8edc0722
|
@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <boost/filesystem/operations.hpp>
|
#include <boost/filesystem/operations.hpp>
|
||||||
#include <boost/intrusive_ptr.hpp>
|
#include <boost/intrusive_ptr.hpp>
|
||||||
#include <boost/detail/atomic_count.hpp>
|
#include <boost/detail/atomic_count.hpp>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
|
||||||
#include "libtorrent/kademlia/node.hpp"
|
#include "libtorrent/kademlia/node.hpp"
|
||||||
#include "libtorrent/kademlia/node_id.hpp"
|
#include "libtorrent/kademlia/node_id.hpp"
|
||||||
|
@ -117,6 +118,12 @@ namespace libtorrent { namespace dht
|
||||||
dht_settings const& m_settings;
|
dht_settings const& m_settings;
|
||||||
int m_refresh_bucket;
|
int m_refresh_bucket;
|
||||||
|
|
||||||
|
// The mutex is used to abort the dht node
|
||||||
|
// it's only used to set m_abort to true
|
||||||
|
typedef boost::mutex mutex_t;
|
||||||
|
mutable mutex_t m_mutex;
|
||||||
|
bool m_abort;
|
||||||
|
|
||||||
// used to resolve hostnames for nodes
|
// used to resolve hostnames for nodes
|
||||||
udp::resolver m_host_resolver;
|
udp::resolver m_host_resolver;
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,7 @@ namespace libtorrent { namespace dht
|
||||||
, m_refresh_timer(sock.get_io_service())
|
, m_refresh_timer(sock.get_io_service())
|
||||||
, m_settings(settings)
|
, m_settings(settings)
|
||||||
, m_refresh_bucket(160)
|
, m_refresh_bucket(160)
|
||||||
|
, m_abort(false)
|
||||||
, m_host_resolver(sock.get_io_service())
|
, m_host_resolver(sock.get_io_service())
|
||||||
, m_refs(0)
|
, m_refs(0)
|
||||||
{
|
{
|
||||||
|
@ -212,6 +213,8 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
void dht_tracker::stop()
|
void dht_tracker::stop()
|
||||||
{
|
{
|
||||||
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
m_abort = true;
|
||||||
m_timer.cancel();
|
m_timer.cancel();
|
||||||
m_connection_timer.cancel();
|
m_connection_timer.cancel();
|
||||||
m_refresh_timer.cancel();
|
m_refresh_timer.cancel();
|
||||||
|
@ -228,7 +231,9 @@ namespace libtorrent { namespace dht
|
||||||
void dht_tracker::connection_timeout(asio::error_code const& e)
|
void dht_tracker::connection_timeout(asio::error_code const& e)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e) return;
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
if (e || m_abort) return;
|
||||||
|
|
||||||
time_duration d = m_dht.connection_timeout();
|
time_duration d = m_dht.connection_timeout();
|
||||||
m_connection_timer.expires_from_now(d);
|
m_connection_timer.expires_from_now(d);
|
||||||
m_connection_timer.async_wait(bind(&dht_tracker::connection_timeout, self(), _1));
|
m_connection_timer.async_wait(bind(&dht_tracker::connection_timeout, self(), _1));
|
||||||
|
@ -245,7 +250,9 @@ namespace libtorrent { namespace dht
|
||||||
void dht_tracker::refresh_timeout(asio::error_code const& e)
|
void dht_tracker::refresh_timeout(asio::error_code const& e)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e) return;
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
if (e || m_abort) return;
|
||||||
|
|
||||||
time_duration d = m_dht.refresh_timeout();
|
time_duration d = m_dht.refresh_timeout();
|
||||||
m_refresh_timer.expires_from_now(d);
|
m_refresh_timer.expires_from_now(d);
|
||||||
m_refresh_timer.async_wait(
|
m_refresh_timer.async_wait(
|
||||||
|
@ -259,7 +266,9 @@ namespace libtorrent { namespace dht
|
||||||
void dht_tracker::tick(asio::error_code const& e)
|
void dht_tracker::tick(asio::error_code const& e)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (e) return;
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
if (e || m_abort) return;
|
||||||
|
|
||||||
m_timer.expires_from_now(minutes(tick_period));
|
m_timer.expires_from_now(minutes(tick_period));
|
||||||
m_timer.async_wait(bind(&dht_tracker::tick, self(), _1));
|
m_timer.async_wait(bind(&dht_tracker::tick, self(), _1));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue