From 155a0a95c34041a89a206e1fc9a2fb1c4c254d30 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 22 May 2013 17:21:55 -0700 Subject: [PATCH] Move SNTPClient to ripple_net module --- modules/ripple_net/ripple_net.cpp | 2 ++ newcoin.vcxproj.filters | 15 +++++++++------ src/cpp/ripple/SNTPClient.cpp | 32 +++++++++++++++---------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/modules/ripple_net/ripple_net.cpp b/modules/ripple_net/ripple_net.cpp index e2dc0223e..8473a4e91 100644 --- a/modules/ripple_net/ripple_net.cpp +++ b/modules/ripple_net/ripple_net.cpp @@ -41,6 +41,8 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) return 512 == iKeyLength ? theApp->getWallet().getDh512() : theApp->getWallet().getDh1024(); } +#include "src/cpp/ripple/SNTPClient.cpp" + #include "src/cpp/ripple/ConnectionPool.cpp" #include "src/cpp/ripple/NetworkOPs.cpp" #include "src/cpp/ripple/Peer.cpp" diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index a9140ac96..c2a6bdd1a 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -110,6 +110,9 @@ {afd09812-59e2-45e2-bf7f-d561b23d7da2} + + {074b2e47-f34b-42f1-945e-7e8083bbfb43} + @@ -406,9 +409,6 @@ Unsorted Sources - - Unsorted Sources - Unsorted Sources @@ -721,6 +721,9 @@ 1. Modules\ripple_ledger\contracts + + 1. Modules\ripple_net\service + @@ -1038,9 +1041,6 @@ Unsorted Sources - - Unsorted Sources - Unsorted Sources @@ -1359,6 +1359,9 @@ 1. Modules\ripple_ledger\contracts + + 1. Modules\ripple_net\service + diff --git a/src/cpp/ripple/SNTPClient.cpp b/src/cpp/ripple/SNTPClient.cpp index c3febd27b..1d17facf8 100644 --- a/src/cpp/ripple/SNTPClient.cpp +++ b/src/cpp/ripple/SNTPClient.cpp @@ -10,8 +10,6 @@ #include "Config.h" #include "Log.h" -SETUP_LOG(); - // #define SNTP_DEBUG static uint8_t SNTPQueryData[48] = @@ -75,7 +73,7 @@ void SNTPClient::resolveComplete(const boost::system::error_code& error, boost:: time_t now = time(NULL); if ((query.mLocalTimeSent == now) || ((query.mLocalTimeSent + 1) == now)) { // This can happen if the same IP address is reached through multiple names - cLog(lsTRACE) << "SNTP: Redundant query suppressed"; + WriteLog (lsTRACE, SNTPClient) << "SNTP: Redundant query suppressed"; return; } query.mReceivedReply = false; @@ -96,23 +94,23 @@ void SNTPClient::receivePacket(const boost::system::error_code& error, std::size { boost::mutex::scoped_lock sl(mLock); #ifdef SNTP_DEBUG - cLog(lsTRACE) << "SNTP: Packet from " << mReceiveEndpoint; + WriteLog (lsTRACE, SNTPClient) << "SNTP: Packet from " << mReceiveEndpoint; #endif std::map::iterator query = mQueries.find(mReceiveEndpoint); if (query == mQueries.end()) - cLog(lsDEBUG) << "SNTP: Reply from " << mReceiveEndpoint << " found without matching query"; + WriteLog (lsDEBUG, SNTPClient) << "SNTP: Reply from " << mReceiveEndpoint << " found without matching query"; else if (query->second.mReceivedReply) - cLog(lsDEBUG) << "SNTP: Duplicate response from " << mReceiveEndpoint; + WriteLog (lsDEBUG, SNTPClient) << "SNTP: Duplicate response from " << mReceiveEndpoint; else { query->second.mReceivedReply = true; if (time(NULL) > (query->second.mLocalTimeSent + 1)) - cLog(lsWARNING) << "SNTP: Late response from " << mReceiveEndpoint; + WriteLog (lsWARNING, SNTPClient) << "SNTP: Late response from " << mReceiveEndpoint; else if (bytes_xferd < 48) - cLog(lsWARNING) << "SNTP: Short reply from " << mReceiveEndpoint + WriteLog (lsWARNING, SNTPClient) << "SNTP: Short reply from " << mReceiveEndpoint << " (" << bytes_xferd << ") " << mReceiveBuffer.size(); else if (reinterpret_cast(&mReceiveBuffer[0])[NTP_OFF_ORGTS_FRAC] != query->second.mQueryNonce) - cLog(lsWARNING) << "SNTP: Reply from " << mReceiveEndpoint << "had wrong nonce"; + WriteLog (lsWARNING, SNTPClient) << "SNTP: Reply from " << mReceiveEndpoint << "had wrong nonce"; else processReply(); } @@ -125,7 +123,7 @@ void SNTPClient::receivePacket(const boost::system::error_code& error, std::size void SNTPClient::sendComplete(const boost::system::error_code& error, std::size_t) { - tLog(error, lsWARNING) << "SNTP: Send error"; + CondLog (error, lsWARNING, SNTPClient) << "SNTP: Send error"; } void SNTPClient::processReply() @@ -139,12 +137,12 @@ void SNTPClient::processReply() if ((info >> 30) == 3) { - cLog(lsINFO) << "SNTP: Alarm condition " << mReceiveEndpoint; + WriteLog (lsINFO, SNTPClient) << "SNTP: Alarm condition " << mReceiveEndpoint; return; } if ((stratum == 0) || (stratum > 14)) { - cLog(lsINFO) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint; + WriteLog (lsINFO, SNTPClient) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint; return; } @@ -172,7 +170,7 @@ void SNTPClient::processReply() if ((mOffset == -1) || (mOffset == 1)) // small corrections likely do more harm than good mOffset = 0; - tLog(timev || mOffset, lsTRACE) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset; + CondLog (timev || mOffset, lsTRACE, SNTPClient) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset; } void SNTPClient::timerEntry(const boost::system::error_code& error) @@ -196,7 +194,7 @@ void SNTPClient::init(const std::vector& servers) std::vector::const_iterator it = servers.begin(); if (it == servers.end()) { - cLog(lsINFO) << "SNTP: no server specified"; + WriteLog (lsINFO, SNTPClient) << "SNTP: no server specified"; return; } BOOST_FOREACH(const std::string& it, servers) @@ -229,13 +227,13 @@ bool SNTPClient::doQuery() best = it; if (best == mServers.end()) { - cLog(lsINFO) << "SNTP: No server to query"; + WriteLog (lsINFO, SNTPClient) << "SNTP: No server to query"; return false; } time_t now = time(NULL); if ((best->second != (time_t) -1) && ((best->second + NTP_MIN_QUERY) >= now)) { - cLog(lsTRACE) << "SNTP: All servers recently queried"; + WriteLog (lsTRACE, SNTPClient) << "SNTP: All servers recently queried"; return false; } best->second = now; @@ -245,7 +243,7 @@ bool SNTPClient::doQuery() boost::bind(&SNTPClient::resolveComplete, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator)); #ifdef SNTP_DEBUG - cLog(lsTRACE) << "SNTP: Resolve pending for " << best->first; + WriteLog (lsTRACE, SNTPClient) << "SNTP: Resolve pending for " << best->first; #endif return true; }