Fix the bug I introduced with the last few changes (deadlock in ConnectionPool).

This commit is contained in:
JoelKatz
2012-11-01 03:09:09 -07:00
parent fba18bf6f7
commit d9ff4f2ad4
4 changed files with 9 additions and 7 deletions

View File

@@ -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);

View File

@@ -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)

View File

@@ -5,6 +5,7 @@
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#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<boost::asio::ip::tcp::socket>::lowest_layer_type& getSocket()

View File

@@ -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,