X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ftrustlistinserter.cpp;h=d3167905a28999a0a7897bf6afd7947c19b09b2b;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=79745ee53e072f6969af538edf19e2363af263aa;hpb=175f098e7e712b839db433b93fe8649a402c6784;p=fms.git diff --git a/src/freenet/trustlistinserter.cpp b/src/freenet/trustlistinserter.cpp index 79745ee..d316790 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; } @@ -142,10 +149,16 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin now.SetToGMTime(); date.SetToGMTime(); + // 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);"); + // 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>=?;"); + //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;"); st.Bind(0,date.Format("%Y-%m-%d")); + st.Bind(1,localidentityid); st.Step(); while(st.RowReturned()) { @@ -199,6 +212,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+";"); }