#include "ifcpmessagehandler.h"\r
#include "iperiodicprocessor.h"\r
\r
+#ifdef XMEM\r
+ #include <xmem.h>\r
+#endif\r
+\r
template <class IDTYPE>\r
class IIndexRequester:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger\r
{\r
public:\r
IIndexRequester();\r
IIndexRequester(FCPv2 *fcp);\r
+ virtual ~IIndexRequester() {}\r
\r
virtual void FCPConnected();\r
virtual void FCPDisconnected();\r
virtual void RemoveFromRequestList(const IDTYPE id);\r
\r
DateTime m_tempdate;\r
+ DateTime m_lastreceived;\r
+ DateTime m_lastpopulated;\r
std::string m_messagebase;\r
std::map<IDTYPE,bool> m_ids; // map of all ids we know and whether we have requested file from them yet\r
std::vector<IDTYPE> m_requesting; // list of ids we are currently requesting from\r
// make sure variables have been initialized by the derived class\r
if(m_maxrequests==-1)\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::FCPConnected maxrequests not initialized correctly!");\r
+ m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected maxrequests not initialized correctly!");\r
}\r
if(m_fcpuniquename=="")\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
+ m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename not initialized correctly!");\r
}\r
if(m_fcpuniquename.find("|")!=std::string::npos)\r
{\r
- m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename contains | character! This is not a valid character!");\r
+ m_log->WriteLog(LogFile::LOGLEVEL_FATAL,"IIndexRequester<IDTYPE>::FCPConnected fcpuniquename contains | character! This is not a valid character!");\r
}\r
\r
+ m_lastreceived.SetToGMTime();\r
m_requesting.clear();\r
PopulateIDList();\r
+ m_lastpopulated.SetToGMTime();\r
}\r
\r
template <class IDTYPE>\r
\r
if(message["Identifier"].find(m_fcpuniquename)==0)\r
{\r
+\r
+ m_lastreceived.SetToGMTime();\r
+\r
if(message.GetName()=="DataFound")\r
{\r
return true;\r
\r
Option::Instance()->Get("MessageBase",m_messagebase);\r
m_tempdate.SetToGMTime();\r
+ m_lastreceived.SetToGMTime();\r
+ m_lastpopulated.SetToGMTime();\r
+ m_lastpopulated.Add(0,-10);\r
}\r
\r
template <class IDTYPE>\r
void IIndexRequester<IDTYPE>::Process()\r
{\r
+ DateTime now;\r
+ now.SetToGMTime();\r
+\r
// max is the smaller of the config value or the total number of ids we will request from\r
typename std::map<IDTYPE,bool>::size_type max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests;\r
\r
}\r
else\r
{\r
- // we requested from all ids in the list, repopulate the list\r
- PopulateIDList();\r
+ // we requested from all ids in the list, repopulate the list (only every 10 minutes)\r
+ if(m_lastpopulated<(now-1.0/144.0))\r
+ {\r
+ PopulateIDList();\r
+ m_lastpopulated.SetToGMTime();\r
+ }\r
}\r
}\r
// special case - if there were 0 ids 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
- DateTime now;\r
- now.SetToGMTime();\r
if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0)))\r
{\r
PopulateIDList();\r
m_tempdate=now;\r
}\r
+ // if we haven't received any messages to this object in 10 minutes, clear the requests and repopulate id list\r
+ if(m_ids.size()>0 && m_lastreceived<(now-(1.0/144.0)))\r
+ {\r
+ m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester<IDTYPE>::Process "+m_fcpuniquename+" Object has not received any messages in 10 minutes. Restarting requests.");\r
+ FCPConnected();\r
+ }\r
\r
}\r
\r