From 65cbd319c17d8f0e331efb18aab664212c7e6583 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 5 Aug 2012 03:56:17 -0700 Subject: [PATCH] Cleanups. --- newcoind.cfg | 6 ++++-- src/Peer.cpp | 4 +++- src/SNTPClient.cpp | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/newcoind.cfg b/newcoind.cfg index 179a14802..774a32129 100644 --- a/newcoind.cfg +++ b/newcoind.cfg @@ -86,7 +86,8 @@ # 2001:0db8:0100:f101:0210:a4ff:fee3:9566 # # [sntp_servers] -# IP address or domain of servers to use for time synchronization. +# IP address or domain of servers to use for time synchronization. +# The default time servers are suitable for servers located in the United States # # [peer_ip]: # IP address or domain to bind to allow external connections from peers. @@ -145,8 +146,9 @@ debug.log [sntp_servers] time.windows.com -us.pool.ntp.org time.apple.com +time.nist.gov +pool.ntp.org [validation_seed] shh1D4oj5czH3PUEjYES8c7Bay3tE diff --git a/src/Peer.cpp b/src/Peer.cpp index 3a8e385f3..7c822dd22 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -575,12 +575,14 @@ void Peer::recvHello(newcoin::TMHello& packet) uint32 minTime = ourTime - 10; uint32 maxTime = ourTime + 10; +#ifdef DEBUG if (packet.has_nettime()) { int64 to = ourTime; to -= packet.nettime(); - Log(lsTRACE) << "Connect: time error " << to; + Log(lsDEBUG) << "Connect: time offset " << to; } +#endif if (packet.has_nettime() && ((packet.nettime() < minTime) || (packet.nettime() > maxTime))) { diff --git a/src/SNTPClient.cpp b/src/SNTPClient.cpp index 5dfe2af07..01931549c 100644 --- a/src/SNTPClient.cpp +++ b/src/SNTPClient.cpp @@ -13,6 +13,9 @@ static uint8_t SNTPQueryData[48] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; +// NTP query frequency - 5 minutes +#define NTP_QUERY_FREQUENCY (5 * 60) + // NTP timestamp constant #define NTP_UNIX_OFFSET 0x83AA7E80 @@ -40,7 +43,7 @@ SNTPClient::SNTPClient(boost::asio::io_service& service) : boost::bind(&SNTPClient::receivePacket, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - mTimer.expires_from_now(boost::posix_time::seconds(1)); + mTimer.expires_from_now(boost::posix_time::seconds(NTP_QUERY_FREQUENCY)); mTimer.async_wait(boost::bind(&SNTPClient::timerEntry, this, boost::asio::placeholders::error)); } @@ -138,11 +141,13 @@ void SNTPClient::processReply() if ((timev == -1) || (timev == 1)) // small corrections likely do more harm than good timev = 0; + // FIXME: We really should use the median of all recent valid offsets if ((mLastOffsetUpdate == (time_t) -1) || (mLastOffsetUpdate < (now - 180))) mOffset = timev; else mOffset = ((mOffset * 7) + timev) / 8; mLastOffsetUpdate = now; + Log(lsTRACE) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset; } @@ -151,7 +156,7 @@ void SNTPClient::timerEntry(const boost::system::error_code& error) if (!error) { doQuery(); - mTimer.expires_from_now(boost::posix_time::seconds(10)); + mTimer.expires_from_now(boost::posix_time::seconds(NTP_QUERY_FREQUENCY)); mTimer.async_wait(boost::bind(&SNTPClient::timerEntry, this, boost::asio::placeholders::error)); } }