}\r
StringFunctions::Convert(index,indexstr);\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
+ if(index<50)\r
{\r
- privatekey=rs2.GetField(0);\r
- if(rs2.GetField(1))\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
- publickey=rs2.GetField(1);\r
- }\r
- if(publickey.size()>=50)\r
- {\r
- // remove - and ~\r
- keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+ privatekey=rs2.GetField(0);\r
+ if(rs2.GetField(1))\r
+ {\r
+ publickey=rs2.GetField(1);\r
+ }\r
+ if(publickey.size()>=50)\r
+ {\r
+ // remove - and ~\r
+ keypart=StringFunctions::Replace(StringFunctions::Replace(publickey.substr(4,43),"-",""),"~","");\r
+ }\r
}\r
- }\r
\r
- Option::Instance()->Get("MessageBase",messagebase);\r
+ Option::Instance()->Get("MessageBase",messagebase);\r
\r
- GenerateCaptcha(encodedpuzzle,solutionstring);\r
+ GenerateCaptcha(encodedpuzzle,solutionstring);\r
\r
- try\r
- {\r
- uuid=uuidgen.createRandom();\r
+ try\r
+ {\r
+ uuid=uuidgen.createRandom();\r
+ }\r
+ catch(...)\r
+ {\r
+ m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID");\r
+ }\r
+\r
+ xml.SetType("captcha");\r
+ std::string uuidstr=uuid.toString();\r
+ StringFunctions::UpperCase(uuidstr,uuidstr);\r
+ xml.SetUUID(uuidstr+"@"+keypart);\r
+ xml.SetPuzzleData(encodedpuzzle);\r
+ xml.SetMimeType("image/bmp");\r
+\r
+ xmldata=xml.GetXML();\r
+ StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
+\r
+ message.SetName("ClientPut");\r
+ message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
+ message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
+ message["UploadFrom"]="direct";\r
+ message["DataLength"]=xmldatasizestr;\r
+ m_fcp->SendMessage(message);\r
+ m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+\r
+ // insert to USK\r
+ message.Reset();\r
+ message.SetName("ClientPutComplexDir");\r
+ message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
+ message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
+ message["DefaultName"]="IntroductionPuzzle.xml";\r
+ message["Files.0.Name"]="IntroductionPuzzle.xml";\r
+ message["Files.0.UplaodFrom"]="direct";\r
+ message["Files.0.DataLength"]=xmldatasizestr;\r
+ m_fcp->SendMessage(message);\r
+ m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
+\r
+ m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
+\r
+ m_inserting.push_back(localidentityid);\r
+\r
+ m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
}\r
- catch(...)\r
+ else\r
{\r
- m_log->fatal("IntroductionPuzzleInserter::StartInsert could not create UUID");\r
+ m_log->warning("IntroductionPuzzleInserter::StartInsert already inserted 50 puzzles for "+idstring);\r
}\r
\r
- xml.SetType("captcha");\r
- std::string uuidstr=uuid.toString();\r
- StringFunctions::UpperCase(uuidstr,uuidstr);\r
- xml.SetUUID(uuidstr+"@"+keypart);\r
- xml.SetPuzzleData(encodedpuzzle);\r
- xml.SetMimeType("image/bmp");\r
-\r
- xmldata=xml.GetXML();\r
- StringFunctions::Convert(xmldata.size(),xmldatasizestr);\r
-\r
- message.SetName("ClientPut");\r
- message["URI"]=privatekey+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
- message["Identifier"]=m_fcpuniquename+"|"+idstring+"|"+indexstr+"|"+xml.GetUUID()+"|"+message["URI"];\r
- message["UploadFrom"]="direct";\r
- message["DataLength"]=xmldatasizestr;\r
- m_fcp->SendMessage(message);\r
- m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
-\r
- // insert to USK\r
- message.Reset();\r
- message.SetName("ClientPutComplexDir");\r
- message["URI"]="USK"+privatekey.substr(3)+messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y.%m.%d")+"|IntroductionPuzzle/0/";\r
- message["Identifier"]=m_fcpuniquename+"USK|"+message["URI"];\r
- message["DefaultName"]="IntroductionPuzzle.xml";\r
- message["Files.0.Name"]="IntroductionPuzzle.xml";\r
- message["Files.0.UplaodFrom"]="direct";\r
- message["Files.0.DataLength"]=xmldatasizestr;\r
- m_fcp->SendMessage(message);\r
- m_fcp->SendRaw(xmldata.c_str(),xmldata.size());\r
-\r
- m_db->Execute("INSERT INTO tblIntroductionPuzzleInserts(UUID,Type,MimeType,LocalIdentityID,PuzzleData,PuzzleSolution) VALUES('"+xml.GetUUID()+"','captcha','image/bmp',"+idstring+",'"+encodedpuzzle+"','"+solutionstring+"');");\r
-\r
- m_inserting.push_back(localidentityid);\r
-\r
- m_log->debug("IntroductionPuzzleInserter::StartInsert started insert for id "+idstring);\r
-\r
return true;\r
\r
}\r
TrustListXML xml;\r
long identityid;\r
long index;\r
+ int insertcount=0;\r
+ int dayinsertcount=0;\r
\r
StringFunctions::Split(message["Identifier"],"|",idparts);\r
StringFunctions::Convert(message["DataLength"],datalength);\r
data.resize(datalength);\r
m_fcp->ReceiveRaw(&data[0],datalength);\r
\r
+ // get count of identities added in last 24 hours\r
+ st=m_db->Prepare("SELECT COUNT(*) FROM tblIdentity WHERE DateAdded>=?;");\r
+ st.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
+ st.Step();\r
+ if(st.RowReturned())\r
+ {\r
+ if(st.ResultNull(0)==false)\r
+ {\r
+ st.ResultInt(0,dayinsertcount);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ m_log->error("TrustListRequester::HandleAllData couldn't get count of identities added in last 24 hours");\r
+ }\r
+\r
// parse file into xml and update the database\r
if(xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
{\r
st.Step();\r
if(st.RowReturned()==false)\r
{\r
- idinsert.Bind(0,identity);\r
- idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
- idinsert.Bind(2,"trust list of "+publisherid);\r
- idinsert.Step(true);\r
- id=idinsert.GetLastInsertRowID();\r
- idinsert.Reset();\r
- // m_db->ExecuteInsert("INSERT INTO tblIdentity(PublicKey,DateAdded,AddedMethod) VALUES('"+identity+"','"+now.Format("%Y-%m-%d %H:%M:%S")+"');",(long &)id);\r
+ if(insertcount<50 && dayinsertcount<100)\r
+ {\r
+ idinsert.Bind(0,identity);\r
+ idinsert.Bind(1,Poco::DateTimeFormatter::format(now,"%Y-%m-%d %H:%M:%S"));\r
+ idinsert.Bind(2,"trust list of "+publisherid);\r
+ idinsert.Step(true);\r
+ id=idinsert.GetLastInsertRowID();\r
+ idinsert.Reset();\r
+ }\r
+ insertcount++;\r
+ dayinsertcount++;\r
}\r
else\r
{\r
trustst.Finalize();\r
st.Finalize();\r
\r
+ if(insertcount>=50)\r
+ {\r
+ m_log->warning("TrustListRequester::HandleAllData TrustList contained more than 50 new identities : "+message["Identifier"]);\r
+ }\r
+ if(dayinsertcount>=100)\r
+ {\r
+ m_log->warning("TrustListRequester::HandleAllData TrustList would have inserted more than 100 new identities in the last 24 hours : "+message["Identifier"]);\r
+ }\r
+\r
st=m_db->Prepare("INSERT INTO tblTrustListRequests(IdentityID,Day,RequestIndex,Found) VALUES(?,?,?,'true');");\r
st.Bind(0,identityid);\r
st.Bind(1,idparts[4]);\r