X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ftrustlistinserter.cpp;h=a858de1f070d59f53054439e4d2430f61feef158;hb=9b22dd53fe62e312c1647310b7ec43aa127090af;hp=79745ee53e072f6969af538edf19e2363af263aa;hpb=175f098e7e712b839db433b93fe8649a402c6784;p=fms.git diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index 79745ee..a858de1 100644 --- a/src/freenet/trustlistinserter.cpp +++ b/src/freenet/trustlistinserter.cpp @@ -72,23 +72,30 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message) if(message.GetName()=="PutSuccessful") { - 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,"TrustListInserter::HandleMessage inserted TrustList xml"); + // 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("INSERT INTO tblTrustListInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");"); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListInserter::HandleMessage inserted TrustList xml"); + } return true; } - if(message.GetName()=="PutFailed") + if(message.GetName()=="PutFailed" && 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"]); - - // if code 9 (collision), then insert index into inserted table - if(message["Code"]=="9") + // non USK + if(idparts[0]=="TrustListInserter") { - m_db->Execute("INSERT INTO tblTrustListInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");"); - } + 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"]); + // if code 9 (collision), then insert index into inserted table + if(message["Code"]=="9") + { + m_db->Execute("INSERT INTO tblTrustListInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");"); + } + } return true; } @@ -132,20 +139,35 @@ 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,-20); // identities seen in last 20 days - SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust, MessageTrustComment, TrustListTrustComment FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;"); + date.Add(0,0,0,-15); // 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(1,localidentityid); st.Step(); while(st.RowReturned()) { @@ -168,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(); } @@ -199,6 +257,18 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin m_fcp->SendMessage(message); m_fcp->SendRaw(data.c_str(),data.size()); + // insert to USK + message.Reset(); + message.SetName("ClientPutComplexDir"); + message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|TrustList/0/"; + message["Identifier"]="TrustListInserterUSK|"+message["URI"]; + message["DefaultName"]="TrustList.xml"; + message["Files.0.Name"]="TrustList.xml"; + message["Files.0.UplaodFrom"]="direct"; + message["Files.0.DataLength"]=datasizestr; + m_fcp->SendMessage(message); + m_fcp->SendRaw(data.c_str(),data.size()); + m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='true' WHERE LocalIdentityID="+localidentityidstr+";"); }