Anoncoin  0.9.4
P2P Digital Currency
Classes | Functions | Variables
util.cpp File Reference
#include "util.h"
#include "chainparams.h"
#include "netbase.h"
#include "sync.h"
#include "ui_interface.h"
#include "uint256.h"
#include "version.h"
#include <stdarg.h>
#include <algorithm>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

class  CInit
 

Functions

void locking_callback (int mode, int i, const char *file, int line)
 
void RandAddSeed ()
 
void RandAddSeedPerfmon ()
 
uint64_t GetRand (uint64_t nMax)
 
int GetRandInt (int nMax)
 
uint256 GetRandHash ()
 
bool LogAcceptCategory (const char *category)
 
int LogPrintStr (const std::string &str)
 
string FormatMoney (int64_t n, bool fPlus)
 
bool ParseMoney (const string &str, int64_t &nRet)
 
bool ParseMoney (const char *pszIn, int64_t &nRet)
 
string SanitizeString (const string &str)
 
bool IsHex (const string &str)
 
vector< unsigned char > ParseHex (const char *psz)
 
vector< unsigned char > ParseHex (const string &str)
 
void ParseParameters (int argc, const char *const argv[])
 
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...
 
string EncodeBase64 (const unsigned char *pch, size_t len)
 
string EncodeBase64 (const string &str)
 
vector< unsigned char > DecodeBase64 (const char *p, bool *pfInvalid)
 
string DecodeBase64 (const string &str)
 
string EncodeBase32 (const unsigned char *pch, size_t len)
 
string EncodeBase32 (const string &str)
 
vector< unsigned char > DecodeBase32 (const char *p, bool *pfInvalid)
 
string DecodeBase32 (const string &str)
 
bool WildcardMatch (const char *psz, const char *mask)
 
bool WildcardMatch (const string &str, const string &mask)
 
void LogException (std::exception *pex, const char *pszThread)
 
void PrintExceptionContinue (std::exception *pex, const char *pszThread)
 
boost::filesystem::path GetDefaultDataDir ()
 
const boost::filesystem::path & GetDataDir (bool fNetSpecific)
 
void ClearDatadirCache ()
 
boost::filesystem::path GetConfigFile ()
 
boost::filesystem::path GetQtStyleFile ()
 
void ReadConfigFile (map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
 
boost::filesystem::path GetPidFile ()
 
void CreatePidFile (const boost::filesystem::path &path, pid_t pid)
 
bool RenameOver (boost::filesystem::path src, boost::filesystem::path dest)
 
bool TryCreateDirectory (const boost::filesystem::path &p)
 
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)
 
void ShrinkDebugFile ()
 
int64_t GetTime ()
 
void SetMockTime (int64_t nMockTimeIn)
 
int64_t GetTimeOffset ()
 
int64_t GetAdjustedTime ()
 
void AddTimeData (const CNetAddr &ip, int64_t nTime)
 
void seed_insecure_rand (bool fDeterministic)
 Seed insecure_rand using the random pool. More...
 
boost::filesystem::path GetTempPath ()
 
void runCommand (std::string strCommand)
 
void RenameThread (const char *name)
 
void SetupEnvironment ()
 
std::string DateTimeStrFormat (const char *pszFormat, int64_t nTime)
 

Variables

map< string, string > mapArgs
 
map< string, vector< string > > mapMultiArgs
 
bool fDebug = false
 
bool fPrintToConsole = false
 
bool fPrintToDebugLog = true
 
bool fDaemon = false
 
bool fServer = false
 
string strMiscWarning
 
bool fNoListen = false
 
bool fLogTimestamps = false
 
volatile bool fReopenDebugLog = false
 
CClientUIInterface uiInterface
 
class CInit instance_of_cinit
 
const signed char p_util_hexdigit [256]
 
uint32_t insecure_rand_Rz = 11
 MWC RNG of George Marsaglia This is intended to be fast. More...
 
uint32_t insecure_rand_Rw = 11
 

Function Documentation

void AddTimeData ( const CNetAddr ip,
int64_t  nTime 
)

Definition at line 1246 of file util.cpp.

Here is the call graph for this function:

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

Definition at line 1145 of file util.cpp.

Here is the caller graph for this function:

void ClearDatadirCache ( )

Definition at line 1001 of file util.cpp.

Here is the caller graph for this function:

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

Definition at line 1058 of file util.cpp.

Here is the caller graph for this function:

std::string DateTimeStrFormat ( const char *  pszFormat,
int64_t  nTime 
)

Definition at line 1411 of file util.cpp.

Here is the caller graph for this function:

vector<unsigned char> DecodeBase32 ( const char *  p,
bool *  pfInvalid 
)

Definition at line 752 of file util.cpp.

Here is the caller graph for this function:

string DecodeBase32 ( const string &  str)

Definition at line 869 of file util.cpp.

Here is the call graph for this function:

vector<unsigned char> DecodeBase64 ( const char *  p,
bool *  pfInvalid 
)

Definition at line 599 of file util.cpp.

Here is the caller graph for this function:

string DecodeBase64 ( const string &  str)

Definition at line 682 of file util.cpp.

Here is the call graph for this function:

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

Definition at line 688 of file util.cpp.

Here is the caller graph for this function:

string EncodeBase32 ( const string &  str)

Definition at line 747 of file util.cpp.

Here is the call graph for this function:

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

Definition at line 548 of file util.cpp.

Here is the caller graph for this function:

string EncodeBase64 ( const string &  str)

Definition at line 594 of file util.cpp.

Here is the call graph for this function:

void FileCommit ( FILE *  fileout)

Definition at line 1097 of file util.cpp.

Here is the caller graph for this function:

string FormatMoney ( int64_t  n,
bool  fPlus 
)

Definition at line 308 of file util.cpp.

Here is the caller graph for this function:

int64_t GetAdjustedTime ( )

Definition at line 1241 of file util.cpp.

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 506 of file util.cpp.

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 513 of file util.cpp.

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 520 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::filesystem::path GetConfigFile ( )

Definition at line 1007 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 968 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::filesystem::path GetDefaultDataDir ( )

Definition at line 936 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::filesystem::path GetPidFile ( )

Definition at line 1050 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::filesystem::path GetQtStyleFile ( )

Definition at line 1014 of file util.cpp.

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.

Here is the caller graph for this function:

uint256 GetRandHash ( )

Definition at line 206 of file util.cpp.

Here is the caller graph for this function:

int GetRandInt ( int  nMax)

Definition at line 201 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

boost::filesystem::path GetTempPath ( )

Definition at line 1339 of file util.cpp.

int64_t GetTime ( )

Definition at line 1220 of file util.cpp.

Here is the caller graph for this function:

int64_t GetTimeOffset ( )

Definition at line 1235 of file util.cpp.

Here is the caller graph for this function:

bool IsHex ( const string &  str)

Definition at line 409 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void locking_callback ( int  mode,
int  i,
const char *  file,
int  line 
)

Definition at line 104 of file util.cpp.

Here is the caller graph for this function:

bool LogAcceptCategory ( const char *  category)

Definition at line 240 of file util.cpp.

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

Definition at line 922 of file util.cpp.

int LogPrintStr ( const std::string &  str)

Definition at line 268 of file util.cpp.

Here is the call graph for this function:

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

Definition at line 419 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 440 of file util.cpp.

Here is the call graph for this function:

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

Definition at line 332 of file util.cpp.

Here is the caller graph for this function:

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

Definition at line 337 of file util.cpp.

Here is the call graph for this function:

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

Definition at line 460 of file util.cpp.

Here is the caller graph for this function:

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

Definition at line 928 of file util.cpp.

Here is the caller graph for this function:

int RaiseFileDescriptorLimit ( int  nMinFD)

Definition at line 1124 of file util.cpp.

Here is the caller graph for this function:

void RandAddSeed ( )

Definition at line 151 of file util.cpp.

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1021 of file util.cpp.

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 1069 of file util.cpp.

Here is the caller graph for this function:

void RenameThread ( const char *  name)

Definition at line 1368 of file util.cpp.

Here is the caller graph for this function:

void runCommand ( std::string  strCommand)

Definition at line 1361 of file util.cpp.

Here is the caller graph for this function:

string SanitizeString ( const string &  str)

Definition at line 380 of file util.cpp.

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 1303 of file util.cpp.

void SetMockTime ( int64_t  nMockTimeIn)

Definition at line 1227 of file util.cpp.

void SetupEnvironment ( )

Definition at line 1394 of file util.cpp.

Here is the caller graph for this function:

void ShrinkDebugFile ( )

Definition at line 1187 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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 531 of file util.cpp.

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 539 of file util.cpp.

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 1114 of file util.cpp.

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

Definition at line 1083 of file util.cpp.

Here is the caller graph for this function:

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

Definition at line 876 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 900 of file util.cpp.

Here is the call graph for this function:

Variable Documentation

bool fDaemon = false

Definition at line 94 of file util.cpp.

bool fDebug = false

Definition at line 91 of file util.cpp.

bool fLogTimestamps = false

Definition at line 98 of file util.cpp.

bool fNoListen = false

Definition at line 97 of file util.cpp.

bool fPrintToConsole = false

Definition at line 92 of file util.cpp.

bool fPrintToDebugLog = true

Definition at line 93 of file util.cpp.

volatile bool fReopenDebugLog = false

Definition at line 99 of file util.cpp.

bool fServer = false

Definition at line 95 of file util.cpp.

uint32_t insecure_rand_Rw = 11

Definition at line 1302 of file util.cpp.

uint32_t insecure_rand_Rz = 11

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 1301 of file util.cpp.

class CInit instance_of_cinit
map<string, string> mapArgs

Definition at line 89 of file util.cpp.

map<string, vector<string> > mapMultiArgs

Definition at line 90 of file util.cpp.

const signed char p_util_hexdigit[256]
Initial value:
=
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, }

Definition at line 391 of file util.cpp.

string strMiscWarning

Definition at line 96 of file util.cpp.

CClientUIInterface uiInterface

Definition at line 100 of file util.cpp.