17 #include <boost/date_time/posix_time/posix_time.hpp>
23 #ifdef _POSIX_C_SOURCE
24 #undef _POSIX_C_SOURCE
27 #define _POSIX_C_SOURCE 200112L
28 #include <sys/prctl.h>
34 #include <sys/resource.h>
40 #pragma warning(disable:4786)
41 #pragma warning(disable:4804)
42 #pragma warning(disable:4805)
43 #pragma warning(disable:4717)
49 #define _WIN32_WINNT 0x0501
54 #define _WIN32_IE 0x0501
56 #define WIN32_LEAN_AND_MEAN 1
65 #include <boost/algorithm/string/case_conv.hpp>
66 #include <boost/algorithm/string/join.hpp>
67 #include <boost/algorithm/string/predicate.hpp>
68 #include <boost/filesystem.hpp>
69 #include <boost/filesystem/fstream.hpp>
70 #include <boost/foreach.hpp>
71 #include <boost/program_options/detail/config_file.hpp>
72 #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));
233 boost::filesystem::path pathDebug =
GetDataDir() /
"debug.log";
234 fileout = fopen(pathDebug.string().c_str(),
"a");
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;
289 boost::filesystem::path pathDebug =
GetDataDir() /
"debug.log";
290 if (freopen(pathDebug.string().c_str(),
"a",
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)
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");
463 mapMultiArgs.clear();
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);
482 mapArgs[str] = strValue;
483 mapMultiArgs[str].push_back(strValue);
487 BOOST_FOREACH(
const PAIRTYPE(
string,
string)& entry, mapArgs)
489 string name = entry.first;
492 if (name.find(
"--") == 0)
494 std::string singleDash(name.begin()+1, name.end());
495 if (mapArgs.count(singleDash) == 0)
496 mapArgs[singleDash] = entry.second;
505 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
507 if (mapArgs.count(strArg))
508 return mapArgs[strArg];
512 int64_t
GetArg(
const std::string& strArg, int64_t nDefault)
514 if (mapArgs.count(strArg))
515 return atoi64(mapArgs[strArg]);
521 if (mapArgs.count(strArg))
523 if (mapArgs[strArg].empty())
525 return (
atoi(mapArgs[strArg]) != 0);
530 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue)
532 if (mapArgs.count(strArg))
534 mapArgs[strArg] = strValue;
549 static const char *pbase64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
552 strRet.reserve((len+2)/3*4);
555 const unsigned char *pchEnd = pch+len;
563 strRet += pbase64[enc >> 2];
564 left = (enc & 3) << 4;
569 strRet += pbase64[left | (enc >> 4)];
570 left = (enc & 15) << 2;
575 strRet += pbase64[left | (enc >> 6)];
576 strRet += pbase64[enc & 63];
584 strRet += pbase64[left];
595 return EncodeBase64((
const unsigned char*)str.c_str(), str.size());
600 static const int decode64_table[256] =
602 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
605 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
606 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
607 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
608 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
609 -1, -1, -1, -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
620 vector<unsigned char> vchRet;
621 vchRet.reserve(strlen(p)*3/4);
628 int dec = decode64_table[(
unsigned char)*p];
629 if (dec == -1)
break;
639 vchRet.push_back((left<<2) | (dec>>4));
645 vchRet.push_back((left<<4) | (dec>>2));
651 vchRet.push_back((left<<6) | dec);
668 if (left || p[0] !=
'=' || p[1] !=
'=' || decode64_table[(
unsigned char)p[2]] != -1)
673 if (left || p[0] !=
'=' || decode64_table[(
unsigned char)p[1]] != -1)
683 vector<unsigned char> vchRet =
DecodeBase64(str.c_str());
684 return string((
const char*)&vchRet[0], vchRet.size());
689 static const char *pbase32 =
"abcdefghijklmnopqrstuvwxyz234567";
692 strRet.reserve((len+4)/5*8);
695 const unsigned char *pchEnd = pch+len;
703 strRet += pbase32[enc >> 3];
704 left = (enc & 7) << 2;
709 strRet += pbase32[left | (enc >> 6)];
710 strRet += pbase32[(enc >> 1) & 31];
711 left = (enc & 1) << 4;
716 strRet += pbase32[left | (enc >> 4)];
717 left = (enc & 15) << 1;
722 strRet += pbase32[left | (enc >> 7)];
723 strRet += pbase32[(enc >> 2) & 31];
724 left = (enc & 3) << 3;
729 strRet += pbase32[left | (enc >> 5)];
730 strRet += pbase32[enc & 31];
735 static const int nPadding[5] = {0, 6, 4, 3, 1};
738 strRet += pbase32[left];
739 for (
int n=0; n<nPadding[mode]; n++)
748 return EncodeBase32((
const unsigned char*)str.c_str(), str.size());
753 static const int decode32_table[256] =
755 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
758 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
759 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
760 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
761 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
762 -1, -1, -1, -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
773 vector<unsigned char> vchRet;
774 vchRet.reserve((strlen(p))*5/8);
781 int dec = decode32_table[(
unsigned char)*p];
782 if (dec == -1)
break;
792 vchRet.push_back((left<<3) | (dec>>2));
798 left = left << 5 | dec;
803 vchRet.push_back((left<<1) | (dec>>4));
809 vchRet.push_back((left<<4) | (dec>>1));
815 left = left << 5 | dec;
820 vchRet.push_back((left<<2) | (dec>>3));
826 vchRet.push_back((left<<5) | dec);
845 if (left || p[0] !=
'=' || p[1] !=
'=' || p[2] !=
'=' || p[3] !=
'=' || p[4] !=
'=' || p[5] !=
'=' || decode32_table[(
unsigned char)p[6]] != -1)
850 if (left || p[0] !=
'=' || p[1] !=
'=' || p[2] !=
'=' || p[3] !=
'=' || decode32_table[(
unsigned char)p[4]] != -1)
855 if (left || p[0] !=
'=' || p[1] !=
'=' || p[2] !=
'=' || decode32_table[(
unsigned char)p[3]] != -1)
860 if (left || p[0] !=
'=' || decode32_table[(
unsigned char)p[1]] != -1)
870 vector<unsigned char> vchRet =
DecodeBase32(str.c_str());
871 return string((
const char*)&vchRet[0], vchRet.size());
882 return (*psz ==
'\0');
915 GetModuleFileNameA(NULL, pszModule,
sizeof(pszModule));
917 const char* pszModule =
"bitcoin";
921 "EXCEPTION: %s \n%s \n%s in %s \n",
typeid(*pex).name(), pex->what(), pszModule, pszThread);
924 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
936 LogPrintf(
"\n\n************************\n%s\n", message);
937 fprintf(stderr,
"\n\n************************\n%s\n", message.c_str());
943 namespace fs = boost::filesystem;
950 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Bitcoin";
953 char* pszHome = getenv(
"HOME");
954 if (pszHome == NULL || strlen(pszHome) == 0)
955 pathRet = fs::path(
"/");
957 pathRet = fs::path(pszHome);
960 pathRet /=
"Library/Application Support";
962 return pathRet /
"Bitcoin";
965 return pathRet /
".bitcoin";
975 namespace fs = boost::filesystem;
989 if (mapArgs.count(
"-datadir")) {
990 path = fs::system_complete(mapArgs[
"-datadir"]);
991 if (!fs::is_directory(path)) {
1001 fs::create_directories(path);
1009 boost::filesystem::path());
1014 boost::filesystem::path pathConfigFile(
GetArg(
"-conf",
"bitcoin.conf"));
1015 if (!pathConfigFile.is_complete()) pathConfigFile =
GetDataDir(
false) / pathConfigFile;
1016 return pathConfigFile;
1020 map<
string, vector<string> >& mapMultiSettingsRet)
1023 if (!streamConfig.good())
1026 set<string> setOptions;
1027 setOptions.insert(
"*");
1029 for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
1032 string strKey = string(
"-") + it->string_key;
1033 if (mapSettingsRet.count(strKey) == 0)
1035 mapSettingsRet[strKey] = it->value[0];
1039 mapMultiSettingsRet[strKey].push_back(it->value[0]);
1047 boost::filesystem::path pathPidFile(
GetArg(
"-pid",
"bitcoind.pid"));
1048 if (!pathPidFile.is_complete()) pathPidFile =
GetDataDir() / pathPidFile;
1055 FILE* file = fopen(path.string().c_str(),
"w");
1058 fprintf(file,
"%d\n", pid);
1064 bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
1067 return MoveFileExA(src.string().c_str(), dest.string().c_str(),
1068 MOVEFILE_REPLACE_EXISTING);
1070 int rc = std::rename(src.string().c_str(), dest.string().c_str());
1082 return boost::filesystem::create_directory(p);
1083 }
catch (boost::filesystem::filesystem_error) {
1084 if (!boost::filesystem::exists(p) || !boost::filesystem::is_directory(p))
1096 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(fileout));
1097 FlushFileBuffers(hFile);
1099 #if defined(__linux__) || defined(__NetBSD__)
1100 fdatasync(fileno(fileout));
1101 #elif defined(__APPLE__) && defined(F_FULLFSYNC)
1102 fcntl(fileno(fileout), F_FULLFSYNC, 0);
1104 fsync(fileno(fileout));
1111 return _chsize(_fileno(file), length) == 0;
1113 return ftruncate(fileno(file), length) == 0;
1123 struct rlimit limitFD;
1124 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1125 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1126 limitFD.rlim_cur = nMinFD;
1127 if (limitFD.rlim_cur > limitFD.rlim_max)
1128 limitFD.rlim_cur = limitFD.rlim_max;
1129 setrlimit(RLIMIT_NOFILE, &limitFD);
1130 getrlimit(RLIMIT_NOFILE, &limitFD);
1132 return limitFD.rlim_cur;
1143 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1144 LARGE_INTEGER nFileSize;
1145 int64_t nEndPos = (int64_t)offset + length;
1146 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1147 nFileSize.u.HighPart = nEndPos >> 32;
1148 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1149 SetEndOfFile(hFile);
1150 #elif defined(MAC_OSX)
1153 fst.fst_flags = F_ALLOCATECONTIG;
1154 fst.fst_posmode = F_PEOFPOSMODE;
1156 fst.fst_length = (off_t)offset + length;
1157 fst.fst_bytesalloc = 0;
1158 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1159 fst.fst_flags = F_ALLOCATEALL;
1160 fcntl(fileno(file), F_PREALLOCATE, &fst);
1162 ftruncate(fileno(file), fst.fst_length);
1163 #elif defined(__linux__)
1165 off_t nEndPos = (off_t)offset + length;
1166 posix_fallocate(fileno(file), 0, nEndPos);
1170 static const char buf[65536] = {};
1171 fseek(file, offset, SEEK_SET);
1172 while (length > 0) {
1173 unsigned int now = 65536;
1176 fwrite(buf, 1, now, file);
1185 boost::filesystem::path pathLog =
GetDataDir() /
"debug.log";
1186 FILE* file = fopen(pathLog.string().c_str(),
"r");
1187 if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000)
1191 fseek(file, -
sizeof(pch), SEEK_END);
1192 int nBytes = fread(pch, 1,
sizeof(pch), file);
1195 file = fopen(pathLog.string().c_str(),
"w");
1198 fwrite(pch, 1, nBytes, file);
1202 else if (file != NULL)
1232 LOCK(cs_nTimeOffset);
1243 int64_t nOffsetSample = nTime -
GetTime();
1245 LOCK(cs_nTimeOffset);
1247 static set<CNetAddr> setKnown;
1248 if (!setKnown.insert(ip).second)
1253 vTimeOffsets.
input(nOffsetSample);
1254 LogPrintf(
"Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.
size(), nOffsetSample, nOffsetSample/60);
1255 if (vTimeOffsets.
size() >= 5 && vTimeOffsets.
size() % 2 == 1)
1257 int64_t nMedian = vTimeOffsets.
median();
1258 std::vector<int64_t> vSorted = vTimeOffsets.
sorted();
1260 if (
abs64(nMedian) < 70 * 60)
1272 bool fMatch =
false;
1273 BOOST_FOREACH(int64_t nOffset, vSorted)
1274 if (nOffset != 0 &&
abs64(nOffset) < 5 * 60)
1280 string strMessage =
_(
"Warning: Please check that your computer's date and time are correct! If your clock is wrong Bitcoin will not work properly.");
1288 BOOST_FOREACH(int64_t n, vSorted)
1307 RAND_bytes((
unsigned char*)&tmp, 4);
1308 }
while(tmp == 0 || tmp == 0x9068ffffU);
1311 RAND_bytes((
unsigned char*)&tmp, 4);
1312 }
while(tmp == 0 || tmp == 0x464fffffU);
1319 if (nVersion%100 == 0)
1320 return strprintf(
"%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100);
1322 return strprintf(
"%d.%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100, nVersion%100);
1331 std::string
FormatSubVersion(
const std::string& name,
int nClientVersion,
const std::vector<std::string>& comments)
1333 std::ostringstream ss;
1336 if (!comments.empty())
1337 ss <<
"(" << boost::algorithm::join(comments,
"; ") <<
")";
1343 boost::filesystem::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1345 namespace fs = boost::filesystem;
1349 if(SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate))
1351 return fs::path(pszPath);
1354 LogPrintf(
"SHGetSpecialFolderPathA() failed, could not obtain requested path.\n");
1355 return fs::path(
"");
1360 #if BOOST_FILESYSTEM_VERSION == 3
1361 return boost::filesystem::temp_directory_path();
1364 boost::filesystem::path path;
1368 if (GetTempPathA(
MAX_PATH, pszPath))
1369 path = boost::filesystem::path(pszPath);
1371 path = boost::filesystem::path(
"/tmp");
1373 if (path.empty() || !boost::filesystem::is_directory(path)) {
1374 LogPrintf(
"GetTempPath(): failed to find temp path\n");
1375 return boost::filesystem::path(
"");
1383 int nErr = ::system(strCommand.c_str());
1385 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1390 #if defined(PR_SET_NAME)
1392 ::prctl(PR_SET_NAME, name, 0, 0, 0);
1393 #elif 0 && (defined(__FreeBSD__) || defined(__OpenBSD__))
1397 pthread_set_name_np(pthread_self(), name);
1399 #elif defined(MAC_OSX) && defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
1402 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
1403 pthread_setname_np(name);
1417 #if BOOST_FILESYSTEM_VERSION == 3
1418 boost::filesystem::path::codecvt();
1419 #else // boost filesystem v2
1422 }
catch(std::runtime_error &e)
1424 setenv(
"LC_ALL",
"C", 1);
1432 std::locale loc(std::locale::classic(),
new boost::posix_time::time_facet(pszFormat));
1433 std::stringstream ss;
1435 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.
string FormatVersion(int nVersion)
boost::filesystem::path GetTempPath()
boost::filesystem::path GetPidFile()
static boost::once_flag debugPrintInitFlag
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]
static void InterpretNegativeSetting(string name, map< string, string > &mapSettingsRet)
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)
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
string SanitizeString(const string &str)
static int LogPrint(const char *category, const char *format)
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)
static CCriticalSection csPathCached
void ParseParameters(int argc, const char *const argv[])
static boost::mutex * mutexDebugLog
#define ENTER_CRITICAL_SECTION(cs)
static std::string FormatException(std::exception *pex, const char *pszThread)
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)
static const int64_t COIN
void ReadConfigFile(map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
const CChainParams & Params()
Return the currently selected parameters.
const std::string CLIENT_BUILD
string FormatFullVersion()
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.
static const int64_t CENT
AnnotatedMixin< boost::recursive_mutex > CCriticalSection
Wrapped boost mutex: supports recursive locking, but no waiting.
static CCriticalSection ** ppmutexOpenSSL
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
uint32_t insecure_rand_Rw
static int64_t nTimeOffset
static void DebugPrintInit()
vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
static string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@")
map< string, vector< string > > mapMultiArgs
vector< unsigned char > ParseHex(const char *psz)
static boost::filesystem::path pathCached[CChainParams::MAX_NETWORK_TYPES+1]
virtual Network NetworkID() const =0
int LogPrintStr(const std::string &str)
static CCriticalSection cs_nTimeOffset
map< string, string > mapArgs
int atoi(const std::string &str)
boost::filesystem::path GetDefaultDataDir()
void runCommand(std::string strCommand)
boost::filesystem::path GetConfigFile()