projects
/
fms.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
version 0.3.20
[fms.git]
/
src
/
freenet
/
introductionpuzzleinserter.cpp
diff --git
a/src/freenet/introductionpuzzleinserter.cpp
b/src/freenet/introductionpuzzleinserter.cpp
index
1fa13c0
..
defa0cb
100644
(file)
--- a/
src/freenet/introductionpuzzleinserter.cpp
+++ b/
src/freenet/introductionpuzzleinserter.cpp
@@
-3,6
+3,10
@@
#include "../../include/stringfunctions.h"
\r
#include "../../include/option.h"
\r
#include "../../include/freenet/captcha/simplecaptcha.h"
\r
#include "../../include/stringfunctions.h"
\r
#include "../../include/option.h"
\r
#include "../../include/freenet/captcha/simplecaptcha.h"
\r
+#ifdef ALTERNATE_CAPTCHA
\r
+#include "../../include/freenet/captcha/alternatecaptcha1.h"
\r
+#include "../../include/freenet/captcha/alternatecaptcha2.h"
\r
+#endif
\r
#include "../../include/base64.h"
\r
\r
#include <Poco/DateTimeFormatter.h>
\r
#include "../../include/base64.h"
\r
\r
#include <Poco/DateTimeFormatter.h>
\r
@@
-33,8
+37,13
@@
void IntroductionPuzzleInserter::CheckForNeededInsert()
\r
while(!rs.AtEnd())
\r
{
\r
\r
while(!rs.AtEnd())
\r
{
\r
- std::string localidentityidstr;
\r
+ int localidentityid=0;
\r
+ std::string localidentityidstr="";
\r
Poco::DateTime now;
\r
Poco::DateTime now;
\r
+ float minutesbetweeninserts=0;
\r
+ minutesbetweeninserts=1440.0/(float)m_maxpuzzleinserts;
\r
+ Poco::DateTime lastinsert=now;
\r
+ lastinsert-=Poco::Timespan(0,0,minutesbetweeninserts,0,0);
\r
\r
if(rs.GetField(0))
\r
{
\r
\r
if(rs.GetField(0))
\r
{
\r
@@
-47,7
+56,15
@@
void IntroductionPuzzleInserter::CheckForNeededInsert()
// identity doesn't have any non-solved puzzles for today - start a new insert
\r
if(rs2.Empty()==true)
\r
{
\r
// identity doesn't have any non-solved puzzles for today - start a new insert
\r
if(rs2.Empty()==true)
\r
{
\r
- StartInsert(rs.GetInt(0));
\r
+ // make sure we are on the next day or the appropriate amount of time has elapsed since the last insert
\r
+ if(m_lastinserted.find(rs.GetInt(0))==m_lastinserted.end() || m_lastinserted[rs.GetInt(0)]<=lastinsert || m_lastinserted[rs.GetInt(0)].day()!=now.day())
\r
+ {
\r
+ m_lastinserted[rs.GetInt(0)]=now;
\r
+ }
\r
+ else
\r
+ {
\r
+ m_log->trace("IntroductionPuzzleInserter::CheckForNeededInsert waiting to insert puzzle for "+localidentityidstr);
\r
+ }
\r
}
\r
\r
rs.Next();
\r
}
\r
\r
rs.Next();
\r
@@
-57,13
+74,26
@@
void IntroductionPuzzleInserter::CheckForNeededInsert()
\r
void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::string &solution)
\r
{
\r
\r
void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::string &solution)
\r
{
\r
- SimpleCaptcha captcha;
\r
+ ICaptcha *cap=0;
\r
+#ifdef ALTERNATE_CAPTCHA
\r
+ if(rand()%2==0)
\r
+ {
\r
+ cap=new AlternateCaptcha1();
\r
+ }
\r
+ else
\r
+ {
\r
+ cap=new AlternateCaptcha2();
\r
+ }
\r
+ m_log->trace("IntroductionPuzzleInserter::GenerateCaptcha using alternate captcha generator");
\r
+#else
\r
+ cap=new SimpleCaptcha();
\r
+#endif
\r
std::vector<unsigned char> puzzle;
\r
std::vector<unsigned char> puzzlesolution;
\r
\r
std::vector<unsigned char> puzzle;
\r
std::vector<unsigned char> puzzlesolution;
\r
\r
- cap
tcha.
Generate();
\r
- cap
tcha.
GetPuzzle(puzzle);
\r
- cap
tcha.
GetSolution(puzzlesolution);
\r
+ cap
->
Generate();
\r
+ cap
->
GetPuzzle(puzzle);
\r
+ cap
->
GetSolution(puzzlesolution);
\r
\r
encodeddata.clear();
\r
solution.clear();
\r
\r
encodeddata.clear();
\r
solution.clear();
\r
@@
-71,6
+101,8
@@
void IntroductionPuzzleInserter::GenerateCaptcha(std::string &encodeddata, std::
Base64::Encode(puzzle,encodeddata);
\r
solution.insert(solution.begin(),puzzlesolution.begin(),puzzlesolution.end());
\r
\r
Base64::Encode(puzzle,encodeddata);
\r
solution.insert(solution.begin(),puzzlesolution.begin(),puzzlesolution.end());
\r
\r
+ delete cap;
\r
+
\r
}
\r
\r
const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message)
\r
}
\r
\r
const bool IntroductionPuzzleInserter::HandlePutFailed(FCPMessage &message)
\r
@@
-139,23
+171,24
@@
const bool IntroductionPuzzleInserter::HandlePutSuccessful(FCPMessage &message)
void IntroductionPuzzleInserter::Initialize()
\r
{
\r
m_fcpuniquename="IntroductionPuzzleInserter";
\r
void IntroductionPuzzleInserter::Initialize()
\r
{
\r
m_fcpuniquename="IntroductionPuzzleInserter";
\r
+ m_maxpuzzleinserts=50;
\r
}
\r
\r
const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
\r
{
\r
Poco::DateTime now;
\r
}
\r
\r
const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
\r
{
\r
Poco::DateTime now;
\r
- std::string idstring;
\r
+ std::string idstring
=""
;
\r
long index=0;
\r
long index=0;
\r
- std::string indexstr;
\r
+ std::string indexstr
=""
;
\r
Poco::UUIDGenerator uuidgen;
\r
Poco::UUID uuid;
\r
Poco::UUIDGenerator uuidgen;
\r
Poco::UUID uuid;
\r
- std::string messagebase;
\r
+ std::string messagebase
=""
;
\r
IntroductionPuzzleXML xml;
\r
IntroductionPuzzleXML xml;
\r
- std::string encodedpuzzle;
\r
- std::string solutionstring;
\r
+ std::string encodedpuzzle
=""
;
\r
+ std::string solutionstring
=""
;
\r
FCPMessage message;
\r
FCPMessage message;
\r
- std::string xmldata;
\r
- std::string xmldatasizestr;
\r
+ std::string xmldata
=""
;
\r
+ std::string xmldatasizestr
=""
;
\r
std::string privatekey="";
\r
std::string publickey="";
\r
std::string keypart="";
\r
std::string privatekey="";
\r
std::string publickey="";
\r
std::string keypart="";
\r
@@
-173,7
+206,7
@@
const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
}
\r
StringFunctions::Convert(index,indexstr);
\r
\r
}
\r
StringFunctions::Convert(index,indexstr);
\r
\r
- if(index<
50
)
\r
+ if(index<
m_maxpuzzleinserts
)
\r
{
\r
SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");
\r
if(rs2.Empty()==false && rs2.GetField(0)!=NULL)
\r
{
\r
SQLite3DB::Recordset rs2=m_db->Query("SELECT PrivateKey,PublicKey FROM tblLocalIdentity WHERE LocalIdentityID="+idstring+";");
\r
if(rs2.Empty()==false && rs2.GetField(0)!=NULL)
\r
@@
-193,6
+226,11
@@
const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
Option::Instance()->Get("MessageBase",messagebase);
\r
\r
GenerateCaptcha(encodedpuzzle,solutionstring);
\r
Option::Instance()->Get("MessageBase",messagebase);
\r
\r
GenerateCaptcha(encodedpuzzle,solutionstring);
\r
+ if(encodedpuzzle.size()==0)
\r
+ {
\r
+ m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create introduction puzzle");
\r
+ return false;
\r
+ }
\r
\r
try
\r
{
\r
\r
try
\r
{
\r
@@
-241,7
+279,7
@@
const bool IntroductionPuzzleInserter::StartInsert(const long &localidentityid)
}
\r
else
\r
{
\r
}
\r
else
\r
{
\r
- m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted
50
puzzles for "+idstring);
\r
+ m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted
max
puzzles for "+idstring);
\r
}
\r
\r
return true;
\r
}
\r
\r
return true;
\r