From d9ff4f2ad4b6f227496cd0504f4faaa47ac948d0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 1 Nov 2012 03:09:09 -0700 Subject: [PATCH] Fix the bug I introduced with the last few changes (deadlock in ConnectionPool). --- src/ConnectionPool.cpp | 2 +- src/Peer.cpp | 4 ++-- src/Peer.h | 7 ++++--- src/PeerDoor.cpp | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ConnectionPool.cpp b/src/ConnectionPool.cpp index f95c0a9704..6b01a14393 100644 --- a/src/ConnectionPool.cpp +++ b/src/ConnectionPool.cpp @@ -313,7 +313,7 @@ Peer::pointer ConnectionPool::peerConnect(const std::string& strIp, int iPort) if ((it = mIpMap.find(pipPeer)) == mIpMap.end()) { - Peer::pointer ppNew(Peer::create(theApp->getIOService(), mCtx)); + Peer::pointer ppNew(Peer::create(theApp->getIOService(), mCtx, ++mLastPeer)); // Did not find it. Not already connecting or connected. ppNew->connect(strIp, iPort); diff --git a/src/Peer.cpp b/src/Peer.cpp index 15a7b0b4f6..83f8f62ad1 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -24,14 +24,14 @@ DECLARE_INSTANCE(Peer); // Node has this long to verify its identity from connection accepted or connection attempt. #define NODE_VERIFY_SECONDS 15 -Peer::Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx) : +Peer::Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 peerID) : mHelloed(false), mDetaching(false), + mPeerId(peerID), mSocketSsl(io_service, ctx), mVerifyTimer(io_service) { cLog(lsDEBUG) << "CREATING PEER: " << ADDRESS(this); - mPeerId = theApp->getConnectionPool().assignPeerId(); } void Peer::handle_write(const boost::system::error_code& error, size_t bytes_transferred) diff --git a/src/Peer.h b/src/Peer.h index 49857e3e6f..256319c831 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "../obj/src/ripple.pb.h" @@ -72,7 +73,7 @@ protected: ripple::TMStatusChange mLastStatus; ripple::TMHello mHello; - Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx); + Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 peerId); void handleShutdown(const boost::system::error_code& error) { ; } static void sHandleShutdown(Peer::ref ptr, const boost::system::error_code& error) @@ -132,9 +133,9 @@ public: void setIpPort(const std::string& strIP, int iPort); - static pointer create(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx) + static pointer create(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 id) { - return pointer(new Peer(io_service, ctx)); + return pointer(new Peer(io_service, ctx, id)); } boost::asio::ssl::stream::lowest_layer_type& getSocket() diff --git a/src/PeerDoor.cpp b/src/PeerDoor.cpp index 3544816729..a3740846b8 100644 --- a/src/PeerDoor.cpp +++ b/src/PeerDoor.cpp @@ -39,7 +39,8 @@ PeerDoor::PeerDoor(boost::asio::io_service& io_service) : void PeerDoor::startListening() { - Peer::pointer new_connection = Peer::create(mAcceptor.get_io_service(), mCtx); + Peer::pointer new_connection = Peer::create(mAcceptor.get_io_service(), mCtx, + theApp->getConnectionPool().assignPeerId()); mAcceptor.async_accept(new_connection->getSocket(), boost::bind(&PeerDoor::handleConnect, this, new_connection,