22 #ifdef _POSIX_C_SOURCE
23 #undef _POSIX_C_SOURCE
26 #define _POSIX_C_SOURCE 200112L
27 #include <sys/prctl.h>
32 #include <sys/resource.h>
38 #pragma warning(disable:4786)
39 #pragma warning(disable:4804)
40 #pragma warning(disable:4805)
41 #pragma warning(disable:4717)
47 #define _WIN32_WINNT 0x0501
52 #define _WIN32_IE 0x0501
54 #define WIN32_LEAN_AND_MEAN 1
63 #include <boost/algorithm/string/case_conv.hpp>
64 #include <boost/algorithm/string/join.hpp>
65 #include <boost/algorithm/string/predicate.hpp>
66 #include <boost/date_time/posix_time/posix_time.hpp>
67 #include <boost/filesystem.hpp>
68 #include <boost/filesystem/fstream.hpp>
69 #include <boost/foreach.hpp>
70 #include <boost/program_options/detail/config_file.hpp>
71 #include <boost/program_options/parsers.hpp>
73 #include <openssl/crypto.h>
74 #include <openssl/rand.h>
81 namespace program_options {
82 std::string to_internal(
const std::string&);
106 if (mode & CRYPTO_LOCK) {
121 for (
int i = 0; i < CRYPTO_num_locks(); i++)
136 CRYPTO_set_locking_callback(NULL);
137 for (
int i = 0; i < CRYPTO_num_locks(); i++)
138 delete ppmutexOpenSSL[i];
139 OPENSSL_free(ppmutexOpenSSL);
155 RAND_add(&nCounter,
sizeof(nCounter), 1.5);
156 memset(&nCounter, 0,
sizeof(nCounter));
164 static int64_t nLastPerfmon;
165 if (
GetTime() < nLastPerfmon + 10 * 60)
172 unsigned char pdata[250000];
173 memset(pdata, 0,
sizeof(pdata));
174 unsigned long nSize =
sizeof(pdata);
175 long ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA,
"Global", NULL, NULL, pdata, &nSize);
176 RegCloseKey(HKEY_PERFORMANCE_DATA);
177 if (ret == ERROR_SUCCESS)
179 RAND_add(pdata, nSize, nSize/100.0);
180 OPENSSL_cleanse(pdata, nSize);
181 LogPrint(
"rand",
"RandAddSeed() %lu bytes\n", nSize);
193 uint64_t nRange = (std::numeric_limits<uint64_t>::max() / nMax) * nMax;
196 RAND_bytes((
unsigned char*)&nRand,
sizeof(nRand));
197 while (nRand >= nRange);
198 return (nRand % nMax);
209 RAND_bytes((
unsigned char*)&hash,
sizeof(hash));
222 static boost::once_flag debugPrintInitFlag = BOOST_ONCE_INIT;
225 static FILE* fileout = NULL;
226 static boost::mutex* mutexDebugLog = NULL;
228 static void DebugPrintInit()
230 assert(fileout == NULL);
231 assert(mutexDebugLog == NULL);
233 boost::filesystem::path pathDebug =
GetDataDir() /
"debug.log";
234 fileout = fopen(pathDebug.string().c_str(),
"a");
235 if (fileout) setbuf(fileout, NULL);
237 mutexDebugLog =
new boost::mutex();
242 if (category != NULL)
251 static boost::thread_specific_ptr<set<string> > ptrCategory;
252 if (ptrCategory.get() == NULL)
254 const vector<string>& categories =
mapMultiArgs[
"-debug"];
255 ptrCategory.reset(
new set<string>(categories.begin(), categories.end()));
258 const set<string>& setCategories = *ptrCategory.get();
261 if (setCategories.count(
string(
"")) == 0 &&
262 setCategories.count(
string(category)) == 0)
274 ret = fwrite(str.data(), 1, str.size(), stdout);
278 static bool fStartedNewLine =
true;
279 boost::call_once(&DebugPrintInit, debugPrintInitFlag);
284 boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
289 boost::filesystem::path pathDebug =
GetDataDir() /
"debug.log";
290 if (freopen(pathDebug.string().c_str(),
"a",fileout) != NULL)
291 setbuf(fileout, NULL);
297 if (!str.empty() && str[str.size()-1] ==
'\n')
298 fStartedNewLine =
true;
300 fStartedNewLine =
false;
302 ret = fwrite(str.data(), 1, str.size(), fileout);
312 int64_t n_abs = (n > 0 ? n : -n);
313 int64_t quotient = n_abs/COIN;
314 int64_t remainder = n_abs%COIN;
315 string str =
strprintf(
"%d.%08d", quotient, remainder);
319 for (
int i = str.size()-1; (str[i] ==
'0' && isdigit(str[i-2])); --i)
322 str.erase(str.size()-nTrim, nTrim);
325 str.insert((
unsigned int)0, 1,
'-');
326 else if (fPlus && n > 0)
327 str.insert((
unsigned int)0, 1,
'+');
341 const char* p = pszIn;
349 int64_t nMult = CENT*10;
350 while (isdigit(*p) && (nMult > 0))
352 nUnits += nMult * (*p++ -
'0');
361 strWhole.insert(strWhole.end(), *p);
366 if (strWhole.size() > 10)
368 if (nUnits < 0 || nUnits > COIN)
370 int64_t nWhole =
atoi64(strWhole);
371 int64_t nValue = nWhole*COIN + nUnits;
379 static string safeChars(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@-()");
383 for (std::string::size_type i = 0; i < str.size(); i++)
385 if (safeChars.find(str[i]) != std::string::npos)
386 strResult.push_back(str[i]);
392 { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
393 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
394 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
395 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
396 -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
397 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
398 -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
399 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
400 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
401 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
402 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
403 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
404 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
405 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
406 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
407 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
411 BOOST_FOREACH(
char c, str)
416 return (str.size() > 0) && (str.size()%2 == 0);
422 vector<unsigned char> vch;
425 while (isspace(*psz))
428 if (c == (
signed char)-1)
430 unsigned char n = (c << 4);
432 if (c == (
signed char)-1)
445 static void InterpretNegativeSetting(
string name, map<string, string>& mapSettingsRet)
448 if (name.find(
"-no") == 0)
450 std::string positive(
"-");
451 positive.append(name.begin()+3, name.end());
452 if (mapSettingsRet.count(positive) == 0)
455 mapSettingsRet[positive] = (value ?
"1" :
"0");
464 for (
int i = 1; i < argc; i++)
466 std::string str(argv[i]);
467 std::string strValue;
468 size_t is_index = str.find(
'=');
469 if (is_index != std::string::npos)
471 strValue = str.substr(is_index+1);
472 str = str.substr(0, is_index);
475 boost::to_lower(str);
476 if (boost::algorithm::starts_with(str,
"/"))
477 str =
"-" + str.substr(1);
490 string name = entry.first;
493 if (name.find(
"--") == 0)
495 std::string singleDash(name.begin()+1, name.end());
496 if (
mapArgs.count(singleDash) == 0)
497 mapArgs[singleDash] = entry.second;
502 InterpretNegativeSetting(name,
mapArgs);
506 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
513 int64_t
GetArg(
const std::string& strArg, int64_t nDefault)
531 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue)
550 static const char *pbase64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
553 strRet.reserve((len+2)/3*4);
556 const unsigned char *pchEnd = pch+len;
564 strRet += pbase64[enc >> 2];
565 left = (enc & 3) << 4;
570 strRet += pbase64[left | (enc >> 4)];
571 left = (enc & 15) << 2;
576 strRet += pbase64[left | (enc >> 6)];
577 strRet += pbase64[enc & 63];
585 strRet += pbase64[left];
596 return EncodeBase64((
const unsigned char*)str.c_str(), str.size());
601 static const int decode64_table[256] =
603 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
604 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
605 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
606 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
607 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
608 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
609 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
610 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
611 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
612 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
613 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
614 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
615 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
621 vector<unsigned char> vchRet;
622 vchRet.reserve(strlen(p)*3/4);
629 int dec = decode64_table[(
unsigned char)*p];
630 if (dec == -1)
break;
640 vchRet.push_back((left<<2) | (dec>>4));
646 vchRet.push_back((left<<4) | (dec>>2));
652 vchRet.push_back((left<<6) | dec);
669 if (left || p[0] !=
'=' || p[1] !=
'=' || decode64_table[(
unsigned char)p[2]] != -1)
674 if (left || p[0] !=
'=' || decode64_table[(
unsigned char)p[1]] != -1)
684 vector<unsigned char> vchRet =
DecodeBase64(str.c_str());
685 return string((
const char*)&vchRet[0], vchRet.size());
690 static const char *pbase32 =
"abcdefghijklmnopqrstuvwxyz234567";
693 strRet.reserve((len+4)/5*8);
696 const unsigned char *pchEnd = pch+len;
704 strRet += pbase32[enc >> 3];
705 left = (enc & 7) << 2;
710 strRet += pbase32[left | (enc >> 6)];
711 strRet += pbase32[(enc >> 1) & 31];
712 left = (enc & 1) << 4;
717 strRet += pbase32[left | (enc >> 4)];
718 left = (enc & 15) << 1;
723 strRet += pbase32[left | (enc >> 7)];
724 strRet += pbase32[(enc >> 2) & 31];
725 left = (enc & 3) << 3;
730 strRet += pbase32[left | (enc >> 5)];
731 strRet += pbase32[enc & 31];
736 static const int nPadding[5] = {0, 6, 4, 3, 1};
739 strRet += pbase32[left];
740 for (
int n=0; n<nPadding[mode]; n++)
749 return EncodeBase32((
const unsigned char*)str.c_str(), str.size());
754 static const int decode32_table[256] =
756 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
757 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
758 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
759 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
760 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
761 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
762 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
763 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
764 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
765 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
766 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
767 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
768 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
774 vector<unsigned char> vchRet;
775 vchRet.reserve((strlen(p))*5/8);
782 int dec = decode32_table[(
unsigned char)*p];
783 if (dec == -1)
break;
793 vchRet.push_back((left<<3) | (dec>>2));
799 left = left << 5 | dec;
804 vchRet.push_back((left<<1) | (dec>>4));
810 vchRet.push_back((left<<4) | (dec>>1));
816 left = left << 5 | dec;
821 vchRet.push_back((left<<2) | (dec>>3));
827 vchRet.push_back((left<<5) | dec);
846 if (left || p[0] !=
'=' || p[1] !=
'=' || p[2] !=
'=' || p[3] !=
'=' || p[4] !=
'=' || p[5] !=
'=' || decode32_table[(
unsigned char)p[6]] != -1)
851 if (left || p[0] !=
'=' || p[1] !=
'=' || p[2] !=
'=' || p[3] !=
'=' || decode32_table[(
unsigned char)p[4]] != -1)
856 if (left || p[0] !=
'=' || p[1] !=
'=' || p[2] !=
'=' || decode32_table[(
unsigned char)p[3]] != -1)
861 if (left || p[0] !=
'=' || decode32_table[(
unsigned char)p[1]] != -1)
871 vector<unsigned char> vchRet =
DecodeBase32(str.c_str());
872 return string((
const char*)&vchRet[0], vchRet.size());
883 return (*psz ==
'\0');
906 static std::string FormatException(std::exception* pex,
const char* pszThread)
910 GetModuleFileNameA(NULL, pszModule,
sizeof(pszModule));
912 const char* pszModule =
"anoncoin";
916 "EXCEPTION: %s \n%s \n%s in %s \n",
typeid(*pex).name(), pex->what(), pszModule, pszThread);
919 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
924 std::string message = FormatException(pex, pszThread);
930 std::string message = FormatException(pex, pszThread);
931 LogPrintf(
"\n\n************************\n%s\n", message);
932 fprintf(stderr,
"\n\n************************\n%s\n", message.c_str());
938 namespace fs = boost::filesystem;
945 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Anoncoin";
948 char* pszHome = getenv(
"HOME");
949 if (pszHome == NULL || strlen(pszHome) == 0)
950 pathRet = fs::path(
"/");
952 pathRet = fs::path(pszHome);
955 pathRet /=
"Library/Application Support";
957 return pathRet /
"Anoncoin";
960 return pathRet /
".anoncoin";
970 namespace fs = boost::filesystem;
977 fs::path &path = pathCached[nNet];
984 if (
mapArgs.count(
"-datadir")) {
985 path = fs::system_complete(
mapArgs[
"-datadir"]);
986 if (!fs::is_directory(path)) {
996 fs::create_directories(path);
1004 boost::filesystem::path());
1009 boost::filesystem::path pathConfigFile(
GetArg(
"-conf",
"anoncoin.conf"));
1010 if (!pathConfigFile.is_complete()) pathConfigFile =
GetDataDir(
false) / pathConfigFile;
1011 return pathConfigFile;
1016 boost::filesystem::path pathConfigFile(
GetArg(
"-style",
"anoncoin.qss"));
1017 if (!pathConfigFile.is_complete()) pathConfigFile =
GetDataDir(
false) / pathConfigFile;
1018 return pathConfigFile;
1022 map<
string, vector<string> >& mapMultiSettingsRet)
1025 if (!streamConfig.good())
1031 set<string> setOptions;
1032 setOptions.insert(
"*");
1034 for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
1037 string strKey = string(
"-") + it->string_key;
1038 if (mapSettingsRet.count(strKey) == 0)
1040 mapSettingsRet[strKey] = it->value[0];
1042 InterpretNegativeSetting(strKey, mapSettingsRet);
1044 mapMultiSettingsRet[strKey].push_back(it->value[0]);
1052 boost::filesystem::path pathPidFile(
GetArg(
"-pid",
"anoncoin.pid"));
1053 if (!pathPidFile.is_complete()) pathPidFile =
GetDataDir() / pathPidFile;
1060 FILE* file = fopen(path.string().c_str(),
"w");
1063 fprintf(file,
"%d\n", pid);
1069 bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
1072 return MoveFileExA(src.string().c_str(), dest.string().c_str(),
1073 MOVEFILE_REPLACE_EXISTING);
1075 int rc = std::rename(src.string().c_str(), dest.string().c_str());
1087 return boost::filesystem::create_directory(p);
1088 }
catch (boost::filesystem::filesystem_error) {
1089 if (!boost::filesystem::exists(p) || !boost::filesystem::is_directory(p))
1101 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(fileout));
1102 FlushFileBuffers(hFile);
1104 #if defined(__linux__) || defined(__NetBSD__)
1105 fdatasync(fileno(fileout));
1106 #elif defined(__APPLE__) && defined(F_FULLFSYNC)
1107 fcntl(fileno(fileout), F_FULLFSYNC, 0);
1109 fsync(fileno(fileout));
1116 return _chsize(_fileno(file), length) == 0;
1118 return ftruncate(fileno(file), length) == 0;
1128 struct rlimit limitFD;
1129 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1130 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1131 limitFD.rlim_cur = nMinFD;
1132 if (limitFD.rlim_cur > limitFD.rlim_max)
1133 limitFD.rlim_cur = limitFD.rlim_max;
1134 setrlimit(RLIMIT_NOFILE, &limitFD);
1135 getrlimit(RLIMIT_NOFILE, &limitFD);
1137 return limitFD.rlim_cur;
1148 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1149 LARGE_INTEGER nFileSize;
1150 int64_t nEndPos = (int64_t)offset + length;
1151 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1152 nFileSize.u.HighPart = nEndPos >> 32;
1153 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1154 SetEndOfFile(hFile);
1155 #elif defined(MAC_OSX)
1158 fst.fst_flags = F_ALLOCATECONTIG;
1159 fst.fst_posmode = F_PEOFPOSMODE;
1161 fst.fst_length = (off_t)offset + length;
1162 fst.fst_bytesalloc = 0;
1163 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1164 fst.fst_flags = F_ALLOCATEALL;
1165 fcntl(fileno(file), F_PREALLOCATE, &fst);
1167 ftruncate(fileno(file), fst.fst_length);
1168 #elif defined(__linux__)
1170 off_t nEndPos = (off_t)offset + length;
1171 posix_fallocate(fileno(file), 0, nEndPos);
1175 static const char buf[65536] = {};
1176 fseek(file, offset, SEEK_SET);
1177 while (length > 0) {
1178 unsigned int now = 65536;
1181 fwrite(buf, 1, now, file);
1190 boost::filesystem::path pathLog =
GetDataDir() /
"debug.log";
1191 FILE* file = fopen(pathLog.string().c_str(),
"r");
1192 if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000)
1196 fseek(file, -
sizeof(pch), SEEK_END);
1197 int nBytes = fread(pch, 1,
sizeof(pch), file);
1200 file = fopen(pathLog.string().c_str(),
"w");
1203 fwrite(pch, 1, nBytes, file);
1207 else if (file != NULL)
1218 static int64_t nMockTime = 0;
1222 if (nMockTime)
return nMockTime;
1229 nMockTime = nMockTimeIn;
1233 static int64_t nTimeOffset = 0;
1237 LOCK(cs_nTimeOffset);
1248 int64_t nOffsetSample = nTime -
GetTime();
1250 LOCK(cs_nTimeOffset);
1252 static set<CNetAddr> setKnown;
1253 if (!setKnown.insert(ip).second)
1258 vTimeOffsets.
input(nOffsetSample);
1259 LogPrintf(
"Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.
size(), nOffsetSample, nOffsetSample/60);
1260 if (vTimeOffsets.
size() >= 5 && vTimeOffsets.
size() % 2 == 1)
1262 int64_t nMedian = vTimeOffsets.
median();
1263 std::vector<int64_t> vSorted = vTimeOffsets.
sorted();
1265 if (
abs64(nMedian) < 35 * 60)
1267 nTimeOffset = nMedian;
1277 bool fMatch =
false;
1278 BOOST_FOREACH(int64_t nOffset, vSorted)
1279 if (nOffset != 0 &&
abs64(nOffset) < 5 * 60)
1285 string strMessage =
_(
"Warning: Please check that your computer's date and time are correct! If your clock is wrong Anoncoin will not work properly.");
1293 BOOST_FOREACH(int64_t n, vSorted)
1297 LogPrintf(
"nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset/60);
1308 insecure_rand_Rz = insecure_rand_Rw = 11;
1312 RAND_bytes((
unsigned char*)&tmp, 4);
1313 }
while(tmp == 0 || tmp == 0x9068ffffU);
1314 insecure_rand_Rz = tmp;
1316 RAND_bytes((
unsigned char*)&tmp, 4);
1317 }
while(tmp == 0 || tmp == 0x464fffffU);
1318 insecure_rand_Rw = tmp;
1323 boost::filesystem::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1325 namespace fs = boost::filesystem;
1329 if(SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate))
1331 return fs::path(pszPath);
1334 LogPrintf(
"SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
1335 return fs::path(
"");
1340 #if BOOST_FILESYSTEM_VERSION == 3
1341 return boost::filesystem::temp_directory_path();
1344 boost::filesystem::path path;
1348 if (GetTempPathA(
MAX_PATH, pszPath))
1349 path = boost::filesystem::path(pszPath);
1351 path = boost::filesystem::path(
"/tmp");
1353 if (path.empty() || !boost::filesystem::is_directory(path)) {
1354 LogPrintf(
"GetTempPath(): failed to find temp path\n");
1355 return boost::filesystem::path(
"");
1363 int nErr = ::system(strCommand.c_str());
1365 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1370 #if defined(PR_SET_NAME)
1372 ::prctl(PR_SET_NAME, name, 0, 0, 0);
1373 #elif 0 && (defined(__FreeBSD__) || defined(__OpenBSD__))
1377 pthread_set_name_np(pthread_self(), name);
1379 #elif defined(MAC_OSX) && defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
1382 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
1383 pthread_setname_np(name);
1399 #if BOOST_FILESYSTEM_VERSION == 3
1400 boost::filesystem::path::codecvt();
1401 #else // boost filesystem v2
1404 }
catch(std::runtime_error &e)
1406 setenv(
"LC_ALL",
"C", 1);
1414 std::locale loc(std::locale::classic(),
new boost::posix_time::time_facet(pszFormat));
1415 std::stringstream ss;
1417 ss << boost::posix_time::from_time_t(nTime);
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
void locking_callback(int mode, int i, const char *file, int line)
const string & DataDir() const
uint64_t GetRand(uint64_t nMax)
void FileCommit(FILE *fileout)
void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
void LogException(std::exception *pex, const char *pszThread)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
boost::filesystem::path GetTempPath()
boost::filesystem::path GetPidFile()
void seed_insecure_rand(bool fDeterministic)
Seed insecure_rand using the random pool.
bool IsHex(const string &str)
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
void RandAddSeedPerfmon()
string FormatMoney(int64_t n, bool fPlus)
Signals for UI communication.
void RenameThread(const char *name)
const signed char p_util_hexdigit[256]
volatile bool fReopenDebugLog
void SetMockTime(int64_t nMockTimeIn)
int RaiseFileDescriptorLimit(int nMinFD)
class CInit instance_of_cinit
signed char HexDigit(char c)
string EncodeBase64(const unsigned char *pch, size_t len)
CClientUIInterface uiInterface
bool TruncateFile(FILE *file, unsigned int length)
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
int64_t GetAdjustedTime()
void AddTimeData(const CNetAddr &ip, int64_t nTime)
#define LEAVE_CRITICAL_SECTION(cs)
string SanitizeString(const string &str)
int64_t atoi64(const char *psz)
bool TryCreateDirectory(const boost::filesystem::path &p)
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
string EncodeBase32(const unsigned char *pch, size_t len)
void PrintExceptionContinue(std::exception *pex, const char *pszThread)
void ParseParameters(int argc, const char *const argv[])
boost::filesystem::path GetQtStyleFile()
#define ENTER_CRITICAL_SECTION(cs)
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
int64_t GetPerformanceCounter()
vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid)
void ReadConfigFile(map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
const CChainParams & Params()
Return the currently selected parameters.
bool WildcardMatch(const char *psz, const char *mask)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
uint32_t insecure_rand_Rz
MWC RNG of George Marsaglia This is intended to be fast.
bool ParseMoney(const string &str, int64_t &nRet)
bool LogAcceptCategory(const char *category)
boost::signals2::signal< bool(const std::string &message, const std::string &caption, unsigned int style), boost::signals2::last_value< bool > > ThreadSafeMessageBox
Show message box.
AnnotatedMixin< boost::recursive_mutex > CCriticalSection
Wrapped boost mutex: supports recursive locking, but no waiting.
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
uint32_t insecure_rand_Rw
vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
map< string, vector< string > > mapMultiArgs
vector< unsigned char > ParseHex(const char *psz)
virtual Network NetworkID() const =0
int LogPrintStr(const std::string &str)
map< string, string > mapArgs
int atoi(const std::string &str)
boost::filesystem::path GetDefaultDataDir()
void runCommand(std::string strCommand)
boost::filesystem::path GetConfigFile()