X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityinserter.cpp;h=aa1f4ab8f19ecb8ebb6e9fa28f3cf0b0cfc3a224;hb=964f55fd550fc711c0320ce6a24ad713040695d0;hp=33a80854c820e037d8bb1834ba56e79f10826606;hpb=d8f51eac91f86a1e00a05a5058a8fa9eb8732464;p=fms.git diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index 33a8085..aa1f4ab 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -17,18 +17,24 @@ IdentityInserter::IdentityInserter(FCPv2 *fcp):IFCPConnected(fcp) Initialize(); } -void IdentityInserter::FCPConnected() -{ - m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false';"); -} - void IdentityInserter::CheckForNeededInsert() { + DateTime now; DateTime date; + now.SetToGMTime(); date.SetToGMTime(); // 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 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;"); if(rs.Empty()==false) @@ -38,6 +44,12 @@ void IdentityInserter::CheckForNeededInsert() } +void IdentityInserter::FCPConnected() +{ + m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false';"); +} + + void IdentityInserter::FCPDisconnected() { @@ -68,16 +80,23 @@ 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]+";"); + } 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") @@ -127,7 +146,7 @@ void IdentityInserter::StartInsert(const long localidentityid) StringFunctions::Convert(localidentityid,idstring); date.SetToGMTime(); - SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse,PublishTrustList,PublishBoardList FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs.Empty()==false) { @@ -141,6 +160,8 @@ void IdentityInserter::StartInsert(const long localidentityid) long index=0; std::string indexstr; std::string singleuse="false"; + std::string publishtrustlist="false"; + std::string publishboardlist="false"; now.SetToGMTime(); @@ -176,6 +197,18 @@ void IdentityInserter::StartInsert(const long localidentityid) } singleuse=="true" ? idxml.SetSingleUse(true) : idxml.SetSingleUse(false); + if(rs.GetField(3)) + { + publishtrustlist=rs.GetField(3); + } + publishtrustlist=="true" ? idxml.SetPublishTrustList(true) : idxml.SetPublishTrustList(false); + + if(rs.GetField(4)) + { + publishboardlist=rs.GetField(4); + } + publishboardlist=="true" ? idxml.SetPublishBoardList(true) : idxml.SetPublishBoardList(false); + data=idxml.GetXML(); StringFunctions::Convert(data.size(),datasizestr);