X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityinserter.cpp;h=85fe2f4ef10f291c6a3a6656cb34b4b48f5b9cd6;hb=ed0732b2550c23c05fc9faf925620e87ee6dee12;hp=f246d66402989d8bb6c75e1bba1fa51bc1786b30;hpb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0;p=fms.git diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index f246d66..85fe2f4 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -3,39 +3,39 @@ #include "../../include/stringfunctions.h" #include "../../include/option.h" +#include +#include + #ifdef XMEM #include #endif -IdentityInserter::IdentityInserter() +IdentityInserter::IdentityInserter(SQLite3DB::DB *db):IDatabase(db) { Initialize(); } -IdentityInserter::IdentityInserter(FCPv2 *fcp):IFCPConnected(fcp) +IdentityInserter::IdentityInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IDatabase(db),IFCPConnected(fcp) { Initialize(); } void IdentityInserter::CheckForNeededInsert() { - DateTime now; - DateTime date; - now.SetToGMTime(); - date.SetToGMTime(); + Poco::DateTime now; + Poco::DateTime date; + // set date to 1 hour back - date.Add(0,0,-1); + date-=Poco::Timespan(0,1,0,0,0); // Because of importance of Identity.xml, if we are now at the next day we immediately want to insert identities so change the date back to 12:00 AM so we find all identities not inserted yet today - if(date.GetDay()!=now.GetDay()) + if(date.day()!=now.day()) { date=now; - date.SetHour(0); - date.SetMinute(0); - date.SetSecond(0); + date.assign(date.year(),date.month(),date.day(),0,0,0); } - SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID FROM tblLocalIdentity WHERE PrivateKey IS NOT NULL AND PrivateKey <> '' AND InsertingIdentity='false' AND (LastInsertedIdentity<'"+date.Format("%Y-%m-%d %H:%M:%S")+"' OR LastInsertedIdentity IS NULL) ORDER BY LastInsertedIdentity;"); + SQLite3DB::Recordset rs=m_db->Query("SELECT LocalIdentityID FROM tblLocalIdentity WHERE PrivateKey IS NOT NULL AND PrivateKey <> '' AND InsertingIdentity='false' AND (LastInsertedIdentity<'"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")+"' OR LastInsertedIdentity IS NULL) ORDER BY LastInsertedIdentity;"); if(rs.Empty()==false) { @@ -55,15 +55,14 @@ void IdentityInserter::FCPDisconnected() } -const bool IdentityInserter::HandleMessage(FCPMessage &message) +const bool IdentityInserter::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("IdentityInserter")==0) { - DateTime now; + Poco::DateTime now; std::vector idparts; - now.SetToGMTime(); StringFunctions::Split(message["Identifier"],"|",idparts); // no action for URIGenerated @@ -82,30 +81,48 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message) { // 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 - DateTime lastdate; - lastdate.Set(idparts[4]); - if(lastdate.GetDay()==now.GetDay()) + Poco::DateTime lastdate; + int tzdiff=0; + Poco::DateTimeParser::tryParse("%Y-%m-%d",idparts[4],lastdate,tzdiff); + + // 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='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + 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->WriteLog(LogFile::LOGLEVEL_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->WriteLog(LogFile::LOGLEVEL_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; @@ -119,15 +136,14 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message) void IdentityInserter::Initialize() { - m_lastchecked.SetToGMTime(); + m_lastchecked=Poco::Timestamp(); } void IdentityInserter::Process() { - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; - if(m_lastchecked<(now-(1.0/1440.0))) + if(m_lastchecked<(now-Poco::Timespan(0,0,1,0,0))) { CheckForNeededInsert(); m_lastchecked=now; @@ -144,19 +160,18 @@ void IdentityInserter::RegisterWithThread(FreenetMasterThread *thread) void IdentityInserter::StartInsert(const long localidentityid) { - DateTime date; + Poco::DateTime date; std::string idstring; StringFunctions::Convert(localidentityid,idstring); - date.SetToGMTime(); SQLite3DB::Recordset rs=m_db->Query("SELECT Name,PrivateKey,SingleUse,PublishTrustList,PublishBoardList,PublishFreesite,FreesiteEdition FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); if(rs.Empty()==false) { IdentityXML idxml; - FCPMessage mess; - DateTime now; + FCPv2::Message mess; + Poco::DateTime now; std::string messagebase; std::string data; std::string datasizestr; @@ -169,9 +184,9 @@ void IdentityInserter::StartInsert(const long localidentityid) std::string freesiteedition=""; int edition=-1; - now.SetToGMTime(); + now=Poco::Timestamp(); - SQLite3DB::Recordset rs2=m_db->Query("SELECT MAX(InsertIndex) FROM tblLocalIdentityInserts WHERE LocalIdentityID="+idstring+" AND Day='"+now.Format("%Y-%m-%d")+"';"); + SQLite3DB::Recordset rs2=m_db->Query("SELECT MAX(InsertIndex) FROM tblLocalIdentityInserts WHERE LocalIdentityID="+idstring+" AND Day='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"';"); if(rs2.Empty()==false) { if(rs2.GetField(0)==NULL) @@ -185,7 +200,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)) { @@ -229,12 +245,22 @@ void IdentityInserter::StartInsert(const long localidentityid) StringFunctions::Convert(data.size(),datasizestr); mess.SetName("ClientPut"); - mess["URI"]=privatekey+messagebase+"|"+now.Format("%Y-%m-%d")+"|Identity|"+indexstr+".xml"; + mess["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Identity|"+indexstr+".xml"; mess["Identifier"]="IdentityInserter|"+idstring+"|"+indexstr+"|"+mess["URI"]; mess["UploadFrom"]="direct"; mess["DataLength"]=datasizestr; - m_fcp->SendMessage(mess); - m_fcp->SendRaw(data.c_str(),data.size()); + 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+";");