X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=include%2Ffreenet%2Fiindexrequester.h;h=e3845e366e76d44845c979c50659e14ce90c1499;hb=befd91205eff729a182f66de15374a577a8718f7;hp=8f9e4e51cca4331a1521d19d99d1fc027738a296;hpb=868c533e84b3c81b6604b45b84efa32073aa20b4;p=fms.git diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index 8f9e4e5..e3845e3 100644 --- a/include/freenet/iindexrequester.h +++ b/include/freenet/iindexrequester.h @@ -11,12 +11,17 @@ #include "ifcpmessagehandler.h" #include "iperiodicprocessor.h" +#ifdef XMEM + #include +#endif + template class IIndexRequester:public IFreenetRegistrable,public IFCPConnected,public IFCPMessageHandler,public IPeriodicProcessor,public IDatabase,public ILogger { public: IIndexRequester(); IIndexRequester(FCPv2 *fcp); + virtual ~IIndexRequester() {} virtual void FCPConnected(); virtual void FCPDisconnected(); @@ -36,6 +41,8 @@ protected: virtual void RemoveFromRequestList(const IDTYPE id); DateTime m_tempdate; + DateTime m_lastreceived; + DateTime m_lastpopulated; std::string m_messagebase; std::map m_ids; // map of all ids we know and whether we have requested file from them yet std::vector m_requesting; // list of ids we are currently requesting from @@ -77,6 +84,8 @@ void IIndexRequester::FCPConnected() m_requesting.clear(); PopulateIDList(); + m_lastreceived.SetToGMTime(); + m_lastpopulated.SetToGMTime(); } template @@ -91,6 +100,9 @@ const bool IIndexRequester::HandleMessage(FCPMessage &message) if(message["Identifier"].find(m_fcpuniquename)==0) { + + m_lastreceived.SetToGMTime(); + if(message.GetName()=="DataFound") { return true; @@ -127,15 +139,21 @@ void IIndexRequester::InitializeIIndexRequester() m_maxrequests=-1; m_fcpuniquename=""; - Option::instance()->Get("MessageBase",m_messagebase); + Option::Instance()->Get("MessageBase",m_messagebase); m_tempdate.SetToGMTime(); + m_lastreceived.SetToGMTime(); + m_lastpopulated.SetToGMTime(); + m_lastpopulated.Add(0,-10); } template void IIndexRequester::Process() { + DateTime now; + now.SetToGMTime(); + // max is the smaller of the config value or the total number of ids we will request from - long max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests; + typename std::map::size_type max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests; // try to keep up to max requests going if(m_requesting.size()::Process() } else { - // we requested from all ids in the list, repopulate the list - PopulateIDList(); + // we requested from all ids in the list, repopulate the list (only every 10 minutes) + if(m_lastpopulated<(now-1.0/144.0)) + { + PopulateIDList(); + m_lastpopulated.SetToGMTime(); + } } } // special case - if there were 0 ids on the list when we started then we will never get a chance to repopulate the list // this will recheck for ids every minute - DateTime now; - now.SetToGMTime(); if(m_ids.size()==0 && m_tempdate<(now-(1.0/1440.0))) { PopulateIDList(); m_tempdate=now; } + // if we haven't received any messages to this object in 10 minutes, clear the requests and repopulate id list + if(m_ids.size()>0 && m_lastreceived<(now-(1.0/144.0))) + { + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester::Process() Object has not received any messages in 10 minutes. Restarting requests."); + FCPConnected(); + } }