From: SomeDude Date: Sat, 7 Jun 2008 10:15:00 +0000 (+0200) Subject: version 0.2.21 X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=commitdiff_plain;h=0236076defe60bcd4b3a25c23efa53c21993a48e version 0.2.21 --- diff --git a/include/global.h b/include/global.h index 2bc49ce..047c917 100644 --- a/include/global.h +++ b/include/global.h @@ -5,7 +5,7 @@ #include #include "pthreadwrapper/thread.h" -#define FMS_VERSION "0.2.20" +#define FMS_VERSION "0.2.21" // opens database and creates tables and initial inserts if necessary void SetupDB(); diff --git a/src/charsetconverter.cpp b/src/charsetconverter.cpp index 4685add..3026207 100644 --- a/src/charsetconverter.cpp +++ b/src/charsetconverter.cpp @@ -66,6 +66,7 @@ const bool CharsetConverter::Convert(const std::string &input, std::string &outp outvec.resize(outptr-&outvec[0]); output=""; output.append(outvec.begin(),outvec.end()); + return true; } else { diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index 126088e..ee67e6b 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -139,24 +139,33 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin std::string publickey; int messagetrust; int trustlisttrust; - DateTime now,date; + DateTime now,date,dateminus30,tempdate; int index; std::string indexstr; std::string localidentityidstr; std::string messagetrustcomment=""; std::string trustlisttrustcomment=""; + int identityid=-1; + int count=0; + bool add=false; + std::string dateadded=""; now.SetToGMTime(); date.SetToGMTime(); + dateminus30.SetToGMTime(); + dateminus30.Add(0,0,0,-30); // 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);"); + // select statement for last message date for an identity + 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 //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 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;"); + 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(1,localidentityid); st.Step(); @@ -181,7 +190,43 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin } st.ResultText(3,messagetrustcomment); st.ResultText(4,trustlisttrustcomment); - xml.AddTrust(publickey,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment); + identityid=-1; + st.ResultInt(5,identityid); + dateadded=""; + st.ResultText(6,dateadded); + + add=false; + + // 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.Step(); + if(countst.RowReturned()) + { + count=0; + countst.ResultInt(0,count); + if(count>0) + { + add=true; + } + } + countst.Reset(); + + // 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)) + { + add=true; + } + } + + if(add==true) + { + xml.AddTrust(publickey,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment); + } + st.Step(); } diff --git a/src/global.cpp b/src/global.cpp index c9bdefe..cfd458c 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -415,6 +415,11 @@ void SetupDB() AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') ) \ GROUP BY TargetIdentityID;"); + db->Execute("CREATE VIEW IF NOT EXISTS vwIdentityStats AS \ + SELECT tblIdentity.IdentityID, COUNT(tblMessage.MessageID) AS MessageCount, MIN(tblMessage.MessageDate) AS FirstMessageDate, MAX(tblMessage.MessageDate) AS LastMessageDate \ + FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID \ + GROUP BY tblIdentity.IdentityID;"); + /* These peer trust calculations are too CPU intensive to be triggers - they were called every time a new trust list was processed All trust levels will now be recalculated every hour in the PeriodicDBMaintenance class diff --git a/src/http/pages/peermaintenancepage.cpp b/src/http/pages/peermaintenancepage.cpp index 3ded4eb..33d1357 100644 --- a/src/http/pages/peermaintenancepage.cpp +++ b/src/http/pages/peermaintenancepage.cpp @@ -59,6 +59,22 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S")); st.Step(); } + else if((*queryvars.find("formaction")).second=="removeposted30daysago") + { + date.SetToGMTime(); + date.Add(0,0,0,-30); + st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID IN (SELECT tblIdentity.IdentityID FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE (SELECT MAX(MessageDate) FROM tblMessage WHERE tblMessage.IdentityID=tblIdentity.IdentityID)<=? GROUP BY tblIdentity.IdentityID);"); + st.Bind(0,date.Format("%Y-%m-%d")); + st.Step(); + } + else if((*queryvars.find("formaction")).second=="removeadded20daysneversent") + { + date.SetToGMTime(); + date.Add(0,0,0,-20); + st=m_db->Prepare("DELETE FROM tblIdentity WHERE IdentityID IN (SELECT tblIdentity.IdentityID FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAddedPeer Maintenance"; @@ -105,6 +121,23 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c content+=""; content+=""; + date.SetToGMTime(); + date.Add(0,0,0,-30); + st=m_db->Prepare("SELECT COUNT(*) FROM (SELECT tblIdentity.IdentityID FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE (SELECT MAX(MessageDate) FROM tblMessage WHERE tblMessage.IdentityID=tblIdentity.IdentityID)<=? GROUP BY tblIdentity.IdentityID);"); + st.Bind(0,date.Format("%Y-%m-%d")); + st.Step(); + st.ResultText(0,tempval); + content+=""; + content+=""+tempval+""; + content+="last sent a message more than 30 days ago"; + content+=""; + content+="
"; + content+=""; + content+=""; + content+="
"; + content+=""; + content+=""; + st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;"); st.Step(); st.ResultText(0,tempval); @@ -121,6 +154,23 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c date.SetToGMTime(); date.Add(0,0,0,-20); + st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded"; + content+=""+tempval+""; + content+="added more than 20 days ago and never sent a message"; + content+=""; + content+="
"; + content+=""; + content+=""; + content+="
"; + content+=""; + content+=""; + + date.SetToGMTime(); + date.Add(0,0,0,-20); st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.LastSeen