X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityintroductionrequester.cpp;h=951e12dc85f308e3a53786afcfe253bd01ba2320;hb=c0ebc7b53a977885ebc2d3a679c586ae20c0bc4a;hp=80a27c21f31a306ff0f1c23cd639a04330773bd4;hpb=c7fcb4c4bc5012a584add81a9509fc1f84c3c688;p=fms.git diff --git a/src/freenet/identityintroductionrequester.cpp b/src/freenet/identityintroductionrequester.cpp index 80a27c2..951e12d 100644 --- a/src/freenet/identityintroductionrequester.cpp +++ b/src/freenet/identityintroductionrequester.cpp @@ -3,9 +3,13 @@ #include "../../include/freenet/freenetssk.h" #include "../../include/option.h" #include "../../include/stringfunctions.h" -#include "../../include/xyssl/sha1.h" #include "../../include/hex.h" +#include +#include +#include +#include + #ifdef XMEM #include #endif @@ -34,7 +38,7 @@ void IdentityIntroductionRequester::FCPDisconnected() const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) { FreenetSSK ssk; - DateTime date; + Poco::DateTime date; std::vector idparts; std::vector data; long datalength; @@ -57,10 +61,13 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) // receive the file data.resize(datalength); - m_fcp->ReceiveRaw(&data[0],datalength); + if(data.size()>0) + { + m_fcp->ReceiveRaw(&data[0],datalength); + } // parse file into xml and update the database - if(xml.ParseXML(std::string(data.begin(),data.end()))==true) + if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) { ssk.SetPublicKey(xml.GetIdentity()); @@ -81,22 +88,23 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) { // we don't already know about this id - add it st.Finalize(); - date.SetToGMTime(); - st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES(?,?);"); + date=Poco::Timestamp(); + st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES(?,?,?);"); st.Bind(0,xml.GetIdentity()); - st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")); + st.Bind(2,"solved captcha"); st.Step(); } st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAddData parsed a valid identity."); + m_log->debug("IdentityIntroductionRequester::HandleAddData parsed a valid identity."); } else { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData parsed, public SSK key was not valid."); + m_log->error("IdentityIntroductionRequester::HandleAllData parsed, public SSK key was not valid."); } - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]); + m_log->debug("IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]); } else { @@ -106,7 +114,7 @@ const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData error parsing IdentityIntroduction XML file : "+message["Identifier"]); + m_log->error("IdentityIntroductionRequester::HandleAllData error parsing IdentityIntroduction XML file : "+message["Identifier"]); } // remove UUID from request list @@ -129,7 +137,7 @@ const bool IdentityIntroductionRequester::HandleGetFailed(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData Fatal GetFailed for "+message["Identifier"]); + m_log->debug("IdentityIntroductionRequester::HandleAllData Fatal GetFailed for "+message["Identifier"]); } // remove UUID from request list @@ -176,32 +184,30 @@ const bool IdentityIntroductionRequester::HandleMessage(FCPMessage &message) void IdentityIntroductionRequester::Initialize() { - std::string tempval=""; - Option::Instance()->Get("MaxIdentityIntroductionRequests",tempval); - StringFunctions::Convert(tempval,m_maxrequests); + m_maxrequests=0; + Option::Instance()->GetInt("MaxIdentityIntroductionRequests",m_maxrequests); if(m_maxrequests<1) { m_maxrequests=1; - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". It must be 1 or greater."); + m_log->error("Option MaxIdentityIntroductionRequests is currently less than 1. It must be 1 or greater."); } if(m_maxrequests>100) { - m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". This value might be incorrectly configured."); + m_log->warning("Option MaxIdentityIntroductionRequests is currently set at more than 100. This value might be incorrectly configured."); } Option::Instance()->Get("MessageBase",m_messagebase); - m_tempdate.SetToGMTime(); + m_tempdate=Poco::Timestamp(); } void IdentityIntroductionRequester::PopulateIDList() { - DateTime date; + Poco::DateTime date; int id; - date.SetToGMTime(); - date.Add(0,0,0,-1); + date-=Poco::Timespan(1,0,0,0,0); // get all identities that have unsolved puzzles from yesterday or today - SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblIntroductionPuzzleInserts WHERE Day>='"+date.Format("%Y-%m-%d")+"' AND FoundSolution='false' GROUP BY LocalIdentityID;"); + 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;"); st.Step(); m_ids.clear(); @@ -241,9 +247,8 @@ void IdentityIntroductionRequester::Process() } // special case - if there were 0 identities on the list when we started then we will never get a chance to repopulate the list // this will recheck for ids every minute - DateTime now; - now.SetToGMTime(); - if(m_tempdate<(now-(1.0/1440.0))) + Poco::DateTime now; + if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0))) { PopulateIDList(); m_tempdate=now; @@ -274,7 +279,6 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID) { std::string day; std::string solution; - std::vector solutionhash; std::string encodedhash; FCPMessage message; SQLite3DB::Statement st=m_db->Prepare("SELECT Day, PuzzleSolution FROM tblIntroductionPuzzleInserts WHERE FoundSolution='false' AND UUID=?;"); @@ -287,9 +291,10 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID) st.ResultText(1,solution); // get the hash of the solution - solutionhash.resize(20); - sha1((unsigned char *)solution.c_str(),solution.size(),&solutionhash[0]); - Hex::Encode(solutionhash,encodedhash); + Poco::SHA1Engine sha1; + sha1.update(solution); + encodedhash=Poco::DigestEngine::digestToHex(sha1.digest()); + StringFunctions::UpperCase(encodedhash,encodedhash); //start request for the solution message.SetName("ClientGet"); @@ -308,16 +313,15 @@ void IdentityIntroductionRequester::StartRequest(const std::string &UUID) void IdentityIntroductionRequester::StartRequests(const long localidentityid) { - DateTime date; + Poco::DateTime date; std::string localidentityidstr; std::string uuid; - date.SetToGMTime(); - date.Add(0,0,0,-1); + date-=Poco::Timespan(1,0,0,0,0); StringFunctions::Convert(localidentityid,localidentityidstr); // get all non-solved puzzles from yesterday and today for this identity - SQLite3DB::Statement st=m_db->Prepare("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE LocalIdentityID="+localidentityidstr+" AND Day>='"+date.Format("%Y-%m-%d")+"' AND FoundSolution='false';"); + 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';"); st.Step(); // start requests for all non-solved puzzles