X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzlerequester.cpp;h=1b5c166ae5404fec77ea8ed509dee864745f5e05;hb=9ae3b1434e51788e6feb72e1415ec800d05c535a;hp=c1efe0f53cdb6ed2a7a8e3688024d39371f9fc50;hpb=d5c9f7e6c1dd263dfc85a3cb5941a378a5ddd923;p=fms.git diff --git a/src/freenet/introductionpuzzlerequester.cpp b/src/freenet/introductionpuzzlerequester.cpp index c1efe0f..1b5c166 100644 --- a/src/freenet/introductionpuzzlerequester.cpp +++ b/src/freenet/introductionpuzzlerequester.cpp @@ -14,28 +14,19 @@ #include #endif -IntroductionPuzzleRequester::IntroductionPuzzleRequester() -{ - Initialize(); -} +std::string IntroductionPuzzleRequester::m_validuuidchars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~@_-"; -IntroductionPuzzleRequester::IntroductionPuzzleRequester(FCPv2 *fcp):IIndexRequester(fcp) +IntroductionPuzzleRequester::IntroductionPuzzleRequester(SQLite3DB::DB *db):IIndexRequester(db) { Initialize(); } -void IntroductionPuzzleRequester::FCPConnected() -{ - m_requesting.clear(); - PopulateIDList(); -} - -void IntroductionPuzzleRequester::FCPDisconnected() +IntroductionPuzzleRequester::IntroductionPuzzleRequester(SQLite3DB::DB *db, FCPv2::Connection *fcp):IIndexRequester(db,fcp) { - + Initialize(); } -const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) +const bool IntroductionPuzzleRequester::HandleAllData(FCPv2::Message &message) { Poco::DateTime now; SQLite3DB::Statement st; @@ -53,23 +44,16 @@ 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); - if(data.size()>0) - { - m_fcp->ReceiveRaw(&data[0],datalength); - } + m_fcp->Receive(data,datalength); // parse file into xml and update the database if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true) @@ -91,7 +75,7 @@ const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message) StringFunctions::SplitMultiple(publickey,"@,",keyparts); StringFunctions::SplitMultiple(xml.GetUUID(),"@",uuidparts); - if(uuidparts.size()>1 && keyparts.size()>1) + if(uuidparts.size()>1 && keyparts.size()>1 && xml.GetUUID().find_first_not_of(m_validuuidchars)==std::string::npos) { keypart=StringFunctions::Replace(StringFunctions::Replace(keyparts[1],"-",""),"~",""); if(keypart!=uuidparts[1]) @@ -169,7 +153,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; @@ -204,7 +188,8 @@ void IntroductionPuzzleRequester::Initialize() { m_fcpuniquename="IntroductionPuzzleRequester"; m_maxrequests=0; - Option::Instance()->GetInt("MaxIntroductionPuzzleRequests",m_maxrequests); + Option option(m_db); + option.GetInt("MaxIntroductionPuzzleRequests",m_maxrequests); if(m_maxrequests<1) { m_maxrequests=1; @@ -232,7 +217,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 (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=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")+"' AND FailureCount<=(SELECT OptionValue FROM tblOption WHERE Option='MaxFailureCount') ORDER BY LocalMessageTrust DESC LIMIT 0,"+limitnum+";"); st.Step(); m_ids.clear(); @@ -248,7 +233,7 @@ void IntroductionPuzzleRequester::PopulateIDList() void IntroductionPuzzleRequester::StartRequest(const long &identityid) { Poco::DateTime now; - FCPMessage message; + FCPv2::Message message; std::string publickey; int index; std::string indexstr; @@ -289,7 +274,7 @@ void IntroductionPuzzleRequester::StartRequest(const long &identityid) message["ReturnType"]="direct"; message["MaxSize"]="1000000"; // 1 MB - m_fcp->SendMessage(message); + m_fcp->Send(message); m_requesting.push_back(identityid); }