Refactor free functions into RandomNumbers

This commit is contained in:
Vinnie Falco
2013-06-04 12:38:54 -07:00
parent 882102e9fd
commit 0523d6a054
16 changed files with 223 additions and 54 deletions

View File

@@ -68,8 +68,8 @@ Application::Application ()
, mSweepTimer (mAuxService)
, mShutdown (false)
{
getRand (mNonce256.begin(), mNonce256.size());
getRand (reinterpret_cast<unsigned char *>(&mNonceST), sizeof(mNonceST));
RandomNumbers::getInstance ().fillBytes (mNonce256.begin(), mNonce256.size());
RandomNumbers::getInstance ().fill (&mNonceST);
}
extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[],

View File

@@ -1782,7 +1782,7 @@ bool NetworkOPs::subServer(InfoSub::ref isrListener, Json::Value& jvResult)
if (theConfig.TESTNET)
jvResult["testnet"] = theConfig.TESTNET;
getRand(uRandom.begin(), uRandom.size());
RandomNumbers::getInstance ().fillBytes (uRandom.begin(), uRandom.size());
jvResult["random"] = uRandom.ToString();
jvResult["server_status"] = strOperatingMode();
jvResult["load_base"] = theApp->getFeeTrack().getLoadBase();

View File

@@ -103,7 +103,7 @@ uint256 ProofOfWork::solve(int maxIterations) const
throw std::runtime_error("invalid proof of work target/iteration");
uint256 nonce;
getRand(nonce.begin(), nonce.size());
RandomNumbers::getInstance ().fill (&nonce);
std::vector<uint256> buf2;
buf2.resize(mIterations);
@@ -162,7 +162,7 @@ bool ProofOfWork::validateToken(const std::string& strToken)
ProofOfWorkGenerator::ProofOfWorkGenerator() : mValidTime(180)
{
setDifficulty(1);
getRand(mSecret.begin(), mSecret.size());
RandomNumbers::getInstance ().fillBytes (mSecret.begin(), mSecret.size());
}
ProofOfWork ProofOfWorkGenerator::getProof()
@@ -173,7 +173,7 @@ ProofOfWork ProofOfWorkGenerator::getProof()
int now = static_cast<int>(time(NULL) / 4);
uint256 challenge;
getRand(challenge.begin(), challenge.size());
RandomNumbers::getInstance ().fillBytes (challenge.begin(), challenge.size());
boost::mutex::scoped_lock sl(mLock);

View File

@@ -1276,7 +1276,7 @@ Json::Value RPCHandler::doRandom(Json::Value jvRequest, int& cost, ScopedLock& M
try
{
getRand(uRandom.begin(), uRandom.size());
RandomNumbers::getInstance ().fillBytes (uRandom.begin(), uRandom.size());
Json::Value jvResult;

View File

@@ -76,7 +76,7 @@ void SNTPClient::resolveComplete(const boost::system::error_code& error, boost::
}
query.mReceivedReply = false;
query.mLocalTimeSent = now;
getRand(reinterpret_cast<unsigned char *>(&query.mQueryNonce), sizeof(query.mQueryNonce));
RandomNumbers::getInstance ().fill (&query.mQueryNonce);
reinterpret_cast<uint32*>(SNTPQueryData)[NTP_OFF_XMITTS_INT] = static_cast<uint32>(time(NULL)) + NTP_UNIX_OFFSET;
reinterpret_cast<uint32*>(SNTPQueryData)[NTP_OFF_XMITTS_FRAC] = query.mQueryNonce;
mSocket.async_send_to(boost::asio::buffer(SNTPQueryData, 48), *sel,

View File

@@ -160,7 +160,7 @@ int main(int argc, char* argv[])
// Prepare to run
//
if (!AddSystemEntropy())
if (! RandomNumbers::getInstance ().initialize ())
{
std::cerr << "Unable to add system entropy" << std::endl;
iResult = 2;

View File

@@ -4,6 +4,11 @@ int DatabaseCon::sCount = 0;
DatabaseCon::DatabaseCon(const std::string& strName, const char *initStrings[], int initCount)
{
++sCount;
// VFALCO: TODO, remove this dependency on the config by making it the caller's
// responsibility to pass in the path. Add a member function to Application
// or Config to compute this path.
//
boost::filesystem::path pPath = (theConfig.RUN_STANDALONE && (theConfig.START_UP != Config::LOAD))
? "" // Use temporary files.
: (theConfig.DATA_DIR / strName); // Use regular db files.