X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzleinserter.cpp;h=b185b9d4a90f6b48a7126ebf574c7e347a698f02;hp=1fa13c0f88e6e410e601e2d6e14f81df6dba3e90;hb=b88f50bfec6dbcd169bb8285e7c42b93baf52b6b;hpb=07319f767b4c4f0e06e9957f217d5107b196617b diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index 1fa13c0..b185b9d 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -33,8 +33,13 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() while(!rs.AtEnd()) { - std::string localidentityidstr; + int localidentityid=0; + std::string localidentityidstr=""; Poco::DateTime now; + float minutesbetweeninserts=0; + minutesbetweeninserts=1440.0/(float)m_maxpuzzleinserts; + Poco::DateTime lastinsert=now; + lastinsert-=Poco::Timespan(0,0,minutesbetweeninserts,0,0); if(rs.GetField(0)) { @@ -47,7 +52,15 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() // identity doesn't have any non-solved puzzles for today - start a new insert if(rs2.Empty()==true) { - StartInsert(rs.GetInt(0)); + if(m_lastinserted.find(rs.GetInt(0))==m_lastinserted.end() || m_lastinserted[rs.GetInt(0)]<=lastinsert) + { + StartInsert(rs.GetInt(0)); + m_lastinserted[rs.GetInt(0)]=now; + } + else + { + m_log->trace("IntroductionPuzzleInserter::CheckForNeededInsert waiting to insert puzzle for "+localidentityidstr); + } } rs.Next(); @@ -139,6 +152,7 @@ const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message) void IntroductionPuzzleInserter::Initialize() { m_fcpuniquename="IntroductionPuzzleInserter"; + m_maxpuzzleinserts=50; } const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) @@ -173,7 +187,7 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) } StringFunctions::Convert(index,indexstr); - if(index<50) + if(indexQuery("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs2.Empty()==false && rs2.GetField(0)!=NULL) @@ -241,7 +255,7 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) } else { - m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted 50 puzzles for "+idstring); + m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted max puzzles for "+idstring); } return true;