version 0.1.9
[fms.git] / src / freenet / trustlistinserter.cpp
index c5cc7df..5f2fbb8 100644 (file)
@@ -21,7 +21,13 @@ void TrustListInserter::CheckForNeededInsert()
 {\r
        DateTime date;\r
        date.SetToGMTime();\r
-       date.Add(0,0,-1);\r
+       int currentday=date.GetDay();\r
+       date.Add(0,0,-6);\r
+       // insert trust lists every 6 hours - if 6 hours ago was different day then set to midnight of current day to insert list today ASAP\r
+       if(currentday!=date.GetDay())\r
+       {\r
+               date.Set(date.GetYear(),date.GetMonth(),currentday);\r
+       }\r
        SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID, PrivateKey FROM tblLocalIdentity WHERE PrivateKey IS NOT NULL AND PrivateKey <> '' AND PublishTrustList='true' AND InsertingTrustList='false' AND (LastInsertedTrustList<='"+date.Format("%Y-%m-%d %H:%M:%S")+"' OR LastInsertedTrustList IS NULL);");\r
 \r
        if(rs.Empty()==false)\r
@@ -68,14 +74,14 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message)
                {\r
                        m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false', LastInsertedTrustList='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
                        m_db->Execute("INSERT INTO tblTrustListInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted TrustList xml");\r
+                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListInserter::HandleMessage inserted TrustList xml");\r
                        return true;\r
                }\r
 \r
                if(message.GetName()=="PutFailed")\r
                {\r
                        m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='false' WHERE LocalIdentityID="+idparts[1]+";");\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failure inserting TrustList xml.  Code="+message["Code"]+" Description="+message["CodeDescription"]);\r
+                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"TrustListInserter::HandleMessage failure inserting TrustList xml.  Code="+message["Code"]+" Description="+message["CodeDescription"]);\r
                        \r
                        // if code 9 (collision), then insert index into inserted table\r
                        if(message["Code"]=="9")\r
@@ -93,7 +99,7 @@ const bool TrustListInserter::HandleMessage(FCPMessage &message)
 \r
 void TrustListInserter::Initialize()\r
 {\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option::Instance()->Get("MessageBase",m_messagebase);\r
        m_lastchecked.SetToGMTime();\r
 }\r
 \r
@@ -126,15 +132,18 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
        std::string publickey;\r
        int messagetrust;\r
        int trustlisttrust;\r
-       DateTime now;\r
+       DateTime now,date;\r
        int index;\r
        std::string indexstr;\r
        std::string localidentityidstr;\r
 \r
        now.SetToGMTime();\r
-       \r
-       // build the xml file\r
-       SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'';");\r
+       date.SetToGMTime();\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,-20);    // identities seen in last 20 days\r
+       SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey, LocalMessageTrust, LocalTrustListTrust FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LastSeen>=?;");\r
+       st.Bind(0,date.Format("%Y-%m-%d"));\r
        st.Step();\r
        while(st.RowReturned())\r
        {\r
@@ -174,4 +183,4 @@ void TrustListInserter::StartInsert(const long localidentityid, const std::strin
 \r
        m_db->Execute("UPDATE tblLocalIdentity SET InsertingTrustList='true' WHERE LocalIdentityID="+localidentityidstr+";");\r
 \r
-}
\ No newline at end of file
+}\r