X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fmessageinserter.cpp;h=3d5af9aa8e4a8ceab2ad6e93c058e84b8e530b47;hp=d28e262d6f4f6a5244a6061bd5310cce85b11191;hb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;hpb=868c533e84b3c81b6604b45b84efa32073aa20b4 diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index d28e262..3d5af9a 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -1,4 +1,5 @@ #include "../../include/freenet/messageinserter.h" +#include "../../include/freenet/messagexml.h" MessageInserter::MessageInserter() { @@ -41,7 +42,7 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) { SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');"); st.Bind(0,localidentityid); - st.Bind(1,idparts[5]); + st.Bind(1,idparts[6]); st.Bind(2,index); st.Step(); } @@ -53,17 +54,46 @@ const bool MessageInserter::HandlePutFailed(FCPMessage &message) const bool MessageInserter::HandlePutSuccessful(FCPMessage &message) { + MessageXML xml; + DateTime date; + int localidentityid; int index; std::vector idparts; StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[3],index); + StringFunctions::Convert(idparts[2],localidentityid); SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;"); - st.Bind(0,idparts[5]); + st.Bind(0,idparts[6]); st.Bind(1,index); st.Bind(2,idparts[1]); st.Step(); + // insert record into temp table so MessageList will be inserted ASAP + date.SetToGMTime(); + st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);"); + st.Bind(0,localidentityid); + st.Bind(1,date.Format("%Y-%m-%d")); + st.Step(); + + // update the messageuuid to the real messageuuid + st=m_db->Prepare("SELECT MessageXML FROM tblMessageInserts WHERE MessageUUID=?;"); + st.Bind(0,idparts[1]); + st.Step(); + if(st.RowReturned()) + { + std::string xmldata=""; + st.ResultText(0,xmldata); + xml.ParseXML(xmldata); + xml.SetMessageID(idparts[4]); + + SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblMessageInserts SET MessageUUID=?, MessageXML=? WHERE MessageUUID=?;"); + st2.Bind(0,idparts[4]); + st2.Bind(1,xml.GetXML()); + st2.Bind(2,idparts[1]); + st2.Step(); + } + RemoveFromInsertList(idparts[1]); m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); @@ -78,9 +108,10 @@ void MessageInserter::Initialize() void MessageInserter::StartInsert(const std::string &messageuuid) { + MessageXML xmlfile; DateTime now; now.SetToGMTime(); - SQLite3DB::Statement st=m_db->Prepare("SELECT MessageXML,PrivateKey,tblLocalIdentity.LocalIdentityID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE MessageUUID=?;"); + 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(); @@ -91,6 +122,7 @@ void MessageInserter::StartInsert(const std::string &messageuuid) std::string xml; std::string xmlsizestr; std::string privatekey; + std::string publickey; FCPMessage message; std::string indexstr; int index=0; @@ -98,7 +130,7 @@ void MessageInserter::StartInsert(const std::string &messageuuid) st.ResultText(0,xml); st.ResultText(1,privatekey); st.ResultInt(2,localidentityid); - StringFunctions::Convert(xml.size(),xmlsizestr); + st.ResultText(3,publickey); StringFunctions::Convert(localidentityid,idstr); st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageInserts WHERE Day=? AND LocalIdentityID=?;"); @@ -113,9 +145,23 @@ void MessageInserter::StartInsert(const std::string &messageuuid) } StringFunctions::Convert(index,indexstr); + // recreate messageuuid in xml - UUID of message will not match entry in MessageInserts table until we successfully insert it + // see HandlePutSuccessful + xmlfile.ParseXML(xml); + // if we don't already have an @sskpart - add it + if(xmlfile.GetMessageID().find("@")==std::string::npos) + { + // remove - and ~ from publickey part + std::string publickeypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~",""); + xmlfile.SetMessageID(xmlfile.GetMessageID()+"@"+publickeypart); + } + xml=xmlfile.GetXML(); + + StringFunctions::Convert(xml.size(),xmlsizestr); + message.SetName("ClientPut"); message["URI"]=privatekey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Message|"+indexstr+".xml"; - message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+message["URI"]; + message["Identifier"]=m_fcpuniquename+"|"+messageuuid+"|"+idstr+"|"+indexstr+"|"+xmlfile.GetMessageID()+"|"+message["URI"]; message["UploadFrom"]="direct"; message["DataLength"]=xmlsizestr; m_fcp->SendMessage(message);