Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
util.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_UTIL_H
7 #define BITCOIN_UTIL_H
8 
9 #if defined(HAVE_CONFIG_H)
10 #include "bitcoin-config.h"
11 #endif
12 
13 #include "compat.h"
14 #include "serialize.h"
15 #include "tinyformat.h"
16 
17 #include <cstdio>
18 #include <exception>
19 #include <map>
20 #include <stdarg.h>
21 #include <stdint.h>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 #ifndef WIN32
27 #include <sys/resource.h>
28 #include <sys/time.h>
29 #include <sys/types.h>
30 #endif
31 
32 #include <boost/filesystem/path.hpp>
33 #include <boost/thread.hpp>
34 
35 class CNetAddr;
36 class uint256;
37 
38 static const int64_t COIN = 100000000;
39 static const int64_t CENT = 1000000;
40 
41 #define BEGIN(a) ((char*)&(a))
42 #define END(a) ((char*)&((&(a))[1]))
43 #define UBEGIN(a) ((unsigned char*)&(a))
44 #define UEND(a) ((unsigned char*)&((&(a))[1]))
45 #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
46 
47 // This is needed because the foreach macro can't get over the comma in pair<t1, t2>
48 #define PAIRTYPE(t1, t2) std::pair<t1, t2>
49 
50 // Align by increasing pointer, must have extra space at end of buffer
51 template <size_t nBytes, typename T>
52 T* alignup(T* p)
53 {
54  union
55  {
56  T* ptr;
57  size_t n;
58  } u;
59  u.ptr = p;
60  u.n = (u.n + (nBytes-1)) & ~(nBytes-1);
61  return u.ptr;
62 }
63 
64 #ifdef WIN32
65 #define MSG_DONTWAIT 0
66 
67 #ifndef S_IRUSR
68 #define S_IRUSR 0400
69 #define S_IWUSR 0200
70 #endif
71 #else
72 #define MAX_PATH 1024
73 #endif
74 // As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0
75 #if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
76 #define MSG_NOSIGNAL 0
77 #endif
78 
79 inline void MilliSleep(int64_t n)
80 {
81 // Boost's sleep_for was uninterruptable when backed by nanosleep from 1.50
82 // until fixed in 1.52. Use the deprecated sleep method for the broken case.
83 // See: https://svn.boost.org/trac/boost/ticket/7238
84 #if defined(HAVE_WORKING_BOOST_SLEEP_FOR)
85  boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
86 #elif defined(HAVE_WORKING_BOOST_SLEEP)
87  boost::this_thread::sleep(boost::posix_time::milliseconds(n));
88 #else
89 //should never get here
90 #error missing boost sleep implementation
91 #endif
92 }
93 
94 
95 
96 extern std::map<std::string, std::string> mapArgs;
97 extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
98 extern bool fDebug;
99 extern bool fPrintToConsole;
100 extern bool fPrintToDebugLog;
101 extern bool fServer;
102 extern std::string strMiscWarning;
103 extern bool fNoListen;
104 extern bool fLogTimestamps;
105 extern volatile bool fReopenDebugLog;
106 
107 void RandAddSeed();
108 void RandAddSeedPerfmon();
109 void SetupEnvironment();
110 
111 /* Return true if log accepts specified category */
112 bool LogAcceptCategory(const char* category);
113 /* Send a string to the log output */
114 int LogPrintStr(const std::string &str);
115 
116 #define strprintf tfm::format
117 #define LogPrintf(...) LogPrint(NULL, __VA_ARGS__)
118 
119 /* When we switch to C++11, this can be switched to variadic templates instead
120  * of this macro-based construction (see tinyformat.h).
121  */
122 #define MAKE_ERROR_AND_LOG_FUNC(n) \
123  /* Print to debug.log if -debug=category switch is given OR category is NULL. */ \
124  template<TINYFORMAT_ARGTYPES(n)> \
125  static inline int LogPrint(const char* category, const char* format, TINYFORMAT_VARARGS(n)) \
126  { \
127  if(!LogAcceptCategory(category)) return 0; \
128  return LogPrintStr(tfm::format(format, TINYFORMAT_PASSARGS(n))); \
129  } \
130  /* Log error and return false */ \
131  template<TINYFORMAT_ARGTYPES(n)> \
132  static inline bool error(const char* format, TINYFORMAT_VARARGS(n)) \
133  { \
134  LogPrintStr("ERROR: " + tfm::format(format, TINYFORMAT_PASSARGS(n)) + "\n"); \
135  return false; \
136  }
137 
139 
140 /* Zero-arg versions of logging and error, these are not covered by
141  * TINYFORMAT_FOREACH_ARGNUM
142  */
143 static inline int LogPrint(const char* category, const char* format)
144 {
145  if(!LogAcceptCategory(category)) return 0;
146  return LogPrintStr(format);
147 }
148 static inline bool error(const char* format)
149 {
150  LogPrintStr(std::string("ERROR: ") + format + "\n");
151  return false;
152 }
153 
154 
155 void LogException(std::exception* pex, const char* pszThread);
156 void PrintExceptionContinue(std::exception* pex, const char* pszThread);
157 std::string FormatMoney(int64_t n, bool fPlus=false);
158 bool ParseMoney(const std::string& str, int64_t& nRet);
159 bool ParseMoney(const char* pszIn, int64_t& nRet);
160 std::string SanitizeString(const std::string& str);
161 std::vector<unsigned char> ParseHex(const char* psz);
162 std::vector<unsigned char> ParseHex(const std::string& str);
163 bool IsHex(const std::string& str);
164 std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid = NULL);
165 std::string DecodeBase64(const std::string& str);
166 std::string EncodeBase64(const unsigned char* pch, size_t len);
167 std::string EncodeBase64(const std::string& str);
168 std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid = NULL);
169 std::string DecodeBase32(const std::string& str);
170 std::string EncodeBase32(const unsigned char* pch, size_t len);
171 std::string EncodeBase32(const std::string& str);
172 void ParseParameters(int argc, const char*const argv[]);
173 bool WildcardMatch(const char* psz, const char* mask);
174 bool WildcardMatch(const std::string& str, const std::string& mask);
175 void FileCommit(FILE *fileout);
176 bool TruncateFile(FILE *file, unsigned int length);
177 int RaiseFileDescriptorLimit(int nMinFD);
178 void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
179 bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest);
180 bool TryCreateDirectory(const boost::filesystem::path& p);
181 boost::filesystem::path GetDefaultDataDir();
182 const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
183 boost::filesystem::path GetConfigFile();
184 boost::filesystem::path GetPidFile();
185 #ifndef WIN32
186 void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
187 #endif
188 void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
189 #ifdef WIN32
190 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
191 #endif
192 boost::filesystem::path GetTempPath();
193 void ShrinkDebugFile();
194 int GetRandInt(int nMax);
195 uint64_t GetRand(uint64_t nMax);
197 int64_t GetTime();
198 void SetMockTime(int64_t nMockTimeIn);
199 int64_t GetAdjustedTime();
200 int64_t GetTimeOffset();
201 std::string FormatFullVersion();
202 std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
203 void AddTimeData(const CNetAddr& ip, int64_t nTime);
204 void runCommand(std::string strCommand);
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 inline std::string i64tostr(int64_t n)
215 {
216  return strprintf("%d", n);
217 }
218 
219 inline std::string itostr(int n)
220 {
221  return strprintf("%d", n);
222 }
223 
224 inline int64_t atoi64(const char* psz)
225 {
226 #ifdef _MSC_VER
227  return _atoi64(psz);
228 #else
229  return strtoll(psz, NULL, 10);
230 #endif
231 }
232 
233 inline int64_t atoi64(const std::string& str)
234 {
235 #ifdef _MSC_VER
236  return _atoi64(str.c_str());
237 #else
238  return strtoll(str.c_str(), NULL, 10);
239 #endif
240 }
241 
242 inline int atoi(const std::string& str)
243 {
244  return atoi(str.c_str());
245 }
246 
247 inline int roundint(double d)
248 {
249  return (int)(d > 0 ? d + 0.5 : d - 0.5);
250 }
251 
252 inline int64_t roundint64(double d)
253 {
254  return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
255 }
256 
257 inline int64_t abs64(int64_t n)
258 {
259  return (n >= 0 ? n : -n);
260 }
261 
262 template<typename T>
263 std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
264 {
265  std::string rv;
266  static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
267  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
268  rv.reserve((itend-itbegin)*3);
269  for(T it = itbegin; it < itend; ++it)
270  {
271  unsigned char val = (unsigned char)(*it);
272  if(fSpaces && it != itbegin)
273  rv.push_back(' ');
274  rv.push_back(hexmap[val>>4]);
275  rv.push_back(hexmap[val&15]);
276  }
277 
278  return rv;
279 }
280 
281 template<typename T>
282 inline std::string HexStr(const T& vch, bool fSpaces=false)
283 {
284  return HexStr(vch.begin(), vch.end(), fSpaces);
285 }
286 
287 template<typename T>
288 void PrintHex(const T pbegin, const T pend, const char* pszFormat="%s", bool fSpaces=true)
289 {
290  LogPrintf(pszFormat, HexStr(pbegin, pend, fSpaces).c_str());
291 }
292 
293 inline void PrintHex(const std::vector<unsigned char>& vch, const char* pszFormat="%s", bool fSpaces=true)
294 {
295  LogPrintf(pszFormat, HexStr(vch, fSpaces).c_str());
296 }
297 
298 inline int64_t GetPerformanceCounter()
299 {
300  int64_t nCounter = 0;
301 #ifdef WIN32
302  QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
303 #else
304  timeval t;
305  gettimeofday(&t, NULL);
306  nCounter = (int64_t) t.tv_sec * 1000000 + t.tv_usec;
307 #endif
308  return nCounter;
309 }
310 
311 inline int64_t GetTimeMillis()
312 {
313  return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
314  boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
315 }
316 
317 inline int64_t GetTimeMicros()
318 {
319  return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
320  boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
321 }
322 
323 std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);
324 
325 template<typename T>
326 void skipspaces(T& it)
327 {
328  while (isspace(*it))
329  ++it;
330 }
331 
332 inline bool IsSwitchChar(char c)
333 {
334 #ifdef WIN32
335  return c == '-' || c == '/';
336 #else
337  return c == '-';
338 #endif
339 }
340 
348 std::string GetArg(const std::string& strArg, const std::string& strDefault);
349 
357 int64_t GetArg(const std::string& strArg, int64_t nDefault);
358 
366 bool GetBoolArg(const std::string& strArg, bool fDefault);
367 
375 bool SoftSetArg(const std::string& strArg, const std::string& strValue);
376 
384 bool SoftSetBoolArg(const std::string& strArg, bool fValue);
385 
393 extern uint32_t insecure_rand_Rz;
394 extern uint32_t insecure_rand_Rw;
395 static inline uint32_t insecure_rand(void)
396 {
397  insecure_rand_Rz = 36969 * (insecure_rand_Rz & 65535) + (insecure_rand_Rz >> 16);
398  insecure_rand_Rw = 18000 * (insecure_rand_Rw & 65535) + (insecure_rand_Rw >> 16);
399  return (insecure_rand_Rw << 16) + insecure_rand_Rz;
400 }
401 
406 void seed_insecure_rand(bool fDeterministic=false);
407 
413 template <typename T>
414 bool TimingResistantEqual(const T& a, const T& b)
415 {
416  if (b.size() == 0) return a.size() == 0;
417  size_t accumulator = a.size() ^ b.size();
418  for (size_t i = 0; i < a.size(); i++)
419  accumulator |= a[i] ^ b[i%b.size()];
420  return accumulator == 0;
421 }
422 
426 template <typename T> class CMedianFilter
427 {
428 private:
429  std::vector<T> vValues;
430  std::vector<T> vSorted;
431  unsigned int nSize;
432 public:
433  CMedianFilter(unsigned int size, T initial_value):
434  nSize(size)
435  {
436  vValues.reserve(size);
437  vValues.push_back(initial_value);
438  vSorted = vValues;
439  }
440 
441  void input(T value)
442  {
443  if(vValues.size() == nSize)
444  {
445  vValues.erase(vValues.begin());
446  }
447  vValues.push_back(value);
448 
449  vSorted.resize(vValues.size());
450  std::copy(vValues.begin(), vValues.end(), vSorted.begin());
451  std::sort(vSorted.begin(), vSorted.end());
452  }
453 
454  T median() const
455  {
456  int size = vSorted.size();
457  assert(size>0);
458  if(size & 1) // Odd number of elements
459  {
460  return vSorted[size/2];
461  }
462  else // Even number of elements
463  {
464  return (vSorted[size/2-1] + vSorted[size/2]) / 2;
465  }
466  }
467 
468  int size() const
469  {
470  return vValues.size();
471  }
472 
473  std::vector<T> sorted () const
474  {
475  return vSorted;
476  }
477 };
478 
479 #ifdef WIN32
480 inline void SetThreadPriority(int nPriority)
481 {
482  SetThreadPriority(GetCurrentThread(), nPriority);
483 }
484 #else
485 
486 // PRIO_MAX is not defined on Solaris
487 #ifndef PRIO_MAX
488 #define PRIO_MAX 20
489 #endif
490 #define THREAD_PRIORITY_LOWEST PRIO_MAX
491 #define THREAD_PRIORITY_BELOW_NORMAL 2
492 #define THREAD_PRIORITY_NORMAL 0
493 #define THREAD_PRIORITY_ABOVE_NORMAL (-2)
494 
495 inline void SetThreadPriority(int nPriority)
496 {
497  // It's unclear if it's even possible to change thread priorities on Linux,
498  // but we really and truly need it for the generation threads.
499 #ifdef PRIO_THREAD
500  setpriority(PRIO_THREAD, 0, nPriority);
501 #else
502  setpriority(PRIO_PROCESS, 0, nPriority);
503 #endif
504 }
505 #endif
506 
507 void RenameThread(const char* name);
508 
509 inline uint32_t ByteReverse(uint32_t value)
510 {
511  value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
512  return (value<<16) | (value>>16);
513 }
514 
515 // Standard wrapper for do-something-forever thread functions.
516 // "Forever" really means until the thread is interrupted.
517 // Use it like:
518 // new boost::thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, 900000));
519 // or maybe:
520 // boost::function<void()> f = boost::bind(&FunctionWithArg, argument);
521 // threadGroup.create_thread(boost::bind(&LoopForever<boost::function<void()> >, "nothing", f, milliseconds));
522 template <typename Callable> void LoopForever(const char* name, Callable func, int64_t msecs)
523 {
524  std::string s = strprintf("bitcoin-%s", name);
525  RenameThread(s.c_str());
526  LogPrintf("%s thread start\n", name);
527  try
528  {
529  while (1)
530  {
531  MilliSleep(msecs);
532  func();
533  }
534  }
535  catch (boost::thread_interrupted)
536  {
537  LogPrintf("%s thread stop\n", name);
538  throw;
539  }
540  catch (std::exception& e) {
541  PrintExceptionContinue(&e, name);
542  throw;
543  }
544  catch (...) {
545  PrintExceptionContinue(NULL, name);
546  throw;
547  }
548 }
549 // .. and a wrapper that just calls func once
550 template <typename Callable> void TraceThread(const char* name, Callable func)
551 {
552  std::string s = strprintf("bitcoin-%s", name);
553  RenameThread(s.c_str());
554  try
555  {
556  LogPrintf("%s thread start\n", name);
557  func();
558  LogPrintf("%s thread exit\n", name);
559  }
560  catch (boost::thread_interrupted)
561  {
562  LogPrintf("%s thread interrupt\n", name);
563  throw;
564  }
565  catch (std::exception& e) {
566  PrintExceptionContinue(&e, name);
567  throw;
568  }
569  catch (...) {
570  PrintExceptionContinue(NULL, name);
571  throw;
572  }
573 }
574 
575 #endif
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Definition: util.cpp:1331
void skipspaces(T &it)
Definition: util.h:326
uint64_t GetRand(uint64_t nMax)
Definition: util.cpp:186
static uint32_t insecure_rand(void)
Definition: util.h:395
void PrintHex(const T pbegin, const T pend, const char *pszFormat="%s", bool fSpaces=true)
Definition: util.h:288
void MilliSleep(int64_t n)
Definition: util.h:79
void ShrinkDebugFile()
Definition: util.cpp:1182
bool fPrintToConsole
Definition: util.cpp:92
void LogException(std::exception *pex, const char *pszThread)
Definition: util.cpp:927
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid=NULL)
Definition: util.cpp:751
void SetMockTime(int64_t nMockTimeIn)
Definition: util.cpp:1222
int64_t GetAdjustedTime()
Definition: util.cpp:1236
void RandAddSeedPerfmon()
Definition: util.cpp:159
std::string i64tostr(int64_t n)
Definition: util.h:214
void RenameThread(const char *name)
Definition: util.cpp:1388
Median filter over a stream of values.
Definition: util.h:426
void ReadConfigFile(std::map< std::string, std::string > &mapSettingsRet, std::map< std::string, std::vector< std::string > > &mapMultiSettingsRet)
Definition: util.cpp:1019
#define strprintf
Definition: util.h:116
static FILE * fileout
Definition: mastercore.cpp:189
std::string SanitizeString(const std::string &str)
Definition: util.cpp:380
int GetRandInt(int nMax)
Definition: util.cpp:201
std::map< std::string, std::vector< std::string > > mapMultiArgs
Definition: util.cpp:90
std::vector< T > vSorted
Definition: util.h:430
std::string FormatFullVersion()
Definition: util.cpp:1325
void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
Definition: util.cpp:1053
void SetupEnvironment()
Definition: util.cpp:1412
int64_t GetTime()
Definition: util.cpp:1215
std::map< std::string, std::string > mapArgs
Definition: util.cpp:89
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
Definition: util.cpp:530
std::vector< unsigned char > ParseHex(const char *psz)
Definition: util.cpp:419
std::vector< T > vValues
Definition: util.h:429
int64_t GetTimeOffset()
Definition: util.cpp:1230
#define LogPrintf(...)
Definition: util.h:117
const boost::filesystem::path & GetDataDir(bool fNetSpecific=true)
Definition: util.cpp:973
void RandAddSeed()
Definition: util.cpp:151
static int LogPrint(const char *category, const char *format)
Definition: util.h:143
void input(T value)
Definition: util.h:441
std::string itostr(int n)
Definition: util.h:219
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: util.cpp:538
bool fNoListen
Definition: util.cpp:97
int64_t atoi64(const char *psz)
Definition: util.h:224
void TraceThread(const char *name, Callable func)
Definition: util.h:550
bool ParseMoney(const std::string &str, int64_t &nRet)
Definition: util.cpp:332
CMedianFilter(unsigned int size, T initial_value)
Definition: util.h:433
static bool error(const char *format)
Definition: util.h:148
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:460
T median() const
Definition: util.h:454
uint256 GetRandHash()
Definition: util.cpp:206
int64_t GetTimeMillis()
Definition: util.h:311
int64_t GetTimeMicros()
Definition: util.h:317
bool fServer
Definition: util.cpp:95
T * alignup(T *p)
Definition: util.h:52
bool IsHex(const std::string &str)
Definition: util.cpp:409
std::string EncodeBase64(const unsigned char *pch, size_t len)
Definition: util.cpp:547
#define MAKE_ERROR_AND_LOG_FUNC(n)
Definition: util.h:122
void SetThreadPriority(int nPriority)
Definition: util.h:495
void PrintExceptionContinue(std::exception *pex, const char *pszThread)
Definition: util.cpp:933
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid=NULL)
Definition: util.cpp:598
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netbase.h:40
std::string EncodeBase32(const unsigned char *pch, size_t len)
Definition: util.cpp:687
int size() const
Definition: util.h:468
256-bit unsigned integer
Definition: uint256.h:531
int64_t GetPerformanceCounter()
Definition: util.h:298
static const int64_t COIN
Definition: util.h:38
std::string strMiscWarning
Definition: util.cpp:96
bool IsSwitchChar(char c)
Definition: util.h:332
uint32_t insecure_rand_Rz
MWC RNG of George Marsaglia This is intended to be fast.
Definition: util.cpp:1296
std::string FormatMoney(int64_t n, bool fPlus=false)
Definition: util.cpp:308
bool TryCreateDirectory(const boost::filesystem::path &p)
Definition: util.cpp:1078
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
Definition: util.cpp:1064
uint32_t ByteReverse(uint32_t value)
Definition: util.h:509
void FileCommit(FILE *fileout)
Definition: util.cpp:1092
bool fDebug
Definition: util.cpp:91
boost::filesystem::path GetConfigFile()
Definition: util.cpp:1012
void seed_insecure_rand(bool fDeterministic=false)
Seed insecure_rand using the random pool.
Definition: util.cpp:1298
boost::filesystem::path GetTempPath()
Definition: util.cpp:1359
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:505
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
Definition: util.h:414
bool WildcardMatch(const char *psz, const char *mask)
Definition: util.cpp:875
bool LogAcceptCategory(const char *category)
Definition: util.cpp:240
static const int64_t CENT
Definition: util.h:39
int RaiseFileDescriptorLimit(int nMinFD)
Definition: util.cpp:1119
std::vector< T > sorted() const
Definition: util.h:473
int64_t roundint64(double d)
Definition: util.h:252
boost::filesystem::path GetPidFile()
Definition: util.cpp:1045
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
Definition: util.cpp:1140
bool TruncateFile(FILE *file, unsigned int length)
Definition: util.cpp:1109
unsigned int nSize
Definition: util.h:431
int64_t abs64(int64_t n)
Definition: util.h:257
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:263
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:519
int LogPrintStr(const std::string &str)
Definition: util.cpp:268
volatile bool fReopenDebugLog
Definition: util.cpp:99
#define TINYFORMAT_FOREACH_ARGNUM(m)
Definition: tinyformat.h:429
bool fLogTimestamps
Definition: util.cpp:98
void LoopForever(const char *name, Callable func, int64_t msecs)
Definition: util.h:522
void format(FormatIterator &fmtIter)
Definition: tinyformat.h:869
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
Definition: util.cpp:1429
boost::filesystem::path GetDefaultDataDir()
Definition: util.cpp:941
uint32_t insecure_rand_Rw
Definition: util.cpp:1297
int roundint(double d)
Definition: util.h:247
int atoi(const std::string &str)
Definition: util.h:242
void runCommand(std::string strCommand)
Definition: util.cpp:1381
bool fPrintToDebugLog
Definition: util.cpp:93
void AddTimeData(const CNetAddr &ip, int64_t nTime)
Definition: util.cpp:1241