X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fidentityinserter.cpp;h=1ae04a533632f7188b9c26fd3874dbdd625aae81;hp=aa1f4ab8f19ecb8ebb6e9fa28f3cf0b0cfc3a224;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hpb=964f55fd550fc711c0320ce6a24ad713040695d0 diff --git a/src/freenet/identityinserter.cpp b/src/freenet/identityinserter.cpp index aa1f4ab..1ae04a5 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,21 +81,27 @@ 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); + + 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', LastInsertedIdentity='"+now.Format("%Y-%m-%d %H:%M:%S")+"' WHERE LocalIdentityID="+idparts[1]+";"); + 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,"IdentityInserter::HandleMessage 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,"IdentityInserter::HandleMessage 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") @@ -115,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; @@ -140,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; + FCPv2::Message mess; + Poco::DateTime now; std::string messagebase; std::string data; std::string datasizestr; @@ -162,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) @@ -179,7 +184,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)) { @@ -209,16 +215,26 @@ 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; - 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())); m_db->Execute("UPDATE tblLocalIdentity SET InsertingIdentity='true' WHERE LocalIdentityID="+idstring+";");