X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffreenet%2Fmessageinserter.cpp;h=a378ee155622a2239a01847cf4e9e561432de693;hp=f3aab0066e882b4652dc59e4723dedd6bb3265c0;hb=ed0732b2550c23c05fc9faf925620e87ee6dee12;hpb=59a5414ec47a2932a7802fcd1d98c4d80166564f diff --git a/src/freenet/messageinserter.cpp b/src/freenet/messageinserter.cpp index f3aab00..a378ee1 100644 --- a/src/freenet/messageinserter.cpp +++ b/src/freenet/messageinserter.cpp @@ -51,23 +51,34 @@ const bool MessageInserter::HandlePutFailed(FCPv2::Message &message) int index; int localidentityid; std::vector idparts; - StringFunctions::Split(message["Identifier"],"|",idparts); - StringFunctions::Convert(idparts[2],localidentityid); - StringFunctions::Convert(idparts[3],index); - // fatal put - or data exists - insert bogus index into database so we'll try to insert this message again - if(message["Fatal"]=="true" || message["Code"]=="9") + // do check to make sure this is the non-editioned SSK - we ignore failure/success for editioned SSK for now + if(message["Identifier"].find(".xml")!=std::string::npos) { - SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');"); - st.Bind(0,localidentityid); - st.Bind(1,idparts[6]); - st.Bind(2,index); - st.Step(); - } - m_log->trace("MessageInserter::HandlePutFailed error code "+message["Code"]+" fatal="+message["Fatal"]); + StringFunctions::Split(message["Identifier"],"|",idparts); + StringFunctions::Convert(idparts[2],localidentityid); + StringFunctions::Convert(idparts[3],index); - RemoveFromInsertList(idparts[1]); + // fatal put - or data exists - insert bogus index into database so we'll try to insert this message again + if(message["Fatal"]=="true" || message["Code"]=="9") + { + SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,Day,InsertIndex,Inserted) VALUES(?,?,?,'true');"); + st.Bind(0,localidentityid); + st.Bind(1,idparts[6]); + st.Bind(2,index); + st.Step(); + } + + m_log->trace("MessageInserter::HandlePutFailed error code "+message["Code"]+" fatal="+message["Fatal"]); + + RemoveFromInsertList(idparts[1]); + + } + else + { + m_log->trace("MessageInserter::HandlePutFailed for editioned SSK error code "+message["Code"]+ " id "+message["Identifier"]); + } return true; } @@ -80,50 +91,60 @@ const bool MessageInserter::HandlePutSuccessful(FCPv2::Message &message) int index; std::vector idparts; - StringFunctions::Split(message["Identifier"],"|",idparts); - StringFunctions::Convert(idparts[3],index); - StringFunctions::Convert(idparts[2],localidentityid); + // do check to make sure this is the non-editioned SSK - we ignore failure/success for editioned SSK for now + if(message["Identifier"].find(".xml")!=std::string::npos) + { - SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;"); - st.Bind(0,idparts[6]); - st.Bind(1,index); - st.Bind(2,idparts[1]); - st.Step(); + StringFunctions::Split(message["Identifier"],"|",idparts); + StringFunctions::Convert(idparts[3],index); + StringFunctions::Convert(idparts[2],localidentityid); - // insert record into temp table so MessageList will be inserted ASAP - date=Poco::Timestamp(); - st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);"); - st.Bind(0,localidentityid); - st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d")); - st.Step(); + SQLite3DB::Statement st=m_db->Prepare("UPDATE tblMessageInserts SET Day=?, InsertIndex=?, Inserted='true' WHERE MessageUUID=?;"); + st.Bind(0,idparts[6]); + st.Bind(1,index); + st.Bind(2,idparts[1]); + 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(); - - //update file insert MessageUUID as well - st2=m_db->Prepare("UPDATE tblFileInserts SET MessageUUID=? WHERE MessageUUID=?;"); - st2.Bind(0,idparts[4]); - st2.Bind(1,idparts[1]); - st2.Step(); - } + // insert record into temp table so MessageList will be inserted ASAP + date=Poco::Timestamp(); + st=m_db->Prepare("INSERT INTO tmpMessageListInsert(LocalIdentityID,Date) VALUES(?,?);"); + st.Bind(0,localidentityid); + st.Bind(1,Poco::DateTimeFormatter::format(date,"%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(); + + //update file insert MessageUUID as well + st2=m_db->Prepare("UPDATE tblFileInserts SET MessageUUID=? WHERE MessageUUID=?;"); + st2.Bind(0,idparts[4]); + st2.Bind(1,idparts[1]); + st2.Step(); + } + + RemoveFromInsertList(idparts[1]); - RemoveFromInsertList(idparts[1]); + m_log->debug("MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); - m_log->debug("MessageInserter::HandlePutSuccessful successfully inserted message "+message["Identifier"]); + } + else + { + m_log->debug("MessageInserter::HandlePutSuccessful for editioned SSK "+message["Identifier"]); + } return true; } @@ -211,6 +232,16 @@ const bool MessageInserter::StartInsert(const std::string &messageuuid) m_fcp->Send(message); m_fcp->Send(std::vector(xml.begin(),xml.end())); + // test insert as editioned SSK + message.Clear(); + message.SetName("ClientPut"); + message["URI"]=privatekey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Message|-"+indexstr; + message["Identifier"]=m_fcpuniquename+"|"+message["URI"]; + message["UploadFrom"]="direct"; + message["DataLength"]=xmlsizestr; + m_fcp->Send(message); + m_fcp->Send(std::vector(xml.begin(),xml.end())); + m_inserting.push_back(messageuuid); m_log->debug("MessageInserter::StartInsert started message insert "+message["URI"]);