X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fperiodicdbmaintenance.cpp;h=63863f80c74ca0879beb89c7e3829ac104dfc7c7;hb=4430e7762844c66428b6f822288beb71b7f82b95;hp=0febbbd736f6210ff8a1ecedf89fe8cec2008e12;hpb=f60495a029c54358f82956482fe203fe2b7b5b23;p=fms.git diff --git a/src/freenet/periodicdbmaintenance.cpp b/src/freenet/periodicdbmaintenance.cpp index 0febbbd..63863f8 100644 --- a/src/freenet/periodicdbmaintenance.cpp +++ b/src/freenet/periodicdbmaintenance.cpp @@ -1,4 +1,5 @@ #include "../../include/freenet/periodicdbmaintenance.h" +#include "../../include/stringfunctions.h" #ifdef XMEM #include @@ -13,8 +14,9 @@ PeriodicDBMaintenance::PeriodicDBMaintenance() m_check1day.SetToGMTime(); // set back times so they will do their first maintenance soon ( within the next hour ) - stagger so not all run at once - m_check1hour.Add(0,-45); - m_check6hours.Add(0,0,-5); + m_check30mins.Add(0,-5); + m_check1hour.Add(0,-42); + m_check6hours.Add(0,-1,-5); m_check1day.Add(0,0,-23); } @@ -83,7 +85,67 @@ void PeriodicDBMaintenance::Do1DayMaintenance() date.SetToGMTime(); date.Add(0,0,0,-2); m_db->Execute("DELETE FROM tblTrustListInserts WHERE Day<'"+date.Format("%Y-%m-%d")+"';"); - m_db->Execute("DELETE FROM tblTrustListRequests WHERE Day<'"+date.Format("%Y-%m-%d")+"';"); + m_db->Execute("DELETE FROM tblTrustListRequests WHERE Day<'"+date.Format("%Y-%m-%d")+"';"); + + // delete trust lists from identities we aren't trusting anymore + m_db->Execute("DELETE FROM tblPeerTrust WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity WHERE (LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust')) AND (PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust')));"); + + // remove identityid from messages where the identity has been deleted + m_db->Execute("UPDATE tblMessage SET IdentityID=NULL WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity);"); + + // try to re-attach messages from identities that were previously deleted, but have been since re-added + // first get the names from messages that have a NULL IdentityID + SQLite3DB::Statement st=m_db->Prepare("SELECT FromName FROM tblMessage WHERE IdentityID IS NULL GROUP BY FromName;"); + st.Step(); + while(st.RowReturned()) + { + std::string name=""; + std::string publickey=""; + int identityid=0; + st.ResultText(0,name); + + std::vector parts; + StringFunctions::Split(name,"@",parts); + + // find identities with this name + SQLite3DB::Statement st2=m_db->Prepare("SELECT IdentityID,PublicKey FROM tblIdentity WHERE Name=?;"); + st2.Bind(0,name); + st2.Step(); + while(st2.RowReturned()) + { + publickey=""; + identityid=0; + st2.ResultText(1,publickey); + // check if public key matches 2nd part + if(parts.size()>1 && publickey.find(parts[1])==4) + { + // we have the identity - so update the messages table with the identityid + st2.ResultInt(0,identityid); + + SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE Name=? AND IdentityID IS NULL;"); + st3.Bind(0,identityid); + st3.Bind(1,name); + st3.Step(); + } + st2.Step(); + } + + st.Step(); + } + + // delete single use identities that are older than 7 days + date.SetToGMTime(); + date.Add(0,0,0,-7); + st=m_db->Prepare("DELETE FROM tblIdentity WHERE SingleUse='true' AND DateAddedPrepare("DELETE FROM tblLocalIdentity WHERE SingleUse='true' AND DateCreated