version 0.1.15
[fms.git] / include / freenet / iindexrequester.h
index 35c16c1..e3845e3 100644 (file)
@@ -41,6 +41,8 @@ protected:
        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
@@ -82,6 +84,8 @@ void IIndexRequester<IDTYPE>::FCPConnected()
 \r
        m_requesting.clear();\r
        PopulateIDList();\r
+       m_lastreceived.SetToGMTime();\r
+       m_lastpopulated.SetToGMTime();\r
 }\r
 \r
 template <class IDTYPE>\r
@@ -96,6 +100,9 @@ const bool IIndexRequester<IDTYPE>::HandleMessage(FCPMessage &message)
 \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
@@ -134,11 +141,17 @@ void IIndexRequester<IDTYPE>::InitializeIIndexRequester()
 \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
@@ -158,19 +171,27 @@ void IIndexRequester<IDTYPE>::Process()
                }\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() Object has not received any messages in 10 minutes.  Restarting requests.");\r
+               FCPConnected();\r
+       }\r
 \r
 }\r
 \r