X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzleinserter.cpp;h=66635bb5ad7f8ed6f12c98fff5be87afdf1e689e;hp=f87e2bd334afafd45c39aa47aabd7f0207d381b5;hb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;hpb=d8f51eac91f86a1e00a05a5058a8fa9eb8732464 diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index f87e2bd..66635bb 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -27,11 +27,17 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() while(!rs.AtEnd()) { + std::string localidentityidstr; DateTime now; now.SetToGMTime(); + if(rs.GetField(0)) + { + localidentityidstr=rs.GetField(0); + } + // if this identity has any non-solved puzzles for today, we don't need to insert a new puzzle - SQLite3DB::Recordset rs2=m_db->Query("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE Day='"+now.Format("%Y-%m-%d")+"' AND FoundSolution='false';"); + SQLite3DB::Recordset rs2=m_db->Query("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE Day='"+now.Format("%Y-%m-%d")+"' AND FoundSolution='false' AND LocalIdentityID="+localidentityidstr+";"); // identity doesn't have any non-solved puzzles for today - start a new insert if(rs2.Empty()==true) @@ -112,7 +118,13 @@ const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failed to insert puzzle "+idparts[3]); + // if fatal error or collision - mark index + if(message["Fatal"]=="true" || message["Code"]=="9") + { + m_db->Execute("UPDATE tblIntroductionPuzzleInserts SET Day='"+idparts[5]+"', InsertIndex="+idparts[2]+", FoundSolution='true' WHERE UUID='"+idparts[3]+"';"); + } + + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleInserter::HandlePutFailed failed to insert puzzle "+idparts[3]); return true; } @@ -143,7 +155,7 @@ const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted puzzle "+idparts[3]); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleInserter::HandlePutSuccessful inserted puzzle "+idparts[3]); return true; } @@ -189,7 +201,9 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid) FCPMessage message; std::string xmldata; std::string xmldatasizestr; - std::string privatekey; + std::string privatekey=""; + std::string publickey=""; + std::string keypart=""; StringFunctions::Convert(localidentityid,idstring); now.SetToGMTime(); @@ -205,20 +219,29 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid) } StringFunctions::Convert(index,indexstr); - SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs2.Empty()==false && rs2.GetField(0)!=NULL) { privatekey=rs2.GetField(0); + if(rs2.GetField(1)) + { + publickey=rs2.GetField(1); + } + if(publickey.size()>=50) + { + // remove - and ~ + keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~",""); + } } - Option::instance()->Get("MessageBase",messagebase); + Option::Instance()->Get("MessageBase",messagebase); GenerateCaptcha(encodedpuzzle,solutionstring); xml.SetType("captcha"); - xml.SetUUID(uuid.Generate()); + xml.SetUUID(uuid.Generate()+"@"+keypart); xml.SetPuzzleData(encodedpuzzle); - xml.SetMimeType("bitmap/image"); + xml.SetMimeType("image/bmp"); xmldata=xml.GetXML(); StringFunctions::Convert(xmldata.size(),xmldatasizestr); @@ -234,6 +257,6 @@ void IntroductionPuzzleInserter::StartInsert(const long localidentityid) m_db->Execute("UPDATE tblLocalIdentity SET InsertingPuzzle='true' WHERE LocalIdentityID="+idstring+";"); m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" started insert for id "+idstring); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IntroductionPuzzleInserter::StartInsert started insert for id "+idstring); }