#include "../../include/freenet/freenetssk.h"\r
#include "../../include/option.h"\r
#include "../../include/stringfunctions.h"\r
-#include "../../include/xyssl/sha1.h"\r
#include "../../include/hex.h"\r
\r
+#include <Poco/DateTime.h>\r
+#include <Poco/Timestamp.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+#include <Poco/SHA1Engine.h>\r
+\r
#ifdef XMEM\r
#include <xmem.h>\r
#endif\r
\r
-IdentityIntroductionRequester::IdentityIntroductionRequester()\r
+IdentityIntroductionRequester::IdentityIntroductionRequester(SQLite3DB::DB *db):IDatabase(db)\r
{\r
Initialize();\r
}\r
\r
-IdentityIntroductionRequester::IdentityIntroductionRequester(FCPv2 *fcp):IFCPConnected(fcp)\r
+IdentityIntroductionRequester::IdentityIntroductionRequester(SQLite3DB::DB *db, FCPv2::Connection *fcp):IDatabase(db),IFCPConnected(fcp)\r
{\r
Initialize();\r
}\r
\r
}\r
\r
-const bool IdentityIntroductionRequester::HandleAllData(FCPMessage &message)\r
+const bool IdentityIntroductionRequester::HandleAllData(FCPv2::Message &message)\r
{\r
FreenetSSK ssk;\r
- DateTime date;\r
+ Poco::DateTime date;\r
std::vector<std::string> idparts;\r
std::vector<char> data;\r
long datalength;\r
StringFunctions::Convert(message["DataLength"],datalength);\r
\r
// wait for all data to be received from connection\r
- while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()<datalength)\r
- {\r
- m_fcp->Update(1);\r
- }\r
+ m_fcp->WaitForBytes(1000,datalength);\r
\r
// if we got disconnected- return immediately\r
- if(m_fcp->Connected()==false)\r
+ if(m_fcp->IsConnected()==false)\r
{\r
return false;\r
}\r
\r
// receive the file\r
- data.resize(datalength);\r
- m_fcp->ReceiveRaw(&data[0],datalength);\r
+ m_fcp->Receive(data,datalength);\r
\r
// parse file into xml and update the database\r
- if(xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
+ if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
{\r
\r
ssk.SetPublicKey(xml.GetIdentity());\r
{\r
// we don't already know about this id - add it\r
st.Finalize();\r
- date.SetToGMTime();\r
- st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded) VALUES(?,?);");\r
+ date=Poco::Timestamp();\r
+ st=m_db->Prepare("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES(?,?,?);");\r
st.Bind(0,xml.GetIdentity());\r
- st.Bind(1,date.Format("%Y-%m-%d %H:%M:%S"));\r
+ st.Bind(1,Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
+ st.Bind(2,"solved captcha");\r
st.Step();\r
}\r
st.Finalize();\r
+\r
+ m_log->debug("IdentityIntroductionRequester::HandleAddData parsed a valid identity.");\r
}\r
else\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData parsed public SSK key was not valid.");\r
+ m_log->error("IdentityIntroductionRequester::HandleAllData parsed, public SSK key was not valid.");\r
}\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]);\r
+ m_log->debug("IdentityIntroductionRequester::HandleAllData parsed IdentityIntroduction XML file : "+message["Identifier"]);\r
}\r
else\r
{\r
st.Step();\r
st.Finalize(); \r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityIntroductionRequester::HandleAllData error parsing IdentityIntroduction XML file : "+message["Identifier"]);\r
+ m_log->error("IdentityIntroductionRequester::HandleAllData error parsing IdentityIntroduction XML file : "+message["Identifier"]);\r
}\r
\r
// remove UUID from request list\r
return true;\r
}\r
\r
-const bool IdentityIntroductionRequester::HandleGetFailed(FCPMessage &message)\r
+const bool IdentityIntroductionRequester::HandleGetFailed(FCPv2::Message &message)\r
{\r
std::vector<std::string> idparts;\r
\r
st.Step();\r
st.Finalize();\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityIntroductionRequester::HandleAllData Fatal GetFailed for "+message["Identifier"]);\r
+ m_log->debug("IdentityIntroductionRequester::HandleAllData Fatal GetFailed for "+message["Identifier"]);\r
}\r
\r
// remove UUID from request list\r
return true;\r
}\r
\r
-const bool IdentityIntroductionRequester::HandleMessage(FCPMessage &message)\r
+const bool IdentityIntroductionRequester::HandleMessage(FCPv2::Message &message)\r
{\r
\r
if(message["Identifier"].find("IdentityIntroductionRequester")==0)\r
\r
void IdentityIntroductionRequester::Initialize()\r
{\r
- std::string tempval="";\r
- Option::instance()->Get("MaxIdentityIntroductionRequests",tempval);\r
- StringFunctions::Convert(tempval,m_maxrequests);\r
+ m_maxrequests=0;\r
+ Option option(m_db);\r
+ option.GetInt("MaxIdentityIntroductionRequests",m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
m_maxrequests=1;\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". It must be 1 or greater.");\r
+ m_log->error("Option MaxIdentityIntroductionRequests is currently less than 1. It must be 1 or greater.");\r
}\r
if(m_maxrequests>100)\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityIntroductionRequests is currently set at "+tempval+". This value might be incorrectly configured.");\r
+ m_log->warning("Option MaxIdentityIntroductionRequests is currently set at more than 100. This value might be incorrectly configured.");\r
}\r
- Option::instance()->Get("MessageBase",m_messagebase);\r
- m_tempdate.SetToGMTime();\r
+ option.Get("MessageBase",m_messagebase);\r
+ m_tempdate=Poco::Timestamp();\r
}\r
\r
void IdentityIntroductionRequester::PopulateIDList()\r
{\r
- DateTime date;\r
+ Poco::DateTime date;\r
int id;\r
\r
- date.SetToGMTime();\r
- date.Add(0,0,0,-1);\r
+ date-=Poco::Timespan(1,0,0,0,0);\r
\r
// get all identities that have unsolved puzzles from yesterday or today\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblIntroductionPuzzleInserts WHERE Day>='"+date.Format("%Y-%m-%d")+"' AND FoundSolution='false' GROUP BY LocalIdentityID;");\r
+ SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblIntroductionPuzzleInserts WHERE Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND FoundSolution='false' GROUP BY LocalIdentityID;");\r
st.Step();\r
\r
m_ids.clear();\r
}\r
// special case - if there were 0 identities on the list when we started then we will never get a chance to repopulate the list\r
// this will recheck for ids every minute\r
- DateTime now;\r
- now.SetToGMTime();\r
- if(m_tempdate<(now-(1.0/1440.0)))\r
+ Poco::DateTime now;\r
+ if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0)))\r
{\r
PopulateIDList();\r
m_tempdate=now;\r
{\r
std::string day;\r
std::string solution;\r
- std::vector<unsigned char> solutionhash;\r
std::string encodedhash;\r
- FCPMessage message;\r
+ FCPv2::Message message;\r
SQLite3DB::Statement st=m_db->Prepare("SELECT Day, PuzzleSolution FROM tblIntroductionPuzzleInserts WHERE FoundSolution='false' AND UUID=?;");\r
st.Bind(0,UUID);\r
st.Step();\r
st.ResultText(1,solution);\r
\r
// get the hash of the solution\r
- solutionhash.resize(20);\r
- sha1((unsigned char *)solution.c_str(),solution.size(),&solutionhash[0]);\r
- Hex::Encode(solutionhash,encodedhash);\r
+ Poco::SHA1Engine sha1;\r
+ sha1.update(solution);\r
+ encodedhash=Poco::DigestEngine::digestToHex(sha1.digest());\r
+ StringFunctions::UpperCase(encodedhash,encodedhash);\r
\r
//start request for the solution\r
message.SetName("ClientGet");\r
message["ReturnType"]="direct";\r
message["MaxSize"]="10000";\r
\r
- m_fcp->SendMessage(message);\r
+ m_fcp->Send(message);\r
\r
m_requesting.push_back(UUID);\r
\r
\r
void IdentityIntroductionRequester::StartRequests(const long localidentityid)\r
{\r
- DateTime date;\r
+ Poco::DateTime date;\r
std::string localidentityidstr;\r
std::string uuid;\r
\r
- date.SetToGMTime();\r
- date.Add(0,0,0,-1);\r
+ date-=Poco::Timespan(1,0,0,0,0);\r
StringFunctions::Convert(localidentityid,localidentityidstr);\r
\r
// get all non-solved puzzles from yesterday and today for this identity\r
- SQLite3DB::Statement st=m_db->Prepare("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE LocalIdentityID="+localidentityidstr+" AND Day>='"+date.Format("%Y-%m-%d")+"' AND FoundSolution='false';");\r
+ SQLite3DB::Statement st=m_db->Prepare("SELECT UUID FROM tblIntroductionPuzzleInserts WHERE LocalIdentityID="+localidentityidstr+" AND Day>='"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d")+"' AND FoundSolution='false';");\r
st.Step();\r
\r
// start requests for all non-solved puzzles\r