From ede296475ba17ac70a2990cd5f225108f6ab1bfc Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 2 May 2012 02:57:41 -0700 Subject: [PATCH] Track a peer's last closed ledger. --- src/Peer.cpp | 13 +++++++++---- src/Peer.h | 16 ++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Peer.cpp b/src/Peer.cpp index dbf3f0ba0..e257679af 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -523,6 +523,12 @@ void Peer::recvHello(newcoin::TMHello& packet) // XXX Set timer: connection is in grace period to be useful. // XXX Set timer: connection idle (idle may vary depending on connection type.) + if ((packet.has_closedledger()) && (packet.closedledger().size() == (256 / 8))) + { + memcpy(mClosedLedgerHash.begin(), packet.closedledger().data(), (256 / 8)); + mClosedLedgerTime = boost::posix_time::second_clock::universal_time(); + } + bDetach = false; } @@ -775,11 +781,10 @@ void Peer::sendHello() Ledger::pointer closedLedger = theApp->getMasterLedger().getClosedLedger(); assert(closedLedger && closedLedger->isClosed()); - if(closedLedger->isClosed()) + if (closedLedger->isClosed()) { - Serializer s(128); - closedLedger->addRaw(s); - h->set_closedledger(s.getDataPtr(), s.getLength()); + uint256 hash = closedLedger->getHash(); + h->set_closedledger(hash.begin(), hash.GetSerializeSize()); } PackedMessage::pointer packet = boost::make_shared diff --git a/src/Peer.h b/src/Peer.h index 87a517c55..5bf424061 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -15,9 +15,9 @@ enum PeerPunish { - PP_INVALID_REQUEST=1, // The peer sent a request that makes no sense - PP_UNKNOWN_REQUEST=2, // The peer sent a request that might be garbage - PP_UNWANTED_DATA=3, // The peer sent us data we didn't want/need + PP_INVALID_REQUEST = 1, // The peer sent a request that makes no sense + PP_UNKNOWN_REQUEST = 2, // The peer sent a request that might be garbage + PP_UNWANTED_DATA = 3, // The peer sent us data we didn't want/need }; typedef std::pair ipPort; @@ -25,8 +25,8 @@ typedef std::pair ipPort; class Peer : public boost::enable_shared_from_this { public: - static const int psbGotHello=0, psbSentHello=1, psbInMap=2, psbTrusted=3; - static const int psbNoLedgers=4, psbNoTransactions=5, psbDownLevel=6; + static const int psbGotHello = 0, psbSentHello = 1, psbInMap = 2, psbTrusted = 3; + static const int psbNoLedgers = 4, psbNoTransactions = 5, psbDownLevel = 6; void handleConnect(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator it); @@ -36,7 +36,11 @@ private: ipPort mIpPort; uint256 mCookieHash; - boost::asio::ssl::stream mSocketSsl; + // network state information + uint256 mClosedLedgerHash; + boost::posix_time::ptime mClosedLedgerTime; + + boost::asio::ssl::stream mSocketSsl; boost::asio::deadline_timer mVerifyTimer;