Track a peer's last closed ledger.

This commit is contained in:
JoelKatz
2012-05-02 02:57:41 -07:00
parent 28952f9f98
commit ede296475b
2 changed files with 19 additions and 10 deletions

View File

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

View File

@@ -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<std::string,int> ipPort;
@@ -25,8 +25,8 @@ typedef std::pair<std::string,int> ipPort;
class Peer : public boost::enable_shared_from_this<Peer>
{
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<boost::asio::ip::tcp::socket> mSocketSsl;
// network state information
uint256 mClosedLedgerHash;
boost::posix_time::ptime mClosedLedgerTime;
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> mSocketSsl;
boost::asio::deadline_timer mVerifyTimer;