X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=include%2Ffreenet%2Fiindexrequester.h;h=aecc00a3fe24f3ad8801312745d151c645ed2b58;hb=8a0a83a78390f22f99d4487cda2569909dfbc28e;hp=7f0276303900eb61d298f7e08b23d21875f1a9ba;hpb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;p=fms.git diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index 7f02763..aecc00a 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 @@ -75,8 +82,10 @@ void IIndexRequester::FCPConnected() m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"IIndexRequester::FCPConnected fcpuniquename contains | character! This is not a valid character!"); } + m_lastreceived.SetToGMTime(); m_requesting.clear(); PopulateIDList(); + 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; @@ -129,11 +141,17 @@ void IIndexRequester::InitializeIIndexRequester() 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 typename std::map::size_type max=m_maxrequests>m_ids.size() ? m_ids.size() : m_maxrequests; @@ -153,19 +171,27 @@ void IIndexRequester::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(); + } }