version 0.3.10
[fms.git] / src / freenet / introductionpuzzleinserter.cpp
index 1fa13c0..b185b9d 100644 (file)
@@ -33,8 +33,13 @@ void IntroductionPuzzleInserter::CheckForNeededInsert()
                \r
                while(!rs.AtEnd())\r
                {\r
-                       std::string localidentityidstr;\r
+                       int localidentityid=0;\r
+                       std::string localidentityidstr="";\r
                        Poco::DateTime now;\r
+                       float minutesbetweeninserts=0;\r
+                       minutesbetweeninserts=1440.0/(float)m_maxpuzzleinserts;\r
+                       Poco::DateTime lastinsert=now;\r
+                       lastinsert-=Poco::Timespan(0,0,minutesbetweeninserts,0,0);\r
 \r
                        if(rs.GetField(0))\r
                        {\r
@@ -47,7 +52,15 @@ void IntroductionPuzzleInserter::CheckForNeededInsert()
                        // identity doesn't have any non-solved puzzles for today - start a new insert\r
                        if(rs2.Empty()==true)\r
                        {\r
-                               StartInsert(rs.GetInt(0));\r
+                               if(m_lastinserted.find(rs.GetInt(0))==m_lastinserted.end() || m_lastinserted[rs.GetInt(0)]<=lastinsert)\r
+                               {\r
+                                       StartInsert(rs.GetInt(0));\r
+                                       m_lastinserted[rs.GetInt(0)]=now;\r
+                               }\r
+                               else\r
+                               {\r
+                                       m_log->trace("IntroductionPuzzleInserter::CheckForNeededInsert waiting to insert puzzle for "+localidentityidstr);\r
+                               }\r
                        }\r
 \r
                        rs.Next();\r
@@ -139,6 +152,7 @@ const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message)
 void IntroductionPuzzleInserter::Initialize()\r
 {\r
        m_fcpuniquename="IntroductionPuzzleInserter";\r
+       m_maxpuzzleinserts=50;\r
 }\r
 \r
 const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)\r
@@ -173,7 +187,7 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
        }\r
        StringFunctions::Convert(index,indexstr);\r
 \r
-       if(index<50)\r
+       if(index<m_maxpuzzleinserts)\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
@@ -241,7 +255,7 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
        }\r
        else\r
        {\r
-               m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted 50 puzzles for "+idstring);\r
+               m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted max puzzles for "+idstring);\r
        }\r
 \r
        return true;\r