X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ftrustlistinserter.cpp;h=5f2fbb8fb394d8f3deab05186d18844533b594cc;hb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;hp=c5cc7df36fda8ddb9ca5ee38096811a2a31f2ef3;hpb=1b0c3b7f86935a772aad271bad4f3d1f37243c2d;p=fms.git diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index c5cc7df..5f2fbb8 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -21,7 +21,13 @@ void TrustListInserter::CheckForNeededInsert() { DateTime date; date.SetToGMTime(); - date.Add(0,0,-1); + int currentday=date.GetDay(); + date.Add(0,0,-6); + // insert trust lists every 6 hours - if 6 hours ago was different day then set to midnight of current day to insert list today ASAP + if(currentday!=date.GetDay()) + { + date.Set(date.GetYear(),date.GetMonth(),currentday); + } SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID, PrivateKey FROM tblLocalIdentity WHERE PrivateKey IS NOT NULL AND PrivateKey <> '' AND PublishTrustList='true' AND InsertingTrustList='false' AND (LastInsertedTrustList<='"+date.Format("%Y-%m-%d %H:%M:%S")+"' OR LastInsertedTrustList IS NULL);"); if(rs.Empty()==false) @@ -68,14 +74,14 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) { m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false', LastInsertedTrustList='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); m_db->Execute("INSERT INTO tblTrustListInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted TrustList xml"); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListInserter::HandleMessage inserted TrustList xml"); return true; } if(message.GetName()=="PutFailed") { m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false' WHERE LocalIdentityID="+idparts[1]+";"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failure inserting TrustList xml. Code="+message["Code"]+" Description="+message["CodeDescription"]); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListInserter::HandleMessage failure inserting TrustList xml. Code="+message["Code"]+" Description="+message["CodeDescription"]); // if code 9 (collision), then insert index into inserted table if(message["Code"]=="9") @@ -93,7 +99,7 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) void TrustListInserter::Initialize() { - Option::instance()->Get("MessageBase",m_messagebase); + Option::Instance()->Get("MessageBase",m_messagebase); m_lastchecked.SetToGMTime(); } @@ -126,15 +132,18 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin std::string publickey; int messagetrust; int trustlisttrust; - DateTime now; + DateTime now,date; int index; std::string indexstr; std::string localidentityidstr; now.SetToGMTime(); - - // build the xml file - SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'';"); + date.SetToGMTime(); + + // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities + date.Add(0,0,0,-20); // identities seen in last 20 days + SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;"); + st.Bind(0,date.Format("%Y-%m-%d")); st.Step(); while(st.RowReturned()) { @@ -174,4 +183,4 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='true' WHERE LocalIdentityID="+localidentityidstr+";"); -} \ No newline at end of file +}