mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Cleanups and small improvements.
This commit is contained in:
@@ -452,7 +452,10 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
||||
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
||||
|
||||
if (!db->executeSQL(sql) || !db->startIterRows())
|
||||
return Ledger::pointer();
|
||||
{
|
||||
cLog(lsWARNING) << "No ledger for query: " << sql;
|
||||
return Ledger::pointer();
|
||||
}
|
||||
|
||||
db->getStr("LedgerHash", hash);
|
||||
ledgerHash.SetHex(hash);
|
||||
@@ -472,8 +475,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
||||
}
|
||||
|
||||
Log(lsTRACE) << "Constructing ledger " << ledgerSeq << " from SQL";
|
||||
Ledger::pointer ret = Ledger::pointer(new Ledger(prevHash, transHash, accountHash, totCoins,
|
||||
closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq));
|
||||
Ledger::pointer ret = boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins,
|
||||
closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq);
|
||||
if (ret->getHash() != ledgerHash)
|
||||
{
|
||||
if (sLog(lsERROR))
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
|
||||
#include "LedgerHistory.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "LedgerHistory.h"
|
||||
#include "Config.h"
|
||||
#include "Application.h"
|
||||
|
||||
@@ -13,13 +14,13 @@
|
||||
#endif
|
||||
|
||||
#ifndef CACHED_LEDGER_AGE
|
||||
#define CACHED_LEDGER_AGE 600
|
||||
#define CACHED_LEDGER_AGE 900
|
||||
#endif
|
||||
|
||||
// FIXME: Need to clean up ledgers by index, probably should switch to just mapping sequence to hash
|
||||
|
||||
LedgerHistory::LedgerHistory() : mLedgersByHash(CACHED_LEDGER_NUM, CACHED_LEDGER_AGE)
|
||||
{
|
||||
;
|
||||
}
|
||||
{ ; }
|
||||
|
||||
void LedgerHistory::addLedger(Ledger::pointer ledger)
|
||||
{
|
||||
|
||||
33
src/Peer.cpp
33
src/Peer.cpp
@@ -993,6 +993,9 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
ripple::TMLedgerData reply;
|
||||
bool fatLeaves = true, fatRoot = false;
|
||||
|
||||
if (packet.has_requestcookie())
|
||||
reply.set_requestcookie(packet.requestcookie());
|
||||
|
||||
if (packet.itype() == ripple::liTS_CANDIDATE)
|
||||
{ // Request is for a transaction candidate set
|
||||
cLog(lsINFO) << "Received request for TX candidate set data " << getIP();
|
||||
@@ -1034,7 +1037,10 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
tLog(!ledger, lsINFO) << "Don't have ledger " << ledgerhash;
|
||||
}
|
||||
else if (packet.has_ledgerseq())
|
||||
{
|
||||
ledger = theApp->getMasterLedger().getLedgerBySeq(packet.ledgerseq());
|
||||
tLog(!ledger, lsINFO) << "Don't have ledger " << packet.ledgerseq();
|
||||
}
|
||||
else if (packet.has_ltype() && (packet.ltype() == ripple::ltCURRENT))
|
||||
ledger = theApp->getMasterLedger().getCurrentLedger();
|
||||
else if (packet.has_ltype() && (packet.ltype() == ripple::ltCLOSED) )
|
||||
@@ -1053,10 +1059,13 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
if ((!ledger) || (packet.has_ledgerseq() && (packet.ledgerseq() != ledger->getLedgerSeq())))
|
||||
{
|
||||
punishPeer(PP_UNKNOWN_REQUEST);
|
||||
if (ledger)
|
||||
cLog(lsWARNING) << "Ledger has wrong sequence";
|
||||
else
|
||||
cLog(lsWARNING) << "Can't find the ledger they want";
|
||||
if (sLog(lsWARNING))
|
||||
{
|
||||
if (ledger)
|
||||
Log(lsWARNING) << "Ledger has wrong sequence";
|
||||
else
|
||||
Log(lsWARNING) << "Can't find the ledger they want";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1068,12 +1077,11 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
|
||||
if(packet.itype() == ripple::liBASE)
|
||||
{ // they want the ledger base data
|
||||
cLog(lsTRACE) << "Want ledger base data";
|
||||
cLog(lsTRACE) << "They want ledger base data";
|
||||
Serializer nData(128);
|
||||
ledger->addRaw(nData);
|
||||
reply.add_nodes()->set_nodedata(nData.getDataPtr(), nData.getLength());
|
||||
|
||||
cLog(lsINFO) << "Ledger root w/map roots request";
|
||||
SHAMap::pointer map = ledger->peekAccountStateMap();
|
||||
if (map && map->getHash().isNonZero())
|
||||
{ // return account state root node if possible
|
||||
@@ -1086,7 +1094,7 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
map = ledger->peekTransactionMap();
|
||||
if (map && map->getHash().isNonZero())
|
||||
{
|
||||
rootNode.resize(0);
|
||||
rootNode.erase();
|
||||
if (map->getRootNode(rootNode, snfWIRE))
|
||||
reply.add_nodes()->set_nodedata(rootNode.getDataPtr(), rootNode.getLength());
|
||||
}
|
||||
@@ -1099,9 +1107,10 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((packet.itype() == ripple::liTX_NODE) || (packet.itype() == ripple::liAS_NODE))
|
||||
map = (packet.itype() == ripple::liTX_NODE) ?
|
||||
ledger->peekTransactionMap() : ledger->peekAccountStateMap();
|
||||
if (packet.itype() == ripple::liTX_NODE)
|
||||
map = ledger->peekTransactionMap();
|
||||
else if (packet.itype() == ripple::liAS_NODE)
|
||||
map = ledger->peekAccountStateMap();
|
||||
}
|
||||
|
||||
if ((!map) || (packet.nodeids_size() == 0))
|
||||
@@ -1125,7 +1134,6 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
{
|
||||
std::vector<SHAMapNode>::iterator nodeIDIterator;
|
||||
std::list< std::vector<unsigned char> >::iterator rawNodeIterator;
|
||||
int count = 0;
|
||||
for(nodeIDIterator = nodeIDs.begin(), rawNodeIterator = rawNodes.begin();
|
||||
nodeIDIterator != nodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator)
|
||||
{
|
||||
@@ -1134,12 +1142,9 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
ripple::TMLedgerNode* node = reply.add_nodes();
|
||||
node->set_nodeid(nID.getDataPtr(), nID.getLength());
|
||||
node->set_nodedata(&rawNodeIterator->front(), rawNodeIterator->size());
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (packet.has_requestcookie())
|
||||
reply.set_requestcookie(packet.requestcookie());
|
||||
PackedMessage::pointer oPacket = boost::make_shared<PackedMessage>(reply, ripple::mtLEDGER_DATA);
|
||||
sendPacket(oPacket);
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ public:
|
||||
{ return getPrefixHash(prefix, reinterpret_cast<const unsigned char *>(strData.c_str()), strData.size()); }
|
||||
|
||||
// totality functions
|
||||
const std::vector<unsigned char>& peekData() const { return mData; }
|
||||
std::vector<unsigned char> getData() const { return mData; }
|
||||
int getCapacity() const { return mData.capacity(); }
|
||||
int getDataLength() const { return mData.size(); }
|
||||
const void* getDataPtr() const { return &mData.front(); }
|
||||
void* getDataPtr() { return &mData.front(); }
|
||||
int getLength() const { return mData.size(); }
|
||||
const std::vector<unsigned char>& peekData() const { return mData; }
|
||||
std::vector<unsigned char> getData() const { return mData; }
|
||||
std::string getString() const { return std::string(static_cast<const char *>(getDataPtr()), size()); }
|
||||
void secureErase() { memset(&(mData.front()), 0, mData.size()); erase(); }
|
||||
void erase() { mData.clear(); }
|
||||
std::string getString() const { return std::string(static_cast<const char *>(getDataPtr()), size()); }
|
||||
void secureErase() { memset(&(mData.front()), 0, mData.size()); erase(); }
|
||||
void erase() { mData.clear(); }
|
||||
int removeLastByte();
|
||||
bool chop(int num);
|
||||
|
||||
@@ -113,10 +113,10 @@ public:
|
||||
void resize(size_t n) { mData.resize(n); }
|
||||
size_t capacity() const { return mData.capacity(); }
|
||||
|
||||
bool operator==(const std::vector<unsigned char>& v) { return v == mData; }
|
||||
bool operator!=(const std::vector<unsigned char>& v) { return v != mData; }
|
||||
bool operator==(const Serializer& v) { return v.mData == mData; }
|
||||
bool operator!=(const Serializer& v) { return v.mData != mData; }
|
||||
bool operator==(const std::vector<unsigned char>& v) { return v == mData; }
|
||||
bool operator!=(const std::vector<unsigned char>& v) { return v != mData; }
|
||||
bool operator==(const Serializer& v) { return v.mData == mData; }
|
||||
bool operator!=(const Serializer& v) { return v.mData != mData; }
|
||||
|
||||
// signature functions
|
||||
bool checkSignature(int pubkeyOffset, int signatureOffset) const;
|
||||
@@ -147,12 +147,12 @@ public:
|
||||
// Reference is not const because we don't want to bind to a temporary
|
||||
SerializerIterator(Serializer& s) : mSerializer(s), mPos(0) { ; }
|
||||
|
||||
void reset(void) { mPos = 0; }
|
||||
void setPos(int p) { mPos = p; }
|
||||
const Serializer& operator*(void) { return mSerializer; }
|
||||
void reset(void) { mPos = 0; }
|
||||
void setPos(int p) { mPos = p; }
|
||||
|
||||
int getPos(void) { return mPos; }
|
||||
bool empty() { return mPos == mSerializer.getLength(); }
|
||||
int getPos(void) { return mPos; }
|
||||
bool empty() { return mPos == mSerializer.getLength(); }
|
||||
int getBytesLeft();
|
||||
|
||||
// get functions throw on error
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
// This class implemented a cache and a map. The cache keeps objects alive
|
||||
|
||||
Reference in New Issue
Block a user