X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityintroductioninserter.cpp;h=5d01882c34676502c5c3dbf28386d33ac9369ae1;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=abf12158b13c6c0afb98dea4dace0251accde96d;hpb=6b896a9e1dc143bba86795be1e9336549db9b85f;p=fms.git diff --git a/src/freenet/identityintroductioninserter.cpp b/src/freenet/identityintroductioninserter.cpp index abf1215..5d01882 100644 --- a/src/freenet/identityintroductioninserter.cpp +++ b/src/freenet/identityintroductioninserter.cpp @@ -1,20 +1,21 @@ #include "../../include/freenet/identityintroductioninserter.h" #include "../../include/freenet/identityintroductionxml.h" -#include "../../include/xyssl/sha1.h" #include "../../include/stringfunctions.h" #include "../../include/hex.h" #include "../../include/option.h" +#include + #ifdef XMEM #include #endif -IdentityIntroductionInserter::IdentityIntroductionInserter() +IdentityIntroductionInserter::IdentityIntroductionInserter(SQLite3DB::DB *db):IDatabase(db) { Initialize(); } -IdentityIntroductionInserter::IdentityIntroductionInserter(FCPv2 *fcp):IFCPConnected(fcp) +IdentityIntroductionInserter::IdentityIntroductionInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IDatabase(db),IFCPConnected(fcp) { Initialize(); } @@ -41,7 +42,7 @@ void IdentityIntroductionInserter::FCPDisconnected() } -const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message) +const bool IdentityIntroductionInserter::HandleMessage(FCPv2::Message &message) { if(message["Identifier"].find("IdentityIntroductionInserter")==0) @@ -61,7 +62,9 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message) if(message["Fatal"]=="true" || message["Code"]=="9") { m_db->Execute("DELETE FROM tblIdentityIntroductionInserts WHERE UUID='"+idparts[3]+"';"); - m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"IdentityIntroductionInserter::HandleMessage received fatal error trying to insert IdentityIntroduction "+idparts[3]); + // update the puzzle from the request table (set to not found) because we don't need it anymore and don't want to user tyring to solve it again + m_db->Execute("UPDATE tblIntroductionPuzzleRequests SET Found='false' WHERE UUID='"+idparts[3]+"';"); + m_log->warning("IdentityIntroductionInserter::HandleMessage received fatal error trying to insert IdentityIntroduction "+idparts[3]); } m_inserting=false; return true; @@ -71,7 +74,7 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message) { m_db->Execute("UPDATE tblIdentityIntroductionInserts SET Inserted='true' WHERE UUID='"+idparts[3]+"';"); m_inserting=false; - m_log->WriteLog(LogFile::LOGLEVEL_INFO,"IdentityIntroductionInserter::HandleMessage successfully inserted IdentityIntroduction "+idparts[3]); + m_log->information("IdentityIntroductionInserter::HandleMessage successfully inserted IdentityIntroduction "+idparts[3]); return true; } @@ -88,16 +91,16 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message) void IdentityIntroductionInserter::Initialize() { m_inserting=false; - Option::instance()->Get("MessageBase",m_messagebase); + Option option(m_db); + option.Get("MessageBase",m_messagebase); } void IdentityIntroductionInserter::Process() { - DateTime now; - now.SetToGMTime(); + Poco::DateTime now; // only do 1 insert at a time - if(!m_inserting && m_lastchecked<(now-(1.0/1440.0))) + if(!m_inserting && m_lastchecked<(now-Poco::Timespan(0,0,1,0,0))) { CheckForNewInserts(); m_lastchecked=now; @@ -113,12 +116,11 @@ void IdentityIntroductionInserter::RegisterWithThread(FreenetMasterThread *threa void IdentityIntroductionInserter::StartInsert(const long localidentityid, const std::string &day, const std::string &UUID, const std::string &solution) { - FCPMessage message; + FCPv2::Message message; IdentityIntroductionXML xml; std::string publickey; std::string data; std::string datasizestr; - std::vector hash; std::string encodedhash; SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LocalIdentityID=?;"); @@ -133,9 +135,10 @@ void IdentityIntroductionInserter::StartInsert(const long localidentityid, const data=xml.GetXML(); StringFunctions::Convert(data.size(),datasizestr); - hash.resize(20); - sha1((unsigned char *)solution.c_str(),solution.size(),&hash[0]); - Hex::Encode(hash,encodedhash); + Poco::SHA1Engine sha1; + sha1.update(solution); + encodedhash=Poco::DigestEngine::digestToHex(sha1.digest()); + StringFunctions::UpperCase(encodedhash,encodedhash); message.SetName("ClientPut"); message["URI"]="KSK@"+m_messagebase+"|"+day+"|"+UUID+"|"+encodedhash+".xml"; @@ -143,14 +146,14 @@ void IdentityIntroductionInserter::StartInsert(const long localidentityid, const message["UploadFrom"]="direct"; message["DataLength"]=datasizestr; - m_fcp->SendMessage(message); - m_fcp->SendRaw(data.c_str(),data.size()); + m_fcp->Send(message); + m_fcp->Send(std::vector(data.begin(),data.end())); m_inserting=true; } else { - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionInserter::StartInsert could not find a public key for identity. It is probably a new identity that doesn't have a key yet."); + m_log->debug("IdentityIntroductionInserter::StartInsert could not find a public key for identity. It is probably a new identity that doesn't have a key yet."); } }