bool fPrintToConsole = false;
bool fPrintToDebugger = false;
char pszSetDataDir[MAX_PATH] = "";
+bool fRequestShutdown = false;
bool fShutdown = false;
bool fDaemon = false;
bool fCommandLine = false;
-string strWarning;
+string strMiscWarning;
void RandAddSeed()
{
// Seed with CPU performance counter
- int64 nCounter = PerformanceCounter();
+ int64 nCounter = GetPerformanceCounter();
RAND_add(&nCounter, sizeof(nCounter), 1.5);
memset(&nCounter, 0, sizeof(nCounter));
}
RegCloseKey(HKEY_PERFORMANCE_DATA);
if (ret == ERROR_SUCCESS)
{
- uint256 hash;
- SHA256(pdata, nSize, (unsigned char*)&hash);
- RAND_add(&hash, sizeof(hash), min(nSize/500.0, (double)sizeof(hash)));
- hash = 0;
+ RAND_add(pdata, nSize, nSize/100.0);
memset(pdata, 0, nSize);
-
printf("%s RandAddSeed() %d bytes\n", DateTimeStrFormat("%x %H:%M", GetTime()).c_str(), nSize);
}
#endif
return (nRand % nMax);
}
+int GetRandInt(int nMax)
+{
+ return GetRand(nMax);
+}
+
vector<unsigned char> ParseHex(const char* psz)
{
- vector<unsigned char> vch;
- while (isspace(*psz))
- psz++;
- vch.reserve((strlen(psz)+1)/3);
-
static char phexdigit[256] =
{ -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, };
- while (*psz)
+ // convert hex dump to vector
+ vector<unsigned char> vch;
+ loop
{
+ while (isspace(*psz))
+ psz++;
char c = phexdigit[(unsigned char)*psz++];
if (c == -1)
break;
unsigned char n = (c << 4);
- if (*psz)
- {
- char c = phexdigit[(unsigned char)*psz++];
- if (c == -1)
- break;
- n |= c;
- vch.push_back(n);
- }
- while (isspace(*psz))
- psz++;
+ c = phexdigit[(unsigned char)*psz++];
+ if (c == -1)
+ break;
+ n |= c;
+ vch.push_back(n);
}
-
return vch;
}
-vector<unsigned char> ParseHex(const std::string& str)
+vector<unsigned char> ParseHex(const string& str)
{
return ParseHex(str.c_str());
}
}
+bool WildcardMatch(const char* psz, const char* mask)
+{
+ loop
+ {
+ switch (*mask)
+ {
+ case '\0':
+ return (*psz == '\0');
+ case '*':
+ return WildcardMatch(psz, mask+1) || (*psz && WildcardMatch(psz+1, mask));
+ case '?':
+ if (*psz == '\0')
+ return false;
+ break;
+ default:
+ if (*psz != *mask)
+ return false;
+ break;
+ }
+ psz++;
+ mask++;
+ }
+}
+
+bool WildcardMatch(const string& str, const string& mask)
+{
+ return WildcardMatch(str.c_str(), mask.c_str());
+}
void LogException(std::exception* pex, const char* pszThread)
{
- char pszMessage[1000];
+ char pszMessage[10000];
FormatException(pszMessage, pex, pszThread);
printf("\n%s", pszMessage);
}
void PrintException(std::exception* pex, const char* pszThread)
{
- char pszMessage[1000];
+ char pszMessage[10000];
FormatException(pszMessage, pex, pszThread);
printf("\n\n************************\n%s\n", pszMessage);
fprintf(stderr, "\n\n************************\n%s\n", pszMessage);
+ strMiscWarning = pszMessage;
#ifdef GUI
if (wxTheApp && !fDaemon)
- MyMessageBox(pszMessage, "Error", wxOK | wxICON_ERROR);
+ MyMessageBox(pszMessage, "Bitcoin", wxOK | wxICON_ERROR);
#endif
throw;
- //DebugBreak();
+}
+
+void ThreadOneMessageBox(string strMessage)
+{
+ // Skip message boxes if one is already open
+ static bool fMessageBoxOpen;
+ if (fMessageBoxOpen)
+ return;
+ fMessageBoxOpen = true;
+ ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION);
+ fMessageBoxOpen = false;
+}
+
+void PrintExceptionContinue(std::exception* pex, const char* pszThread)
+{
+ char pszMessage[10000];
+ FormatException(pszMessage, pex, pszThread);
+ printf("\n\n************************\n%s\n", pszMessage);
+ fprintf(stderr, "\n\n************************\n%s\n", pszMessage);
+ strMiscWarning = pszMessage;
+#ifdef GUI
+ if (wxTheApp && !fDaemon)
+ boost::thread(bind(ThreadOneMessageBox, string(pszMessage)));
+#endif
}
string GetConfigFile()
{
namespace fs = boost::filesystem;
- fs::path pathConfig(mapArgs.count("-conf") ? mapArgs["-conf"] : string("bitcoin.conf"));
+ fs::path pathConfig(GetArg("-conf", "bitcoin.conf"));
if (!pathConfig.is_complete())
pathConfig = fs::path(GetDataDir()) / pathConfig;
return pathConfig.string();
//
// "Never go to sea with two chronometers; take one or three."
-// Our three chronometers are:
+// Our three time sources are:
// - System clock
-// - Median of other server's clocks
-// - NTP servers
-//
-// note: NTP isn't implemented yet, so until then we just use the median
-// of other nodes clocks to correct ours.
+// - Median of other nodes's clocks
+// - The user (asking the user to fix the system clock if the first two disagree)
//
int64 GetTime()
{
// If nobody else has the same time as us, give a warning
bool fMatch = false;
foreach(int64 nOffset, vTimeOffsets)
- if (nOffset != 0 && abs64(nOffset) < 10 * 60)
+ if (nOffset != 0 && abs64(nOffset) < 5 * 60)
fMatch = true;
static bool fDone;
if (!fMatch && !fDone)
{
fDone = true;
- string strMessage = _("Warning: Check your system date and time, you may not be able to generate or receive the most recent blocks!");
- strWarning = strMessage;
+ string strMessage = _("Warning: Please check that your computer's date and time are correct. If your clock is wrong Bitcoin will not work properly.");
+ strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
boost::thread(bind(ThreadSafeMessageBox, strMessage+" ", string("Bitcoin"), wxOK | wxICON_EXCLAMATION, (wxWindow*)NULL, -1, -1));
}