version 0.3.29
[fms.git] / src / freenet / identityintroductioninserter.cpp
index dce7b78..5d01882 100644 (file)
@@ -1,20 +1,21 @@
 #include "../../include/freenet/identityintroductioninserter.h"\r
 #include "../../include/freenet/identityintroductionxml.h"\r
-#include "../../include/xyssl/sha1.h"\r
 #include "../../include/stringfunctions.h"\r
 #include "../../include/hex.h"\r
 #include "../../include/option.h"\r
 \r
+#include <Poco/SHA1Engine.h>\r
+\r
 #ifdef XMEM\r
        #include <xmem.h>\r
 #endif\r
 \r
-IdentityIntroductionInserter::IdentityIntroductionInserter()\r
+IdentityIntroductionInserter::IdentityIntroductionInserter(SQLite3DB::DB *db):IDatabase(db)\r
 {\r
        Initialize();\r
 }\r
 \r
-IdentityIntroductionInserter::IdentityIntroductionInserter(FCPv2 *fcp):IFCPConnected(fcp)\r
+IdentityIntroductionInserter::IdentityIntroductionInserter(SQLite3DB::DB *db, FCPv2::Connection *fcp):IDatabase(db),IFCPConnected(fcp)\r
 {\r
        Initialize();\r
 }\r
@@ -41,7 +42,7 @@ void IdentityIntroductionInserter::FCPDisconnected()
 \r
 }\r
 \r
-const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message)\r
+const bool IdentityIntroductionInserter::HandleMessage(FCPv2::Message &message)\r
 {\r
 \r
        if(message["Identifier"].find("IdentityIntroductionInserter")==0)\r
@@ -61,7 +62,9 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message)
                        if(message["Fatal"]=="true" || message["Code"]=="9")\r
                        {\r
                                m_db->Execute("DELETE FROM tblIdentityIntroductionInserts WHERE UUID='"+idparts[3]+"';");\r
-                               m_log->WriteLog(LogFile::LOGLEVEL_WARNING,__FUNCTION__" received fatal error trying to insert IdentityIntroduction "+idparts[3]);\r
+                               // 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\r
+                               m_db->Execute("UPDATE tblIntroductionPuzzleRequests SET Found='false' WHERE UUID='"+idparts[3]+"';");\r
+                               m_log->warning("IdentityIntroductionInserter::HandleMessage received fatal error trying to insert IdentityIntroduction "+idparts[3]);\r
                        }\r
                        m_inserting=false;\r
                        return true;\r
@@ -71,7 +74,7 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message)
                {\r
                        m_db->Execute("UPDATE tblIdentityIntroductionInserts SET Inserted='true' WHERE UUID='"+idparts[3]+"';");\r
                        m_inserting=false;\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_INFO,__FUNCTION__" successfully inserted IdentityIntroduction "+idparts[3]);\r
+                       m_log->information("IdentityIntroductionInserter::HandleMessage successfully inserted IdentityIntroduction "+idparts[3]);\r
                        return true;\r
                }\r
 \r
@@ -88,16 +91,16 @@ const bool IdentityIntroductionInserter::HandleMessage(FCPMessage &message)
 void IdentityIntroductionInserter::Initialize()\r
 {\r
        m_inserting=false;\r
-       Option::instance()->Get("MessageBase",m_messagebase);\r
+       Option option(m_db);\r
+       option.Get("MessageBase",m_messagebase);\r
 }\r
 \r
 void IdentityIntroductionInserter::Process()\r
 {\r
-       DateTime now;\r
-       now.SetToGMTime();\r
+       Poco::DateTime now;\r
 \r
        // only do 1 insert at a time\r
-       if(!m_inserting && m_lastchecked<(now-(1.0/1440.0)))\r
+       if(!m_inserting && m_lastchecked<(now-Poco::Timespan(0,0,1,0,0)))\r
        {\r
                CheckForNewInserts();\r
                m_lastchecked=now;\r
@@ -113,12 +116,11 @@ void IdentityIntroductionInserter::RegisterWithThread(FreenetMasterThread *threa
 \r
 void IdentityIntroductionInserter::StartInsert(const long localidentityid, const std::string &day, const std::string &UUID, const std::string &solution)\r
 {\r
-       FCPMessage message;\r
+       FCPv2::Message message;\r
        IdentityIntroductionXML xml;\r
        std::string publickey;\r
        std::string data;\r
        std::string datasizestr;\r
-       std::vector<unsigned char> hash;\r
        std::string encodedhash;\r
        \r
        SQLite3DB::Statement st=m_db->Prepare("SELECT PublicKey FROM tblLocalIdentity WHERE PublicKey IS NOT NULL AND PublicKey<>'' AND LocalIdentityID=?;");\r
@@ -133,9 +135,10 @@ void IdentityIntroductionInserter::StartInsert(const long localidentityid, const
                data=xml.GetXML();\r
                StringFunctions::Convert(data.size(),datasizestr);\r
 \r
-               hash.resize(20);\r
-               sha1((unsigned char *)solution.c_str(),solution.size(),&hash[0]);\r
-               Hex::Encode(hash,encodedhash);\r
+               Poco::SHA1Engine sha1;\r
+               sha1.update(solution);\r
+               encodedhash=Poco::DigestEngine::digestToHex(sha1.digest());\r
+               StringFunctions::UpperCase(encodedhash,encodedhash);\r
 \r
                message.SetName("ClientPut");\r
                message["URI"]="KSK@"+m_messagebase+"|"+day+"|"+UUID+"|"+encodedhash+".xml";\r
@@ -143,14 +146,14 @@ void IdentityIntroductionInserter::StartInsert(const long localidentityid, const
                message["UploadFrom"]="direct";\r
                message["DataLength"]=datasizestr;\r
 \r
-               m_fcp->SendMessage(message);\r
-               m_fcp->SendRaw(data.c_str(),data.size());\r
+               m_fcp->Send(message);\r
+               m_fcp->Send(std::vector<char>(data.begin(),data.end()));\r
 \r
                m_inserting=true;\r
        }\r
        else\r
        {\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" could not find a public key for identity.  It is probably a new identity that doesn't have a key yet.");\r
+               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.");\r
        }\r
 \r
-}
\ No newline at end of file
+}\r