X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ftrustlistinserter.cpp;h=fc02e8bfbbddf4ce4e9edc4133bb49063fb9164b;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=ee67e6bd283c6f71f35b81dd5d97190bcc83b41f;hpb=0236076defe60bcd4b3a25c23efa53c21993a48e;p=fms.git diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index ee67e6b..fc02e8b 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -3,6 +3,10 @@ #include "../../include/freenet/trustlistxml.h" #include "../../include/stringfunctions.h" +#include +#include +#include + #ifdef XMEM #include #endif @@ -19,16 +23,15 @@ TrustListInserter::TrustListInserter(FCPv2 *fcp):IFCPConnected(fcp) void TrustListInserter::CheckForNeededInsert() { - DateTime date; - date.SetToGMTime(); - int currentday=date.GetDay(); - date.Add(0,0,-6); + Poco::DateTime date; + int currentday=date.day(); + date-=Poco::Timespan(0,6,0,0,0); // 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()) + if(currentday!=date.day()) { - date.Set(date.GetYear(),date.GetMonth(),currentday); + date.assign(date.year(),date.month(),currentday,0,0,0); } - 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);"); + 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<='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")+"' OR LastInsertedTrustList IS NULL);"); if(rs.Empty()==false) { @@ -52,10 +55,9 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) if(message["Identifier"].find("TrustListInserter")==0) { - DateTime now; + Poco::DateTime now; std::vector idparts; - now.SetToGMTime(); StringFunctions::Split(message["Identifier"],"|",idparts); // no action for URIGenerated @@ -75,9 +77,9 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) // non USK if(idparts[0]=="TrustListInserter") { - m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false', LastInsertedTrustList='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false', LastInsertedTrustList='"+Poco::DateTimeFormatter::format(now,"%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,"TrustListInserter::HandleMessage inserted TrustList xml"); + m_log->debug("TrustListInserter::HandleMessage inserted TrustList xml"); } return true; } @@ -88,7 +90,7 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) if(idparts[0]=="TrustListInserter") { m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false' WHERE LocalIdentityID="+idparts[1]+";"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListInserter::HandleMessage failure inserting TrustList xml. Code="+message["Code"]+" Description="+message["CodeDescription"]); + m_log->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") @@ -107,16 +109,15 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) void TrustListInserter::Initialize() { Option::Instance()->Get("MessageBase",m_messagebase); - m_lastchecked.SetToGMTime(); + m_lastchecked=Poco::Timestamp(); } void TrustListInserter::Process() { - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; // check every minute - if(m_lastchecked<=(now-(1.0/1440.0))) + if(m_lastchecked<=(now-Poco::Timespan(0,0,1,0,0))) { CheckForNeededInsert(); m_lastchecked=now; @@ -139,7 +140,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin std::string publickey; int messagetrust; int trustlisttrust; - DateTime now,date,dateminus30,tempdate; + Poco::DateTime now,date,dateminus30,tempdate; int index; std::string indexstr; std::string localidentityidstr; @@ -150,10 +151,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin bool add=false; std::string dateadded=""; - now.SetToGMTime(); - date.SetToGMTime(); - dateminus30.SetToGMTime(); - dateminus30.Add(0,0,0,-30); + dateminus30-=Poco::Timespan(30,0,0,0,0); // insert all identities not in trust list already m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);"); @@ -162,11 +160,11 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin SQLite3DB::Statement countst=m_db->Prepare("SELECT COUNT(*) FROM tblMessage WHERE IdentityID=? AND MessageDate>=?;"); // 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,-15); // identities seen in last 15 days + date-=Poco::Timespan(15,0,0,0,0); // identities seen in last 15 days - the maintenance page lets us delete identities not seen in 20 days, so this gives us a window where the identity won't be deleted and then found in a trust list and readded immediately //SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;"); // we want to order by public key so we can't do identity correllation based on the sequence of identities in the list. SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, tblIdentityTrust.LocalMessageTrust, tblIdentityTrust.LocalTrustListTrust, tblIdentityTrust.MessageTrustComment, tblIdentityTrust.TrustListTrustComment, tblIdentity.IdentityID, tblIdentity.DateAdded FROM tblIdentity INNER JOIN tblIdentityTrust ON tblIdentity.IdentityID=tblIdentityTrust.IdentityID WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=? AND tblIdentityTrust.LocalIdentityID=? ORDER BY PublicKey;"); - st.Bind(0,date.Format("%Y-%m-%d")); + st.Bind(0,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); st.Bind(1,localidentityid); st.Step(); while(st.RowReturned()) @@ -199,7 +197,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin // add the identity to the trust list if they have posted a message in the last 30 days countst.Bind(0,identityid); - countst.Bind(1,dateminus30.Format("%Y-%m-%d")); + countst.Bind(1,Poco::DateTimeFormatter::format(dateminus30,"%Y-%m-%d")); countst.Step(); if(countst.RowReturned()) { @@ -215,8 +213,13 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin // no messages in last 30 days - add the identity if we learned about them less than 5 days ago if(add==false && dateadded!="") { - tempdate.Set(dateadded); - if(tempdate>=(now-5.0)) + int tzdiff=0; + if(Poco::DateTimeParser::tryParse(dateadded,tempdate,tzdiff)==false) + { + tempdate=Poco::Timestamp(); + m_log->fatal("TrustListInserter::StartInsert could not parse date "+dateadded); + } + if(tempdate>=(now-Poco::Timespan(5,0,0,0,0))) { add=true; } @@ -233,7 +236,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin // get next insert index st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblTrustListInserts WHERE LocalIdentityID=? AND Day=?;"); st.Bind(0,localidentityid); - st.Bind(1,now.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st.Step(); index=0; @@ -250,7 +253,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin StringFunctions::Convert(data.size(),datasizestr); message.SetName("ClientPut"); - message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|TrustList|"+indexstr+".xml"; + message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|TrustList|"+indexstr+".xml"; message["Identifier"]="TrustListInserter|"+localidentityidstr+"|"+indexstr+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=datasizestr; @@ -260,7 +263,7 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin // insert to USK message.Reset(); message.SetName("ClientPutComplexDir"); - message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|TrustList/0/"; + message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|TrustList/0/"; message["Identifier"]="TrustListInserterUSK|"+message["URI"]; message["DefaultName"]="TrustList.xml"; message["Files.0.Name"]="TrustList.xml";