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