#include "../../include/freenet/freenetssk.h"\r
#include "../../include/option.h"\r
#include "../../include/stringfunctions.h"\r
-#include "../../include/xyssl/sha1.h"\r
#include "../../include/hex.h"\r
\r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timestamp.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+#include <Poco/SHA1Engine.h>\r
+\r
#ifdef XMEM\r
#include <xmem.h>\r
#endif\r
const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message)\r
{\r
FreenetSSK ssk;\r
- DateTime date;\r
+ Poco::DateTime date;\r
std::vector<std::string> idparts;\r
std::vector<char> data;\r
long datalength;\r
{\r
// we don't already know about this id - add it\r
st.Finalize();\r
- date.SetToGMTime();\r
- st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES(?,?);");\r
+ date=Poco::Timestamp();\r
+ st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES(?,?,?);");\r
st.Bind(0,xml.GetIdentity());\r
- st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S"));\r
+ st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
+ st.Bind(2,"solved captcha");\r
st.Step();\r
}\r
st.Finalize();\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAddData parsed a valid identity.");\r
+ m_log->debug("IdentityIntroductionRequester::HandleAddData parsed a valid identity.");\r
}\r
else\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData parsed, public SSK key was not valid.");\r
+ m_log->error("IdentityIntroductionRequester::HandleAllData parsed, public SSK key was not valid.");\r
}\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]);\r
+ m_log->debug("IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]);\r
}\r
else\r
{\r
st.Step();\r
st.Finalize(); \r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData error parsing IdentityIntroduction XML file : "+message["Identifier"]);\r
+ m_log->error("IdentityIntroductionRequester::HandleAllData error parsing IdentityIntroduction XML file : "+message["Identifier"]);\r
}\r
\r
// remove UUID from request list\r
st.Step();\r
st.Finalize();\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData Fatal GetFailed for "+message["Identifier"]);\r
+ m_log->debug("IdentityIntroductionRequester::HandleAllData Fatal GetFailed for "+message["Identifier"]);\r
}\r
\r
// remove UUID from request list\r
if(m_maxrequests<1)\r
{\r
m_maxrequests=1;\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". It must be 1 or greater.");\r
+ m_log->error("Option MaxIdentityIntroductionRequests is currently set at "+tempval+". It must be 1 or greater.");\r
}\r
if(m_maxrequests>100)\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
+ m_log->warning("Option MaxIdentityIntroductionRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
}\r
Option::Instance()->Get("MessageBase",m_messagebase);\r
- m_tempdate.SetToGMTime();\r
+ m_tempdate=Poco::Timestamp();\r
}\r
\r
void IdentityIntroductionRequester::PopulateIDList()\r
{\r
- DateTime date;\r
+ Poco::DateTime date;\r
int id;\r
\r
- date.SetToGMTime();\r
- date.Add(0,0,0,-1);\r
+ date-=Poco::Timespan(1,0,0,0,0);\r
\r
// get all identities that have unsolved puzzles from yesterday or today\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblIntroductionPuzzleInserts WHERE Day>='"+date.Format("%Y-%m-%d")+"' AND FoundSolution='false' GROUP BY LocalIdentityID;");\r
+ SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblIntroductionPuzzleInserts WHERE Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND FoundSolution='false' GROUP BY LocalIdentityID;");\r
st.Step();\r
\r
m_ids.clear();\r
}\r
// special case - if there were 0 identities on the list when we started then we will never get a chance to repopulate the list\r
// this will recheck for ids every minute\r
- DateTime now;\r
- now.SetToGMTime();\r
- if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0)))\r
+ Poco::DateTime now;\r
+ if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0)))\r
{\r
PopulateIDList();\r
m_tempdate=now;\r
{\r
std::string day;\r
std::string solution;\r
- std::vector<unsigned char> solutionhash;\r
std::string encodedhash;\r
FCPMessage message;\r
SQLite3DB::Statement st=m_db->Prepare("SELECT Day, PuzzleSolution FROM tblIntroductionPuzzleInserts WHERE FoundSolution='false' AND UUID=?;");\r
st.ResultText(1,solution);\r
\r
// get the hash of the solution\r
- solutionhash.resize(20);\r
- sha1((unsigned char *)solution.c_str(),solution.size(),&solutionhash[0]);\r
- Hex::Encode(solutionhash,encodedhash);\r
+ Poco::SHA1Engine sha1;\r
+ sha1.update(solution);\r
+ encodedhash=Poco::DigestEngine::digestToHex(sha1.digest());\r
+ StringFunctions::UpperCase(encodedhash,encodedhash);\r
\r
//start request for the solution\r
message.SetName("ClientGet");\r
\r
void IdentityIntroductionRequester::StartRequests(const long localidentityid)\r
{\r
- DateTime date;\r
+ Poco::DateTime date;\r
std::string localidentityidstr;\r
std::string uuid;\r
\r
- date.SetToGMTime();\r
- date.Add(0,0,0,-1);\r
+ date-=Poco::Timespan(1,0,0,0,0);\r
StringFunctions::Convert(localidentityid,localidentityidstr);\r
\r
// get all non-solved puzzles from yesterday and today for this identity\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE LocalIdentityID="+localidentityidstr+" AND Day>='"+date.Format("%Y-%m-%d")+"' AND FoundSolution='false';");\r
+ SQLite3DB::Statement st=m_db->Prepare("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE LocalIdentityID="+localidentityidstr+" AND Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND FoundSolution='false';");\r
st.Step();\r
\r
// start requests for all non-solved puzzles\r