Initialize();\r
}\r
\r
-IntroductionPuzzleRequester::IntroductionPuzzleRequester(FCPv2 *fcp):IFCPConnected(fcp)\r
+IntroductionPuzzleRequester::IntroductionPuzzleRequester(FCPv2 *fcp):IIndexRequester<long>(fcp)\r
{\r
Initialize();\r
}\r
\r
-void IntroductionPuzzleRequester::FCPConnected()\r
-{\r
- m_requesting.clear();\r
- PopulateIDList();\r
-}\r
-\r
-void IntroductionPuzzleRequester::FCPDisconnected()\r
-{\r
- \r
-}\r
-\r
const bool IntroductionPuzzleRequester::HandleAllData(FCPMessage &message)\r
{\r
Poco::DateTime now;\r
\r
// receive the file\r
data.resize(datalength);\r
- m_fcp->ReceiveRaw(&data[0],datalength);\r
+ if(data.size()>0)\r
+ {\r
+ m_fcp->ReceiveRaw(&data[0],datalength);\r
+ }\r
\r
// parse file into xml and update the database\r
- if(xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
+ if(data.size()>0 && xml.ParseXML(std::string(data.begin(),data.end()))==true)\r
{\r
\r
// check if last part of UUID matches first part of public key of identity who inserted it\r
\r
}\r
\r
-const bool IntroductionPuzzleRequester::HandleMessage(FCPMessage &message)\r
-{\r
-\r
- if(message["Identifier"].find("IntroductionPuzzleRequester")==0)\r
- {\r
- if(message.GetName()=="DataFound")\r
- {\r
- return true;\r
- }\r
-\r
- if(message.GetName()=="AllData")\r
- {\r
- return HandleAllData(message);\r
- }\r
-\r
- if(message.GetName()=="GetFailed")\r
- {\r
- return HandleGetFailed(message);\r
- }\r
- \r
- if(message.GetName()=="IdentifierCollision")\r
- {\r
- // remove one of the ids from the requesting list\r
- long identityid=0;\r
- std::vector<std::string> idparts;\r
- StringFunctions::Split(message["Identifier"],"|",idparts);\r
- StringFunctions::Convert(idparts[1],identityid);\r
- RemoveFromRequestList(identityid);\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
-}\r
-\r
void IntroductionPuzzleRequester::Initialize()\r
{\r
+ m_fcpuniquename="IntroductionPuzzleRequester";\r
m_maxrequests=0;\r
Option::Instance()->GetInt("MaxIntroductionPuzzleRequests",m_maxrequests);\r
if(m_maxrequests<1)\r
{\r
m_log->warning("Option MaxIntroductionPuzzleRequests is currently set at more than 100. This value might be incorrectly configured.");\r
}\r
- Option::Instance()->Get("MessageBase",m_messagebase);\r
- m_tempdate=Poco::Timestamp();\r
}\r
\r
void IntroductionPuzzleRequester::PopulateIDList()\r
}\r
}\r
\r
-void IntroductionPuzzleRequester::Process()\r
-{\r
- // max is the smaller of the config value or the total number of identities we will request from\r
- long max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests;\r
-\r
- // try to keep up to max requests going\r
- if(m_requesting.size()<max)\r
- {\r
- std::map<long,bool>::iterator i=m_ids.begin();\r
- while(i!=m_ids.end() && (*i).second==true)\r
- {\r
- i++;\r
- }\r
-\r
- if(i!=m_ids.end())\r
- {\r
- StartRequest((*i).first);\r
- }\r
- else\r
- {\r
- // we requested from all ids in the list, repopulate the list\r
- PopulateIDList();\r
- }\r
- }\r
- // special case - if there were 0 identities on the list when we started then we will never get a chance to repopulate the list\r
- // this will recheck for ids every minute\r
- Poco::DateTime now;\r
- if(m_ids.size()==0 && m_tempdate<(now-Poco::Timespan(0,0,1,0,0)))\r
- {\r
- PopulateIDList();\r
- m_tempdate=now;\r
- }\r
-}\r
-\r
-void IntroductionPuzzleRequester::RegisterWithThread(FreenetMasterThread *thread)\r
-{\r
- thread->RegisterFCPConnected(this);\r
- thread->RegisterFCPMessageHandler(this);\r
- thread->RegisterPeriodicProcessor(this);\r
-}\r
-\r
-void IntroductionPuzzleRequester::RemoveFromRequestList(const long identityid)\r
-{\r
- std::vector<long>::iterator i=m_requesting.begin();\r
- while(i!=m_requesting.end() && (*i)!=identityid)\r
- {\r
- i++;\r
- }\r
- if(i!=m_requesting.end())\r
- {\r
- m_requesting.erase(i);\r
- }\r
-}\r
-\r
-void IntroductionPuzzleRequester::StartRequest(const long identityid)\r
+void IntroductionPuzzleRequester::StartRequest(const long &identityid)\r
{\r
Poco::DateTime now;\r
FCPMessage message;\r
\r
message.SetName("ClientGet");\r
message["URI"]=publickey+m_messagebase+"|"+Poco::DateTimeFormatter::format(now,"%Y-%m-%d")+"|IntroductionPuzzle|"+indexstr+".xml";\r
- message["Identifier"]="IntroductionPuzzleRequester|"+identityidstr+"|"+indexstr+"|"+message["URI"];\r
+ message["Identifier"]=m_fcpuniquename+"|"+identityidstr+"|"+indexstr+"|"+message["URI"];\r
message["ReturnType"]="direct";\r
message["MaxSize"]="1000000"; // 1 MB\r
\r