version 0.1.12
[fms.git] / src / freenet / introductionpuzzlerequester.cpp
index 44c165a..03d4a41 100644 (file)
@@ -64,6 +64,9 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)
        // parse file into xml and update the database\r
        if(xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
        {\r
+\r
+               // TODO - check if last part of UUID matches public key of identity who inserted it\r
+\r
                st=m_db->Prepare("INSERT INTO tblIntroductionPuzzleRequests(IdentityID,Day,RequestIndex,Found,UUID,Type,MimeType,PuzzleData) VALUES(?,?,?,?,?,?,?,?);");\r
                st.Bind(0,identityid);\r
                st.Bind(1,idparts[4]);\r
@@ -188,11 +191,21 @@ void IntroductionPuzzleRequester::PopulateIDList()
 {\r
        DateTime now;\r
        int id;\r
+       std::string limitnum="30";\r
+\r
+       // if we don't have an identity that we haven't seen yet, then set limit to 5\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity LEFT JOIN tblIdentity ON tblLocalIdentity.PublicKey=tblIdentity.PublicKey WHERE tblIdentity.IdentityID IS NULL;");\r
+       st.Step();\r
+       if(!st.RowReturned())\r
+       {\r
+               limitnum="5";\r
+       }\r
+       st.Finalize();\r
 \r
        now.SetToGMTime();\r
 \r
-       // select identities that aren't single use and have been seen today\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+now.Format("%Y-%m-%d")+"';");\r
+       // select identities that aren't single use and have been seen today ( order by trust DESC and limit to limitnum )\r
+       st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+now.Format("%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";");\r
        st.Step();\r
 \r
        m_ids.clear();\r