X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ffreenetmasterthread.cpp;h=73d26b6a11598d87cdc765b065fa2f3521e84694;hb=63376b2a82c3f6cdf2df56b1f134bd7df0aaab3a;hp=01f03a083ae8b7d628d5ba86ae9435fa21f01244;hpb=d8f51eac91f86a1e00a05a5058a8fa9eb8732464;p=fms.git diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index 01f03a0..73d26b6 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -1,5 +1,6 @@ #include "../../include/freenet/freenetmasterthread.h" #include "../../include/option.h" +#include "../../include/uuidgenerator.h" #include "../../include/stringfunctions.h" #include "../../include/freenet/unkeyedidcreator.h" #include "../../include/freenet/identityinserter.h" @@ -7,10 +8,20 @@ #include "../../include/freenet/introductionpuzzleinserter.h" #include "../../include/freenet/identityintroductionrequester.h" #include "../../include/freenet/introductionpuzzlerequester.h" -#include "../../include/freenet/introductionpuzzleremover.h" #include "../../include/freenet/identityintroductioninserter.h" - -#include +#include "../../include/freenet/trustlistinserter.h" +#include "../../include/freenet/trustlistrequester.h" +#include "../../include/freenet/messagelistrequester.h" +#include "../../include/freenet/messagerequester.h" +#include "../../include/freenet/messageinserter.h" +#include "../../include/freenet/messagelistinserter.h" +#include "../../include/freenet/periodicdbmaintenance.h" +#include "../../include/freenet/boardlistinserter.h" +#include "../../include/freenet/boardlistrequester.h" +#include "../../include/freenet/siteinserter.h" +#include "../../include/freenet/fileinserter.h" + +#include "../../include/pthreadwrapper/thread.h" #ifdef XMEM #include @@ -20,22 +31,22 @@ FreenetMasterThread::FreenetMasterThread() { std::string fcpport; - if(Option::instance()->Get("FCPHost",m_fcphost)==false) + if(Option::Instance()->Get("FCPHost",m_fcphost)==false) { m_fcphost="localhost"; - Option::instance()->Set("FCPHost",m_fcphost); + Option::Instance()->Set("FCPHost",m_fcphost); } - if(Option::instance()->Get("FCPPort",fcpport)==false) + if(Option::Instance()->Get("FCPPort",fcpport)==false) { fcpport="9481"; - Option::instance()->Set("FCPPort",fcpport); + Option::Instance()->Set("FCPPort",fcpport); } // convert fcp port to long, and make sure it's within the valid port range if(StringFunctions::Convert(fcpport,m_fcpport)==false) { m_fcpport=9481; - Option::instance()->Set("FCPPort","9481"); + Option::Instance()->Set("FCPPort","9481"); } m_receivednodehello=false; @@ -59,14 +70,16 @@ const bool FreenetMasterThread::FCPConnect() m_receivednodehello=false; } - m_log->WriteLog(LogFile::LOGLEVEL_INFO,__FUNCTION__" trying to connect to node "+m_fcphost); + m_log->WriteLog(LogFile::LOGLEVEL_INFO,"FreenetMasterThread::FCPConnect trying to connect to node "+m_fcphost); if(m_fcp.Connect(m_fcphost.c_str(),m_fcpport)==true) { + UUIDGenerator uuid; + std::string clientname="FMSClient-"+uuid.Generate(); // send ClientHello message to node - m_fcp.SendMessage("ClientHello",2,"Name","FMSClient","ExpectedVersion","2.0"); + m_fcp.SendMessage("ClientHello",2,"Name",clientname.c_str(),"ExpectedVersion","2.0"); - m_log->WriteLog(LogFile::LOGLEVEL_INFO,__FUNCTION__" connected to node"); + m_log->WriteLog(LogFile::LOGLEVEL_INFO,"FreenetMasterThread::FCPConnect connected to node"); return true; } @@ -108,7 +121,7 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) { info+="\t\t\t\t"+(*mi).first+"="+(*mi).second+"\r\n"; } - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,__FUNCTION__" received unhandled "+message.GetName()+" message. Message content :\r\n"+info); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"FreenetMasterThread::HandleMessage received unhandled "+message.GetName()+" message. Message content :\r\n"+info); // if unhandled message was alldata - we must retrieve the data if(message.GetName()=="AllData") @@ -133,7 +146,7 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) } else { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,__FUNCTION__" received "+message.GetName()+" message before NodeHello"); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::HandleMessage received "+message.GetName()+" message before NodeHello"); } return false; @@ -154,33 +167,50 @@ void FreenetMasterThread::RegisterPeriodicProcessor(IPeriodicProcessor *obj) m_processors.push_back(obj); } -void FreenetMasterThread::run() +void FreenetMasterThread::Run() { + DateTime lastreceivedmessage; + DateTime lastconnected; + DateTime now; FCPMessage message; bool done=false; + lastconnected.SetToGMTime(); + lastconnected.Add(0,-1); + + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"FreenetMasterThread::run thread started."); + Setup(); do { if(m_fcp.Connected()==false) { - if(FCPConnect()==false) + // wait at least 1 minute since last successful connect + now.SetToGMTime(); + if(lastconnected<=(now-(1.0/1440.0))) { + if(FCPConnect()==false) + { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,__FUNCTION__" could not connect to node. Waiting 60 seconds."); + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::run could not connect to node. Waiting 60 seconds."); - // wait 60 seconds - will then try to connect again - try - { - ZThread::Thread::sleep(60000); + for(int i=0; i<60 && !IsCancelled(); i++) + { + Sleep(1000); + } } - catch(...) + else { - done=true; + lastreceivedmessage.SetToGMTime(); + lastconnected.SetToGMTime(); } } + else + { + Sleep(1000); + } } // fcp is connected else @@ -196,6 +226,7 @@ void FreenetMasterThread::run() if(message.GetName()!="") { HandleMessage(message); + lastreceivedmessage.SetToGMTime(); } } @@ -205,13 +236,28 @@ void FreenetMasterThread::run() (*i)->Process(); } + // if we haven't received any messages from the node in 10 minutes, something is wrong + now.SetToGMTime(); + if(lastreceivedmessage<(now-(1.0/144.0))) + { + m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"FreenetMasterThread::Run The Freenet node has not responded in 10 minutes. Trying to reconnect."); + m_fcp.Disconnect(); + } + + if(m_fcp.Connected()==false) + { + m_log->WriteLog(LogFile::LOGLEVEL_INFO,"FreenetMasterThread::Run Disconnected from Freenet node."); + } + } - }while(!ZThread::Thread::interrupted() && done==false); + }while(!IsCancelled() && done==false); m_fcp.Disconnect(); Shutdown(); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"FreenetMasterThread::run thread exiting."); + } void FreenetMasterThread::Setup() @@ -226,8 +272,18 @@ void FreenetMasterThread::Setup() m_registrables.push_back(new IntroductionPuzzleInserter(&m_fcp)); m_registrables.push_back(new IdentityIntroductionRequester(&m_fcp)); m_registrables.push_back(new IntroductionPuzzleRequester(&m_fcp)); - m_registrables.push_back(new IntroductionPuzzleRemover()); m_registrables.push_back(new IdentityIntroductionInserter(&m_fcp)); + m_registrables.push_back(new TrustListInserter(&m_fcp)); + m_registrables.push_back(new TrustListRequester(&m_fcp)); + m_registrables.push_back(new MessageListInserter(&m_fcp)); + m_registrables.push_back(new MessageListRequester(&m_fcp)); + m_registrables.push_back(new MessageRequester(&m_fcp)); + m_registrables.push_back(new MessageInserter(&m_fcp)); + m_registrables.push_back(new BoardListInserter(&m_fcp)); + m_registrables.push_back(new BoardListRequester(&m_fcp)); + m_registrables.push_back(new SiteInserter(&m_fcp)); + m_registrables.push_back(new FileInserter(&m_fcp)); + m_registrables.push_back(new PeriodicDBMaintenance()); for(std::vector::iterator i=m_registrables.begin(); i!=m_registrables.end(); i++) { @@ -238,9 +294,9 @@ void FreenetMasterThread::Setup() void FreenetMasterThread::Shutdown() { - // delete each registerable object + // delete each registrable object for(std::vector::iterator i=m_registrables.begin(); i!=m_registrables.end(); i++) { delete (*i); } -} \ No newline at end of file +}