X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityinserter.cpp;h=f246d66402989d8bb6c75e1bba1fa51bc1786b30;hb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0;hp=028f49568f30b1c75b74c76d3a99b2a8bff42cde;hpb=1b0c3b7f86935a772aad271bad4f3d1f37243c2d;p=fms.git diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index 028f495..f246d66 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -26,10 +26,13 @@ void IdentityInserter::CheckForNeededInsert() // set date to 1 hour back date.Add(0,0,-1); - // Because of importance of Identity.xml, if we are now at the next day we immediately want to insert identities so change the date back to now + // Because of importance of Identity.xml, if we are now at the next day we immediately want to insert identities so change the date back to 12:00 AM so we find all identities not inserted yet today if(date.GetDay()!=now.GetDay()) { date=now; + date.SetHour(0); + date.SetMinute(0); + date.SetSecond(0); } SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID FROM tblLocalIdentity WHERE PrivateKey IS NOT NULL AND PrivateKey <> '' AND InsertingIdentity='false' AND (LastInsertedIdentity<'"+date.Format("%Y-%m-%d %H:%M:%S")+"' OR LastInsertedIdentity IS NULL) ORDER BY LastInsertedIdentity;"); @@ -77,16 +80,27 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message) if(message.GetName()=="PutSuccessful") { - m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity. + // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today + DateTime lastdate; + lastdate.Set(idparts[4]); + if(lastdate.GetDay()==now.GetDay()) + { + m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + } + else + { + m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";"); + } m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted identity xml"); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage inserted Identity xml"); return true; } if(message.GetName()=="PutFailed") { m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failure inserting identity xml. Code="+message["Code"]+" Description="+message["CodeDescription"]); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityInserter::HandleMessage failure inserting Identity xml. Code="+message["Code"]+" Description="+message["CodeDescription"]); // if code 9 (collision), then insert index into inserted table if(message["Code"]=="9") @@ -136,7 +150,7 @@ void IdentityInserter::StartInsert(const long localidentityid) StringFunctions::Convert(localidentityid,idstring); date.SetToGMTime(); - SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse,PublishTrustList,PublishBoardList FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite,FreesiteEdition FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs.Empty()==false) { @@ -152,6 +166,8 @@ void IdentityInserter::StartInsert(const long localidentityid) std::string singleuse="false"; std::string publishtrustlist="false"; std::string publishboardlist="false"; + std::string freesiteedition=""; + int edition=-1; now.SetToGMTime(); @@ -169,7 +185,7 @@ void IdentityInserter::StartInsert(const long localidentityid) } StringFunctions::Convert(index,indexstr); - Option::instance()->Get("MessageBase",messagebase); + Option::Instance()->Get("MessageBase",messagebase); if(rs.GetField(0)) { @@ -195,10 +211,20 @@ void IdentityInserter::StartInsert(const long localidentityid) if(rs.GetField(4)) { - publishboardlist=rs.GetField(3); + publishboardlist=rs.GetField(4); } publishboardlist=="true" ? idxml.SetPublishBoardList(true) : idxml.SetPublishBoardList(false); + if(rs.GetField(5) && rs.GetField(6)) + { + if(std::string(rs.GetField(5))=="true") + { + freesiteedition=rs.GetField(6); + StringFunctions::Convert(freesiteedition,edition); + idxml.SetFreesiteEdition(edition); + } + } + data=idxml.GetXML(); StringFunctions::Convert(data.size(),datasizestr);