Move SNTPClient to ripple_net module

This commit is contained in:
Vinnie Falco
2013-05-22 17:21:55 -07:00
parent 3b801a4433
commit 155a0a95c3
3 changed files with 26 additions and 23 deletions

View File

@@ -41,6 +41,8 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
return 512 == iKeyLength ? theApp->getWallet().getDh512() : theApp->getWallet().getDh1024(); 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/ConnectionPool.cpp"
#include "src/cpp/ripple/NetworkOPs.cpp" #include "src/cpp/ripple/NetworkOPs.cpp"
#include "src/cpp/ripple/Peer.cpp" #include "src/cpp/ripple/Peer.cpp"

View File

@@ -110,6 +110,9 @@
<Filter Include="1. Modules\ripple_net\sockets"> <Filter Include="1. Modules\ripple_net\sockets">
<UniqueIdentifier>{afd09812-59e2-45e2-bf7f-d561b23d7da2}</UniqueIdentifier> <UniqueIdentifier>{afd09812-59e2-45e2-bf7f-d561b23d7da2}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="1. Modules\ripple_net\service">
<UniqueIdentifier>{074b2e47-f34b-42f1-945e-7e8083bbfb43}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\cpp\database\sqlite3.c"> <ClCompile Include="src\cpp\database\sqlite3.c">
@@ -406,9 +409,6 @@
<ClCompile Include="src\cpp\ripple\PFRequest.cpp"> <ClCompile Include="src\cpp\ripple\PFRequest.cpp">
<Filter>Unsorted Sources</Filter> <Filter>Unsorted Sources</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\cpp\ripple\SNTPClient.cpp">
<Filter>Unsorted Sources</Filter>
</ClCompile>
<ClCompile Include="src\cpp\ripple\Suppression.cpp"> <ClCompile Include="src\cpp\ripple\Suppression.cpp">
<Filter>Unsorted Sources</Filter> <Filter>Unsorted Sources</Filter>
</ClCompile> </ClCompile>
@@ -721,6 +721,9 @@
<ClCompile Include="src\cpp\ripple\ScriptData.cpp"> <ClCompile Include="src\cpp\ripple\ScriptData.cpp">
<Filter>1. Modules\ripple_ledger\contracts</Filter> <Filter>1. Modules\ripple_ledger\contracts</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\cpp\ripple\SNTPClient.cpp">
<Filter>1. Modules\ripple_net\service</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="database\sqlite3ext.h"> <ClInclude Include="database\sqlite3ext.h">
@@ -1038,9 +1041,6 @@
<ClInclude Include="src\cpp\ripple\PFRequest.h"> <ClInclude Include="src\cpp\ripple\PFRequest.h">
<Filter>Unsorted Sources</Filter> <Filter>Unsorted Sources</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\cpp\ripple\SNTPClient.h">
<Filter>Unsorted Sources</Filter>
</ClInclude>
<ClInclude Include="src\cpp\ripple\Suppression.h"> <ClInclude Include="src\cpp\ripple\Suppression.h">
<Filter>Unsorted Sources</Filter> <Filter>Unsorted Sources</Filter>
</ClInclude> </ClInclude>
@@ -1359,6 +1359,9 @@
<ClInclude Include="src\cpp\ripple\ScriptData.h"> <ClInclude Include="src\cpp\ripple\ScriptData.h">
<Filter>1. Modules\ripple_ledger\contracts</Filter> <Filter>1. Modules\ripple_ledger\contracts</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\cpp\ripple\SNTPClient.h">
<Filter>1. Modules\ripple_net\service</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="wallet.xml" /> <None Include="wallet.xml" />

View File

@@ -10,8 +10,6 @@
#include "Config.h" #include "Config.h"
#include "Log.h" #include "Log.h"
SETUP_LOG();
// #define SNTP_DEBUG // #define SNTP_DEBUG
static uint8_t SNTPQueryData[48] = static uint8_t SNTPQueryData[48] =
@@ -75,7 +73,7 @@ void SNTPClient::resolveComplete(const boost::system::error_code& error, boost::
time_t now = time(NULL); time_t now = time(NULL);
if ((query.mLocalTimeSent == now) || ((query.mLocalTimeSent + 1) == now)) if ((query.mLocalTimeSent == now) || ((query.mLocalTimeSent + 1) == now))
{ // This can happen if the same IP address is reached through multiple names { // 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; return;
} }
query.mReceivedReply = false; query.mReceivedReply = false;
@@ -96,23 +94,23 @@ void SNTPClient::receivePacket(const boost::system::error_code& error, std::size
{ {
boost::mutex::scoped_lock sl(mLock); boost::mutex::scoped_lock sl(mLock);
#ifdef SNTP_DEBUG #ifdef SNTP_DEBUG
cLog(lsTRACE) << "SNTP: Packet from " << mReceiveEndpoint; WriteLog (lsTRACE, SNTPClient) << "SNTP: Packet from " << mReceiveEndpoint;
#endif #endif
std::map<boost::asio::ip::udp::endpoint, SNTPQuery>::iterator query = mQueries.find(mReceiveEndpoint); std::map<boost::asio::ip::udp::endpoint, SNTPQuery>::iterator query = mQueries.find(mReceiveEndpoint);
if (query == mQueries.end()) 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) else if (query->second.mReceivedReply)
cLog(lsDEBUG) << "SNTP: Duplicate response from " << mReceiveEndpoint; WriteLog (lsDEBUG, SNTPClient) << "SNTP: Duplicate response from " << mReceiveEndpoint;
else else
{ {
query->second.mReceivedReply = true; query->second.mReceivedReply = true;
if (time(NULL) > (query->second.mLocalTimeSent + 1)) 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) else if (bytes_xferd < 48)
cLog(lsWARNING) << "SNTP: Short reply from " << mReceiveEndpoint WriteLog (lsWARNING, SNTPClient) << "SNTP: Short reply from " << mReceiveEndpoint
<< " (" << bytes_xferd << ") " << mReceiveBuffer.size(); << " (" << bytes_xferd << ") " << mReceiveBuffer.size();
else if (reinterpret_cast<uint32*>(&mReceiveBuffer[0])[NTP_OFF_ORGTS_FRAC] != query->second.mQueryNonce) else if (reinterpret_cast<uint32*>(&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 else
processReply(); 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) 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() void SNTPClient::processReply()
@@ -139,12 +137,12 @@ void SNTPClient::processReply()
if ((info >> 30) == 3) if ((info >> 30) == 3)
{ {
cLog(lsINFO) << "SNTP: Alarm condition " << mReceiveEndpoint; WriteLog (lsINFO, SNTPClient) << "SNTP: Alarm condition " << mReceiveEndpoint;
return; return;
} }
if ((stratum == 0) || (stratum > 14)) if ((stratum == 0) || (stratum > 14))
{ {
cLog(lsINFO) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint; WriteLog (lsINFO, SNTPClient) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint;
return; return;
} }
@@ -172,7 +170,7 @@ void SNTPClient::processReply()
if ((mOffset == -1) || (mOffset == 1)) // small corrections likely do more harm than good if ((mOffset == -1) || (mOffset == 1)) // small corrections likely do more harm than good
mOffset = 0; 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) void SNTPClient::timerEntry(const boost::system::error_code& error)
@@ -196,7 +194,7 @@ void SNTPClient::init(const std::vector<std::string>& servers)
std::vector<std::string>::const_iterator it = servers.begin(); std::vector<std::string>::const_iterator it = servers.begin();
if (it == servers.end()) if (it == servers.end())
{ {
cLog(lsINFO) << "SNTP: no server specified"; WriteLog (lsINFO, SNTPClient) << "SNTP: no server specified";
return; return;
} }
BOOST_FOREACH(const std::string& it, servers) BOOST_FOREACH(const std::string& it, servers)
@@ -229,13 +227,13 @@ bool SNTPClient::doQuery()
best = it; best = it;
if (best == mServers.end()) if (best == mServers.end())
{ {
cLog(lsINFO) << "SNTP: No server to query"; WriteLog (lsINFO, SNTPClient) << "SNTP: No server to query";
return false; return false;
} }
time_t now = time(NULL); time_t now = time(NULL);
if ((best->second != (time_t) -1) && ((best->second + NTP_MIN_QUERY) >= now)) 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; return false;
} }
best->second = now; best->second = now;
@@ -245,7 +243,7 @@ bool SNTPClient::doQuery()
boost::bind(&SNTPClient::resolveComplete, this, boost::bind(&SNTPClient::resolveComplete, this,
boost::asio::placeholders::error, boost::asio::placeholders::iterator)); boost::asio::placeholders::error, boost::asio::placeholders::iterator));
#ifdef SNTP_DEBUG #ifdef SNTP_DEBUG
cLog(lsTRACE) << "SNTP: Resolve pending for " << best->first; WriteLog (lsTRACE, SNTPClient) << "SNTP: Resolve pending for " << best->first;
#endif #endif
return true; return true;
} }