X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=include%2Ffreenet%2Fiindexrequester.h;h=e3845e366e76d44845c979c50659e14ce90c1499;hp=35c16c1ca95d801c22b72bdc430cbdca10e0cf60;hb=befd91205eff729a182f66de15374a577a8718f7;hpb=4430e7762844c66428b6f822288beb71b7f82b95 diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index 35c16c1..e3845e3 100644 --- a/include/freenet/iindexrequester.h +++ b/include/freenet/iindexrequester.h @@ -41,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 @@ -82,6 +84,8 @@ void IIndexRequester::FCPConnected() m_requesting.clear(); PopulateIDList(); + m_lastreceived.SetToGMTime(); + m_lastpopulated.SetToGMTime(); } template @@ -96,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; @@ -134,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; @@ -158,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(); + } }