Emit 256 bits of random on RPC server subscribe.

This commit is contained in:
Arthur Britto
2012-12-06 00:02:02 -08:00
parent 10ba85a493
commit de9cffe5c5
3 changed files with 20 additions and 7 deletions

View File

@@ -774,14 +774,13 @@ SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
if ( (parms & lepCREATE) == 0 )
{
parms = lepMISSING;
cLog(lsDEBUG) << "getASNode: MISSING";
return SLE::pointer();
}
parms = parms | lepCREATED | lepOKAY;
SLE::pointer sle=boost::make_shared<SLE>(let, nodeID);
cLog(lsDEBUG) << "getASNode: CREATED";
return sle;
}
@@ -790,14 +789,12 @@ cLog(lsDEBUG) << "getASNode: CREATED";
if (sle->getType() != let)
{ // maybe it's a currency or something
cLog(lsDEBUG) << "getASNode: WRONG TYPE";
parms = parms | lepWRONGTYPE;
return SLE::pointer();
}
parms = parms | lepOKAY;
cLog(lsDEBUG) << "getASNode: FOUND";
return sle;
}

View File

@@ -1307,8 +1307,24 @@ bool NetworkOPs::unsubLedger(InfoSub* ispListener)
// <-- bool: true=added, false=already there
bool NetworkOPs::subServer(InfoSub* ispListener, Json::Value& jvResult)
{
uint256 uRandom;
jvResult["stand_alone"] = theConfig.RUN_STANDALONE;
switch (RAND_bytes(uRandom.begin(), uRandom.size()))
{
case 0:
case 1:
jvResult["random"] = uRandom.ToString();
break;
case -1:
default:
// XXX Should probably stop running.
cLog(lsFATAL) << "Internal error: unable to generate secure random.";
break;
}
return mSubServer.insert(ispListener).second;
}

View File

@@ -658,13 +658,13 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
// Result:
// {
// random: <uint160>
// random: <uint256>
// }
Json::Value RPCHandler::doRandom(Json::Value jvRequest)
{
uint160 uRandom;
uint256 uRandom;
switch (RAND_pseudo_bytes(uRandom.begin(), uRandom.size()))
switch (RAND_bytes(uRandom.begin(), uRandom.size()))
{
case 0:
case 1: