mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Correctly track direction and privilege of peer connections, pass to load tracking.
This commit is contained in:
@@ -312,8 +312,8 @@ Peer::pointer ConnectionPool::peerConnect(const std::string& strIp, int iPort)
|
||||
|
||||
if ((it = mIpMap.find(pipPeer)) == mIpMap.end())
|
||||
{
|
||||
Peer::pointer ppNew(Peer::create(theApp->getIOService(),
|
||||
theApp->getPeerDoor().getSSLContext(), ++mLastPeer));
|
||||
Peer::pointer ppNew(Peer::create(theApp->getIOService(), theApp->getPeerDoor().getSSLContext(),
|
||||
++mLastPeer, false));
|
||||
|
||||
// Did not find it. Not already connecting or connected.
|
||||
ppNew->connect(strIp, iPort);
|
||||
|
||||
@@ -24,10 +24,12 @@ 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, uint64 peerID) :
|
||||
Peer::Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 peerID, bool inbound) :
|
||||
mInbound(inbound),
|
||||
mHelloed(false),
|
||||
mDetaching(false),
|
||||
mActive(true),
|
||||
mCluster(false),
|
||||
mPeerId(peerID),
|
||||
mSocketSsl(io_service, ctx),
|
||||
mActivityTimer(io_service)
|
||||
@@ -684,6 +686,13 @@ void Peer::recvHello(ripple::TMHello& packet)
|
||||
<< "Peer speaks version " <<
|
||||
(packet.protoversion() >> 16) << "." << (packet.protoversion() & 0xFF);
|
||||
mHello = packet;
|
||||
if (theApp->getUNL().nodeInCluster(mNodePublic))
|
||||
{
|
||||
mCluster = true;
|
||||
mLoad.setPrivileged();
|
||||
}
|
||||
if (isOutbound())
|
||||
mLoad.setOutbound();
|
||||
|
||||
if (mClientConnect)
|
||||
{
|
||||
|
||||
@@ -33,10 +33,12 @@ public:
|
||||
void handleConnect(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator it);
|
||||
|
||||
private:
|
||||
bool mInbound; // Connection is inbound
|
||||
bool mClientConnect; // In process of connecting as client.
|
||||
bool mHelloed; // True, if hello accepted.
|
||||
bool mDetaching; // True, if detaching.
|
||||
bool mActive;
|
||||
bool mCluster; // Node in our cluster
|
||||
RippleAddress mNodePublic; // Node public key of peer.
|
||||
ipPort mIpPort;
|
||||
ipPort mIpPortConnect;
|
||||
@@ -65,7 +67,7 @@ protected:
|
||||
ripple::TMStatusChange mLastStatus;
|
||||
ripple::TMHello mHello;
|
||||
|
||||
Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 peerId);
|
||||
Peer(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 peerId, bool inbound);
|
||||
|
||||
void handleShutdown(const boost::system::error_code& error) { ; }
|
||||
void handleWrite(const boost::system::error_code& error, size_t bytes_transferred);
|
||||
@@ -117,9 +119,9 @@ public:
|
||||
|
||||
void setIpPort(const std::string& strIP, int iPort);
|
||||
|
||||
static pointer create(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 id)
|
||||
static pointer create(boost::asio::io_service& io_service, boost::asio::ssl::context& ctx, uint64 id, bool inbound)
|
||||
{
|
||||
return pointer(new Peer(io_service, ctx, id));
|
||||
return pointer(new Peer(io_service, ctx, id, inbound));
|
||||
}
|
||||
|
||||
boost::asio::ssl::stream<boost::asio::ip::tcp::socket>::lowest_layer_type& getSocket()
|
||||
@@ -144,6 +146,8 @@ public:
|
||||
|
||||
Json::Value getJson();
|
||||
bool isConnected() const { return mHelloed && !mDetaching; }
|
||||
bool isInbound() const { return mInbound; }
|
||||
bool isOutbound() const { return !mInbound; }
|
||||
|
||||
uint256 getClosedLedgerHash() const { return mClosedLedgerHash; }
|
||||
bool hasLedger(const uint256& hash) const;
|
||||
|
||||
@@ -43,7 +43,7 @@ PeerDoor::PeerDoor(boost::asio::io_service& io_service) :
|
||||
void PeerDoor::startListening()
|
||||
{
|
||||
Peer::pointer new_connection = Peer::create(mAcceptor.get_io_service(), mCtx,
|
||||
theApp->getConnectionPool().assignPeerId());
|
||||
theApp->getConnectionPool().assignPeerId(), true);
|
||||
|
||||
mAcceptor.async_accept(new_connection->getSocket(),
|
||||
boost::bind(&PeerDoor::handleConnect, this, new_connection,
|
||||
|
||||
Reference in New Issue
Block a user