X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityinserter.cpp;h=f28a73851894b13875bf2e31eeb8c1a6b7bf5981;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=4fac82f0c2d4c96583d6cd6d52da3dc781c5da73;hpb=9048d8e482c91960265f29c2b5b3112f2a52f3d8;p=fms.git diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index 4fac82f..f28a738 100644 --- a/src/freenet/identityinserter.cpp +++ b/src/freenet/identityinserter.cpp @@ -3,6 +3,9 @@ #include "../../include/stringfunctions.h" #include "../../include/option.h" +#include +#include + #ifdef XMEM #include #endif @@ -19,23 +22,20 @@ IdentityInserter::IdentityInserter(FCPv2 *fcp):IFCPConnected(fcp) 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) { @@ -60,10 +60,9 @@ const bool IdentityInserter::HandleMessage(FCPMessage &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 @@ -80,16 +79,29 @@ const bool IdentityInserter::HandleMessage(FCPMessage &message) if(message.GetName()=="PutSuccessful") { - m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='false', LastInsertedIdentity='"+now.Format("%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->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" inserted Identity xml"); + 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->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" failure inserting identity xml. Code="+message["Code"]+" Description="+message["CodeDescription"]); + 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") @@ -108,15 +120,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; @@ -133,19 +144,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 FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";"); + 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; + Poco::DateTime now; std::string messagebase; std::string data; std::string datasizestr; @@ -155,10 +165,12 @@ void IdentityInserter::StartInsert(const long localidentityid) std::string singleuse="false"; std::string publishtrustlist="false"; std::string publishboardlist="false"; + 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) @@ -172,7 +184,7 @@ void IdentityInserter::StartInsert(const long localidentityid) } StringFunctions::Convert(index,indexstr); - Option::instance()->Get("MessageBase",messagebase); + Option::Instance()->Get("MessageBase",messagebase); if(rs.GetField(0)) { @@ -202,11 +214,21 @@ void IdentityInserter::StartInsert(const long localidentityid) } publishboardlist=="true" ? idxml.SetPublishBoardList(true) : idxml.SetPublishBoardList(false); + if(rs.GetField(5) && rs.GetField(6)) + { + if(std::string(rs.GetField(5))=="true") + { + freesiteedition=rs.GetField(6); + StringFunctions::Convert(freesiteedition,edition); + idxml.SetFreesiteEdition(edition); + } + } + data=idxml.GetXML(); 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;