X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzlerequester.cpp;h=9f1ee76c416604278d1702f4cd58a3737e8ffa8d;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=f7d53174354ee0b7ad30b0765aacf8b162a10553;hpb=dec33c63afafabf83c3039e916725cac6faef9b3;p=fms.git diff --git a/src/freenet/introductionpuzzlerequester.cpp b/src/freenet/introductionpuzzlerequester.cpp index f7d5317..9f1ee76 100644 --- a/src/freenet/introductionpuzzlerequester.cpp +++ b/src/freenet/introductionpuzzlerequester.cpp @@ -14,28 +14,17 @@ #include #endif -IntroductionPuzzleRequester::IntroductionPuzzleRequester() +IntroductionPuzzleRequester::IntroductionPuzzleRequester(SQLite3DB::DB *db):IIndexRequester(db) { Initialize(); } -IntroductionPuzzleRequester::IntroductionPuzzleRequester(FCPv2 *fcp):IFCPConnected(fcp) +IntroductionPuzzleRequester::IntroductionPuzzleRequester(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexRequester(db,fcp) { Initialize(); } -void IntroductionPuzzleRequester::FCPConnected() -{ - m_requesting.clear(); - PopulateIDList(); -} - -void IntroductionPuzzleRequester::FCPDisconnected() -{ - -} - -const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) +const bool IntroductionPuzzleRequester::HandleAllData(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -53,23 +42,19 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) 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) { // check if last part of UUID matches first part of public key of identity who inserted it @@ -112,6 +97,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) // we can only validate bitmaps for now BitmapValidator val; + val.SetMax(200,200); std::vector puzzledata; Base64::Decode(xml.GetPuzzleData(),puzzledata); if(xml.GetMimeType()!="image/bmp" || val.Validate(puzzledata)==false) @@ -165,7 +151,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) } -const bool IntroductionPuzzleRequester::HandleGetFailed(FCPMessage &message) +const bool IntroductionPuzzleRequester::HandleGetFailed(FCPv2::Message &message) { SQLite3DB::Statement st; std::vector idparts; @@ -196,57 +182,21 @@ const bool IntroductionPuzzleRequester::HandleGetFailed(FCPMessage &message) } -const bool IntroductionPuzzleRequester::HandleMessage(FCPMessage &message) -{ - - if(message["Identifier"].find("IntroductionPuzzleRequester")==0) - { - if(message.GetName()=="DataFound") - { - return true; - } - - if(message.GetName()=="AllData") - { - return HandleAllData(message); - } - - if(message.GetName()=="GetFailed") - { - return HandleGetFailed(message); - } - - if(message.GetName()=="IdentifierCollision") - { - // remove one of the ids from the requesting list - long identityid=0; - std::vector idparts; - StringFunctions::Split(message["Identifier"],"|",idparts); - StringFunctions::Convert(idparts[1],identityid); - RemoveFromRequestList(identityid); - return true; - } - } - - return false; -} - void IntroductionPuzzleRequester::Initialize() { - std::string tempval=""; - Option::Instance()->Get("MaxIntroductionPuzzleRequests",tempval); - StringFunctions::Convert(tempval,m_maxrequests); + m_fcpuniquename="IntroductionPuzzleRequester"; + m_maxrequests=0; + Option option(m_db); + option.GetInt("MaxIntroductionPuzzleRequests",m_maxrequests); if(m_maxrequests<1) { m_maxrequests=1; - m_log->error("Option MaxIntroductionPuzzleRequests is currently set at "+tempval+". It must be 1 or greater."); + m_log->error("Option MaxIntroductionPuzzleRequests is currently set at less than 1. It must be 1 or greater."); } if(m_maxrequests>100) { - m_log->warning("Option MaxIntroductionPuzzleRequests is currently set at "+tempval+". This value might be incorrectly configured."); + m_log->warning("Option MaxIntroductionPuzzleRequests is currently set at more than 100. This value might be incorrectly configured."); } - Option::Instance()->Get("MessageBase",m_messagebase); - m_tempdate=Poco::Timestamp(); } void IntroductionPuzzleRequester::PopulateIDList() @@ -265,7 +215,7 @@ void IntroductionPuzzleRequester::PopulateIDList() st.Finalize(); // select identities that aren't single use, are publishing a trust list, and have been seen today ( order by trust DESC and limit to limitnum ) - st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublishTrustList='true' AND PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND LastSeen>='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";"); + st=m_db->Prepare("SELECT IdentityID FROM tblIdentity WHERE PublishTrustList='true' AND PublicKey IS NOT NULL AND PublicKey <> '' AND SingleUse='false' AND (LocalTrustListTrust IS NULL OR LocalTrustListTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalTrustListTrust')) AND LastSeen>='"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"' ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";"); st.Step(); m_ids.clear(); @@ -278,64 +228,10 @@ void IntroductionPuzzleRequester::PopulateIDList() } } -void IntroductionPuzzleRequester::Process() -{ - // max is the smaller of the config value or the total number of identities we will request from - long max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests; - - // try to keep up to max requests going - if(m_requesting.size()::iterator i=m_ids.begin(); - while(i!=m_ids.end() && (*i).second==true) - { - i++; - } - - if(i!=m_ids.end()) - { - StartRequest((*i).first); - } - else - { - // we requested from all ids in the list, repopulate the list - PopulateIDList(); - } - } - // special case - if there were 0 identities on the list when we started then we will never get a chance to repopulate the list - // this will recheck for ids every minute - Poco::DateTime now; - if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0))) - { - PopulateIDList(); - m_tempdate=now; - } -} - -void IntroductionPuzzleRequester::RegisterWithThread(FreenetMasterThread *thread) -{ - thread->RegisterFCPConnected(this); - thread->RegisterFCPMessageHandler(this); - thread->RegisterPeriodicProcessor(this); -} - -void IntroductionPuzzleRequester::RemoveFromRequestList(const long identityid) -{ - std::vector::iterator i=m_requesting.begin(); - while(i!=m_requesting.end() && (*i)!=identityid) - { - i++; - } - if(i!=m_requesting.end()) - { - m_requesting.erase(i); - } -} - -void IntroductionPuzzleRequester::StartRequest(const long identityid) +void IntroductionPuzzleRequester::StartRequest(const long &identityid) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; int index; std::string indexstr; @@ -372,11 +268,11 @@ void IntroductionPuzzleRequester::StartRequest(const long identityid) message.SetName("ClientGet"); message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml"; - message["Identifier"]="IntroductionPuzzleRequester|"+identityidstr+"|"+indexstr+"|"+message["URI"]; + message["Identifier"]=m_fcpuniquename+"|"+identityidstr+"|"+indexstr+"|"+message["URI"]; message["ReturnType"]="direct"; message["MaxSize"]="1000000"; // 1 MB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); }