X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fidentityrequester.cpp;h=07386988dd84c8f75a826822ca49bdeb258406aa;hb=e662ea47fba8715474851ceebacba400984ee433;hp=e464cfbf14ff591dc962e35bc94e95a7513270a5;hpb=5c0453c8697cfaa843dd7f799e5404733ee56e13;p=fms.git diff --git a/src/freenet/identityrequester.cpp b/src/freenet/identityrequester.cpp index e464cfb..0738698 100644 --- a/src/freenet/identityrequester.cpp +++ b/src/freenet/identityrequester.cpp @@ -2,7 +2,11 @@ #include "../../include/freenet/identityxml.h" #include "../../include/stringfunctions.h" #include "../../include/option.h" -#include "../../include/datetime.h" + +#include +#include +#include +#include #ifdef XMEM #include @@ -20,7 +24,7 @@ IdentityRequester::IdentityRequester(FCPv2 *fcp):IIndexRequester(fcp) const bool IdentityRequester::HandleAllData(FCPMessage &message) { - DateTime now; + Poco::DateTime now; SQLite3DB::Statement st; std::vector idparts; long datalength; @@ -30,7 +34,7 @@ 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); @@ -50,13 +54,16 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) // receive the file data.resize(datalength); - m_fcp->ReceiveRaw(&data[0],datalength); + if(data.size()>0) + { + m_fcp->ReceiveRaw(&data[0],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=? WHERE IdentityID=?"); + st=m_db->Prepare("UPDATE tblIdentity SET Name=?, SingleUse=?, LastSeen=?, PublishTrustList=?, PublishBoardList=?, FreesiteEdition=? WHERE IdentityID=?"); name=xml.GetName(); if(name.size()>40) { @@ -71,7 +78,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"); @@ -88,7 +95,15 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) { st.Bind(4,"false"); } - st.Bind(5,identityid); + if(xml.GetFreesiteEdition()>=0) + { + st.Bind(5,xml.GetFreesiteEdition()); + } + else + { + st.Bind(5); + } + st.Bind(6,identityid); st.Step(); st.Finalize(); @@ -99,7 +114,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 { @@ -111,7 +126,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 @@ -123,13 +138,11 @@ const bool IdentityRequester::HandleAllData(FCPMessage &message) const bool IdentityRequester::HandleGetFailed(FCPMessage &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); @@ -144,7 +157,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 @@ -156,33 +169,32 @@ 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::Instance()->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(); @@ -197,7 +209,7 @@ void IdentityRequester::PopulateIDList() void IdentityRequester::StartRequest(const long &identityid) { - DateTime now; + Poco::DateTime now; FCPMessage message; std::string publickey; int index; @@ -212,10 +224,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(); @@ -234,7 +246,7 @@ 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