Raven Core  3.0.0
P2P Digital Currency
Classes | Functions | Variables
util.cpp File Reference
#include "util.h"
#include "init.h"
#include "chainparamsbase.h"
#include "fs.h"
#include "random.h"
#include "serialize.h"
#include "utilstrencodings.h"
#include "utiltime.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/predicate.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <openssl/conf.h>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

class  CInit
 
struct  CLogCategoryDesc
 

Functions

std::atomic< bool > fReopenDebugLog (false)
 
std::atomic< uint32_t > logCategories (0)
 Log categories bitfield. More...
 
void locking_callback (int mode, int i, const char *file, int line) NO_THREAD_SAFETY_ANALYSIS
 
void OpenDebugLog ()
 
bool GetLogCategory (uint32_t *f, const std::string *str)
 Return true if str parses as a log category and set the flags in f. More...
 
std::string ListLogCategories ()
 Returns a string with the log categories. More...
 
std::vector< CLogCategoryActiveListActiveLogCategories ()
 Returns a vector of the active log categories. More...
 
int LogPrintStr (const std::string &str)
 Send a string to the log output. More...
 
std::string HelpMessageGroup (const std::string &message)
 Format a string to be used as group of options in help messages. More...
 
std::string HelpMessageOpt (const std::string &option, const std::string &message)
 Format a string to be used as option description in help messages. More...
 
void PrintExceptionContinue (const std::exception *pex, const char *pszThread)
 
fs::path GetDefaultDataDir ()
 
const fs::path & GetDataDir (bool fNetSpecific)
 
void ClearDatadirCache ()
 
fs::path GetConfigFile (const std::string &confPath)
 
fs::path GetPidFile ()
 
void CreatePidFile (const fs::path &path, pid_t pid)
 
bool RenameOver (fs::path src, fs::path dest)
 
bool TryCreateDirectories (const fs::path &p)
 Ignores exceptions thrown by Boost's create_directories if the requested directory exists. More...
 
void FileCommit (FILE *file)
 
bool TruncateFile (FILE *file, unsigned int length)
 
int RaiseFileDescriptorLimit (int nMinFD)
 this function tries to raise the file descriptor limit to the requested number. More...
 
void AllocateFileRange (FILE *file, unsigned int offset, unsigned int length)
 this function tries to make a particular range of a file allocated (corresponding to disk space) it is advisory, and the range specified in the arguments will never contain live data More...
 
void ShrinkDebugFile ()
 
void runCommand (const std::string &strCommand)
 
void RenameThread (const char *name)
 
void SetupEnvironment ()
 
bool SetupNetworking ()
 
int GetNumCores ()
 Return the number of physical cores available on the current system. More...
 
std::string CopyrightHolders (const std::string &strPrefix)
 
int64_t GetStartupTime ()
 Server/client environment: argument handling, config file parsing, logging, thread wrappers, startup time. More...
 
void SetThreadPriority (int nPriority)
 

Variables

const int64_t nStartupTime = GetTime()
 
const char *const RAVEN_CONF_FILENAME = "raven.conf"
 
const char *const RAVEN_PID_FILENAME = "ravend.pid"
 
ArgsManager gArgs
 
bool fPrintToConsole = false
 
bool fPrintToDebugLog = true
 
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS
 
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS
 
bool fLogIPs = DEFAULT_LOGIPS
 
CTranslationInterface translationInterface
 
class CInit instance_of_cinit
 
const CLogCategoryDesc LogCategories []
 

Function Documentation

◆ AllocateFileRange()

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

this function tries to make a particular range of a file allocated (corresponding to disk space) it is advisory, and the range specified in the arguments will never contain live data

Definition at line 755 of file util.cpp.

Here is the caller graph for this function:

◆ ClearDatadirCache()

void ClearDatadirCache ( )

Definition at line 604 of file util.cpp.

Here is the caller graph for this function:

◆ CopyrightHolders()

std::string CopyrightHolders ( const std::string &  strPrefix)

Definition at line 917 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePidFile()

void CreatePidFile ( const fs::path &  path,
pid_t  pid 
)

Definition at line 656 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileCommit()

void FileCommit ( FILE *  file)

Definition at line 699 of file util.cpp.

Here is the caller graph for this function:

◆ fReopenDebugLog()

std::atomic<bool> fReopenDebugLog ( false  )

◆ GetConfigFile()

fs::path GetConfigFile ( const std::string &  confPath)

Definition at line 612 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDataDir()

const fs::path& GetDataDir ( bool  fNetSpecific)

Definition at line 572 of file util.cpp.

Here is the caller graph for this function:

◆ GetDefaultDataDir()

fs::path GetDefaultDataDir ( )

Definition at line 542 of file util.cpp.

Here is the caller graph for this function:

◆ GetLogCategory()

bool GetLogCategory ( uint32_t *  f,
const std::string *  str 
)

Return true if str parses as a log category and set the flags in f.

Definition at line 256 of file util.cpp.

Here is the caller graph for this function:

◆ GetNumCores()

int GetNumCores ( )

Return the number of physical cores available on the current system.

Note
This does not count virtual cores, such as those provided by HyperThreading when boost is newer than 1.56.

Definition at line 908 of file util.cpp.

Here is the caller graph for this function:

◆ GetPidFile()

fs::path GetPidFile ( )

Definition at line 649 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetStartupTime()

int64_t GetStartupTime ( )

Server/client environment: argument handling, config file parsing, logging, thread wrappers, startup time.

Definition at line 930 of file util.cpp.

Here is the caller graph for this function:

◆ HelpMessageGroup()

std::string HelpMessageGroup ( const std::string &  message)

Format a string to be used as group of options in help messages.

Parameters
messageGroup name (e.g. "RPC server options:")
Returns
the formatted string

Definition at line 506 of file util.cpp.

Here is the caller graph for this function:

◆ HelpMessageOpt()

std::string HelpMessageOpt ( const std::string &  option,
const std::string &  message 
)

Format a string to be used as option description in help messages.

Parameters
optionOption message (e.g. "-rpcuser=<user>")
messageOption description (e.g. "Username for JSON-RPC connections")
Returns
the formatted string

Definition at line 511 of file util.cpp.

Here is the caller graph for this function:

◆ ListActiveLogCategories()

std::vector<CLogCategoryActive> ListActiveLogCategories ( )

Returns a vector of the active log categories.

Definition at line 294 of file util.cpp.

Here is the caller graph for this function:

◆ ListLogCategories()

std::string ListLogCategories ( )

Returns a string with the log categories.

Definition at line 277 of file util.cpp.

Here is the caller graph for this function:

◆ locking_callback()

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

Definition at line 110 of file util.cpp.

◆ logCategories()

std::atomic<uint32_t> logCategories ( )

Log categories bitfield.

◆ LogPrintStr()

int LogPrintStr ( const std::string &  str)

Send a string to the log output.

Definition at line 346 of file util.cpp.

Here is the caller graph for this function:

◆ OpenDebugLog()

void OpenDebugLog ( )

Definition at line 198 of file util.cpp.

Here is the caller graph for this function:

◆ PrintExceptionContinue()

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

Definition at line 535 of file util.cpp.

Here is the caller graph for this function:

◆ RaiseFileDescriptorLimit()

int RaiseFileDescriptorLimit ( int  nMinFD)

this function tries to raise the file descriptor limit to the requested number.

It returns the actual file descriptor limit (which may be more or less than nMinFD)

Definition at line 729 of file util.cpp.

Here is the caller graph for this function:

◆ RenameOver()

bool RenameOver ( fs::path  src,
fs::path  dest 
)

Definition at line 668 of file util.cpp.

Here is the caller graph for this function:

◆ RenameThread()

void RenameThread ( const char *  name)

Definition at line 849 of file util.cpp.

Here is the caller graph for this function:

◆ runCommand()

void runCommand ( const std::string &  strCommand)

Definition at line 841 of file util.cpp.

Here is the caller graph for this function:

◆ SetThreadPriority()

void SetThreadPriority ( int  nPriority)

Definition at line 935 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupEnvironment()

void SetupEnvironment ( )

Definition at line 865 of file util.cpp.

Here is the caller graph for this function:

◆ SetupNetworking()

bool SetupNetworking ( )

Definition at line 896 of file util.cpp.

Here is the caller graph for this function:

◆ ShrinkDebugFile()

void ShrinkDebugFile ( )

Definition at line 799 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TruncateFile()

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 716 of file util.cpp.

Here is the caller graph for this function:

◆ TryCreateDirectories()

bool TryCreateDirectories ( const fs::path &  p)

Ignores exceptions thrown by Boost's create_directories if the requested directory exists.

Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory.

Definition at line 684 of file util.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ fLogIPs

bool fLogIPs = DEFAULT_LOGIPS

Definition at line 100 of file util.cpp.

◆ fLogTimeMicros

bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS

Definition at line 99 of file util.cpp.

◆ fLogTimestamps

bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS

Definition at line 98 of file util.cpp.

◆ fPrintToConsole

bool fPrintToConsole = false

Definition at line 95 of file util.cpp.

◆ fPrintToDebugLog

bool fPrintToDebugLog = true

Definition at line 96 of file util.cpp.

◆ gArgs

ArgsManager gArgs

Definition at line 94 of file util.cpp.

◆ instance_of_cinit

class CInit instance_of_cinit

◆ LogCategories

const CLogCategoryDesc LogCategories[]
Initial value:
=
{
{BCLog::NONE, "0"},
{BCLog::NET, "net"},
{BCLog::TOR, "tor"},
{BCLog::MEMPOOL, "mempool"},
{BCLog::HTTP, "http"},
{BCLog::BENCH, "bench"},
{BCLog::ZMQ, "zmq"},
{BCLog::DB, "db"},
{BCLog::RPC, "rpc"},
{BCLog::ESTIMATEFEE, "estimatefee"},
{BCLog::ADDRMAN, "addrman"},
{BCLog::SELECTCOINS, "selectcoins"},
{BCLog::REINDEX, "reindex"},
{BCLog::CMPCTBLOCK, "cmpctblock"},
{BCLog::RAND, "rand"},
{BCLog::PRUNE, "prune"},
{BCLog::PROXY, "proxy"},
{BCLog::MEMPOOLREJ, "mempoolrej"},
{BCLog::LIBEVENT, "libevent"},
{BCLog::COINDB, "coindb"},
{BCLog::QT, "qt"},
{BCLog::LEVELDB, "leveldb"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
}
Definition: util.h:93

Definition at line 228 of file util.cpp.

◆ nStartupTime

const int64_t nStartupTime = GetTime()

Definition at line 89 of file util.cpp.

◆ RAVEN_CONF_FILENAME

const char* const RAVEN_CONF_FILENAME = "raven.conf"

Definition at line 91 of file util.cpp.

◆ RAVEN_PID_FILENAME

const char* const RAVEN_PID_FILENAME = "ravend.pid"

Definition at line 92 of file util.cpp.

◆ translationInterface

CTranslationInterface translationInterface

Definition at line 102 of file util.cpp.