fixed race condition when saving DHT state
This commit is contained in:
parent
2b4a49ea19
commit
9b5aa967b0
|
@ -47,6 +47,7 @@ release 0.14.2
|
||||||
* fixed bug in http_connection when binding to a particular IP
|
* fixed bug in http_connection when binding to a particular IP
|
||||||
* fixed typo in python binding (torrent_handle::piece_prioritize should
|
* fixed typo in python binding (torrent_handle::piece_prioritize should
|
||||||
be torrent_handle::piece_priorities)
|
be torrent_handle::piece_priorities)
|
||||||
|
* fixed race condition when saving DHT state
|
||||||
|
|
||||||
release 0.14.1
|
release 0.14.1
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <boost/thread/recursive_mutex.hpp>
|
#include <boost/thread/recursive_mutex.hpp>
|
||||||
|
#include <boost/thread/condition_variable.hpp>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
@ -176,6 +177,7 @@ namespace libtorrent
|
||||||
dht_settings const& get_dht_settings() const { return m_dht_settings; }
|
dht_settings const& get_dht_settings() const { return m_dht_settings; }
|
||||||
void start_dht(entry const& startup_state);
|
void start_dht(entry const& startup_state);
|
||||||
void stop_dht();
|
void stop_dht();
|
||||||
|
|
||||||
entry dht_state() const;
|
entry dht_state() const;
|
||||||
void maybe_update_udp_mapping(int nat, int local_port, int external_port);
|
void maybe_update_udp_mapping(int nat, int local_port, int external_port);
|
||||||
#endif
|
#endif
|
||||||
|
@ -327,6 +329,8 @@ namespace libtorrent
|
||||||
|
|
||||||
// private:
|
// private:
|
||||||
|
|
||||||
|
void session_impl::dht_state_callback(boost::condition_variable_any& c
|
||||||
|
, entry& e, bool& done) const;
|
||||||
void on_lsd_peer(tcp::endpoint peer, sha1_hash const& ih);
|
void on_lsd_peer(tcp::endpoint peer, sha1_hash const& ih);
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||||
|
@ -347,7 +351,7 @@ namespace libtorrent
|
||||||
// this is where all active sockets are stored.
|
// this is where all active sockets are stored.
|
||||||
// the selector can sleep while there's no activity on
|
// the selector can sleep while there's no activity on
|
||||||
// them
|
// them
|
||||||
io_service m_io_service;
|
mutable io_service m_io_service;
|
||||||
|
|
||||||
// handles disk io requests asynchronously
|
// handles disk io requests asynchronously
|
||||||
// peers have pointers into the disk buffer
|
// peers have pointers into the disk buffer
|
||||||
|
|
|
@ -2331,11 +2331,27 @@ namespace aux {
|
||||||
m_dht_settings.service_port = m_listen_interface.port();
|
m_dht_settings.service_port = m_listen_interface.port();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void session_impl::dht_state_callback(boost::condition_variable_any& c
|
||||||
|
, entry& e, bool& done) const
|
||||||
|
{
|
||||||
|
if (m_dht) e = m_dht->state();
|
||||||
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
|
done = true;
|
||||||
|
l.unlock();
|
||||||
|
c.notify_all();
|
||||||
|
}
|
||||||
|
|
||||||
entry session_impl::dht_state() const
|
entry session_impl::dht_state() const
|
||||||
{
|
{
|
||||||
|
boost::condition_variable_any cond;
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
if (!m_dht) return entry();
|
if (!m_dht) return entry();
|
||||||
return m_dht->state();
|
entry e;
|
||||||
|
bool done = false;
|
||||||
|
m_io_service.post(boost::bind(&session_impl::dht_state_callback
|
||||||
|
, this, boost::ref(cond), boost::ref(e), boost::ref(done)));
|
||||||
|
while (!done) cond.wait(l);
|
||||||
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_impl::add_dht_node(std::pair<std::string, int> const& node)
|
void session_impl::add_dht_node(std::pair<std::string, int> const& node)
|
||||||
|
|
Loading…
Reference in New Issue