version 0.3.0
[fms.git] / src / freenet / identityintroductionrequester.cpp
index 0e5e3dd..7def9f2 100644 (file)
@@ -3,9 +3,13 @@
 #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
@@ -34,7 +38,7 @@ void IdentityIntroductionRequester::FCPDisconnected()
 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
@@ -81,23 +85,23 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message)
                        {\r
                                // we don't already know about this id - add it\r
                                st.Finalize();\r
-                               date.SetToGMTime();\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
@@ -107,7 +111,7 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message)
                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
@@ -130,7 +134,7 @@ const bool IdentityIntroductionRequester::HandleGetFailed(FCPMessage &message)
                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
@@ -183,26 +187,25 @@ void IdentityIntroductionRequester::Initialize()
        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
@@ -242,9 +245,8 @@ void IdentityIntroductionRequester::Process()
        }\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
@@ -275,7 +277,7 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID)
 {\r
        std::string day;\r
        std::string solution;\r
-       std::vector<unsigned char> solutionhash;\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
@@ -287,10 +289,15 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID)
                st.ResultText(0,day);\r
                st.ResultText(1,solution);\r
 \r
+               Poco::SHA1Engine sha1;\r
+               sha1.update(solution);\r
+               encodedhash=Poco::DigestEngine::digestToHex(sha1.digest());\r
+               StringFunctions::UpperCase(encodedhash,encodedhash);\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
+//             solutionhash.resize(20);\r
+//             sha1((unsigned char *)solution.c_str(),solution.size(),&solutionhash[0]);\r
+//             Hex::Encode(solutionhash,encodedhash);\r
 \r
                //start request for the solution\r
                message.SetName("ClientGet");\r
@@ -309,16 +316,15 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID)
 \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