mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 07:25:51 +00:00
Handle pongs. Ready timer for ping timing.
This commit is contained in:
@@ -27,9 +27,10 @@ DECLARE_INSTANCE(Peer);
|
|||||||
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) :
|
||||||
mHelloed(false),
|
mHelloed(false),
|
||||||
mDetaching(false),
|
mDetaching(false),
|
||||||
|
mActive(true),
|
||||||
mPeerId(peerID),
|
mPeerId(peerID),
|
||||||
mSocketSsl(io_service, ctx),
|
mSocketSsl(io_service, ctx),
|
||||||
mVerifyTimer(io_service)
|
mActivityTimer(io_service)
|
||||||
{
|
{
|
||||||
cLog(lsDEBUG) << "CREATING PEER: " << ADDRESS(this);
|
cLog(lsDEBUG) << "CREATING PEER: " << ADDRESS(this);
|
||||||
}
|
}
|
||||||
@@ -91,7 +92,7 @@ void Peer::detach(const char *rsn)
|
|||||||
|
|
||||||
mSendQ.clear();
|
mSendQ.clear();
|
||||||
|
|
||||||
(void) mVerifyTimer.cancel();
|
(void) mActivityTimer.cancel();
|
||||||
mSocketSsl.async_shutdown(boost::bind(&Peer::handleShutdown, shared_from_this(), boost::asio::placeholders::error));
|
mSocketSsl.async_shutdown(boost::bind(&Peer::handleShutdown, shared_from_this(), boost::asio::placeholders::error));
|
||||||
|
|
||||||
if (mNodePublic.isValid())
|
if (mNodePublic.isValid())
|
||||||
@@ -168,8 +169,8 @@ void Peer::connect(const std::string& strIp, int iPort)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mVerifyTimer.expires_from_now(boost::posix_time::seconds(NODE_VERIFY_SECONDS), err);
|
mActivityTimer.expires_from_now(boost::posix_time::seconds(NODE_VERIFY_SECONDS), err);
|
||||||
mVerifyTimer.async_wait(boost::bind(&Peer::handleVerifyTimer, shared_from_this(),
|
mActivityTimer.async_wait(boost::bind(&Peer::handleVerifyTimer, shared_from_this(),
|
||||||
boost::asio::placeholders::error));
|
boost::asio::placeholders::error));
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
@@ -611,8 +612,8 @@ void Peer::recvHello(ripple::TMHello& packet)
|
|||||||
{
|
{
|
||||||
bool bDetach = true;
|
bool bDetach = true;
|
||||||
|
|
||||||
// Cancel verification timeout.
|
// Cancel verification timeout. - FIXME Start ping/pong timer
|
||||||
(void) mVerifyTimer.cancel();
|
(void) mActivityTimer.cancel();
|
||||||
|
|
||||||
uint32 ourTime = theApp->getOPs().getNetworkTimeNC();
|
uint32 ourTime = theApp->getOPs().getNetworkTimeNC();
|
||||||
uint32 minTime = ourTime - 20;
|
uint32 minTime = ourTime - 20;
|
||||||
@@ -1157,11 +1158,15 @@ void Peer::recvGetObjectByHash(ripple::TMGetObjectByHash& packet)
|
|||||||
|
|
||||||
void Peer::recvPing(ripple::TMPing& packet)
|
void Peer::recvPing(ripple::TMPing& packet)
|
||||||
{
|
{
|
||||||
if (packet.type() == ripple::TMPing::PING)
|
if (packet.type() == ripple::TMPing::ptPING)
|
||||||
{
|
{
|
||||||
packet.set_type(ripple::TMPing::PONG);
|
packet.set_type(ripple::TMPing::ptPONG);
|
||||||
sendPacket(boost::make_shared<PackedMessage>(packet, ripple::mtPING));
|
sendPacket(boost::make_shared<PackedMessage>(packet, ripple::mtPING));
|
||||||
}
|
}
|
||||||
|
else if (packet.type() == ripple::TMPing::ptPONG)
|
||||||
|
{
|
||||||
|
mActive = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::recvErrorMessage(ripple::TMErrorMsg& packet)
|
void Peer::recvErrorMessage(ripple::TMErrorMsg& packet)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ private:
|
|||||||
bool mClientConnect; // In process of connecting as client.
|
bool mClientConnect; // In process of connecting as client.
|
||||||
bool mHelloed; // True, if hello accepted.
|
bool mHelloed; // True, if hello accepted.
|
||||||
bool mDetaching; // True, if detaching.
|
bool mDetaching; // True, if detaching.
|
||||||
|
bool mActive;
|
||||||
RippleAddress mNodePublic; // Node public key of peer.
|
RippleAddress mNodePublic; // Node public key of peer.
|
||||||
ipPort mIpPort;
|
ipPort mIpPort;
|
||||||
ipPort mIpPortConnect;
|
ipPort mIpPortConnect;
|
||||||
@@ -50,7 +51,7 @@ private:
|
|||||||
|
|
||||||
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> mSocketSsl;
|
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> mSocketSsl;
|
||||||
|
|
||||||
boost::asio::deadline_timer mVerifyTimer;
|
boost::asio::deadline_timer mActivityTimer;
|
||||||
|
|
||||||
void handleStart(const boost::system::error_code& ecResult);
|
void handleStart(const boost::system::error_code& ecResult);
|
||||||
void handleVerifyTimer(const boost::system::error_code& ecResult);
|
void handleVerifyTimer(const boost::system::error_code& ecResult);
|
||||||
|
|||||||
@@ -292,8 +292,8 @@ message TMLedgerData {
|
|||||||
|
|
||||||
message TMPing {
|
message TMPing {
|
||||||
enum pingType {
|
enum pingType {
|
||||||
PING = 0; // we want a reply
|
ptPING = 0; // we want a reply
|
||||||
PONG = 1; // this is a reply
|
ptPONG = 1; // this is a reply
|
||||||
}
|
}
|
||||||
required pingType type = 1;
|
required pingType type = 1;
|
||||||
optional uint32 seq = 2; // detect stale replies, ensure other side is reading
|
optional uint32 seq = 2; // detect stale replies, ensure other side is reading
|
||||||
|
|||||||
Reference in New Issue
Block a user