Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Macros | Functions | Variables
util.h File Reference
#include "compat.h"
#include "serialize.h"
#include "tinyformat.h"
#include <cstdio>
#include <exception>
#include <map>
#include <stdarg.h>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <boost/filesystem/path.hpp>
#include <boost/thread.hpp>
+ Include dependency graph for util.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CMedianFilter< T >
 Median filter over a stream of values. More...
 

Macros

#define BEGIN(a)   ((char*)&(a))
 
#define END(a)   ((char*)&((&(a))[1]))
 
#define UBEGIN(a)   ((unsigned char*)&(a))
 
#define UEND(a)   ((unsigned char*)&((&(a))[1]))
 
#define ARRAYLEN(array)   (sizeof(array)/sizeof((array)[0]))
 
#define PAIRTYPE(t1, t2)   std::pair<t1, t2>
 
#define MAX_PATH   1024
 
#define MSG_NOSIGNAL   0
 
#define strprintf   tfm::format
 
#define LogPrintf(...)   LogPrint(NULL, __VA_ARGS__)
 
#define MAKE_ERROR_AND_LOG_FUNC(n)
 
#define PRIO_MAX   20
 
#define THREAD_PRIORITY_LOWEST   PRIO_MAX
 
#define THREAD_PRIORITY_BELOW_NORMAL   2
 
#define THREAD_PRIORITY_NORMAL   0
 
#define THREAD_PRIORITY_ABOVE_NORMAL   (-2)
 

Functions

template<size_t nBytes, typename T >
T * alignup (T *p)
 
void MilliSleep (int64_t n)
 
void RandAddSeed ()
 
void RandAddSeedPerfmon ()
 
void SetupEnvironment ()
 
bool LogAcceptCategory (const char *category)
 
int LogPrintStr (const std::string &str)
 
static int LogPrint (const char *category, const char *format)
 
static bool error (const char *format)
 
void LogException (std::exception *pex, const char *pszThread)
 
void PrintExceptionContinue (std::exception *pex, const char *pszThread)
 
std::string FormatMoney (int64_t n, bool fPlus=false)
 
bool ParseMoney (const std::string &str, int64_t &nRet)
 
bool ParseMoney (const char *pszIn, int64_t &nRet)
 
std::string SanitizeString (const std::string &str)
 
std::vector< unsigned char > ParseHex (const char *psz)
 
std::vector< unsigned char > ParseHex (const std::string &str)
 
bool IsHex (const std::string &str)
 
std::vector< unsigned char > DecodeBase64 (const char *p, bool *pfInvalid=NULL)
 
std::string DecodeBase64 (const std::string &str)
 
std::string EncodeBase64 (const unsigned char *pch, size_t len)
 
std::string EncodeBase64 (const std::string &str)
 
std::vector< unsigned char > DecodeBase32 (const char *p, bool *pfInvalid=NULL)
 
std::string DecodeBase32 (const std::string &str)
 
std::string EncodeBase32 (const unsigned char *pch, size_t len)
 
std::string EncodeBase32 (const std::string &str)
 
void ParseParameters (int argc, const char *const argv[])
 
bool WildcardMatch (const char *psz, const char *mask)
 
bool WildcardMatch (const std::string &str, const std::string &mask)
 
void FileCommit (FILE *fileout)
 
bool TruncateFile (FILE *file, unsigned int length)
 
int RaiseFileDescriptorLimit (int nMinFD)
 
void AllocateFileRange (FILE *file, unsigned int offset, unsigned int length)
 
bool RenameOver (boost::filesystem::path src, boost::filesystem::path dest)
 
bool TryCreateDirectory (const boost::filesystem::path &p)
 
boost::filesystem::path GetDefaultDataDir ()
 
const boost::filesystem::path & GetDataDir (bool fNetSpecific=true)
 
boost::filesystem::path GetConfigFile ()
 
boost::filesystem::path GetPidFile ()
 
void CreatePidFile (const boost::filesystem::path &path, pid_t pid)
 
void ReadConfigFile (std::map< std::string, std::string > &mapSettingsRet, std::map< std::string, std::vector< std::string > > &mapMultiSettingsRet)
 
boost::filesystem::path GetTempPath ()
 
void ShrinkDebugFile ()
 
int GetRandInt (int nMax)
 
uint64_t GetRand (uint64_t nMax)
 
uint256 GetRandHash ()
 
int64_t GetTime ()
 
void SetMockTime (int64_t nMockTimeIn)
 
int64_t GetAdjustedTime ()
 
int64_t GetTimeOffset ()
 
std::string FormatFullVersion ()
 
std::string FormatSubVersion (const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
 
void AddTimeData (const CNetAddr &ip, int64_t nTime)
 
void runCommand (std::string strCommand)
 
std::string i64tostr (int64_t n)
 
std::string itostr (int n)
 
int64_t atoi64 (const char *psz)
 
int64_t atoi64 (const std::string &str)
 
int atoi (const std::string &str)
 
int roundint (double d)
 
int64_t roundint64 (double d)
 
int64_t abs64 (int64_t n)
 
template<typename T >
std::string HexStr (const T itbegin, const T itend, bool fSpaces=false)
 
template<typename T >
std::string HexStr (const T &vch, bool fSpaces=false)
 
template<typename T >
void PrintHex (const T pbegin, const T pend, const char *pszFormat="%s", bool fSpaces=true)
 
void PrintHex (const std::vector< unsigned char > &vch, const char *pszFormat="%s", bool fSpaces=true)
 
int64_t GetPerformanceCounter ()
 
int64_t GetTimeMillis ()
 
int64_t GetTimeMicros ()
 
std::string DateTimeStrFormat (const char *pszFormat, int64_t nTime)
 
template<typename T >
void skipspaces (T &it)
 
bool IsSwitchChar (char c)
 
std::string GetArg (const std::string &strArg, const std::string &strDefault)
 Return string argument or default value. More...
 
int64_t GetArg (const std::string &strArg, int64_t nDefault)
 Return integer argument or default value. More...
 
bool GetBoolArg (const std::string &strArg, bool fDefault)
 Return boolean argument or default value. More...
 
bool SoftSetArg (const std::string &strArg, const std::string &strValue)
 Set an argument if it doesn't already have a value. More...
 
bool SoftSetBoolArg (const std::string &strArg, bool fValue)
 Set a boolean argument if it doesn't already have a value. More...
 
static uint32_t insecure_rand (void)
 
void seed_insecure_rand (bool fDeterministic=false)
 Seed insecure_rand using the random pool. More...
 
template<typename T >
bool TimingResistantEqual (const T &a, const T &b)
 Timing-attack-resistant comparison. More...
 
void SetThreadPriority (int nPriority)
 
void RenameThread (const char *name)
 
uint32_t ByteReverse (uint32_t value)
 
template<typename Callable >
void LoopForever (const char *name, Callable func, int64_t msecs)
 
template<typename Callable >
void TraceThread (const char *name, Callable func)
 

Variables

static const int64_t COIN = 100000000
 
static const int64_t CENT = 1000000
 
std::map< std::string, std::string > mapArgs
 
std::map< std::string, std::vector< std::string > > mapMultiArgs
 
bool fDebug
 
bool fPrintToConsole
 
bool fPrintToDebugLog
 
bool fServer
 
std::string strMiscWarning
 
bool fNoListen
 
bool fLogTimestamps
 
volatile bool fReopenDebugLog
 
uint32_t insecure_rand_Rz
 MWC RNG of George Marsaglia This is intended to be fast. More...
 
uint32_t insecure_rand_Rw
 

Macro Definition Documentation

#define ARRAYLEN (   array)    (sizeof(array)/sizeof((array)[0]))

Definition at line 45 of file util.h.

Referenced by CInv::CInv(), CMainParams::CMainParams(), and CInv::IsKnownType().

#define BEGIN (   a)    ((char*)&(a))
#define END (   a)    ((char*)&((&(a))[1]))
#define LogPrintf (   ...)    LogPrint(NULL, __VA_ARGS__)

Definition at line 117 of file util.h.

Referenced by AbortNode(), AddLocal(), AddTimeData(), CWallet::AddToWallet(), AppInit2(), BackupWallet(), BindListenPort(), CWallet::ChangeWalletPassphrase(), CAddrMan::Check(), CheckForkWarningConditions(), CLevelDBWrapper::CLevelDBWrapper(), CWallet::CommitTransaction(), ConnectBlock(), ConnectNode(), ConnectSocketDirectly(), ConnectTip(), CreateNewBlock(), DisconnectTip(), Discover(), CWallet::EncryptWallet(), CDBEnv::EnvShutdown(), CLevelDBWrapper::Exists(), FindBlockPos(), FindUndoPos(), CWalletDB::FindWalletTx(), CWalletTx::GetAmounts(), GetMyExternalIP2(), GetNextWorkRequired(), CReserveKey::GetReservedKey(), GetTempPath(), HandleError(), importwallet(), InitBlockIndex(), BitcoinCore::initialize(), BitcoinApplication::initializeResult(), InitMessage(), InvalidChainFound(), CMessageHeader::IsValid(), CWallet::KeepKey(), LoadBlockIndexDB(), CWallet::LoadCScript(), LoadExternalBlockFile(), CWalletDB::LoadWallet(), LogException(), LoopForever(), Misbehaving(), msc_file_load(), CWallet::NewKeyPool(), noui_InitMessage(), noui_ThreadSafeMessageBox(), CDBEnv::Open(), OpenDiskFile(), COutPoint::print(), COrphan::print(), CUnsignedAlert::print(), CNetAddr::print(), CTxIn::print(), CService::print(), CInv::print(), CTxOut::print(), CTransaction::print(), CBlock::print(), CScript::print(), COutput::print(), CBlockIndex::print(), CDiskBlockIndex::print(), PrintBlockTree(), PrintExceptionContinue(), PrintHex(), CScript::PrintHex(), ProcessBlock(), ProcessGetData(), ProcessMessage(), ProcessMessages(), CLevelDBWrapper::Read(), CWalletDB::Recover(), CWalletTx::RelayWalletTransaction(), BitcoinApplication::requestInitialize(), BitcoinApplication::requestShutdown(), CWallet::ResendWalletTransactions(), CWallet::ReserveKeyFromKeyPool(), CWallet::ReturnKey(), CDB::Rewrite(), RPCAcceptHandler(), runCommand(), CDBEnv::Salvage(), CWallet::ScanForWalletTransactions(), mastercore::send_INTERNAL_1packet(), SendMessages(), CWallet::SendMoney(), ServiceConnection(), Shutdown(), BitcoinCore::shutdown(), BitcoinApplication::shutdownResult(), SignatureHash(), SocketSendData(), Socks4(), Socks5(), StartNode(), StartRPCThreads(), StopNode(), StopRPCThreads(), ThreadDNSAddressSeed(), ThreadGetMyExternalIP(), ThreadImport(), ThreadOpenConnections(), ThreadSocketHandler(), CWallet::TopUpKeyPool(), TraceThread(), UpdateTip(), VerifyDB(), BitcoinApplication::~BitcoinApplication(), and CNetCleanup::~CNetCleanup().

#define MAKE_ERROR_AND_LOG_FUNC (   n)
Value:
/* Print to debug.log if -debug=category switch is given OR category is NULL. */ \
template<TINYFORMAT_ARGTYPES(n)> \
static inline int LogPrint(const char* category, const char* format, TINYFORMAT_VARARGS(n)) \
{ \
if(!LogAcceptCategory(category)) return 0; \
return LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
} \
/* Log error and return false */ \
template<TINYFORMAT_ARGTYPES(n)> \
static inline bool error(const char* format, TINYFORMAT_VARARGS(n)) \
{ \
LogPrintStr("ERROR: " + tfm::format(format, TINYFORMAT_PASSARGS(n)) + "\n"); \
return false; \
}
#define TINYFORMAT_PASSARGS(n)
Definition: tinyformat.h:322
#define TINYFORMAT_VARARGS(n)
Definition: tinyformat.h:321
#define TINYFORMAT_ARGTYPES(n)
Definition: tinyformat.h:320
static int LogPrint(const char *category, const char *format)
Definition: util.h:143
static bool error(const char *format)
Definition: util.h:148
bool LogAcceptCategory(const char *category)
Definition: util.cpp:240
int LogPrintStr(const std::string &str)
Definition: util.cpp:268
void format(FormatIterator &fmtIter)
Definition: tinyformat.h:869

Definition at line 122 of file util.h.

#define MAX_PATH   1024

Definition at line 72 of file util.h.

Referenced by FormatException(), and GetTempPath().

#define MSG_NOSIGNAL   0

Definition at line 76 of file util.h.

Referenced by GetMyExternalIP2(), SocketSendData(), Socks4(), and Socks5().

#define PAIRTYPE (   t1,
  t2 
)    std::pair<t1, t2>
#define PRIO_MAX   20

Definition at line 488 of file util.h.

#define strprintf   tfm::format
#define THREAD_PRIORITY_ABOVE_NORMAL   (-2)

Definition at line 493 of file util.h.

#define THREAD_PRIORITY_BELOW_NORMAL   2

Definition at line 491 of file util.h.

Referenced by ThreadMessageHandler().

#define THREAD_PRIORITY_LOWEST   PRIO_MAX

Definition at line 490 of file util.h.

#define THREAD_PRIORITY_NORMAL   0

Definition at line 492 of file util.h.

#define UBEGIN (   a)    ((unsigned char*)&(a))

Definition at line 43 of file util.h.

#define UEND (   a)    ((unsigned char*)&((&(a))[1]))

Definition at line 44 of file util.h.

Function Documentation

int64_t abs64 ( int64_t  n)
inline

Definition at line 257 of file util.h.

Referenced by AddTimeData().

+ Here is the caller graph for this function:

void AddTimeData ( const CNetAddr ip,
int64_t  nTime 
)

Definition at line 1241 of file util.cpp.

References _(), abs64(), fDebug, GetTime(), CMedianFilter< T >::input(), LOCK, LogPrintf, CMedianFilter< T >::median(), CClientUIInterface::MSG_WARNING, nTimeOffset, CMedianFilter< T >::size(), CMedianFilter< T >::sorted(), strMiscWarning, and CClientUIInterface::ThreadSafeMessageBox.

Referenced by ProcessMessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<size_t nBytes, typename T >
T* alignup ( T *  p)

Definition at line 52 of file util.h.

void AllocateFileRange ( FILE *  file,
unsigned int  offset,
unsigned int  length 
)

Definition at line 1140 of file util.cpp.

Referenced by FindBlockPos(), and FindUndoPos().

+ Here is the caller graph for this function:

int atoi ( const std::string &  str)
inline
int64_t atoi64 ( const char *  psz)
inline

Definition at line 224 of file util.h.

Referenced by GetArg(), ParseMoney(), and ReadOrderPos().

+ Here is the caller graph for this function:

int64_t atoi64 ( const std::string &  str)
inline

Definition at line 233 of file util.h.

uint32_t ByteReverse ( uint32_t  value)
inline

Definition at line 509 of file util.h.

Referenced by FormatHashBuffers(), and SHA256Transform().

+ Here is the caller graph for this function:

void CreatePidFile ( const boost::filesystem::path &  path,
pid_t  pid 
)

Definition at line 1053 of file util.cpp.

Referenced by AppInit().

+ Here is the caller graph for this function:

std::string DateTimeStrFormat ( const char *  pszFormat,
int64_t  nTime 
)
std::vector<unsigned char> DecodeBase32 ( const char *  p,
bool *  pfInvalid = NULL 
)

Definition at line 751 of file util.cpp.

Referenced by DecodeBase32(), and CNetAddr::SetSpecial().

+ Here is the caller graph for this function:

std::string DecodeBase32 ( const std::string &  str)

Definition at line 868 of file util.cpp.

References DecodeBase32().

+ Here is the call graph for this function:

std::vector<unsigned char> DecodeBase64 ( const char *  p,
bool *  pfInvalid = NULL 
)

Definition at line 598 of file util.cpp.

Referenced by DecodeBase64(), HTTPAuthorized(), SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked(), and verifymessage().

+ Here is the caller graph for this function:

std::string DecodeBase64 ( const std::string &  str)

Definition at line 681 of file util.cpp.

References DecodeBase64().

+ Here is the call graph for this function:

std::string EncodeBase32 ( const unsigned char *  pch,
size_t  len 
)

Definition at line 687 of file util.cpp.

Referenced by EncodeBase32(), and CNetAddr::ToStringIP().

+ Here is the caller graph for this function:

std::string EncodeBase32 ( const std::string &  str)

Definition at line 746 of file util.cpp.

References EncodeBase32().

+ Here is the call graph for this function:

std::string EncodeBase64 ( const unsigned char *  pch,
size_t  len 
)

Definition at line 547 of file util.cpp.

Referenced by CallRPC(), EncodeBase64(), SignVerifyMessageDialog::on_signMessageButton_SM_clicked(), and signmessage().

+ Here is the caller graph for this function:

std::string EncodeBase64 ( const std::string &  str)

Definition at line 593 of file util.cpp.

References EncodeBase64().

+ Here is the call graph for this function:

static bool error ( const char *  format)
inlinestatic
void FileCommit ( FILE *  fileout)

Definition at line 1092 of file util.cpp.

Referenced by FlushBlockFile(), CAddrDB::Write(), and WriteBlockToDisk().

+ Here is the caller graph for this function:

std::string FormatFullVersion ( )

Definition at line 1325 of file util.cpp.

References CLIENT_BUILD.

Referenced by AppInit(), AppInit2(), AppInitRPC(), ClientModel::formatFullVersion(), HelpMessageDialog::HelpMessageDialog(), HTTPPost(), and HTTPReply().

+ Here is the caller graph for this function:

std::string FormatMoney ( int64_t  n,
bool  fPlus = false 
)

Definition at line 308 of file util.cpp.

References COIN, and strprintf.

Referenced by HelpMessage(), CWallet::SelectCoinsMinConf(), CWallet::SendMoney(), and COutput::ToString().

+ Here is the caller graph for this function:

std::string FormatSubVersion ( const std::string &  name,
int  nClientVersion,
const std::vector< std::string > &  comments 
)

Definition at line 1331 of file util.cpp.

References FormatVersion().

Referenced by CAlert::AppliesToMe(), and CNode::PushVersion().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t GetAdjustedTime ( )

Definition at line 1236 of file util.cpp.

References GetTime(), and GetTimeOffset().

Referenced by CAddrMan::Add_(), CWallet::AddToWallet(), CheckBlock(), ConnectNode(), TransactionDesc::FormatTxStatus(), GetLocalAddress(), IsFinalTx(), CAlert::IsInEffect(), movecmd(), ProcessMessage(), CNode::PushVersion(), CAlert::RelayTo(), ThreadOpenConnections(), TransactionRecord::updateStatus(), and UpdateTime().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string GetArg ( const std::string &  strArg,
const std::string &  strDefault 
)

Return string argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. "1")
Returns
command-line argument or default value

Definition at line 505 of file util.cpp.

Referenced by AcceptToMemoryPool(), ActivateBestChain(), CWallet::AddToWallet(), AppInit2(), CNode::Ban(), CallRPC(), CheckForkWarningConditions(), CreateNewBlock(), CNode::EndMessage(), CDB::Flush(), GetConfigFile(), GetListenPort(), getmininginfo(), GetPidFile(), initTranslations(), PaymentServer::LoadRootCAs(), Misbehaving(), CWallet::NewKeyPool(), Intro::pickDataDirectory(), CAlert::ProcessAlert(), ProcessMessage(), PruneOrphanBlocks(), ReceiveFloodSize(), SendBufferSize(), CSignatureCache::Set(), StartRPCThreads(), CWallet::TopUpKeyPool(), and verifychain().

+ Here is the caller graph for this function:

int64_t GetArg ( const std::string &  strArg,
int64_t  nDefault 
)

Return integer argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. 1)
Returns
command-line argument (0 if invalid number) or default value

Definition at line 512 of file util.cpp.

References atoi64().

+ Here is the call graph for this function:

bool GetBoolArg ( const std::string &  strArg,
bool  fDefault 
)

Return boolean argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(true or false)
Returns
command-line argument or default value

Definition at line 519 of file util.cpp.

References atoi().

Referenced by AppInit(), AppInit2(), BitcoinGUI::BitcoinGUI(), CallRPC(), mastercore::checkExpiredAlerts(), CreateNewBlock(), CRPCTable::execute(), GetWarnings(), HelpMessage(), InitBlockIndex(), BitcoinApplication::initializeResult(), InterpretNegativeSetting(), main(), mastercore_init(), CDBEnv::Open(), Intro::pickDataDirectory(), SelectParamsFromCommandLine(), StartNode(), StartRPCThreads(), ThreadDNSAddressSeed(), and ThreadFlushWalletDB().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boost::filesystem::path GetConfigFile ( )

Definition at line 1012 of file util.cpp.

References GetArg(), and GetDataDir().

Referenced by CallRPC(), ReadConfigFile(), and StartRPCThreads().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const boost::filesystem::path& GetDataDir ( bool  fNetSpecific = true)

Definition at line 973 of file util.cpp.

References CChainParams::DataDir(), GetDefaultDataDir(), LOCK, CChainParams::MAX_NETWORK_TYPES, CChainParams::NetworkID(), Params(), and pathCached.

Referenced by AppInit(), AppInit2(), AppInitRPC(), BackupWallet(), CAddrDB::CAddrDB(), CDB::CDB(), CheckDiskSpace(), DebugPrintInit(), mastercore::dumpCrowdsaleInfo(), GetConfigFile(), GetPidFile(), CMPTransaction::interpretPacket(), ipcServerName(), LogPrintStr(), main(), mastercore_init(), mp_DebugPrintInit(), mp_LogPrintStr(), GUIUtil::openDebugLogfile(), OpenDiskFile(), ShrinkDebugFile(), shrinkDebugFile(), StartRPCThreads(), ThreadImport(), and CAddrDB::Write().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boost::filesystem::path GetDefaultDataDir ( )

Definition at line 941 of file util.cpp.

References TryCreateDirectory().

Referenced by AppInit2(), GetDataDir(), and Intro::getDefaultDataDirectory().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t GetPerformanceCounter ( )
inline

Definition at line 298 of file util.h.

Referenced by RandAddSeed().

+ Here is the caller graph for this function:

boost::filesystem::path GetPidFile ( )

Definition at line 1045 of file util.cpp.

References GetArg(), and GetDataDir().

Referenced by AppInit(), and Shutdown().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint64_t GetRand ( uint64_t  nMax)

Definition at line 186 of file util.cpp.

Referenced by mastercore::ClassB_send(), CMainParams::CMainParams(), CNode::EndMessage(), CNode::Fuzz(), GetRandInt(), ProcessMessage(), CWallet::ResendWalletTransactions(), ThreadDNSAddressSeed(), and ThreadMessageHandler().

+ Here is the caller graph for this function:

uint256 GetRandHash ( )

Definition at line 206 of file util.cpp.

Referenced by LimitOrphanTxSize(), ProcessMessage(), SendMessages(), and CSignatureCache::Set().

+ Here is the caller graph for this function:

int GetRandInt ( int  nMax)

Definition at line 201 of file util.cpp.

References GetRand().

Referenced by CAddrMan::Add_(), CAddrMan::GetAddr_(), CAddrMan::Good_(), CAddrMan::Select_(), CWallet::SelectCoinsMinConf(), CAddrMan::SelectTried(), and CAddrMan::ShrinkNew().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boost::filesystem::path GetTempPath ( )

Definition at line 1359 of file util.cpp.

References LogPrintf, and MAX_PATH.

int64_t GetTime ( )
int64_t GetTimeMicros ( )
inline

Definition at line 317 of file util.h.

Referenced by CNode::AskFor(), ConnectBlock(), ConnectTip(), CNode::copyStats(), DisconnectTip(), ProcessMessage(), SendMessages(), and WriteChainState().

+ Here is the caller graph for this function:

int64_t GetTimeMillis ( )
inline

Definition at line 311 of file util.h.

Referenced by AppInit2(), CWallet::ChangeWalletPassphrase(), DumpAddresses(), CWallet::EncryptWallet(), CDBEnv::Flush(), getnettotals(), LoadExternalBlockFile(), and ThreadFlushWalletDB().

+ Here is the caller graph for this function:

int64_t GetTimeOffset ( )

Definition at line 1230 of file util.cpp.

References LOCK, and nTimeOffset.

Referenced by GetAdjustedTime(), getinfo(), and getnetworkinfo().

+ Here is the caller graph for this function:

template<typename T >
std::string HexStr ( const T  itbegin,
const T  itend,
bool  fSpaces = false 
)
template<typename T >
std::string HexStr ( const T &  vch,
bool  fSpaces = false 
)
inline

Definition at line 282 of file util.h.

References HexStr().

+ Here is the call graph for this function:

std::string i64tostr ( int64_t  n)
inline

Definition at line 214 of file util.h.

References strprintf.

Referenced by WriteOrderPos().

+ Here is the caller graph for this function:

static uint32_t insecure_rand ( void  )
inlinestatic

Definition at line 395 of file util.h.

References insecure_rand_Rw, and insecure_rand_Rz.

Referenced by ApproximateBestSubset(), and PruneOrphanBlocks().

+ Here is the caller graph for this function:

bool IsHex ( const std::string &  str)

Definition at line 409 of file util.cpp.

References HexDigit().

Referenced by _createmultisig_redeemScript(), lockunspent(), ParseHashV(), and ParseHexV().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool IsSwitchChar ( char  c)
inline

Definition at line 332 of file util.h.

Referenced by AppInit(), and CommandLineRPC().

+ Here is the caller graph for this function:

std::string itostr ( int  n)
inline

Definition at line 219 of file util.h.

References strprintf.

Referenced by CallRPC(), and ProcessMessage().

+ Here is the caller graph for this function:

bool LogAcceptCategory ( const char *  category)

Definition at line 240 of file util.cpp.

References fDebug.

Referenced by LogPrint().

+ Here is the caller graph for this function:

void LogException ( std::exception *  pex,
const char *  pszThread 
)

Definition at line 927 of file util.cpp.

References FormatException(), and LogPrintf.

+ Here is the call graph for this function:

static int LogPrint ( const char *  category,
const char *  format 
)
inlinestatic

Definition at line 143 of file util.h.

References LogAcceptCategory(), and LogPrintStr().

Referenced by CNode::AbortMessage(), AcceptToMemoryPool(), CAddrMan::Add(), AddOrphanTx(), CNode::AskFor(), CCoinsViewDB::BatchWrite(), CNode::BeginMessage(), CTxMemPool::check(), CNode::CloseSocketDisconnect(), ConnectNode(), ConnectSocketDirectly(), DebugMessageHandler(), DumpAddresses(), CNode::EndMessage(), EraseOrphansFor(), CDBEnv::Flush(), CAddrMan::Good_(), CDBEnv::MakeMock(), JSONRequest::parse(), CAlert::ProcessAlert(), ProcessMessage(), CNode::PushVersion(), RandAddSeedPerfmon(), RecvLine(), CWallet::SelectCoinsMinConf(), SendMessages(), ThreadFlushWalletDB(), and ThreadSocketHandler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int LogPrintStr ( const std::string &  str)

Definition at line 268 of file util.cpp.

References DateTimeStrFormat(), DebugPrintInit(), debugPrintInitFlag, fileout, fLogTimestamps, fPrintToConsole, fPrintToDebugLog, fReopenDebugLog, GetDataDir(), GetTime(), and mutexDebugLog.

Referenced by error(), and LogPrint().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Callable >
void LoopForever ( const char *  name,
Callable  func,
int64_t  msecs 
)

Definition at line 522 of file util.h.

References LogPrintf, MilliSleep(), PrintExceptionContinue(), RenameThread(), and strprintf.

Referenced by StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MilliSleep ( int64_t  n)
inline

Definition at line 79 of file util.h.

Referenced by BackupWallet(), CallRPC(), DetectShutdownThread(), LoopForever(), RecvLine(), CDB::Rewrite(), ServiceConnection(), StopNode(), ThreadDNSAddressSeed(), ThreadFlushWalletDB(), ThreadMessageHandler(), ThreadOpenAddedConnections(), ThreadOpenConnections(), and ThreadSocketHandler().

+ Here is the caller graph for this function:

std::vector<unsigned char> ParseHex ( const char *  psz)

Definition at line 419 of file util.cpp.

References HexDigit().

Referenced by _createmultisig_redeemScript(), mastercore::ClassB_send(), CMainParams::CMainParams(), CTestNetParams::CTestNetParams(), ParseHex(), ParseHexV(), parseTransaction(), CDBEnv::Salvage(), sendrawtx_MP(), and submitblock().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<unsigned char> ParseHex ( const std::string &  str)

Definition at line 440 of file util.cpp.

References ParseHex().

+ Here is the call graph for this function:

bool ParseMoney ( const std::string &  str,
int64_t &  nRet 
)

Definition at line 332 of file util.cpp.

References ParseMoney().

Referenced by AppInit2(), and ParseMoney().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ParseMoney ( const char *  pszIn,
int64_t &  nRet 
)

Definition at line 337 of file util.cpp.

References atoi64(), CENT, and COIN.

+ Here is the call graph for this function:

void ParseParameters ( int  argc,
const char *const  argv[] 
)

Definition at line 460 of file util.cpp.

References InterpretNegativeSetting(), and PAIRTYPE.

Referenced by AppInit(), AppInitRPC(), and main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PrintExceptionContinue ( std::exception *  pex,
const char *  pszThread 
)

Definition at line 933 of file util.cpp.

References FormatException(), LogPrintf, and strMiscWarning.

Referenced by AppInit(), CommandLineRPC(), BitcoinCore::handleRunawayException(), LoopForever(), main(), ProcessMessages(), and TraceThread().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
void PrintHex ( const T  pbegin,
const T  pend,
const char *  pszFormat = "%s",
bool  fSpaces = true 
)

Definition at line 288 of file util.h.

References HexStr(), and LogPrintf.

+ Here is the call graph for this function:

void PrintHex ( const std::vector< unsigned char > &  vch,
const char *  pszFormat = "%s",
bool  fSpaces = true 
)
inline

Definition at line 293 of file util.h.

References HexStr(), and LogPrintf.

+ Here is the call graph for this function:

int RaiseFileDescriptorLimit ( int  nMinFD)

Definition at line 1119 of file util.cpp.

Referenced by AppInit2().

+ Here is the caller graph for this function:

void RandAddSeed ( )

Definition at line 151 of file util.cpp.

References GetPerformanceCounter().

Referenced by CInit::CInit(), and RandAddSeedPerfmon().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RandAddSeedPerfmon ( )

Definition at line 159 of file util.cpp.

References GetTime(), LogPrint(), and RandAddSeed().

Referenced by AppInit2(), CWallet::EncryptWallet(), CWallet::GenerateNewKey(), and ProcessMessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ReadConfigFile ( std::map< std::string, std::string > &  mapSettingsRet,
std::map< std::string, std::vector< std::string > > &  mapMultiSettingsRet 
)

Definition at line 1019 of file util.cpp.

References ClearDatadirCache(), GetConfigFile(), and InterpretNegativeSetting().

Referenced by AppInit(), AppInitRPC(), and main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool RenameOver ( boost::filesystem::path  src,
boost::filesystem::path  dest 
)

Definition at line 1064 of file util.cpp.

Referenced by ThreadImport(), and CAddrDB::Write().

+ Here is the caller graph for this function:

void RenameThread ( const char *  name)

Definition at line 1388 of file util.cpp.

Referenced by LoopForever(), Shutdown(), ThreadFlushWalletDB(), ThreadImport(), ThreadScriptCheck(), and TraceThread().

+ Here is the caller graph for this function:

int roundint ( double  d)
inline

Definition at line 247 of file util.h.

int64_t roundint64 ( double  d)
inline

Definition at line 252 of file util.h.

Referenced by AmountFromValue().

+ Here is the caller graph for this function:

void runCommand ( std::string  strCommand)

Definition at line 1381 of file util.cpp.

References LogPrintf.

Referenced by ActivateBestChain(), CWallet::AddToWallet(), CheckForkWarningConditions(), and CAlert::ProcessAlert().

+ Here is the caller graph for this function:

std::string SanitizeString ( const std::string &  str)

Definition at line 380 of file util.cpp.

References safeChars().

Referenced by CAlert::ProcessAlert(), and ProcessMessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void seed_insecure_rand ( bool  fDeterministic = false)

Seed insecure_rand using the random pool.

Parameters
DeterministicUse a determinstic seed

Definition at line 1298 of file util.cpp.

References insecure_rand_Rw, and insecure_rand_Rz.

Referenced by ApproximateBestSubset().

+ Here is the caller graph for this function:

void SetMockTime ( int64_t  nMockTimeIn)

Definition at line 1222 of file util.cpp.

References nMockTime.

void SetThreadPriority ( int  nPriority)
inline

Definition at line 495 of file util.h.

Referenced by ThreadMessageHandler().

+ Here is the caller graph for this function:

void SetupEnvironment ( )

Definition at line 1412 of file util.cpp.

Referenced by main().

+ Here is the caller graph for this function:

void ShrinkDebugFile ( )

Definition at line 1182 of file util.cpp.

References GetDataDir().

Referenced by AppInit2().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
void skipspaces ( T &  it)

Definition at line 326 of file util.h.

bool SoftSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Set an argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
strValueValue (e.g. "1")
Returns
true if argument gets set, false if it already had a value

Definition at line 530 of file util.cpp.

Referenced by OptionsModel::Init(), Intro::pickDataDirectory(), and SoftSetBoolArg().

+ Here is the caller graph for this function:

bool SoftSetBoolArg ( const std::string &  strArg,
bool  fValue 
)

Set a boolean argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
fValueValue (e.g. false)
Returns
true if argument gets set, false if it already had a value

Definition at line 538 of file util.cpp.

References SoftSetArg().

Referenced by AppInit(), AppInit2(), OptionsModel::Init(), and CWalletDB::LoadWallet().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
bool TimingResistantEqual ( const T &  a,
const T &  b 
)

Timing-attack-resistant comparison.

Takes time proportional to length of first argument.

Definition at line 414 of file util.h.

Referenced by HTTPAuthorized().

+ Here is the caller graph for this function:

template<typename Callable >
void TraceThread ( const char *  name,
Callable  func 
)

Definition at line 550 of file util.h.

References LogPrintf, PrintExceptionContinue(), RenameThread(), and strprintf.

Referenced by Discover(), and StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 1109 of file util.cpp.

Referenced by FlushBlockFile().

+ Here is the caller graph for this function:

bool TryCreateDirectory ( const boost::filesystem::path &  p)

Definition at line 1078 of file util.cpp.

Referenced by CLevelDBWrapper::CLevelDBWrapper(), GetDefaultDataDir(), CDBEnv::Open(), and Intro::pickDataDirectory().

+ Here is the caller graph for this function:

bool WildcardMatch ( const char *  psz,
const char *  mask 
)

Definition at line 875 of file util.cpp.

References WildcardMatch().

Referenced by ClientAllowed(), and WildcardMatch().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool WildcardMatch ( const std::string &  str,
const std::string &  mask 
)

Definition at line 899 of file util.cpp.

References WildcardMatch().

+ Here is the call graph for this function:

Variable Documentation

const int64_t CENT = 1000000
static
const int64_t COIN = 100000000
static
bool fDebug
bool fLogTimestamps

Definition at line 98 of file util.cpp.

Referenced by AppInit2(), LogPrintStr(), and mp_LogPrintStr().

bool fNoListen

Definition at line 97 of file util.cpp.

Referenced by AppInit2(), GetLocal(), ProcessMessage(), and SendMessages().

bool fPrintToConsole

Definition at line 92 of file util.cpp.

Referenced by AppInit2(), LogPrintStr(), and mp_LogPrintStr().

bool fPrintToDebugLog

Definition at line 93 of file util.cpp.

Referenced by LogPrintStr(), and mp_LogPrintStr().

volatile bool fReopenDebugLog

Definition at line 99 of file util.cpp.

Referenced by HandleSIGHUP(), LogPrintStr(), and mp_LogPrintStr().

bool fServer

Definition at line 95 of file util.cpp.

Referenced by AppInit2().

uint32_t insecure_rand_Rw

Definition at line 1297 of file util.cpp.

Referenced by insecure_rand(), and seed_insecure_rand().

uint32_t insecure_rand_Rz

MWC RNG of George Marsaglia This is intended to be fast.

It has a period of 2^59.3, though the least significant 16 bits only have a period of about 2^30.1.

Returns
random value

Definition at line 1296 of file util.cpp.

Referenced by insecure_rand(), and seed_insecure_rand().

std::map<std::string, std::string> mapArgs
std::map<std::string, std::vector<std::string> > mapMultiArgs
std::string strMiscWarning