Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2013-03-08 13:56:44 -08:00
10 changed files with 38 additions and 46 deletions

View File

@@ -239,25 +239,25 @@ void SqliteDatabase::runWal()
{
{
boost::mutex::scoped_lock sl(walMutex);
walDBs.swap(walSet);
if (walSet.empty())
if (walDBs.empty())
{
walRunning = false;
return;
}
walDBs.swap(walSet);
}
BOOST_FOREACH(const std::string& db, walSet)
{
int log, ckpt;
int log = 0, ckpt = 0;
int ret = sqlite3_wal_checkpoint_v2(mConnection, db.c_str(), SQLITE_CHECKPOINT_PASSIVE, &log, &ckpt);
if (ret != SQLITE_OK)
{
cLog((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING) << "WAL " << mHost << ":"
cLog((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING) << "WAL " << name << ":"
<< db << " error " << ret;
}
else
cLog(lsTRACE) << "WAL(" << mHost << "): pass=" << pass << ", frames=" << log << ", written=" << ckpt;
cLog(lsTRACE) << "WAL(" << name << "): pass=" << pass << ", frames=" << log << ", written=" << ckpt;
}
walSet.clear();
++pass;

View File

@@ -72,6 +72,7 @@ Json::Value rpcError(int iError, Json::Value jvResult)
{ rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method." },
{ rpcWRONG_SEED, "wrongSeed", "The regular key does not point as the master key." },
{ rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now." },
{ rpcSLOW_DOWN, "slowDown", "You are placing too much load on the server." },
};
int i;

View File

@@ -18,6 +18,7 @@ enum {
rpcNO_EVENTS,
rpcNOT_STANDALONE,
rpcTOO_BUSY,
rpcSLOW_DOWN,
// Networking
rpcNO_CLOSED,

View File

@@ -1152,6 +1152,13 @@ Json::Value RPCHandler::doRandom(Json::Value jvRequest, int& cost)
// - From a trusted server, allows clients to use path without manipulation.
Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest, int& cost)
{
int jc = theApp->getJobQueue().getJobCountGE(jtCLIENT);
if (jc > 200)
{
cLog(lsDEBUG) << "Too busy for RPF: " << jc;
return rpcError(rpcTOO_BUSY);
}
RippleAddress raSrc;
RippleAddress raDst;
STAmount saDstAmount;
@@ -1161,11 +1168,7 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest, int& cost)
if (!lpLedger)
return jvResult;
if (theApp->getJobQueue().getJobCountGE(jtCLIENT) > 200)
{
jvResult = rpcError(rpcTOO_BUSY);
}
else if (!jvRequest.isMember("source_account"))
if (!jvRequest.isMember("source_account"))
{
jvResult = rpcError(rpcSRC_ACT_MISSING);
}
@@ -2891,8 +2894,15 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole, int &
{
if (cost == 0)
cost = rpcCOST_DEFAULT;
if ((iRole != ADMIN) && (theApp->getJobQueue().getJobCountGE(jtCLIENT) > 500))
return rpcError(rpcTOO_BUSY);
if (iRole != ADMIN)
{
int jc = theApp->getJobQueue().getJobCountGE(jtCLIENT);
if (jc > 500)
{
cLog(lsDEBUG) << "Too busy for command: " << jc;
return rpcError(rpcTOO_BUSY);
}
}
if (!jvRequest.isMember("command"))
return rpcError(rpcCOMMAND_MISSING);

View File

@@ -37,6 +37,9 @@ private:
void setHash() const;
protected:
SHAMapNode(int depth, const uint256& id, bool) : mNodeID(id), mDepth(depth), mHash(0) { ; }
public:
static const int rootDepth = 0;
@@ -63,13 +66,14 @@ public:
bool operator<(const SHAMapNode&) const;
bool operator>(const SHAMapNode&) const;
bool operator==(const SHAMapNode&) const;
bool operator==(const uint256&) const;
bool operator!=(const SHAMapNode&) const;
bool operator!=(const uint256&) const;
bool operator<=(const SHAMapNode&) const;
bool operator>=(const SHAMapNode&) const;
bool operator==(const SHAMapNode& n) const { return (mDepth == n.mDepth) && (mNodeID == n.mNodeID); }
bool operator==(const uint256& n) const { return n == mNodeID; }
bool operator!=(const SHAMapNode& n) const { return (mDepth != n.mDepth) || (mNodeID != n.mNodeID); }
bool operator!=(const uint256& n) const { return n != mNodeID; }
virtual std::string getString() const;
void dump() const;

View File

@@ -60,26 +60,6 @@ bool SHAMapNode::operator>=(const SHAMapNode &s) const
return mNodeID >= s.mNodeID;
}
bool SHAMapNode::operator==(const SHAMapNode &s) const
{
return (s.mDepth == mDepth) && (s.mNodeID == mNodeID);
}
bool SHAMapNode::operator!=(const SHAMapNode &s) const
{
return (s.mDepth != mDepth) || (s.mNodeID != mNodeID);
}
bool SHAMapNode::operator==(const uint256 &s) const
{
return s == mNodeID;
}
bool SHAMapNode::operator!=(const uint256 &s) const
{
return s != mNodeID;
}
bool SMN_j = SHAMapNode::ClassInit();
bool SHAMapNode::ClassInit()
@@ -102,9 +82,10 @@ uint256 SHAMapNode::getNodeID(int depth, const uint256& hash)
return hash & smMasks[depth];
}
SHAMapNode::SHAMapNode(int depth, const uint256 &hash) : mNodeID(getNodeID(depth,hash)), mDepth(depth), mHash(0)
SHAMapNode::SHAMapNode(int depth, const uint256 &hash) : mNodeID(hash), mDepth(depth), mHash(0)
{ // canonicalize the hash to a node ID for this depth
assert((depth >= 0) && (depth < 65));
mNodeID &= smMasks[depth];
}
SHAMapNode::SHAMapNode(const void *ptr, int len) : mHash(0)
@@ -136,10 +117,9 @@ SHAMapNode SHAMapNode::getChildNodeID(int m) const
assert((m >= 0) && (m < 16));
uint256 child(mNodeID);
child.begin()[mDepth/2] |= (mDepth & 1) ? m : (m << 4);
child.begin()[mDepth/2] |= (mDepth & 1) ? m : m << 4;
return SHAMapNode(mDepth + 1, child);
return SHAMapNode(mDepth + 1, child, true);
}
int SHAMapNode::selectBranch(const uint256& hash) const

View File

@@ -93,7 +93,7 @@ public:
connection_ptr ptr = mConnection.lock();
if (ptr)
ptr->close(websocketpp::close::status::PROTOCOL_ERROR, "overload");
return rpcError(rpcTOO_BUSY);
return rpcError(rpcSLOW_DOWN);
}
if (!jvRequest.isMember("command"))