From e000d36b3c9187539bdb36ba18d0d8c0c218a399 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 7 Aug 2015 19:50:35 +0200 Subject: [PATCH 1/4] debug --- libp2p/NodeTable.cpp | 15 ++++++++++++--- libp2p/NodeTable.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 44ab0aa99..19c86cc0f 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -46,6 +46,7 @@ NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint m_socket(new NodeSocket(_io, *this, (bi::udp::endpoint)m_node.endpoint)), m_socketPointer(m_socket.get()), m_timers(_io) + ,m_debug_destroyed(false) { for (unsigned i = 0; i < s_bins; i++) m_state[i].distance = i; @@ -67,8 +68,12 @@ NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint NodeTable::~NodeTable() { - m_timers.stop(); - m_socketPointer->disconnect(); + DEV_GUARDED(x_debug) + { + m_debug_destroyed = true; + m_timers.stop(); + m_socketPointer->disconnect(); + } } void NodeTable::processEvents() @@ -200,7 +205,11 @@ void NodeTable::doDiscover(NodeId _node, unsigned _round, shared_ptr Date: Mon, 10 Aug 2015 20:37:56 +0200 Subject: [PATCH 2/4] bugfix: error code 995 --- libp2p/Common.h | 4 +++- libp2p/NodeTable.cpp | 24 ++++++++++++------------ libp2p/NodeTable.h | 3 --- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/libp2p/Common.h b/libp2p/Common.h index 1b65d4759..5d4b136ff 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -221,7 +221,7 @@ class DeadlineOps { public: DeadlineOp(ba::io_service& _io, unsigned _msInFuture, std::function const& _f): m_timer(new ba::deadline_timer(_io)) { m_timer->expires_from_now(boost::posix_time::milliseconds(_msInFuture)); m_timer->async_wait(_f); } - ~DeadlineOp() {} + ~DeadlineOp() { if (m_timer) m_timer->cancel(); } DeadlineOp(DeadlineOp&& _s): m_timer(_s.m_timer.release()) {} DeadlineOp& operator=(DeadlineOp&& _s) { m_timer.reset(_s.m_timer.release()); return *this; } @@ -241,6 +241,8 @@ public: void schedule(unsigned _msInFuture, std::function const& _f) { if (m_stopped) return; DEV_GUARDED(x_timers) m_timers.emplace_back(m_io, _msInFuture, _f); } void stop() { m_stopped = true; DEV_GUARDED(x_timers) m_timers.clear(); } + + bool isStopped() const { return m_stopped; } protected: void reap(); diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 19c86cc0f..94803f3f0 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -46,7 +46,6 @@ NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint m_socket(new NodeSocket(_io, *this, (bi::udp::endpoint)m_node.endpoint)), m_socketPointer(m_socket.get()), m_timers(_io) - ,m_debug_destroyed(false) { for (unsigned i = 0; i < s_bins; i++) m_state[i].distance = i; @@ -68,12 +67,8 @@ NodeTable::NodeTable(ba::io_service& _io, KeyPair const& _alias, NodeIPEndpoint NodeTable::~NodeTable() { - DEV_GUARDED(x_debug) - { - m_debug_destroyed = true; - m_timers.stop(); - m_socketPointer->disconnect(); - } + m_socketPointer->disconnect(); + m_timers.stop(); } void NodeTable::processEvents() @@ -204,12 +199,17 @@ void NodeTable::doDiscover(NodeId _node, unsigned _round, shared_ptr Date: Tue, 11 Aug 2015 13:08:46 +0200 Subject: [PATCH 3/4] style update --- libp2p/NodeTable.cpp | 9 +++++---- libp2p/NodeTable.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 94803f3f0..c550a2343 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -201,12 +201,13 @@ void NodeTable::doDiscover(NodeId _node, unsigned _round, shared_ptr m_socket; ///< Shared pointer for our UDPSocket; ASIO requires shared_ptr. NodeSocket* m_socketPointer; ///< Set to m_socket.get(). Socket is created in constructor and disconnected in destructor to ensure access to pointer is safe. - DeadlineOps m_timers; + DeadlineOps m_timers; ///< this should be the last member - it must be destroyed first }; inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable) From dd14158a089ce06f912f2fbce217f600b8ba283a Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Tue, 11 Aug 2015 17:28:42 +0200 Subject: [PATCH 4/4] verbosity changed --- libp2p/NodeTable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index c550a2343..f20d7436f 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -199,7 +199,7 @@ void NodeTable::doDiscover(NodeId _node, unsigned _round, shared_ptr