warning message if clock is too far off

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@141 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
s_nakamoto
2010-08-20 16:55:14 +00:00
parent 05454818dc
commit 2201a0808e
6 changed files with 64 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ char pszSetDataDir[MAX_PATH] = "";
bool fShutdown = false;
bool fDaemon = false;
bool fCommandLine = false;
string strWarning;
@@ -742,14 +743,28 @@ void AddTimeData(unsigned int ip, int64 nTime)
{
sort(vTimeOffsets.begin(), vTimeOffsets.end());
int64 nMedian = vTimeOffsets[vTimeOffsets.size()/2];
nTimeOffset = nMedian;
if ((nMedian > 0 ? nMedian : -nMedian) > 70 * 60)
// Only let other nodes change our time by so much
if (abs64(nMedian) < 70 * 60)
{
nTimeOffset = nMedian;
}
else
{
// Only let other nodes change our clock so far before we
// go to the NTP servers
/// todo: Get time from NTP servers, then set a flag
/// to make sure it doesn't get changed again
nTimeOffset = 0;
// 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)
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;
printf("*** %s\n", strMessage.c_str());
boost::thread(bind(ThreadSafeMessageBox, strMessage+" ", string("Bitcoin"), wxOK | wxICON_EXCLAMATION, (wxWindow*)NULL, -1, -1));
}
}
foreach(int64 n, vTimeOffsets)
printf("%+"PRI64d" ", n);