X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzleinserter.cpp;h=defa0cb392ba56ad0038a27ac432601fbe40f639;hb=c0ebc7b53a977885ebc2d3a679c586ae20c0bc4a;hp=6904186b8fb87179cb8971f082333ce29bd10ebc;hpb=fcb124f8d6d3f5678e82049fb8e5e23c8cfaec6d;p=fms.git diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index 6904186..defa0cb 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -3,6 +3,10 @@ #include "../../include/stringfunctions.h" #include "../../include/option.h" #include "../../include/freenet/captcha/simplecaptcha.h" +#ifdef ALTERNATE_CAPTCHA +#include "../../include/freenet/captcha/alternatecaptcha1.h" +#include "../../include/freenet/captcha/alternatecaptcha2.h" +#endif #include "../../include/base64.h" #include @@ -55,7 +59,6 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() // make sure we are on the next day or the appropriate amount of time has elapsed since the last insert if(m_lastinserted.find(rs.GetInt(0))==m_lastinserted.end() || m_lastinserted[rs.GetInt(0)]<=lastinsert || m_lastinserted[rs.GetInt(0)].day()!=now.day()) { - StartInsert(rs.GetInt(0)); m_lastinserted[rs.GetInt(0)]=now; } else @@ -71,13 +74,26 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::string &solution) { - SimpleCaptcha captcha; + ICaptcha *cap=0; +#ifdef ALTERNATE_CAPTCHA + if(rand()%2==0) + { + cap=new AlternateCaptcha1(); + } + else + { + cap=new AlternateCaptcha2(); + } + m_log->trace("IntroductionPuzzleInserter::GenerateCaptcha using alternate captcha generator"); +#else + cap=new SimpleCaptcha(); +#endif std::vector puzzle; std::vector puzzlesolution; - captcha.Generate(); - captcha.GetPuzzle(puzzle); - captcha.GetSolution(puzzlesolution); + cap->Generate(); + cap->GetPuzzle(puzzle); + cap->GetSolution(puzzlesolution); encodeddata.clear(); solution.clear(); @@ -85,6 +101,8 @@ void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std:: Base64::Encode(puzzle,encodeddata); solution.insert(solution.begin(),puzzlesolution.begin(),puzzlesolution.end()); + delete cap; + } const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message) @@ -159,18 +177,18 @@ void IntroductionPuzzleInserter::Initialize() const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) { Poco::DateTime now; - std::string idstring; + std::string idstring=""; long index=0; - std::string indexstr; + std::string indexstr=""; Poco::UUIDGenerator uuidgen; Poco::UUID uuid; - std::string messagebase; + std::string messagebase=""; IntroductionPuzzleXML xml; - std::string encodedpuzzle; - std::string solutionstring; + std::string encodedpuzzle=""; + std::string solutionstring=""; FCPMessage message; - std::string xmldata; - std::string xmldatasizestr; + std::string xmldata=""; + std::string xmldatasizestr=""; std::string privatekey=""; std::string publickey=""; std::string keypart=""; @@ -208,6 +226,11 @@ const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid) Option::Instance()->Get("MessageBase",messagebase); GenerateCaptcha(encodedpuzzle,solutionstring); + if(encodedpuzzle.size()==0) + { + m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create introduction puzzle"); + return false; + } try {