X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=include%2Ffreenet%2Fiindexrequester.h;h=aecc00a3fe24f3ad8801312745d151c645ed2b58;hb=8a0a83a78390f22f99d4487cda2569909dfbc28e;hp=35c16c1ca95d801c22b72bdc430cbdca10e0cf60;hpb=df316253862dc50e8e5a790d9634ef90be37badb;p=fms.git diff --git a/include/freenet/iindexrequester.h b/include/freenet/iindexrequester.h index 35c16c1..aecc00a 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 @@ -80,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 @@ -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(); + } }