X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Ftrustlistinserter.cpp;h=ee67e6bd283c6f71f35b81dd5d97190bcc83b41f;hp=126088eda2b4a5765957c78fb887fa8ffadbe421;hb=0236076defe60bcd4b3a25c23efa53c21993a48e;hpb=853f67b0b7b8121d572cff34d40f7b28cac8f65e 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(); }