version 0.3.33
[fms.git] / src / freenet / identityinserter.cpp
index 85fe2f4..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,15 +80,15 @@ 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
                        // 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
+                               // 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
@@ -137,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
@@ -149,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
@@ -255,7 +268,7 @@ void IdentityInserter::StartInsert(const long localidentityid)
                // 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["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