version 0.3.9
[fms.git] / src / freenet / introductionpuzzleinserter.cpp
index 409a0f7..1fa13c0 100644 (file)
@@ -173,70 +173,77 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
        }\r
        StringFunctions::Convert(index,indexstr);\r
 \r
-       SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");\r
-       if(rs2.Empty()==false && rs2.GetField(0)!=NULL)\r
+       if(index<50)\r
        {\r
-               privatekey=rs2.GetField(0);\r
-               if(rs2.GetField(1))\r
+               SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");\r
+               if(rs2.Empty()==false && rs2.GetField(0)!=NULL)\r
                {\r
-                       publickey=rs2.GetField(1);\r
-               }\r
-               if(publickey.size()>=50)\r
-               {\r
-                       // remove - and ~\r
-                       keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+                       privatekey=rs2.GetField(0);\r
+                       if(rs2.GetField(1))\r
+                       {\r
+                               publickey=rs2.GetField(1);\r
+                       }\r
+                       if(publickey.size()>=50)\r
+                       {\r
+                               // remove - and ~\r
+                               keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+                       }\r
                }\r
-       }\r
 \r
-       Option::Instance()->Get("MessageBase",messagebase);\r
+               Option::Instance()->Get("MessageBase",messagebase);\r
 \r
-       GenerateCaptcha(encodedpuzzle,solutionstring);\r
+               GenerateCaptcha(encodedpuzzle,solutionstring);\r
 \r
-       try\r
-       {\r
-               uuid=uuidgen.createRandom();\r
+               try\r
+               {\r
+                       uuid=uuidgen.createRandom();\r
+               }\r
+               catch(...)\r
+               {\r
+                       m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID");\r
+               }\r
+\r
+               xml.SetType("captcha");\r
+               std::string uuidstr=uuid.toString();\r
+               StringFunctions::UpperCase(uuidstr,uuidstr);\r
+               xml.SetUUID(uuidstr+"@"+keypart);\r
+               xml.SetPuzzleData(encodedpuzzle);\r
+               xml.SetMimeType("image/bmp");\r
+\r
+               xmldata=xml.GetXML();\r
+               StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
+\r
+               message.SetName("ClientPut");\r
+               message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
+               message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
+               message["UploadFrom"]="direct";\r
+               message["DataLength"]=xmldatasizestr;\r
+               m_fcp->SendMessage(message);\r
+               m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+\r
+               // insert to USK\r
+               message.Reset();\r
+               message.SetName("ClientPutComplexDir");\r
+               message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
+               message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
+               message["DefaultName"]="IntroductionPuzzle.xml";\r
+               message["Files.0.Name"]="IntroductionPuzzle.xml";\r
+               message["Files.0.UplaodFrom"]="direct";\r
+               message["Files.0.DataLength"]=xmldatasizestr;\r
+               m_fcp->SendMessage(message);\r
+               m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+\r
+               m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
+\r
+               m_inserting.push_back(localidentityid);\r
+\r
+               m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
        }\r
-       catch(...)\r
+       else\r
        {\r
-               m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID");\r
+               m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted 50 puzzles for "+idstring);\r
        }\r
 \r
-       xml.SetType("captcha");\r
-       std::string uuidstr=uuid.toString();\r
-       StringFunctions::UpperCase(uuidstr,uuidstr);\r
-       xml.SetUUID(uuidstr+"@"+keypart);\r
-       xml.SetPuzzleData(encodedpuzzle);\r
-       xml.SetMimeType("image/bmp");\r
-\r
-       xmldata=xml.GetXML();\r
-       StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
-\r
-       message.SetName("ClientPut");\r
-       message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
-       message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
-       message["UploadFrom"]="direct";\r
-       message["DataLength"]=xmldatasizestr;\r
-       m_fcp->SendMessage(message);\r
-       m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
-\r
-       // insert to USK\r
-       message.Reset();\r
-       message.SetName("ClientPutComplexDir");\r
-       message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
-       message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
-       message["DefaultName"]="IntroductionPuzzle.xml";\r
-       message["Files.0.Name"]="IntroductionPuzzle.xml";\r
-       message["Files.0.UplaodFrom"]="direct";\r
-       message["Files.0.DataLength"]=xmldatasizestr;\r
-       m_fcp->SendMessage(message);\r
-       m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
-\r
-       m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
-\r
-       m_inserting.push_back(localidentityid);\r
-\r
-       m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
-\r
        return true;\r
 \r
 }\r