mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-30 02:20:10 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin into new_pathfinding
This commit is contained in:
@@ -1187,7 +1187,7 @@ STAmount STAmount::getPay(const STAmount& offerOut, const STAmount& offerIn, con
|
||||
|
||||
STAmount STAmount::deserialize(SerializerIterator& it)
|
||||
{
|
||||
std::auto_ptr<STAmount> s(dynamic_cast<STAmount*>(construct(it, sfGeneric)));
|
||||
UPTR_T<STAmount> s(dynamic_cast<STAmount*>(construct(it, sfGeneric)));
|
||||
STAmount ret(*s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,8 @@ public:
|
||||
else
|
||||
{ // autodetect
|
||||
mSocket->next_layer().async_receive(basio::buffer(mBuffer), basio::socket_base::message_peek,
|
||||
boost::bind(&AutoSocket::handle_autodetect, this, cbFunc, basio::placeholders::error));
|
||||
boost::bind(&AutoSocket::handle_autodetect, this, cbFunc,
|
||||
basio::placeholders::error, basio::placeholders::bytes_transferred));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +206,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void handle_autodetect(callback cbFunc, const error_code& ec)
|
||||
void handle_autodetect(callback cbFunc, const error_code& ec, size_t bytesTransferred)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
@@ -213,15 +214,17 @@ protected:
|
||||
cbFunc(ec);
|
||||
}
|
||||
else if ((mBuffer[0] < 127) && (mBuffer[0] > 31) &&
|
||||
(mBuffer[1] < 127) && (mBuffer[1] > 31) &&
|
||||
(mBuffer[2] < 127) && (mBuffer[2] > 31) &&
|
||||
(mBuffer[3] < 127) && (mBuffer[3] > 31))
|
||||
((bytesTransferred < 2) || ((mBuffer[1] < 127) && (mBuffer[1] > 31))) &&
|
||||
((bytesTransferred < 3) || ((mBuffer[2] < 127) && (mBuffer[2] > 31))) &&
|
||||
((bytesTransferred < 4) || ((mBuffer[3] < 127) && (mBuffer[3] > 31))))
|
||||
{ // not ssl
|
||||
Log(lsTRACE, AutoSocketPartition) << "non-SSL";
|
||||
mSecure = false;
|
||||
cbFunc(ec);
|
||||
}
|
||||
else
|
||||
{ // ssl
|
||||
Log(lsTRACE, AutoSocketPartition) << "SSL";
|
||||
mSecure = true;
|
||||
mSocket->async_handshake(ssl_socket::server, cbFunc);
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ void Config::load()
|
||||
Json::Value jvCommand;
|
||||
|
||||
if (!jrReader.parse(strJson, jvCommand))
|
||||
throw std::runtime_error(boost::str(boost::format("Couldn't parse ["SECTION_RPC_STARTUP"] command: %s") % strJson));
|
||||
throw std::runtime_error(boost::str(boost::format("Couldn't parse [" SECTION_RPC_STARTUP "] command: %s") % strJson));
|
||||
|
||||
jvArray.append(jvCommand);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
|
||||
{
|
||||
mWritePending = true;
|
||||
theApp->getJobQueue().addJob(jtWRITE, "HashedObject::store",
|
||||
boost::bind(&HashedObjectStore::bulkWrite, this));
|
||||
BIND_TYPE(&HashedObjectStore::bulkWrite, this));
|
||||
}
|
||||
}
|
||||
// else
|
||||
@@ -261,7 +261,7 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
|
||||
int HashedObjectStore::import(const std::string& file)
|
||||
{
|
||||
cLog(lsWARNING) << "Hash import from \"" << file << "\".";
|
||||
std::auto_ptr<Database> importDB(new SqliteDatabase(file.c_str()));
|
||||
UPTR_T<Database> importDB(new SqliteDatabase(file.c_str()));
|
||||
importDB->connect();
|
||||
|
||||
int countYes = 0, countNo = 0;
|
||||
|
||||
@@ -39,6 +39,7 @@ const char* Job::toString(JobType t)
|
||||
case jtVALIDATION_ut: return "untrustedValidation";
|
||||
case jtPROOFWORK: return "proofOfWork";
|
||||
case jtPROPOSAL_ut: return "untrustedProposal";
|
||||
case jtLEDGER_DATA: return "ledgerData";
|
||||
case jtCLIENT: return "clientCommand";
|
||||
case jtTRANSACTION: return "transaction";
|
||||
case jtPUBLEDGER: return "publishNewLedger";
|
||||
@@ -96,7 +97,7 @@ bool Job::operator<=(const Job& j) const
|
||||
return mJobIndex <= j.mJobIndex;
|
||||
}
|
||||
|
||||
void JobQueue::addJob(JobType type, const std::string& name, const boost::function<void(Job&)>& jobFunc)
|
||||
void JobQueue::addJob(JobType type, const std::string& name, const FUNCTION_TYPE<void(Job&)>& jobFunc)
|
||||
{
|
||||
assert(type != jtINVALID);
|
||||
|
||||
@@ -245,7 +246,7 @@ void JobQueue::setThreadCount(int c)
|
||||
while (mThreadCount < c)
|
||||
{
|
||||
++mThreadCount;
|
||||
boost::thread(boost::bind(&JobQueue::threadEntry, this)).detach();
|
||||
boost::thread(BIND_TYPE(&JobQueue::threadEntry, this)).detach();
|
||||
}
|
||||
while (mThreadCount > c)
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
#include "../json/value.h"
|
||||
|
||||
@@ -25,16 +25,17 @@ enum JobType
|
||||
jtVALIDATION_ut = 2, // A validation from an untrusted source
|
||||
jtPROOFWORK = 3, // A proof of work demand from another server
|
||||
jtPROPOSAL_ut = 4, // A proposal from an untrusted source
|
||||
jtCLIENT = 5, // A websocket command from the client
|
||||
jtTRANSACTION = 6, // A transaction received from the network
|
||||
jtPUBLEDGER = 7, // Publish a fully-accepted ledger
|
||||
jtWAL = 8, // Write-ahead logging
|
||||
jtVALIDATION_t = 9, // A validation from a trusted source
|
||||
jtWRITE = 10, // Write out hashed objects
|
||||
jtTRANSACTION_l = 11, // A local transaction
|
||||
jtPROPOSAL_t = 12, // A proposal from a trusted source
|
||||
jtADMIN = 13, // An administrative operation
|
||||
jtDEATH = 14, // job of death, used internally
|
||||
jtLEDGER_DATA = 5, // Received data for a ledger we're acquiring
|
||||
jtCLIENT = 6, // A websocket command from the client
|
||||
jtTRANSACTION = 7, // A transaction received from the network
|
||||
jtPUBLEDGER = 8, // Publish a fully-accepted ledger
|
||||
jtWAL = 9, // Write-ahead logging
|
||||
jtVALIDATION_t = 10, // A validation from a trusted source
|
||||
jtWRITE = 11, // Write out hashed objects
|
||||
jtTRANSACTION_l = 12, // A local transaction
|
||||
jtPROPOSAL_t = 13, // A proposal from a trusted source
|
||||
jtADMIN = 14, // An administrative operation
|
||||
jtDEATH = 15, // job of death, used internally
|
||||
|
||||
// special types not dispatched by the job pool
|
||||
jtPEER = 24,
|
||||
@@ -51,7 +52,7 @@ class Job
|
||||
protected:
|
||||
JobType mType;
|
||||
uint64 mJobIndex;
|
||||
boost::function<void(Job&)> mJob;
|
||||
FUNCTION_TYPE<void(Job&)> mJob;
|
||||
LoadEvent::pointer mLoadMonitor;
|
||||
std::string mName;
|
||||
|
||||
@@ -62,7 +63,7 @@ public:
|
||||
Job(JobType type, uint64 index) : mType(type), mJobIndex(index)
|
||||
{ ; }
|
||||
|
||||
Job(JobType type, const std::string& name, uint64 index, LoadMonitor& lm, const boost::function<void(Job&)>& job)
|
||||
Job(JobType type, const std::string& name, uint64 index, LoadMonitor& lm, const FUNCTION_TYPE<void(Job&)>& job)
|
||||
: mType(type), mJobIndex(index), mJob(job), mName(name)
|
||||
{
|
||||
mLoadMonitor = boost::make_shared<LoadEvent>(boost::ref(lm), name, false);
|
||||
@@ -101,7 +102,7 @@ public:
|
||||
|
||||
JobQueue();
|
||||
|
||||
void addJob(JobType type, const std::string& name, const boost::function<void(Job&)>& job);
|
||||
void addJob(JobType type, const std::string& name, const FUNCTION_TYPE<void(Job&)>& job);
|
||||
|
||||
int getJobCount(JobType t); // Jobs waiting at this priority
|
||||
int getJobCountTotal(JobType t); // Jobs waiting plus running at this priority
|
||||
|
||||
@@ -455,9 +455,9 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
|
||||
const std::vector<RippleAddress>& accts = vt.second.getAffected();
|
||||
if (!accts.empty())
|
||||
{
|
||||
std::string sql = "INSERT OR REPLACE INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES ";
|
||||
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES ";
|
||||
bool first = true;
|
||||
for (std::vector<RippleAddress>::const_iterator it = accts.begin(), end = accts.end(); it != end; ++it)
|
||||
for (std::vector<RippleAddress>::const_iterator it = accts.begin(), end = accts.end(); it != end; ++it)
|
||||
{
|
||||
if (!first)
|
||||
sql += ", ('";
|
||||
@@ -474,28 +474,14 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
|
||||
sql += ")";
|
||||
}
|
||||
sql += ";";
|
||||
Log(lsTRACE) << "ActTx: " << sql;
|
||||
db->executeSQL(sql); // may already be in there
|
||||
cLog(lsTRACE) << "ActTx: " << sql;
|
||||
db->executeSQL(sql);
|
||||
}
|
||||
else
|
||||
cLog(lsWARNING) << "Transaction in ledger " << mLedgerSeq << " affects no accounts";
|
||||
|
||||
if (SQL_EXISTS(db, boost::str(transExists % txID.GetHex())))
|
||||
{
|
||||
// In Transactions, update LedgerSeq, metadata and Status.
|
||||
db->executeSQL(boost::str(updateTx
|
||||
% getLedgerSeq()
|
||||
% TXN_SQL_VALIDATED
|
||||
% vt.second.getEscMeta()
|
||||
% txID.GetHex()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not in Transactions, insert the whole thing..
|
||||
db->executeSQL(
|
||||
SerializedTransaction::getMetaSQLInsertHeader() +
|
||||
vt.second.getTxn()->getMetaSQL(getLedgerSeq(), vt.second.getEscMeta()) + ";");
|
||||
}
|
||||
db->executeSQL(SerializedTransaction::getMetaSQLInsertReplaceHeader() +
|
||||
vt.second.getTxn()->getMetaSQL(getLedgerSeq(), vt.second.getEscMeta()) + ";");
|
||||
}
|
||||
db->executeSQL("COMMIT TRANSACTION;");
|
||||
}
|
||||
@@ -505,12 +491,13 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
|
||||
theApp->getLedgerDB()->getDB()->executeSQL(boost::str(addLedger %
|
||||
getHash().GetHex() % mLedgerSeq % mParentHash.GetHex() %
|
||||
boost::lexical_cast<std::string>(mTotCoins) % mCloseTime % mParentCloseTime %
|
||||
mCloseResolution % mCloseFlags %
|
||||
mAccountHash.GetHex() % mTransHash.GetHex()));
|
||||
mCloseResolution % mCloseFlags % mAccountHash.GetHex() % mTransHash.GetHex()));
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!fromConsensus)
|
||||
dropCache();
|
||||
#endif
|
||||
|
||||
if (theApp->getJobQueue().getJobCountTotal(jtPUBOLDLEDGER) < 2)
|
||||
theApp->getLedgerMaster().resumeAcquiring();
|
||||
@@ -1553,7 +1540,7 @@ void Ledger::pendSave(bool fromConsensus)
|
||||
|
||||
theApp->getJobQueue().addJob(fromConsensus ? jtPUBLEDGER : jtPUBOLDLEDGER,
|
||||
fromConsensus ? "Ledger::pendSave" : "Ledger::pendOldSave",
|
||||
boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(), _1, fromConsensus));
|
||||
BIND_TYPE(&Ledger::saveAcceptedLedger, shared_from_this(), P_1, fromConsensus));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Log.h"
|
||||
@@ -48,6 +47,7 @@ void PeerSet::setTimer()
|
||||
|
||||
void PeerSet::invokeOnTimer()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (isDone())
|
||||
return;
|
||||
|
||||
@@ -71,10 +71,14 @@ void PeerSet::TimerEntry(boost::weak_ptr<PeerSet> wptr, const boost::system::err
|
||||
{
|
||||
if (result == boost::asio::error::operation_aborted)
|
||||
return;
|
||||
|
||||
ScopedLock sl(theApp->getMasterLock());
|
||||
boost::shared_ptr<PeerSet> ptr = wptr.lock();
|
||||
if (ptr)
|
||||
theApp->getJobQueue().addJob(jtLEDGER_DATA, "timerEntry",
|
||||
BIND_TYPE(&PeerSet::TimerJobEntry, P_1, ptr));
|
||||
}
|
||||
|
||||
void PeerSet::TimerJobEntry(Job&, boost::shared_ptr<PeerSet> ptr)
|
||||
{
|
||||
ptr->invokeOnTimer();
|
||||
}
|
||||
|
||||
@@ -249,7 +253,7 @@ void LedgerAcquire::done()
|
||||
|
||||
assert(isComplete() || isFailed());
|
||||
|
||||
std::vector< boost::function<void (LedgerAcquire::pointer)> > triggers;
|
||||
std::vector< FUNCTION_TYPE<void (LedgerAcquire::pointer)> > triggers;
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
triggers.swap(mOnComplete);
|
||||
@@ -270,7 +274,7 @@ void LedgerAcquire::done()
|
||||
triggers[i](shared_from_this());
|
||||
}
|
||||
|
||||
bool LedgerAcquire::addOnComplete(boost::function<void (LedgerAcquire::pointer)> trigger)
|
||||
bool LedgerAcquire::addOnComplete(FUNCTION_TYPE<void (LedgerAcquire::pointer)> trigger)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (isDone())
|
||||
@@ -281,6 +285,7 @@ bool LedgerAcquire::addOnComplete(boost::function<void (LedgerAcquire::pointer)>
|
||||
|
||||
void LedgerAcquire::trigger(Peer::ref peer)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (mAborted || mComplete || mFailed)
|
||||
{
|
||||
cLog(lsTRACE) << "Trigger on ledger:" <<
|
||||
@@ -476,6 +481,7 @@ void LedgerAcquire::trigger(Peer::ref peer)
|
||||
{
|
||||
cLog(lsDEBUG) << "Done:" << (mComplete ? " complete" : "") << (mFailed ? " failed " : " ")
|
||||
<< mLedger->getLedgerSeq();
|
||||
sl.unlock();
|
||||
done();
|
||||
}
|
||||
}
|
||||
@@ -585,7 +591,8 @@ bool LedgerAcquire::takeBase(const std::string& data) // data must not have hash
|
||||
cLog(lsTRACE) << "got base acquiring ledger " << mHash;
|
||||
#endif
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (mHaveBase) return true;
|
||||
if (mHaveBase)
|
||||
return true;
|
||||
mLedger = boost::make_shared<Ledger>(data, false);
|
||||
if (mLedger->getHash() != mHash)
|
||||
{
|
||||
@@ -616,8 +623,11 @@ bool LedgerAcquire::takeBase(const std::string& data) // data must not have hash
|
||||
bool LedgerAcquire::takeTxNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
const std::list< std::vector<unsigned char> >& data, SMAddNode& san)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (!mHaveBase)
|
||||
return false;
|
||||
if (mHaveTransactions)
|
||||
return true;
|
||||
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin();
|
||||
std::list< std::vector<unsigned char> >::const_iterator nodeDatait = data.begin();
|
||||
@@ -657,11 +667,14 @@ bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
cLog(lsTRACE) << "got ASdata (" << nodeIDs.size() <<") acquiring ledger " << mHash;
|
||||
tLog(nodeIDs.size() == 1, lsTRACE) << "got AS node: " << nodeIDs.front();
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (!mHaveBase)
|
||||
{
|
||||
cLog(lsWARNING) << "Don't have ledger base";
|
||||
return false;
|
||||
}
|
||||
if (mHaveState)
|
||||
return true;
|
||||
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin();
|
||||
std::list< std::vector<unsigned char> >::const_iterator nodeDatait = data.begin();
|
||||
@@ -700,6 +713,7 @@ bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
|
||||
bool LedgerAcquire::takeAsRootNode(const std::vector<unsigned char>& data, SMAddNode& san)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (!mHaveBase)
|
||||
return false;
|
||||
AccountStateSF tFilter(mLedger->getLedgerSeq());
|
||||
@@ -709,6 +723,7 @@ bool LedgerAcquire::takeAsRootNode(const std::vector<unsigned char>& data, SMAdd
|
||||
|
||||
bool LedgerAcquire::takeTxRootNode(const std::vector<unsigned char>& data, SMAddNode& san)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
if (!mHaveBase)
|
||||
return false;
|
||||
TransactionStateSF tFilter(mLedger->getLedgerSeq());
|
||||
@@ -820,13 +835,19 @@ void LedgerAcquireMaster::dropLedger(const uint256& hash)
|
||||
mLedgers.erase(hash);
|
||||
}
|
||||
|
||||
SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer::ref peer)
|
||||
void LedgerAcquireMaster::gotLedgerData(Job&, boost::shared_ptr<ripple::TMLedgerData> packet_ptr,
|
||||
boost::weak_ptr<Peer> wPeer)
|
||||
{
|
||||
ripple::TMLedgerData& packet = *packet_ptr;
|
||||
Peer::pointer peer = wPeer.lock();
|
||||
if (!peer)
|
||||
return;
|
||||
|
||||
uint256 hash;
|
||||
if (packet.ledgerhash().size() != 32)
|
||||
{
|
||||
std::cerr << "Acquire error" << std::endl;
|
||||
return SMAddNode::invalid();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
return;
|
||||
}
|
||||
memcpy(hash.begin(), packet.ledgerhash().data(), 32);
|
||||
cLog(lsTRACE) << "Got data (" << packet.nodes().size() << ") for acquiring ledger: " << hash;
|
||||
@@ -835,7 +856,8 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
||||
if (!ledger)
|
||||
{
|
||||
cLog(lsINFO) << "Got data for ledger we're not acquiring";
|
||||
return SMAddNode();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.type() == ripple::liBASE)
|
||||
@@ -843,12 +865,14 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
||||
if (packet.nodes_size() < 1)
|
||||
{
|
||||
cLog(lsWARNING) << "Got empty base data";
|
||||
return SMAddNode::invalid();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
return;
|
||||
}
|
||||
if (!ledger->takeBase(packet.nodes(0).nodedata()))
|
||||
{
|
||||
cLog(lsWARNING) << "Got invalid base data";
|
||||
return SMAddNode::invalid();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
return;
|
||||
}
|
||||
SMAddNode san = SMAddNode::useful();
|
||||
if ((packet.nodes().size() > 1) && !ledger->takeAsRootNode(strCopy(packet.nodes(1).nodedata()), san))
|
||||
@@ -861,7 +885,7 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
||||
}
|
||||
if (!san.isInvalid())
|
||||
ledger->trigger(peer);
|
||||
return san;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((packet.type() == ripple::liTX_NODE) || (packet.type() == ripple::liAS_NODE))
|
||||
@@ -872,7 +896,8 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
||||
if (packet.nodes().size() <= 0)
|
||||
{
|
||||
cLog(lsINFO) << "Got response with no nodes";
|
||||
return SMAddNode::invalid();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < packet.nodes().size(); ++i)
|
||||
{
|
||||
@@ -880,7 +905,8 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
||||
if (!node.has_nodeid() || !node.has_nodedata())
|
||||
{
|
||||
cLog(lsWARNING) << "Got bad node";
|
||||
return SMAddNode::invalid();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
nodeIDs.push_back(SHAMapNode(node.nodeid().data(), node.nodeid().size()));
|
||||
@@ -892,12 +918,12 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
||||
else
|
||||
ledger->takeAsNode(nodeIDs, nodeData, ret);
|
||||
if (!ret.isInvalid())
|
||||
ledger->trigger(peer);
|
||||
return ret;
|
||||
ledger->trigger(peer);
|
||||
return;
|
||||
}
|
||||
|
||||
cLog(lsWARNING) << "Not sure what ledger data we got";
|
||||
return SMAddNode::invalid();
|
||||
peer->punishPeer(LT_InvalidRequest);
|
||||
}
|
||||
|
||||
void LedgerAcquireMaster::sweep()
|
||||
|
||||
@@ -75,6 +75,7 @@ protected:
|
||||
|
||||
private:
|
||||
static void TimerEntry(boost::weak_ptr<PeerSet>, const boost::system::error_code& result);
|
||||
static void TimerJobEntry(Job&, boost::shared_ptr<PeerSet>);
|
||||
};
|
||||
|
||||
class LedgerAcquire :
|
||||
@@ -90,7 +91,7 @@ protected:
|
||||
std::set<SHAMapNode> mRecentTXNodes;
|
||||
std::set<SHAMapNode> mRecentASNodes;
|
||||
|
||||
std::vector< boost::function<void (LedgerAcquire::pointer)> > mOnComplete;
|
||||
std::vector< FUNCTION_TYPE<void (LedgerAcquire::pointer)> > mOnComplete;
|
||||
|
||||
void done();
|
||||
void onTimer(bool progress);
|
||||
@@ -111,7 +112,7 @@ public:
|
||||
void abort() { mAborted = true; }
|
||||
bool setAccept() { if (mAccept) return false; mAccept = true; return true; }
|
||||
|
||||
bool addOnComplete(boost::function<void (LedgerAcquire::pointer)>);
|
||||
bool addOnComplete(FUNCTION_TYPE<void (LedgerAcquire::pointer)>);
|
||||
|
||||
bool takeBase(const std::string& data);
|
||||
bool takeTxNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data,
|
||||
@@ -147,7 +148,7 @@ public:
|
||||
LedgerAcquire::pointer find(const uint256& hash);
|
||||
bool hasLedger(const uint256& ledgerHash);
|
||||
void dropLedger(const uint256& ledgerHash);
|
||||
SMAddNode gotLedgerData(ripple::TMLedgerData& packet, Peer::ref);
|
||||
void gotLedgerData(Job&, boost::shared_ptr<ripple::TMLedgerData> packet, boost::weak_ptr<Peer> peer);
|
||||
|
||||
int getFetchCount(int& timeoutCount);
|
||||
void logFailure(const uint256& h) { mRecentFailures.add(h); }
|
||||
|
||||
@@ -529,7 +529,7 @@ TER LedgerEntrySet::dirAdd(
|
||||
uint64& uNodeDir,
|
||||
const uint256& uRootIndex,
|
||||
const uint256& uLedgerIndex,
|
||||
boost::function<void (SLE::ref)> fDescriber)
|
||||
FUNCTION_TYPE<void (SLE::ref)> fDescriber)
|
||||
{
|
||||
cLog(lsDEBUG)
|
||||
<< boost::str(boost::format("dirAdd: uRootIndex=%s uLedgerIndex=%s")
|
||||
@@ -1195,7 +1195,7 @@ TER LedgerEntrySet::trustCreate(
|
||||
uLowNode,
|
||||
Ledger::getOwnerDirIndex(uLowAccountID),
|
||||
sleRippleState->getIndex(),
|
||||
boost::bind(&Ledger::ownerDirDescriber, _1, uLowAccountID));
|
||||
BIND_TYPE(&Ledger::ownerDirDescriber, P_1, uLowAccountID));
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
{
|
||||
@@ -1203,7 +1203,7 @@ TER LedgerEntrySet::trustCreate(
|
||||
uHighNode,
|
||||
Ledger::getOwnerDirIndex(uHighAccountID),
|
||||
sleRippleState->getIndex(),
|
||||
boost::bind(&Ledger::ownerDirDescriber, _1, uHighAccountID));
|
||||
BIND_TYPE(&Ledger::ownerDirDescriber, P_1, uHighAccountID));
|
||||
}
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define __LEDGERENTRYSET__
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include "SerializedLedger.h"
|
||||
#include "TransactionMeta.h"
|
||||
@@ -106,7 +105,7 @@ public:
|
||||
uint64& uNodeDir, // Node of entry.
|
||||
const uint256& uRootIndex,
|
||||
const uint256& uLedgerIndex,
|
||||
boost::function<void (SLE::ref)> fDescriber);
|
||||
FUNCTION_TYPE<void (SLE::ref)> fDescriber);
|
||||
|
||||
TER dirDelete(
|
||||
const bool bKeepRoot,
|
||||
|
||||
@@ -197,7 +197,7 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
|
||||
{
|
||||
cLog(lsTRACE) << "Ledger hash found in database";
|
||||
theApp->getJobQueue().addJob(jtPUBOLDLEDGER, "LedgerMaster::asyncAccept",
|
||||
boost::bind(&LedgerMaster::asyncAccept, this, ledger));
|
||||
BIND_TYPE(&LedgerMaster::asyncAccept, this, ledger));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ bool LedgerMaster::acquireMissingLedger(Ledger::ref origLedger, const uint256& l
|
||||
mMissingSeq = ledgerSeq;
|
||||
if (mMissingLedger->setAccept())
|
||||
{
|
||||
if (!mMissingLedger->addOnComplete(boost::bind(&LedgerMaster::missingAcquireComplete, this, _1)))
|
||||
if (!mMissingLedger->addOnComplete(BIND_TYPE(&LedgerMaster::missingAcquireComplete, this, P_1)))
|
||||
theApp->getIOService().post(boost::bind(&LedgerMaster::missingAcquireComplete, this, mMissingLedger));
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ void LedgerMaster::tryPublish()
|
||||
theApp->getOPs().clearNeedNetworkLedger();
|
||||
mPubThread = true;
|
||||
theApp->getJobQueue().addJob(jtPUBLEDGER, "Ledger::pubThread",
|
||||
boost::bind(&LedgerMaster::pubThread, this));
|
||||
BIND_TYPE(&LedgerMaster::pubThread, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
class LedgerMaster
|
||||
{
|
||||
public:
|
||||
typedef boost::function<void(Ledger::ref)> callback;
|
||||
typedef FUNCTION_TYPE<void(Ledger::ref)> callback;
|
||||
|
||||
protected:
|
||||
boost::recursive_mutex mLock;
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "utils.h"
|
||||
#include "types.h"
|
||||
|
||||
extern int upTime();
|
||||
|
||||
// Monitors load levels and response times
|
||||
@@ -54,7 +56,7 @@ class LoadEvent
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<LoadEvent> pointer;
|
||||
typedef std::auto_ptr<LoadEvent> autoptr;
|
||||
typedef UPTR_T<LoadEvent> autoptr;
|
||||
|
||||
protected:
|
||||
LoadMonitor& mMonitor;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
#include "NetworkOPs.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "utils.h"
|
||||
@@ -1380,7 +1379,7 @@ void NetworkOPs::reportFeeChange()
|
||||
(theApp->getFeeTrack().getLoadFactor() == mLastLoadFactor))
|
||||
return;
|
||||
|
||||
theApp->getJobQueue().addJob(jtCLIENT, "reportFeeChange->pubServer", boost::bind(&NetworkOPs::pubServer, this));
|
||||
theApp->getJobQueue().addJob(jtCLIENT, "reportFeeChange->pubServer", BIND_TYPE(&NetworkOPs::pubServer, this));
|
||||
}
|
||||
|
||||
Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terResult, bool bValidated,
|
||||
|
||||
@@ -534,7 +534,7 @@ TER OfferCreateTransactor::doApply()
|
||||
|
||||
// Add offer to owner's directory.
|
||||
terResult = lesActive.dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex,
|
||||
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
|
||||
BIND_TYPE(&Ledger::qualityDirDescriber, P_1, saTakerPays.getCurrency(), uPaysIssuerID,
|
||||
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
|
||||
|
||||
|
||||
@@ -555,7 +555,7 @@ TER OfferCreateTransactor::doApply()
|
||||
|
||||
// Add offer to order book.
|
||||
terResult = lesActive.dirAdd(uBookNode, uDirectory, uLedgerIndex,
|
||||
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
|
||||
BIND_TYPE(&Ledger::qualityDirDescriber, P_1, saTakerPays.getCurrency(), uPaysIssuerID,
|
||||
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
|
||||
}
|
||||
|
||||
|
||||
@@ -590,8 +590,8 @@ void Peer::processReadBuffer()
|
||||
case ripple::mtLEDGER_DATA:
|
||||
{
|
||||
event->reName("Peer::ledgerdata");
|
||||
ripple::TMLedgerData msg;
|
||||
if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
|
||||
boost::shared_ptr<ripple::TMLedgerData> msg = boost::make_shared<ripple::TMLedgerData>();
|
||||
if (msg->ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
|
||||
recvLedger(msg);
|
||||
else
|
||||
cLog(lsWARNING) << "parse error: " << type;
|
||||
@@ -870,7 +870,7 @@ void Peer::recvTransaction(ripple::TMTransaction& packet)
|
||||
}
|
||||
|
||||
theApp->getJobQueue().addJob(jtTRANSACTION, "recvTransction->checkTransaction",
|
||||
boost::bind(&checkTransaction, _1, flags, stx, boost::weak_ptr<Peer>(shared_from_this())));
|
||||
BIND_TYPE(&checkTransaction, P_1, flags, stx, boost::weak_ptr<Peer>(shared_from_this())));
|
||||
|
||||
#ifndef TRUST_NETWORK
|
||||
}
|
||||
@@ -931,7 +931,7 @@ static void checkPropose(Job& job, boost::shared_ptr<ripple::TMProposeSet> packe
|
||||
if (isTrusted)
|
||||
{
|
||||
theApp->getJobQueue().addJob(jtPROPOSAL_t, "trustedProposal",
|
||||
boost::bind(&NetworkOPs::processTrustedProposal, &theApp->getOPs(),
|
||||
BIND_TYPE(&NetworkOPs::processTrustedProposal, &theApp->getOPs(),
|
||||
proposal, packet, nodePublic, prevLedger, sigGood));
|
||||
}
|
||||
else if (sigGood && (prevLedger == consensusLCL))
|
||||
@@ -1002,7 +1002,7 @@ void Peer::recvPropose(const boost::shared_ptr<ripple::TMProposeSet>& packet)
|
||||
set.proposeseq(), proposeHash, set.closetime(), signerPublic, suppression);
|
||||
|
||||
theApp->getJobQueue().addJob(isTrusted ? jtPROPOSAL_t : jtPROPOSAL_ut, "recvPropose->checkPropose",
|
||||
boost::bind(&checkPropose, _1, packet, proposal, consensusLCL,
|
||||
BIND_TYPE(&checkPropose, P_1, packet, proposal, consensusLCL,
|
||||
mNodePublic, boost::weak_ptr<Peer>(shared_from_this())));
|
||||
}
|
||||
|
||||
@@ -1078,7 +1078,7 @@ void Peer::recvValidation(const boost::shared_ptr<ripple::TMValidation>& packet)
|
||||
|
||||
bool isTrusted = theApp->getUNL().nodeInUNL(val->getSignerPublic());
|
||||
theApp->getJobQueue().addJob(isTrusted ? jtVALIDATION_t : jtVALIDATION_ut, "recvValidation->checkValidation",
|
||||
boost::bind(&checkValidation, _1, val, signingHash, isTrusted, packet,
|
||||
BIND_TYPE(&checkValidation, P_1, val, signingHash, isTrusted, packet,
|
||||
boost::weak_ptr<Peer>(shared_from_this())));
|
||||
}
|
||||
#ifndef TRUST_NETWORK
|
||||
@@ -1315,7 +1315,7 @@ void Peer::recvProofWork(ripple::TMProofWork& packet)
|
||||
}
|
||||
|
||||
theApp->getJobQueue().addJob(jtPROOFWORK, "recvProof->doProof",
|
||||
boost::bind(&Peer::doProofOfWork, _1, boost::weak_ptr<Peer>(shared_from_this()), pow));
|
||||
BIND_TYPE(&Peer::doProofOfWork, P_1, boost::weak_ptr<Peer>(shared_from_this()), pow));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1606,8 +1606,9 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
||||
sendPacket(oPacket, true);
|
||||
}
|
||||
|
||||
void Peer::recvLedger(ripple::TMLedgerData& packet)
|
||||
void Peer::recvLedger(const boost::shared_ptr<ripple::TMLedgerData>& packet_ptr)
|
||||
{
|
||||
ripple::TMLedgerData& packet = *packet_ptr;
|
||||
if (packet.nodes().size() <= 0)
|
||||
{
|
||||
cLog(lsWARNING) << "Ledger/TXset data with no nodes";
|
||||
@@ -1664,9 +1665,9 @@ void Peer::recvLedger(ripple::TMLedgerData& packet)
|
||||
return;
|
||||
}
|
||||
|
||||
SMAddNode san = theApp->getMasterLedgerAcquire().gotLedgerData(packet, shared_from_this());
|
||||
if (san.isInvalid())
|
||||
punishPeer(LT_UnwantedData);
|
||||
theApp->getJobQueue().addJob(jtLEDGER_DATA, "gotLedgerData",
|
||||
BIND_TYPE(&LedgerAcquireMaster::gotLedgerData, &theApp->getMasterLedgerAcquire(),
|
||||
P_1, packet_ptr, boost::weak_ptr<Peer>(shared_from_this())));
|
||||
}
|
||||
|
||||
bool Peer::hasLedger(const uint256& hash) const
|
||||
|
||||
@@ -99,7 +99,7 @@ protected:
|
||||
void recvGetAccount(ripple::TMGetAccount& packet);
|
||||
void recvAccount(ripple::TMAccount& packet);
|
||||
void recvGetLedger(ripple::TMGetLedger& packet);
|
||||
void recvLedger(ripple::TMLedgerData& packet);
|
||||
void recvLedger(const boost::shared_ptr<ripple::TMLedgerData>& packet);
|
||||
void recvStatus(ripple::TMStatusChange& packet);
|
||||
void recvPropose(const boost::shared_ptr<ripple::TMProposeSet>& packet);
|
||||
void recvHaveTxSet(ripple::TMHaveTransactionSet& packet);
|
||||
|
||||
@@ -270,7 +270,7 @@ Json::Value RPCHandler::transactionSign(Json::Value jvRequest, bool bSubmit)
|
||||
return rpcError(rpcSRC_ACT_NOT_FOUND);
|
||||
}
|
||||
|
||||
std::auto_ptr<STObject> sopTrans;
|
||||
UPTR_T<STObject> sopTrans;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -288,7 +288,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
throw std::runtime_error("invalid PIN node");
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
s.get256(mHashes[i] , i * 32);
|
||||
s.get256(mHashes[i], i * 32);
|
||||
if (mHashes[i].isNonZero())
|
||||
mIsBranch |= (1 << i);
|
||||
}
|
||||
|
||||
@@ -17,56 +17,56 @@ SETUP_LOG();
|
||||
DECLARE_INSTANCE(SerializedObject);
|
||||
DECLARE_INSTANCE(SerializedArray);
|
||||
|
||||
std::auto_ptr<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, SField::ref name)
|
||||
UPTR_T<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, SField::ref name)
|
||||
{
|
||||
assert((id == STI_NOTPRESENT) || (id == name.fieldType));
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case STI_NOTPRESENT:
|
||||
return std::auto_ptr<SerializedType>(new SerializedType(name));
|
||||
return UPTR_T<SerializedType>(new SerializedType(name));
|
||||
|
||||
case STI_UINT8:
|
||||
return std::auto_ptr<SerializedType>(new STUInt8(name));
|
||||
return UPTR_T<SerializedType>(new STUInt8(name));
|
||||
|
||||
case STI_UINT16:
|
||||
return std::auto_ptr<SerializedType>(new STUInt16(name));
|
||||
return UPTR_T<SerializedType>(new STUInt16(name));
|
||||
|
||||
case STI_UINT32:
|
||||
return std::auto_ptr<SerializedType>(new STUInt32(name));
|
||||
return UPTR_T<SerializedType>(new STUInt32(name));
|
||||
|
||||
case STI_UINT64:
|
||||
return std::auto_ptr<SerializedType>(new STUInt64(name));
|
||||
return UPTR_T<SerializedType>(new STUInt64(name));
|
||||
|
||||
case STI_AMOUNT:
|
||||
return std::auto_ptr<SerializedType>(new STAmount(name));
|
||||
return UPTR_T<SerializedType>(new STAmount(name));
|
||||
|
||||
case STI_HASH128:
|
||||
return std::auto_ptr<SerializedType>(new STHash128(name));
|
||||
return UPTR_T<SerializedType>(new STHash128(name));
|
||||
|
||||
case STI_HASH160:
|
||||
return std::auto_ptr<SerializedType>(new STHash160(name));
|
||||
return UPTR_T<SerializedType>(new STHash160(name));
|
||||
|
||||
case STI_HASH256:
|
||||
return std::auto_ptr<SerializedType>(new STHash256(name));
|
||||
return UPTR_T<SerializedType>(new STHash256(name));
|
||||
|
||||
case STI_VECTOR256:
|
||||
return std::auto_ptr<SerializedType>(new STVector256(name));
|
||||
return UPTR_T<SerializedType>(new STVector256(name));
|
||||
|
||||
case STI_VL:
|
||||
return std::auto_ptr<SerializedType>(new STVariableLength(name));
|
||||
return UPTR_T<SerializedType>(new STVariableLength(name));
|
||||
|
||||
case STI_ACCOUNT:
|
||||
return std::auto_ptr<SerializedType>(new STAccount(name));
|
||||
return UPTR_T<SerializedType>(new STAccount(name));
|
||||
|
||||
case STI_PATHSET:
|
||||
return std::auto_ptr<SerializedType>(new STPathSet(name));
|
||||
return UPTR_T<SerializedType>(new STPathSet(name));
|
||||
|
||||
case STI_OBJECT:
|
||||
return std::auto_ptr<SerializedType>(new STObject(name));
|
||||
return UPTR_T<SerializedType>(new STObject(name));
|
||||
|
||||
case STI_ARRAY:
|
||||
return std::auto_ptr<SerializedType>(new STArray(name));
|
||||
return UPTR_T<SerializedType>(new STArray(name));
|
||||
|
||||
default:
|
||||
cLog(lsFATAL) << "Object type: " << lexical_cast_i(id);
|
||||
@@ -75,7 +75,7 @@ std::auto_ptr<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, S
|
||||
}
|
||||
}
|
||||
|
||||
std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID id, SField::ref name,
|
||||
UPTR_T<SerializedType> STObject::makeDeserializedObject(SerializedTypeID id, SField::ref name,
|
||||
SerializerIterator& sit, int depth)
|
||||
{
|
||||
switch(id)
|
||||
@@ -192,7 +192,7 @@ bool STObject::setType(const SOTemplate &type)
|
||||
<< elem->e_field.fieldName;
|
||||
valid = false;
|
||||
}
|
||||
newData.push_back(makeNonPresentObject(elem->e_field));
|
||||
newData.push_back(makeNonPresentObject(elem->e_field).release());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,10 +252,10 @@ bool STObject::set(SerializerIterator& sit, int depth)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::auto_ptr<SerializedType> STObject::deserialize(SerializerIterator& sit, SField::ref name)
|
||||
UPTR_T<SerializedType> STObject::deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{
|
||||
STObject *o;
|
||||
std::auto_ptr<SerializedType> object(o = new STObject(name));
|
||||
UPTR_T<SerializedType> object(o = new STObject(name));
|
||||
o->set(sit, 1);
|
||||
return object;
|
||||
}
|
||||
@@ -482,7 +482,7 @@ SerializedType* STObject::makeFieldPresent(SField::ref field)
|
||||
SerializedType* f = getPIndex(index);
|
||||
if (f->getSType() != STI_NOTPRESENT)
|
||||
return f;
|
||||
mData.replace(index, makeDefaultObject(f->getFName()));
|
||||
mData.replace(index, makeDefaultObject(f->getFName()).release());
|
||||
return getPIndex(index);
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ void STObject::makeFieldAbsent(SField::ref field)
|
||||
if (f.getSType() == STI_NOTPRESENT)
|
||||
return;
|
||||
|
||||
mData.replace(index, makeNonPresentObject(f.getFName()));
|
||||
mData.replace(index, makeNonPresentObject(f.getFName()).release());
|
||||
}
|
||||
|
||||
bool STObject::delField(SField::ref field)
|
||||
@@ -957,7 +957,7 @@ void STArray::sort(bool (*compare)(const STObject&, const STObject&))
|
||||
value.sort(compare);
|
||||
}
|
||||
|
||||
std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::ref inName, int depth)
|
||||
UPTR_T<STObject> STObject::parseJson(const Json::Value& object, SField::ref inName, int depth)
|
||||
{
|
||||
if (!object.isObject())
|
||||
throw std::runtime_error("Value is not an object");
|
||||
@@ -1219,7 +1219,7 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
|
||||
throw std::runtime_error("Inner value is not an object");
|
||||
if (depth > 64)
|
||||
throw std::runtime_error("Json nest depth exceeded");
|
||||
data.push_back(parseJson(value, field, depth + 1));
|
||||
data.push_back(parseJson(value, field, depth + 1).release());
|
||||
break;
|
||||
|
||||
case STI_ARRAY:
|
||||
@@ -1238,7 +1238,7 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
|
||||
}
|
||||
}
|
||||
|
||||
return std::auto_ptr<STObject>(new STObject(*name, data));
|
||||
return UPTR_T<STObject>(new STObject(*name, data));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(SerializedObject)
|
||||
|
||||
@@ -58,13 +58,13 @@ public:
|
||||
STObject(const SOTemplate& type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
|
||||
{ set(sit); setType(type); }
|
||||
|
||||
std::auto_ptr<STObject> oClone() const { return std::auto_ptr<STObject>(new STObject(*this)); }
|
||||
UPTR_T<STObject> oClone() const { return UPTR_T<STObject>(new STObject(*this)); }
|
||||
|
||||
static std::auto_ptr<STObject> parseJson(const Json::Value& value, SField::ref name = sfGeneric, int depth = 0);
|
||||
static UPTR_T<STObject> parseJson(const Json::Value& value, SField::ref name = sfGeneric, int depth = 0);
|
||||
|
||||
virtual ~STObject() { ; }
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name);
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name);
|
||||
|
||||
bool setType(const SOTemplate& type);
|
||||
bool isValidForType();
|
||||
@@ -85,8 +85,8 @@ public:
|
||||
std::string getText() const;
|
||||
virtual Json::Value getJson(int options) const;
|
||||
|
||||
int addObject(const SerializedType& t) { mData.push_back(t.clone()); return mData.size() - 1; }
|
||||
int giveObject(std::auto_ptr<SerializedType> t) { mData.push_back(t); return mData.size() - 1; }
|
||||
int addObject(const SerializedType& t) { mData.push_back(t.clone().release()); return mData.size() - 1; }
|
||||
int giveObject(UPTR_T<SerializedType> t) { mData.push_back(t.release()); return mData.size() - 1; }
|
||||
int giveObject(SerializedType* t) { mData.push_back(t); return mData.size() - 1; }
|
||||
const boost::ptr_vector<SerializedType>& peekData() const { return mData; }
|
||||
boost::ptr_vector<SerializedType>& peekData() { return mData; }
|
||||
@@ -157,13 +157,13 @@ public:
|
||||
bool delField(SField::ref field);
|
||||
void delField(int index);
|
||||
|
||||
static std::auto_ptr<SerializedType> makeDefaultObject(SerializedTypeID id, SField::ref name);
|
||||
static std::auto_ptr<SerializedType> makeDeserializedObject(SerializedTypeID id, SField::ref name,
|
||||
static UPTR_T<SerializedType> makeDefaultObject(SerializedTypeID id, SField::ref name);
|
||||
static UPTR_T<SerializedType> makeDeserializedObject(SerializedTypeID id, SField::ref name,
|
||||
SerializerIterator&, int depth);
|
||||
|
||||
static std::auto_ptr<SerializedType> makeNonPresentObject(SField::ref name)
|
||||
static UPTR_T<SerializedType> makeNonPresentObject(SField::ref name)
|
||||
{ return makeDefaultObject(STI_NOTPRESENT, name); }
|
||||
static std::auto_ptr<SerializedType> makeDefaultObject(SField::ref name)
|
||||
static UPTR_T<SerializedType> makeDefaultObject(SField::ref name)
|
||||
{ return makeDefaultObject(name.fieldType, name); }
|
||||
|
||||
// field iterator stuff
|
||||
@@ -221,14 +221,14 @@ public:
|
||||
STArray(SField::ref f, const vector& v) : SerializedType(f), value(v) { ; }
|
||||
STArray(vector& v) : value(v) { ; }
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
const vector& getValue() const { return value; }
|
||||
vector& getValue() { return value; }
|
||||
|
||||
// vector-like functions
|
||||
void push_back(const STObject& object) { value.push_back(object.oClone()); }
|
||||
void push_back(const STObject& object) { value.push_back(object.oClone().release()); }
|
||||
STObject& operator[](int j) { return value[j]; }
|
||||
const STObject& operator[](int j) const { return value[j]; }
|
||||
iterator begin() { return value.begin(); }
|
||||
|
||||
@@ -236,6 +236,11 @@ std::string SerializedTransaction::getMetaSQLInsertHeader()
|
||||
return "INSERT INTO Transactions " + getMetaSQLValueHeader() + " VALUES ";
|
||||
}
|
||||
|
||||
std::string SerializedTransaction::getMetaSQLInsertReplaceHeader()
|
||||
{
|
||||
return "INSERT OR REPLACE INTO Transactions " + getMetaSQLValueHeader() + " VALUES ";
|
||||
}
|
||||
|
||||
std::string SerializedTransaction::getSQL(uint32 inLedger, char status) const
|
||||
{
|
||||
Serializer s;
|
||||
@@ -300,7 +305,7 @@ BOOST_AUTO_TEST_CASE( STrans_test )
|
||||
Log(lsFATAL) << copy.getJson(0);
|
||||
BOOST_FAIL("Transaction fails serialize/deserialize test");
|
||||
}
|
||||
std::auto_ptr<STObject> new_obj = STObject::parseJson(j.getJson(0), sfGeneric);
|
||||
UPTR_T<STObject> new_obj = STObject::parseJson(j.getJson(0), sfGeneric);
|
||||
if (new_obj.get() == NULL) BOOST_FAIL("Unable to build object from json");
|
||||
|
||||
if (STObject(j) != *new_obj)
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
// SQL Functions with metadata
|
||||
static std::string getMetaSQLValueHeader();
|
||||
static std::string getMetaSQLInsertHeader();
|
||||
static std::string getMetaSQLInsertReplaceHeader();
|
||||
std::string getMetaSQL(uint32 inLedger, const std::string& escapedMetaData) const;
|
||||
std::string getMetaSQL(Serializer rawTxn, uint32 inLedger, char status, const std::string& escapedMetaData) const;
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ STVector256* STVector256::construct(SerializerIterator& u, SField::ref name)
|
||||
{
|
||||
std::vector<unsigned char> data = u.getVL();
|
||||
|
||||
std::auto_ptr<STVector256> vec(new STVector256(name));
|
||||
UPTR_T<STVector256> vec(new STVector256(name));
|
||||
|
||||
int count = data.size() / (256 / 8);
|
||||
vec->mValue.reserve(count);
|
||||
|
||||
@@ -58,15 +58,15 @@ public:
|
||||
SerializedType(SField::ref n) : fName(&n) { assert(fName); }
|
||||
virtual ~SerializedType() { ; }
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(new SerializedType(name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(new SerializedType(name)); }
|
||||
|
||||
void setFName(SField::ref n) { fName = &n; assert(fName); }
|
||||
SField::ref getFName() const { return *fName; }
|
||||
std::string getName() const { return fName->fieldName; }
|
||||
|
||||
virtual SerializedTypeID getSType() const { return STI_NOTPRESENT; }
|
||||
std::auto_ptr<SerializedType> clone() const { return std::auto_ptr<SerializedType>(duplicate()); }
|
||||
UPTR_T<SerializedType> clone() const { return UPTR_T<SerializedType>(duplicate()); }
|
||||
|
||||
virtual std::string getFullText() const;
|
||||
virtual std::string getText() const // just the value
|
||||
@@ -107,8 +107,8 @@ public:
|
||||
|
||||
STUInt8(unsigned char v = 0) : value(v) { ; }
|
||||
STUInt8(SField::ref n, unsigned char v = 0) : SerializedType(n), value(v) { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_UINT8; }
|
||||
std::string getText() const;
|
||||
@@ -135,8 +135,8 @@ public:
|
||||
|
||||
STUInt16(uint16 v = 0) : value(v) { ; }
|
||||
STUInt16(SField::ref n, uint16 v = 0) : SerializedType(n), value(v) { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_UINT16; }
|
||||
std::string getText() const;
|
||||
@@ -163,8 +163,8 @@ public:
|
||||
|
||||
STUInt32(uint32 v = 0) : value(v) { ; }
|
||||
STUInt32(SField::ref n, uint32 v = 0) : SerializedType(n), value(v) { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_UINT32; }
|
||||
std::string getText() const;
|
||||
@@ -191,8 +191,8 @@ public:
|
||||
|
||||
STUInt64(uint64 v = 0) : value(v) { ; }
|
||||
STUInt64(SField::ref n, uint64 v = 0) : SerializedType(n), value(v) { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_UINT64; }
|
||||
std::string getText() const;
|
||||
@@ -331,8 +331,8 @@ public:
|
||||
|
||||
static STAmount createFromInt64(SField::ref n, int64 v);
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
bool bSetJson(const Json::Value& jvSource);
|
||||
|
||||
@@ -493,8 +493,8 @@ public:
|
||||
STHash128(SField::ref n, const std::string &v) : SerializedType(n) { value.SetHex(v); }
|
||||
STHash128(SField::ref n) : SerializedType(n) { ; }
|
||||
STHash128() { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_HASH128; }
|
||||
virtual std::string getText() const;
|
||||
@@ -524,8 +524,8 @@ public:
|
||||
STHash160(SField::ref n, const std::string &v) : SerializedType(n) { value.SetHex(v); }
|
||||
STHash160(SField::ref n) : SerializedType(n) { ; }
|
||||
STHash160() { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_HASH160; }
|
||||
virtual std::string getText() const;
|
||||
@@ -555,8 +555,8 @@ public:
|
||||
STHash256(SField::ref n, const std::string &v) : SerializedType(n) { value.SetHex(v); }
|
||||
STHash256(SField::ref n) : SerializedType(n) { ; }
|
||||
STHash256() { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_HASH256; }
|
||||
std::string getText() const;
|
||||
@@ -585,8 +585,8 @@ public:
|
||||
STVariableLength(SField::ref n) : SerializedType(n) { ; }
|
||||
STVariableLength(SerializerIterator&, SField::ref name = sfGeneric);
|
||||
STVariableLength() { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
virtual SerializedTypeID getSType() const { return STI_VL; }
|
||||
virtual std::string getText() const;
|
||||
@@ -615,8 +615,8 @@ public:
|
||||
STAccount(SField::ref n, const uint160& v);
|
||||
STAccount(SField::ref n) : STVariableLength(n) { ; }
|
||||
STAccount() { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
SerializedTypeID getSType() const { return STI_ACCOUNT; }
|
||||
std::string getText() const;
|
||||
@@ -770,8 +770,8 @@ public:
|
||||
STPathSet(SField::ref n) : SerializedType(n) { ; }
|
||||
STPathSet(const std::vector<STPath>& v) : value(v) { ; }
|
||||
STPathSet(SField::ref n, const std::vector<STPath>& v) : SerializedType(n), value(v) { ; }
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
// std::string getText() const;
|
||||
void add(Serializer& s) const;
|
||||
@@ -848,8 +848,8 @@ public:
|
||||
SerializedTypeID getSType() const { return STI_VECTOR256; }
|
||||
void add(Serializer& s) const;
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||
static UPTR_T<SerializedType> deserialize(SerializerIterator& sit, SField::ref name)
|
||||
{ return UPTR_T<SerializedType>(construct(sit, name)); }
|
||||
|
||||
const std::vector<uint256>& peekValue() const { return mValue; }
|
||||
std::vector<uint256>& peekValue() { return mValue; }
|
||||
|
||||
@@ -93,7 +93,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa
|
||||
}
|
||||
#endif
|
||||
|
||||
std::auto_ptr<Transactor> transactor = Transactor::makeTransactor(txn,params,this);
|
||||
UPTR_T<Transactor> transactor = Transactor::makeTransactor(txn,params,this);
|
||||
if (transactor.get() != NULL)
|
||||
{
|
||||
uint256 txID = txn.getTransactionID();
|
||||
|
||||
@@ -17,7 +17,7 @@ TransactionMetaSet::TransactionMetaSet(const uint256& txid, uint32 ledger, const
|
||||
Serializer s(vec);
|
||||
SerializerIterator sit(s);
|
||||
|
||||
std::auto_ptr<SerializedType> pobj = STObject::deserialize(sit, sfAffectedNodes);
|
||||
UPTR_T<SerializedType> pobj = STObject::deserialize(sit, sfAffectedNodes);
|
||||
STObject *obj = static_cast<STObject*>(pobj.get());
|
||||
if (!obj)
|
||||
throw std::runtime_error("bad metadata");
|
||||
|
||||
@@ -21,7 +21,7 @@ class TXQEntry
|
||||
public:
|
||||
typedef boost::shared_ptr<TXQEntry> pointer;
|
||||
typedef const boost::shared_ptr<TXQEntry>& ref;
|
||||
typedef boost::function<void (Transaction::pointer, TER)> stCallback; // must complete immediately
|
||||
typedef FUNCTION_TYPE<void (Transaction::pointer, TER)> stCallback; // must complete immediately
|
||||
|
||||
protected:
|
||||
Transaction::pointer mTxn;
|
||||
|
||||
@@ -11,26 +11,26 @@
|
||||
|
||||
SETUP_LOG();
|
||||
|
||||
std::auto_ptr<Transactor> Transactor::makeTransactor(const SerializedTransaction& txn,TransactionEngineParams params, TransactionEngine* engine)
|
||||
UPTR_T<Transactor> Transactor::makeTransactor(const SerializedTransaction& txn,TransactionEngineParams params, TransactionEngine* engine)
|
||||
{
|
||||
switch(txn.getTxnType())
|
||||
{
|
||||
case ttPAYMENT:
|
||||
return std::auto_ptr<Transactor>(new PaymentTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new PaymentTransactor(txn, params, engine));
|
||||
case ttACCOUNT_SET:
|
||||
return std::auto_ptr<Transactor>(new AccountSetTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new AccountSetTransactor(txn, params, engine));
|
||||
case ttREGULAR_KEY_SET:
|
||||
return std::auto_ptr<Transactor>(new RegularKeySetTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new RegularKeySetTransactor(txn, params, engine));
|
||||
case ttTRUST_SET:
|
||||
return std::auto_ptr<Transactor>(new TrustSetTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new TrustSetTransactor(txn, params, engine));
|
||||
case ttOFFER_CREATE:
|
||||
return std::auto_ptr<Transactor>(new OfferCreateTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new OfferCreateTransactor(txn, params, engine));
|
||||
case ttOFFER_CANCEL:
|
||||
return std::auto_ptr<Transactor>(new OfferCancelTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new OfferCancelTransactor(txn, params, engine));
|
||||
case ttWALLET_ADD:
|
||||
return std::auto_ptr<Transactor>(new WalletAddTransactor(txn, params, engine));
|
||||
return UPTR_T<Transactor>(new WalletAddTransactor(txn, params, engine));
|
||||
default:
|
||||
return std::auto_ptr<Transactor>();
|
||||
return UPTR_T<Transactor>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifndef __TRANSACTOR__
|
||||
#define __TRANSACTOR__
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "SerializedTransaction.h"
|
||||
#include "TransactionErr.h"
|
||||
#include "TransactionEngine.h"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class Transactor
|
||||
{
|
||||
@@ -38,7 +39,7 @@ protected:
|
||||
public:
|
||||
typedef boost::shared_ptr<Transactor> pointer;
|
||||
|
||||
static std::auto_ptr<Transactor> makeTransactor(const SerializedTransaction& txn,TransactionEngineParams params, TransactionEngine* engine);
|
||||
static UPTR_T<Transactor> makeTransactor(const SerializedTransaction& txn,TransactionEngineParams params, TransactionEngine* engine);
|
||||
|
||||
TER apply();
|
||||
};
|
||||
|
||||
@@ -669,7 +669,7 @@ void UniqueNodeList::processIps(const std::string& strSite, const RippleAddress&
|
||||
else
|
||||
{
|
||||
cLog(lsTRACE)
|
||||
<< str(boost::format("Validator: '%s' ["SECTION_IPS"]: rejecting '%s'")
|
||||
<< str(boost::format("Validator: '%s' [" SECTION_IPS "]: rejecting '%s'")
|
||||
% strSite % strReferral);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ void ValidationCollection::condWrite()
|
||||
return;
|
||||
mWriting = true;
|
||||
theApp->getJobQueue().addJob(jtWRITE, "ValidationCollection::doWrite",
|
||||
boost::bind(&ValidationCollection::doWrite, this, _1));
|
||||
BIND_TYPE(&ValidationCollection::doWrite, this, P_1));
|
||||
}
|
||||
|
||||
void ValidationCollection::doWrite(Job&)
|
||||
|
||||
@@ -153,13 +153,13 @@ public:
|
||||
|
||||
// Must be done without holding the websocket send lock
|
||||
theApp->getJobQueue().addJob(jtCLIENT, "WSClient::destroy",
|
||||
boost::bind(&WSConnection<endpoint_type>::destroy, ptr));
|
||||
BIND_TYPE(&WSConnection<endpoint_type>::destroy, ptr));
|
||||
}
|
||||
|
||||
void on_message(connection_ptr cpClient, message_ptr mpMessage)
|
||||
{
|
||||
theApp->getJobQueue().addJob(jtCLIENT, "WSClient::command",
|
||||
boost::bind(&WSServerHandler<endpoint_type>::do_message, this, _1, cpClient, mpMessage));
|
||||
BIND_TYPE(&WSServerHandler<endpoint_type>::do_message, this, P_1, cpClient, mpMessage));
|
||||
}
|
||||
|
||||
void do_message(Job& job, connection_ptr cpClient, message_ptr mpMessage)
|
||||
|
||||
@@ -286,6 +286,34 @@ template<typename T, typename U> T range_check_cast(const U& value, const T& min
|
||||
|
||||
bool parseUrl(const std::string& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath);
|
||||
|
||||
#if (!defined(FORCE_NO_C11X) && (__cplusplus > 201100L)) || defined(FORCE_C11X)
|
||||
|
||||
#define C11X
|
||||
#include <functional>
|
||||
#define UPTR_T std::unique_ptr
|
||||
#define MOVE_P(p) std::move(p)
|
||||
#define BIND_TYPE std::bind
|
||||
#define FUNCTION_TYPE std::function
|
||||
#define P_1 std::placeholders::_1
|
||||
#define P_2 std::placeholders::_2
|
||||
#define P_3 std::placeholders::_3
|
||||
#define P_4 std::placeholders::_4
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#define UPTR_T std::auto_ptr
|
||||
#define MOVE_P(p) (p)
|
||||
#define BIND_TYPE boost::bind
|
||||
#define FUNCTION_TYPE boost::function
|
||||
#define P_1 _1
|
||||
#define P_2 _2
|
||||
#define P_3 _3
|
||||
#define P_4 _4
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -50,6 +50,14 @@ namespace parser {
|
||||
|
||||
typedef std::map<std::string,std::string> header_list;
|
||||
|
||||
static std::string tolower(const std::string& in)
|
||||
{
|
||||
std::string out = in;
|
||||
for (int i = 0; i < out.size(); ++i)
|
||||
if (isupper(out[i]))
|
||||
out[i] = ::tolower(out[i]);
|
||||
return out;
|
||||
}
|
||||
|
||||
class parser {
|
||||
public:
|
||||
@@ -69,7 +77,7 @@ public:
|
||||
}
|
||||
|
||||
std::string header(const std::string& key) const {
|
||||
header_list::const_iterator h = m_headers.find(key);
|
||||
header_list::const_iterator h = m_headers.find(tolower(key));
|
||||
|
||||
if (h == m_headers.end()) {
|
||||
return "";
|
||||
@@ -80,21 +88,21 @@ public:
|
||||
|
||||
// multiple calls to add header will result in values aggregating.
|
||||
// use replace_header if you do not want this behavior.
|
||||
void add_header(const std::string &key,const std::string &val) {
|
||||
void add_header(const std::string &key, const std::string &val) {
|
||||
// TODO: prevent use of reserved headers?
|
||||
if (this->header(key) == "") {
|
||||
m_headers[key] = val;
|
||||
m_headers[tolower(key)] = val;
|
||||
} else {
|
||||
m_headers[key] += ", " + val;
|
||||
m_headers[tolower(key)] += ", " + val;
|
||||
}
|
||||
}
|
||||
|
||||
void replace_header(const std::string &key,const std::string &val) {
|
||||
m_headers[key] = val;
|
||||
void replace_header(const std::string &key, const std::string &val) {
|
||||
m_headers[tolower(key)] = val;
|
||||
}
|
||||
|
||||
void remove_header(const std::string &key) {
|
||||
m_headers.erase(key);
|
||||
m_headers.erase(tolower(key));
|
||||
}
|
||||
protected:
|
||||
bool parse_headers(std::istream& s) {
|
||||
|
||||
@@ -55,33 +55,41 @@ namespace websocketpp {
|
||||
|
||||
typedef boost::asio::buffers_iterator<boost::asio::streambuf::const_buffers_type> bufIterator;
|
||||
|
||||
static std::pair<bufIterator, bool> match_header(bufIterator begin, bufIterator end)
|
||||
static std::pair<bufIterator, bool> match_header(boost::shared_ptr<std::string> string,
|
||||
bufIterator nBegin, bufIterator nEnd)
|
||||
{
|
||||
if (nBegin == nEnd)
|
||||
return std::make_pair(nEnd, false);
|
||||
|
||||
(*string) += std::string(nBegin, nEnd);
|
||||
std::string::const_iterator begin = string->begin();
|
||||
std::string::const_iterator end = string->end();
|
||||
|
||||
static const std::string eol_match = "\n";
|
||||
static const std::string header_match = "\n\r\n";
|
||||
static const std::string alt_header_match = "\n\n";
|
||||
static const std::string header_match = "\r\n\r\n";
|
||||
static const std::string flash_match = "<policy-file-request/>";
|
||||
|
||||
// Do we have a complete HTTP request
|
||||
bufIterator it = std::search(begin, end, header_match.begin(), header_match.end());
|
||||
std::string::const_iterator it = std::search(begin, end, header_match.begin(), header_match.end());
|
||||
if (it != end)
|
||||
return std::make_pair(it + header_match.size(), true);
|
||||
it = std::search(begin, end, alt_header_match.begin(), alt_header_match.end());
|
||||
if (it != end)
|
||||
return std::make_pair(it + alt_header_match.size(), true);
|
||||
{
|
||||
int leftOver = (end - (it + header_match.size()));
|
||||
return std::make_pair(nEnd - leftOver, true);
|
||||
}
|
||||
|
||||
// If we don't have a flash policy request, we're done
|
||||
it = std::search(begin, end, flash_match.begin(), flash_match.end());
|
||||
if (it == end) // No match
|
||||
return std::make_pair(end, false);
|
||||
return std::make_pair(nEnd, false);
|
||||
|
||||
// If we have a line ending before the flash policy request, treat as http
|
||||
bufIterator it2 = std::search(begin, end, eol_match.begin(), eol_match.end());
|
||||
std::string::const_iterator it2 = std::search(begin, end, eol_match.begin(), eol_match.end());
|
||||
if ((it2 != end) && (it2 < it))
|
||||
return std::make_pair(end, false);
|
||||
return std::make_pair(nEnd, false);
|
||||
|
||||
// Treat as flash policy request
|
||||
return std::make_pair(it + flash_match.size(), true);
|
||||
int leftOver = (end - (it + flash_match.size()));
|
||||
return std::make_pair(nEnd - leftOver, true);
|
||||
}
|
||||
|
||||
// Forward declarations
|
||||
@@ -170,7 +178,7 @@ public:
|
||||
|
||||
// initializes the websocket connection
|
||||
void async_init();
|
||||
void handle_read_request(const boost::system::error_code& error,
|
||||
void handle_read_request(boost::shared_ptr<std::string>, const boost::system::error_code& error,
|
||||
std::size_t bytes_transferred);
|
||||
void handle_short_key3(const boost::system::error_code& error,
|
||||
std::size_t bytes_transferred);
|
||||
@@ -543,12 +551,14 @@ void server<endpoint>::connection<connection_type>::async_init() {
|
||||
m_connection.register_timeout(5000,fail::status::TIMEOUT_WS,
|
||||
"Timeout on WebSocket handshake");
|
||||
|
||||
boost::shared_ptr<std::string> stringPtr = boost::make_shared<std::string>();
|
||||
m_connection.get_socket().async_read_until(
|
||||
m_connection.buffer(),
|
||||
match_header,
|
||||
boost::bind(&match_header, stringPtr, _1, _2),
|
||||
m_connection.get_strand().wrap(boost::bind(
|
||||
&type::handle_read_request,
|
||||
m_connection.shared_from_this(),
|
||||
stringPtr,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred
|
||||
))
|
||||
@@ -562,6 +572,7 @@ void server<endpoint>::connection<connection_type>::async_init() {
|
||||
template <class endpoint>
|
||||
template <class connection_type>
|
||||
void server<endpoint>::connection<connection_type>::handle_read_request(
|
||||
boost::shared_ptr<std::string> header,
|
||||
const boost::system::error_code& error, std::size_t /*bytes_transferred*/)
|
||||
{
|
||||
if (error) {
|
||||
@@ -571,9 +582,11 @@ void server<endpoint>::connection<connection_type>::handle_read_request(
|
||||
m_connection.terminate(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_connection.buffer().consume(header->size());
|
||||
|
||||
try {
|
||||
std::istream request(&m_connection.buffer());
|
||||
std::istringstream request(*header);
|
||||
|
||||
if (!m_request.parse_complete(request)) {
|
||||
// not a valid HTTP request/response
|
||||
|
||||
Reference in New Issue
Block a user