version 0.3.33
[fms.git] / src / freenet / identityinserter.cpp
index 1ae04a5..988aa25 100644 (file)
@@ -64,6 +64,7 @@ const bool IdentityInserter::HandleMessage(FCPv2::Message &message)
                std::vector<std::string> idparts;\r
 \r
                StringFunctions::Split(message["Identifier"],"|",idparts);\r
+               m_lastreceivedmessage=now;\r
 \r
                // no action for URIGenerated\r
                if(message.GetName()=="URIGenerated")\r
@@ -79,34 +80,50 @@ const bool IdentityInserter::HandleMessage(FCPv2::Message &message)
 \r
                if(message.GetName()=="PutSuccessful")\r
                {\r
-                       // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity.\r
-                       // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
-                       Poco::DateTime lastdate;\r
-                       int tzdiff=0;\r
-                       Poco::DateTimeParser::tryParse("%Y-%m-%d",idparts[4],lastdate,tzdiff);\r
-\r
-                       if(lastdate.day()==now.day())\r
+       \r
+                       // do check to make sure this is the non-editioned SSK - we ignore failure/success for editioned SSK for now\r
+                       if(message["Identifier"].find(".xml")!=std::string::npos)\r
                        {\r
-                               m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
+                               // a little hack here - if we just inserted index yesterday and it is now the next day - we would have inserted todays date not yesterdays as LastInsertedIdentity.\r
+                               // If this is the case, we will skip updating LastInsertedIdentity so that we can insert this identity again for today\r
+                               Poco::DateTime lastdate;\r
+                               int tzdiff=0;\r
+                               Poco::DateTimeParser::tryParse("%Y-%m-%d",idparts[4],lastdate,tzdiff);\r
+                               if(lastdate.day()==now.day())\r
+                               {\r
+                                       m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";");\r
+                               }\r
+                               else\r
+                               {\r
+                                       m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+                               }\r
+                               m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
+                               m_log->debug("IdentityInserter::HandleMessage inserted Identity xml");\r
                        }\r
                        else\r
                        {\r
-                               m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+                               m_log->trace("IdentityInserter::HandleMessage inserted editioned Identity xml");\r
                        }\r
-                       m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
-                       m_log->debug("IdentityInserter::HandleMessage inserted Identity xml");\r
                        return true;\r
                }\r
 \r
                if(message.GetName()=="PutFailed")\r
                {\r
-                       m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
-                       m_log->debug("IdentityInserter::HandleMessage failure inserting Identity 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
+                       // do check to make sure this is the non-editioned SSK - we ignore failure/success for editioned SSK for now\r
+                       if(message["Identifier"].find(".xml")!=std::string::npos)\r
                        {\r
-                               m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
+                               m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false' WHERE LocalIdentityID="+idparts[1]+";");\r
+                               m_log->debug("IdentityInserter::HandleMessage failure inserting Identity 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
+                               {\r
+                                       m_db->Execute("INSERT INTO tblLocalIdentityInserts(LocalIdentityID,Day,InsertIndex) VALUES("+idparts[1]+",'"+idparts[4]+"',"+idparts[2]+");");\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               m_log->trace("IdentityInserter::HandleMessage PutFailed for editioned SSK error code "+message["Code"]+ " id "+message["Identifier"]);\r
                        }\r
                        \r
                        return true;\r
@@ -121,6 +138,7 @@ const bool IdentityInserter::HandleMessage(FCPv2::Message &message)
 void IdentityInserter::Initialize()\r
 {\r
        m_lastchecked=Poco::Timestamp();\r
+       m_lastreceivedmessage=Poco::Timestamp();\r
 }\r
 \r
 void IdentityInserter::Process()\r
@@ -133,6 +151,17 @@ void IdentityInserter::Process()
                m_lastchecked=now;\r
        }\r
 \r
+       if(m_lastreceivedmessage<(now-Poco::Timespan(0,0,10,0,0)))\r
+       {\r
+               SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE InsertingIdentity='true';");\r
+               st.Step();\r
+               if(st.RowReturned())\r
+               {\r
+                       m_log->debug("IdentityInserter::Process 10 minutes have passed without an insert response from the node.  Restarting inserts.");\r
+                       m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false';");\r
+               }\r
+       }\r
+\r
 }\r
 \r
 void IdentityInserter::RegisterWithThread(FreenetMasterThread *thread)\r
@@ -236,6 +265,16 @@ void IdentityInserter::StartInsert(const long localidentityid)
                m_fcp->Send(mess);\r
                m_fcp->Send(std::vector<char>(data.begin(),data.end()));\r
 \r
+               // test insert as editioned SSK\r
+               mess.Clear();\r
+               mess.SetName("ClientPut");\r
+               mess["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Identity-"+indexstr;\r
+               mess["Identifier"]="IdentityInserter|"+mess["URI"];\r
+               mess["UploadFrom"]="direct";\r
+               mess["DataLength"]=datasizestr;\r
+               m_fcp->Send(mess);\r
+               m_fcp->Send(std::vector<char>(data.begin(),data.end()));\r
+\r
                m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='true' WHERE LocalIdentityID="+idstring+";");\r
 \r
        }\r