X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessagelistinserter.cpp;h=56e70136d824bda8392fb92aeb7d22714d0edb36;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=833b55610ee2295f5fff89192364733543c29761;hpb=6836fbb5db8464f56e682989996b2210b14231d0;p=fms.git diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index 833b556..56e7013 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -2,16 +2,20 @@ #include "../../include/freenet/messagexml.h" #include "../../include/freenet/messagelistxml.h" +#include +#include +#include + #ifdef XMEM #include #endif -MessageListInserter::MessageListInserter() +MessageListInserter::MessageListInserter(SQLite3DB::DB *db):IIndexInserter(db) { Initialize(); } -MessageListInserter::MessageListInserter(FCPv2 *fcp):IIndexInserter(fcp) +MessageListInserter::MessageListInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexInserter(db,fcp) { Initialize(); } @@ -22,20 +26,17 @@ void MessageListInserter::CheckForNeededInsert() if(m_inserting.size()==0) { std::string sql; - DateTime now; - DateTime previous; + Poco::DateTime now; + Poco::DateTime previous; bool startedinsert=false; - now.SetToGMTime(); - previous.SetToGMTime(); - // reset the last inserted xml doc to nothing if the day has changed - if(m_lastchecked.GetDay()!=now.GetDay()) + if(m_lastchecked.day()!=now.day()) { m_lastinsertedxml.clear(); } - previous.Add(0,0,0,-m_daysbackward); + previous-=Poco::Timespan(m_daysbackward,0,0,0,0); // query for identities that have messages in the past X days and (we haven't inserted lists for in the past 30 minutes OR identity has a record in tmpMessageListInsert) sql="SELECT tblLocalIdentity.LocalIdentityID "; @@ -44,8 +45,8 @@ void MessageListInserter::CheckForNeededInsert() sql+="GROUP BY tblLocalIdentity.LocalIdentityID;"; SQLite3DB::Statement st=m_db->Prepare(sql); - st.Bind(0,previous.Format("%Y-%m-%d")); - st.Bind(1,(now-(1.0/48.0)).Format("%Y-%m-%d %H:%M:%S")); + st.Bind(0,Poco::DateTimeFormatter::format(previous,"%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format((now-Poco::Timespan(0,0,30,0,0)),"%Y-%m-%d %H:%M:%S")); st.Step(); while(st.RowReturned() && startedinsert==false) @@ -59,7 +60,7 @@ void MessageListInserter::CheckForNeededInsert() } -const bool MessageListInserter::HandlePutFailed(FCPMessage &message) +const bool MessageListInserter::HandlePutFailed(FCPv2::Message &message) { std::vector idparts; long localidentityid; @@ -87,14 +88,18 @@ const bool MessageListInserter::HandlePutFailed(FCPMessage &message) // reset the last inserted xml doc to nothing so we will try to insert this one again m_lastinsertedxml[localidentityid]=""; } + else + { + m_log->debug("MessageListInserter::HandlePutFailed "+message["Identifier"]); + } return true; } -const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message) +const bool MessageListInserter::HandlePutSuccessful(FCPv2::Message &message) { - DateTime now; + Poco::DateTime now; std::vector idparts; long localidentityid; long index; @@ -113,20 +118,33 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message) st.Bind(2,index); st.Step(); - now.SetToGMTime(); + now=Poco::Timestamp(); st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;"); - st.Bind(0,now.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); st.Bind(1,localidentityid); st.Step(); - // delete any record from tmpMessageListInsert - st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;"); + // delete only a single record from tmpMessageListInsert + st=m_db->Prepare("SELECT MessageListInsertID FROM tmpMessageListInsert WHERE LocalIdentityID=?;"); st.Bind(0,localidentityid); st.Step(); + if(st.RowReturned()) + { + int id=-1; + st.ResultInt(0,id); + + st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE MessageListInsertID=?;"); + st.Bind(0,id); + st.Step(); + } RemoveFromInsertList(localidentityid); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + m_log->debug("MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + } + else + { + m_log->debug("MessageListInserter::HandlePutSuccessful inserted USK MessageList "+message["Identifier"]); } return true; @@ -134,19 +152,20 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message) void MessageListInserter::Initialize() { - std::string tempval; - + std::string tempval(""); m_fcpuniquename="MessageListInserter"; m_daysbackward=0; - Option::Instance()->Get("MessageListDaysBackward",tempval); + Option option(m_db); + + option.Get("MessageListDaysBackward",tempval); StringFunctions::Convert(tempval,m_daysbackward); } const bool MessageListInserter::StartInsert(const long &localidentityid) { - FCPMessage message; - DateTime date; - DateTime now; + FCPv2::Message message; + Poco::DateTime date; + Poco::DateTime now; std::string privatekey; std::string localidentityidstr; MessageListXML mlxml; @@ -156,14 +175,12 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) int index; std::string indexstr; - now.SetToGMTime(); - date.SetToGMTime(); - date.Add(0,0,0,-m_daysbackward); + date-=Poco::Timespan(m_daysbackward,0,0,0,0); StringFunctions::Convert(localidentityid,localidentityidstr); - SQLite3DB::Statement st=m_db->Prepare("SELECT Day, InsertIndex, MessageXML, PrivateKey FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.LocalIdentityID=? AND Day>=?;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Day, InsertIndex, MessageXML, PrivateKey FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.LocalIdentityID=? AND Day>=? AND tblMessageInserts.MessageUUID IS NOT NULL;"); st.Bind(0,localidentityid); - st.Bind(1,date.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); st.Step(); while(st.RowReturned()) @@ -224,7 +241,7 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) index=0; st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageListInserts WHERE LocalIdentityID=? AND Day=?;"); st.Bind(0,localidentityid); - st.Bind(1,now.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st.Step(); if(st.ResultNull(0)==false) { @@ -242,23 +259,23 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) StringFunctions::Convert(xmlstr.size(),xmlsizestr); message.SetName("ClientPut"); - message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|MessageList|"+indexstr+".xml"; + message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|MessageList|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+localidentityidstr+"|"+indexstr+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xmlstr.begin(),xmlstr.end())); - message.Reset(); + message.Clear(); message.SetName("ClientPutComplexDir"); - message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+now.Format("%Y.%m.%d")+"|MessageList/0/"; + message["URI"]="USK"+privatekey.substr(3)+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|MessageList/0/"; message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"]; message["DefaultName"]="MessageList.xml"; message["Files.0.Name"]="MessageList.xml"; message["Files.0.UploadFrom"]="direct"; message["Files.0.DataLength"]=xmlsizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xmlstr.c_str(),xmlstr.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xmlstr.begin(),xmlstr.end())); m_inserting.push_back(localidentityid); m_lastinsertedxml[localidentityid]=xmlstr;