X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityrequester.cpp;h=18810d562a9845603ffabeb1c3be03d833172f0a;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=c0f6c8a74cddfafea36b4ecb73e46ba1ffc0afb3;hpb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0;p=fms.git diff --git a/src/freenet/identityrequester.cpp b/src/freenet/identityrequester.cpp index c0f6c8a..18810d5 100644 --- a/src/freenet/identityrequester.cpp +++ b/src/freenet/identityrequester.cpp @@ -2,25 +2,29 @@ #include "../../include/freenet/identityxml.h" #include "../../include/stringfunctions.h" #include "../../include/option.h" -#include "../../include/datetime.h" + +#include +#include +#include +#include #ifdef XMEM #include #endif -IdentityRequester::IdentityRequester() +IdentityRequester::IdentityRequester(SQLite3DB::DB *db):IIndexRequester(db) { Initialize(); } -IdentityRequester::IdentityRequester(FCPv2 *fcp):IIndexRequester(fcp) +IdentityRequester::IdentityRequester(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexRequester(db,fcp) { Initialize(); } -const bool IdentityRequester::HandleAllData(FCPMessage &message) +const bool IdentityRequester::HandleAllData(FCPv2::Message &message) { - DateTime now; + Poco::DateTime now; SQLite3DB::Statement st; std::vector idparts; long datalength; @@ -30,30 +34,26 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) long index; std::string name=""; - now.SetToGMTime(); + now=Poco::Timestamp(); StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(message["DataLength"],datalength); StringFunctions::Convert(idparts[1],identityid); StringFunctions::Convert(idparts[2],index); // wait for all data to be received from connection - while(m_fcp->Connected() && m_fcp->ReceiveBufferSize()Update(1); - } + m_fcp->WaitForBytes(1000,datalength); // if we got disconnected- return immediately - if(m_fcp->Connected()==false) + if(m_fcp->IsConnected()==false) { return false; } // receive the file - data.resize(datalength); - m_fcp->ReceiveRaw(&data[0],datalength); + m_fcp->Receive(data,datalength); // parse file into xml and update the database - if(xml.ParseXML(std::string(data.begin(),data.end()))==true) + if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) { st=m_db->Prepare("UPDATE tblIdentity SET Name=?, SingleUse=?, LastSeen=?, PublishTrustList=?, PublishBoardList=?, FreesiteEdition=? WHERE IdentityID=?"); @@ -71,7 +71,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) { st.Bind(1,"false"); } - st.Bind(2,now.Format("%Y-%m-%d %H:%M:%S")); + st.Bind(2,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S")); if(xml.GetPublishTrustList()==true) { st.Bind(3,"true"); @@ -107,7 +107,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"IdentityRequester::HandleAllData parsed Identity XML file : "+message["Identifier"]); + m_log->debug(m_fcpuniquename+"::HandleAllData parsed Identity XML file : "+message["Identifier"]); } else { @@ -119,7 +119,7 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityRequester::HandleAllData error parsing Identity XML file : "+message["Identifier"]); + m_log->error(m_fcpuniquename+"::HandleAllData error parsing Identity XML file : "+message["Identifier"]); } // remove this identityid from request list @@ -129,15 +129,13 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) } -const bool IdentityRequester::HandleGetFailed(FCPMessage &message) +const bool IdentityRequester::HandleGetFailed(FCPv2::Message &message) { - DateTime now; SQLite3DB::Statement st; std::vector idparts; long identityid; long index; - now.SetToGMTime(); StringFunctions::Split(message["Identifier"],"|",idparts); StringFunctions::Convert(idparts[1],identityid); StringFunctions::Convert(idparts[2],index); @@ -152,7 +150,7 @@ const bool IdentityRequester::HandleGetFailed(FCPMessage &message) st.Step(); st.Finalize(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IdentityRequester::HandleGetFailed fatal error requesting "+message["Identifier"]); + m_log->error(m_fcpuniquename+"::HandleGetFailed fatal error requesting "+message["Identifier"]); } // remove this identityid from request list @@ -164,33 +162,33 @@ const bool IdentityRequester::HandleGetFailed(FCPMessage &message) void IdentityRequester::Initialize() { - std::string tempval=""; - m_fcpuniquename="IdentityRequester"; - Option::Instance()->Get("MaxIdentityRequests",tempval); - StringFunctions::Convert(tempval,m_maxrequests); + m_fcpuniquename="KnownIdentityRequester"; + Option option(m_db); + option.GetInt("MaxIdentityRequests",m_maxrequests); + + // known identities get 4/5 + any remaining if not evenly divisible - unknown identities get 1/5 of the max requests option + m_maxrequests=((m_maxrequests*4)/5)+(m_maxrequests%5); + if(m_maxrequests<1) { m_maxrequests=1; - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"Option MaxIdentityRequests is currently set at "+tempval+". It must be 1 or greater."); + m_log->error("Option MaxIdentityRequests is currently set at less than 1. It must be 1 or greater."); } if(m_maxrequests>100) { - m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxIdentityRequests is currently set at "+tempval+". This value might be incorrectly configured."); + m_log->warning("Option MaxIdentityRequests is currently set at more than 100. This value might be incorrectly configured."); } } void IdentityRequester::PopulateIDList() { - DateTime date; + Poco::DateTime date; int id; - date.SetToGMTime(); - date.SetHour(0); - date.SetMinute(0); - date.SetSecond(0); + date.assign(date.year(),date.month(),date.day(),0,0,0); // select identities we want to query (haven't seen yet today) - sort by their trust level (descending) with secondary sort on how long ago we saw them (ascending) - SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND (LastSeen IS NULL OR LastSeen<'"+date.Format("%Y-%m-%d %H:%M:%S")+"') ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublicKey IS NOT NULL AND PublicKey <> '' AND LastSeen IS NOT NULL AND LastSeen<'"+Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")+"' ORDER BY LocalMessageTrust+LocalTrustListTrust DESC, LastSeen;"); st.Step(); m_ids.clear(); @@ -205,8 +203,8 @@ void IdentityRequester::PopulateIDList() void IdentityRequester::StartRequest(const long &identityid) { - DateTime now; - FCPMessage message; + Poco::DateTime now; + FCPv2::Message message; std::string publickey; int index; std::string indexstr; @@ -220,10 +218,10 @@ void IdentityRequester::StartRequest(const long &identityid) { st.ResultText(0,publickey); - now.SetToGMTime(); + now=Poco::Timestamp(); SQLite3DB::Statement st2=m_db->Prepare("SELECT MAX(RequestIndex) FROM tblIdentityRequests WHERE Day=? AND IdentityID=?;"); - st2.Bind(0,now.Format("%Y-%m-%d")); + st2.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); st2.Bind(1,identityid); st2.Step(); @@ -242,12 +240,12 @@ void IdentityRequester::StartRequest(const long &identityid) StringFunctions::Convert(identityid,identityidstr); message.SetName("ClientGet"); - message["URI"]=publickey+m_messagebase+"|"+now.Format("%Y-%m-%d")+"|Identity|"+indexstr+".xml"; + message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|Identity|"+indexstr+".xml"; message["Identifier"]=m_fcpuniquename+"|"+identityidstr+"|"+indexstr+"|"+message["URI"]; message["ReturnType"]="direct"; message["MaxSize"]="10000"; // 10 KB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); }