X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffreenet%2Fidentityinserter.cpp;h=988aa25ca1d49b7ccc7563d3ba2481b4b9dedda7;hb=HEAD;hp=15e52aa1aba0b57cfde548c27cc170167f09002b;hpb=4e96d123460d6363cf7274e36bd9357768eb86ad;p=fms.git diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index 15e52aa..988aa25 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -10,12 +10,12 @@ #include #endif -IdentityInserter::IdentityInserter() +IdentityInserter::IdentityInserter(SQLite3DB::DB *db):IDatabase(db) { Initialize(); } -IdentityInserter::IdentityInserter(FCPv2::Connection *fcp):IFCPConnected(fcp) +IdentityInserter::IdentityInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IDatabase(db),IFCPConnected(fcp) { Initialize(); } @@ -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) @@ -184,7 +213,8 @@ void IdentityInserter::StartInsert(const long localidentityid) } StringFunctions::Convert(index,indexstr); - Option::Instance()->Get("MessageBase",messagebase); + Option option(m_db); + option.Get("MessageBase",messagebase); if(rs.GetField(0)) { @@ -235,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+";"); }