version 0.2.21
authorSomeDude <SomeDude@NuBL7aaJ6Cn4fB7GXFb9Zfi8w1FhPyW3oKgU9TweZMw>
Sat, 7 Jun 2008 10:15:00 +0000 (12:15 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sat, 7 Jun 2008 10:15:00 +0000 (12:15 +0200)
include/global.h
src/charsetconverter.cpp
src/freenet/trustlistinserter.cpp
src/global.cpp
src/http/pages/peermaintenancepage.cpp

index 2bc49ce..047c917 100644 (file)
@@ -5,7 +5,7 @@
 #include <vector>\r
 #include "pthreadwrapper/thread.h"\r
 \r
-#define FMS_VERSION    "0.2.20"\r
+#define FMS_VERSION    "0.2.21"\r
 \r
 // opens database and creates tables and initial inserts if necessary\r
 void SetupDB();\r
index 4685add..3026207 100644 (file)
@@ -66,6 +66,7 @@ const bool CharsetConverter::Convert(const std::string &input, std::string &outp
                        outvec.resize(outptr-&outvec[0]);\r
                        output="";\r
                        output.append(outvec.begin(),outvec.end());\r
+                       return true;\r
                }\r
                else\r
                {\r
index 126088e..ee67e6b 100644 (file)
@@ -139,24 +139,33 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
        std::string publickey;\r
        int messagetrust;\r
        int trustlisttrust;\r
-       DateTime now,date;\r
+       DateTime now,date,dateminus30,tempdate;\r
        int index;\r
        std::string indexstr;\r
        std::string localidentityidstr;\r
        std::string messagetrustcomment="";\r
        std::string trustlisttrustcomment="";\r
+       int identityid=-1;\r
+       int count=0;\r
+       bool add=false;\r
+       std::string dateadded="";\r
 \r
        now.SetToGMTime();\r
        date.SetToGMTime();\r
+       dateminus30.SetToGMTime();\r
+       dateminus30.Add(0,0,0,-30);\r
 \r
        // insert all identities not in trust list already\r
        m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);");\r
 \r
+       // select statement for last message date for an identity\r
+       SQLite3DB::Statement countst=m_db->Prepare("SELECT COUNT(*) FROM tblMessage WHERE IdentityID=? AND MessageDate>=?;");\r
+\r
        // build the xml file - we only want to add identities that we recently saw, otherwise we could be inserting a ton of identities\r
        date.Add(0,0,0,-15);    // identities seen in last 15 days\r
        //SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
        // we want to order by public key so we can't do identity correllation based on the sequence of identities in the list.\r
-       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;");\r
+       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;");\r
        st.Bind(0,date.Format("%Y-%m-%d"));\r
        st.Bind(1,localidentityid);\r
        st.Step();\r
@@ -181,7 +190,43 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
                }\r
                st.ResultText(3,messagetrustcomment);\r
                st.ResultText(4,trustlisttrustcomment);\r
-               xml.AddTrust(publickey,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment);\r
+               identityid=-1;\r
+               st.ResultInt(5,identityid);\r
+               dateadded="";\r
+               st.ResultText(6,dateadded);\r
+\r
+               add=false;\r
+\r
+               // add the identity to the trust list if they have posted a message in the last 30 days\r
+               countst.Bind(0,identityid);\r
+               countst.Bind(1,dateminus30.Format("%Y-%m-%d"));\r
+               countst.Step();\r
+               if(countst.RowReturned())\r
+               {\r
+                       count=0;\r
+                       countst.ResultInt(0,count);\r
+                       if(count>0)\r
+                       {\r
+                               add=true;\r
+                       }\r
+               }\r
+               countst.Reset();\r
+\r
+               // no messages in last 30 days - add the identity if we learned about them less than 5 days ago\r
+               if(add==false && dateadded!="")\r
+               {\r
+                       tempdate.Set(dateadded);\r
+                       if(tempdate>=(now-5.0))\r
+                       {\r
+                               add=true;\r
+                       }\r
+               }\r
+\r
+               if(add==true)\r
+               {\r
+                       xml.AddTrust(publickey,messagetrust,trustlisttrust,messagetrustcomment,trustlisttrustcomment);\r
+               }\r
+\r
                st.Step();\r
        }\r
 \r
index c9bdefe..cfd458c 100644 (file)
@@ -415,6 +415,11 @@ void SetupDB()
                                AND ( PeerTrustListTrust IS NULL OR PeerTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerTrustListTrust') ) \\r
                                GROUP BY TargetIdentityID;");\r
 \r
+       db->Execute("CREATE VIEW IF NOT EXISTS vwIdentityStats AS \\r
+                               SELECT tblIdentity.IdentityID, COUNT(tblMessage.MessageID) AS MessageCount, MIN(tblMessage.MessageDate) AS FirstMessageDate, MAX(tblMessage.MessageDate) AS LastMessageDate \\r
+                               FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID \\r
+                               GROUP BY tblIdentity.IdentityID;");\r
+\r
        /*\r
                These peer trust calculations are too CPU intensive to be triggers - they were called every time a new trust list was processed\r
                All trust levels will now be recalculated every hour in the PeriodicDBMaintenance class\r
index 3ded4eb..33d1357 100644 (file)
@@ -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"));\r
                        st.Step();\r
                }\r
+               else if((*queryvars.find("formaction")).second=="removeposted30daysago")\r
+               {\r
+                       date.SetToGMTime();\r
+                       date.Add(0,0,0,-30);\r
+                       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);");\r
+                       st.Bind(0,date.Format("%Y-%m-%d"));\r
+                       st.Step();\r
+               }\r
+               else if((*queryvars.find("formaction")).second=="removeadded20daysneversent")\r
+               {\r
+                       date.SetToGMTime();\r
+                       date.Add(0,0,0,-20);\r
+                       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.DateAdded<?);");\r
+                       st.Bind(0,date.Format("%Y-%m-%d"));\r
+                       st.Step();\r
+               }\r
        }\r
 \r
        content+="<h2>Peer Maintenance</h2>";\r
@@ -105,6 +121,23 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
        content+="</td>";\r
        content+="</tr>";\r
 \r
+       date.SetToGMTime();\r
+       date.Add(0,0,0,-30);\r
+       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);");\r
+       st.Bind(0,date.Format("%Y-%m-%d"));\r
+       st.Step();\r
+       st.ResultText(0,tempval);\r
+       content+="<tr>";\r
+       content+="<td>"+tempval+"</td>";\r
+       content+="<td>last sent a message more than 30 days ago</td>";\r
+       content+="<td>";\r
+       content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"removeposted30daysago\">";\r
+       content+="<input type=\"submit\" value=\"Remove\">";\r
+       content+="</form>";\r
+       content+="</td>";\r
+       content+="</tr>";\r
+\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL;");\r
        st.Step();\r
        st.ResultText(0,tempval);\r
@@ -121,6 +154,23 @@ const std::string PeerMaintenancePage::GeneratePage(const std::string &method, c
 \r
        date.SetToGMTime();\r
        date.Add(0,0,0,-20);\r
+       st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.DateAdded<?;");\r
+       st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
+       st.Step();\r
+       st.ResultText(0,tempval);\r
+       content+="<tr>";\r
+       content+="<td>"+tempval+"</td>";\r
+       content+="<td>added more than 20 days ago and never sent a message</td>";\r
+       content+="<td>";\r
+       content+="<form name=\"frmremove\" method=\"POST\">";\r
+       content+="<input type=\"hidden\" name=\"formaction\" value=\"removeadded20daysneversent\">";\r
+       content+="<input type=\"submit\" value=\"Remove\">";\r
+       content+="</form>";\r
+       content+="</td>";\r
+       content+="</tr>";\r
+\r
+       date.SetToGMTime();\r
+       date.Add(0,0,0,-20);\r
        st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity LEFT JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.IdentityID IS NULL AND tblIdentity.LastSeen<?;");\r
        st.Bind(0,date.Format("%Y-%m-%d %H:%M:%S"));\r
        st.Step();\r