X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessageinserter.cpp;h=f3aab0066e882b4652dc59e4723dedd6bb3265c0;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=3dc1203cf4b2e3f11bd21429864690f2fb867eb7;hpb=9a14c0d9f7f7c319e539583b93664953764e83b7;p=fms.git diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index 3dc1203..f3aab00 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -1,23 +1,29 @@ #include "../../include/freenet/messageinserter.h" #include "../../include/freenet/messagexml.h" -MessageInserter::MessageInserter() +#include +#include +#include + +MessageInserter::MessageInserter(SQLite3DB::DB *db):IIndexInserter(db) { Initialize(); } -MessageInserter::MessageInserter(FCPv2 *fcp):IIndexInserter(fcp) +MessageInserter::MessageInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexInserter(db,fcp) { Initialize(); } void MessageInserter::CheckForNeededInsert() { + Poco::DateTime now; bool didinsert=false; // only do 1 insert at a time if(m_inserting.size()==0) { - SQLite3DB::Statement st=m_db->Prepare("SELECT MessageUUID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' AND tblMessageInserts.Inserted='false';"); + SQLite3DB::Statement st=m_db->Prepare("SELECT MessageUUID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' AND tblMessageInserts.Inserted='false' AND tblMessageInserts.SendDate<=?;"); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); st.Step(); while(st.RowReturned() && m_inserting.size()==0) @@ -40,7 +46,7 @@ void MessageInserter::CheckForNeededInsert() } } -const bool MessageInserter::HandlePutFailed(FCPMessage &message) +const bool MessageInserter::HandlePutFailed(FCPv2::Message &message) { int index; int localidentityid; @@ -59,15 +65,17 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) st.Step(); } + m_log->trace("MessageInserter::HandlePutFailed error code "+message["Code"]+" fatal="+message["Fatal"]); + RemoveFromInsertList(idparts[1]); return true; } -const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) +const bool MessageInserter::HandlePutSuccessful(FCPv2::Message &message) { MessageXML xml; - DateTime date; + Poco::DateTime date; int localidentityid; int index; std::vector idparts; @@ -83,10 +91,10 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) st.Step(); // insert record into temp table so MessageList will be inserted ASAP - date.SetToGMTime(); + date=Poco::Timestamp(); st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);"); st.Bind(0,localidentityid); - st.Bind(1,date.Format("%Y-%m-%d")); + st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); st.Step(); // update the messageuuid to the real messageuuid @@ -115,7 +123,7 @@ const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) RemoveFromInsertList(idparts[1]); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); + m_log->debug("MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); return true; } @@ -128,8 +136,7 @@ void MessageInserter::Initialize() const bool MessageInserter::StartInsert(const std::string &messageuuid) { MessageXML xmlfile; - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; SQLite3DB::Statement st=m_db->Prepare("SELECT MessageXML,PrivateKey,tblLocalIdentity.LocalIdentityID,PublicKey FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE MessageUUID=?;"); st.Bind(0,messageuuid); st.Step(); @@ -142,7 +149,7 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid) std::string xmlsizestr; std::string privatekey; std::string publickey; - FCPMessage message; + FCPv2::Message message; std::string indexstr; int index=0; @@ -153,7 +160,7 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid) StringFunctions::Convert(localidentityid,idstr); st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageInserts WHERE Day=? AND LocalIdentityID=?;"); - st.Bind(0,now.Format("%Y-%m-%d")); + st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st.Bind(1,localidentityid); st.Step(); @@ -197,16 +204,16 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid) StringFunctions::Convert(xml.size(),xmlsizestr); message.SetName("ClientPut"); - message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Message|"+indexstr+".xml"; + message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Message|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+xmlfile.GetMessageID()+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(xml.c_str(),xml.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(xml.begin(),xml.end())); m_inserting.push_back(messageuuid); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::StartInsert started message insert "+message["URI"]); + m_log->debug("MessageInserter::StartInsert started message insert "+message["URI"]); return true; }