X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fintroductionpuzzleinserter.cpp;h=5ccb25e37de6d0f09b45ecea185e7e5bf89c3ec6;hb=e7848d3900faf539dddfa6c7b3aac13ddc099e15;hp=ba0ffabef15ef4eec3335163239a5907fbe0e58f;hpb=822f84f5dac64183c556bd86fea8cd7b0527f528;p=fms.git diff --git a/src/freenet/introductionpuzzleinserter.cpp b/src/freenet/introductionpuzzleinserter.cpp index ba0ffab..5ccb25e 100644 --- a/src/freenet/introductionpuzzleinserter.cpp +++ b/src/freenet/introductionpuzzleinserter.cpp @@ -5,6 +5,7 @@ #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" @@ -74,18 +75,26 @@ void IntroductionPuzzleInserter::CheckForNeededInsert() void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::string &solution) { + ICaptcha *cap=0; #ifdef ALTERNATE_CAPTCHA - AlternateCaptcha1 captcha; + if(rand()%2==0) + { + cap=new AlternateCaptcha1(); + } + else + { + cap=new AlternateCaptcha2(); + } m_log->trace("IntroductionPuzzleInserter::GenerateCaptcha using alternate captcha generator"); #else - SimpleCaptcha captcha; + 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(); @@ -93,6 +102,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) @@ -167,18 +178,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=""; @@ -216,6 +227,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 {