X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ffreenetmasterthread.cpp;h=c23ee2719c4c5cf4ca3c3874b6e3984337f3024f;hb=278ee758050cb7772cd95946688c5b40104f4d8b;hp=01f03a083ae8b7d628d5ba86ae9435fa21f01244;hpb=d8f51eac91f86a1e00a05a5058a8fa9eb8732464;p=fms.git diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index 01f03a0..c23ee27 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -7,10 +7,26 @@ #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/messagelistinserter.h" +#include "../../include/freenet/messagerequester.h" +#include "../../include/freenet/messageinserter.h" +#include "../../include/freenet/boardlistinserter.h" +#include "../../include/freenet/boardlistrequester.h" +#include "../../include/freenet/siteinserter.h" +#include "../../include/freenet/fileinserter.h" +#include "../../include/freenet/fmsversionrequester.h" + +#include +#include +#include +#include +#include + +#include #ifdef XMEM #include @@ -18,24 +34,24 @@ 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()->GetInt("FCPPort",m_fcpport)==false) { - fcpport="9481"; - Option::instance()->Set("FCPPort",fcpport); + m_fcpport=9481; + Option::Instance()->Set("FCPPort",m_fcpport); } - - // convert fcp port to long, and make sure it's within the valid port range - if(StringFunctions::Convert(fcpport,m_fcpport)==false) + else { - m_fcpport=9481; - Option::instance()->Set("FCPPort","9481"); + if(m_fcpport<1 || m_fcpport>65535) + { + m_fcpport=9481; + Option::Instance()->Set("FCPPort",m_fcpport); + } } m_receivednodehello=false; @@ -59,14 +75,27 @@ const bool FreenetMasterThread::FCPConnect() m_receivednodehello=false; } - m_log->WriteLog(LogFile::LOGLEVEL_INFO,__FUNCTION__" trying to connect to node "+m_fcphost); + m_log->information("FreenetMasterThread::FCPConnect trying to connect to node "+m_fcphost); if(m_fcp.Connect(m_fcphost.c_str(),m_fcpport)==true) { + Poco::UUIDGenerator uuidgen; + Poco::UUID uuid; + + try + { + uuid=uuidgen.createRandom(); + } + catch(...) + { + m_log->fatal("FreenetMasterThread::FCPConnect could not generate UUID"); + } + + std::string clientname="FMSClient-"+uuid.toString(); // 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->information("FreenetMasterThread::FCPConnect connected to node"); return true; } @@ -108,7 +137,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->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 +162,7 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) } else { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,__FUNCTION__" received "+message.GetName()+" message before NodeHello"); + m_log->error("FreenetMasterThread::HandleMessage received "+message.GetName()+" message before NodeHello"); } return false; @@ -157,61 +186,104 @@ void FreenetMasterThread::RegisterPeriodicProcessor(IPeriodicProcessor *obj) void FreenetMasterThread::run() { + Poco::DateTime lastreceivedmessage; + Poco::DateTime lastconnected; + Poco::DateTime now; FCPMessage message; bool done=false; + lastconnected-=Poco::Timespan(0,0,1,0,0); + + m_log->debug("FreenetMasterThread::run thread started."); + Setup(); do { - if(m_fcp.Connected()==false) + try { - if(FCPConnect()==false) + if(m_fcp.Connected()==false) { - - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,__FUNCTION__" could not connect to node. Waiting 60 seconds."); - - // wait 60 seconds - will then try to connect again - try + // wait at least 1 minute since last successful connect + now=Poco::Timestamp(); + if(lastconnected<=(now-Poco::Timespan(0,0,1,0,0))) { - ZThread::Thread::sleep(60000); + if(FCPConnect()==false) + { + + m_log->error("FreenetMasterThread::run could not connect to node. Waiting 60 seconds."); + + for(int i=0; i<60 && !IsCancelled(); i++) + { + Poco::Thread::sleep(1000); + } + } + else + { + lastreceivedmessage=Poco::Timestamp(); + lastconnected=Poco::Timestamp(); + } } - catch(...) + else { - done=true; + Poco::Thread::sleep(1000); } } - } - // fcp is connected - else - { - m_fcp.Update(1); - - // check for message on receive buffer and handle it - if(m_fcp.ReceiveBufferSize()>0) + // fcp is connected + else { - message.Reset(); - message=m_fcp.ReceiveMessage(); + m_fcp.Update(1); - if(message.GetName()!="") + // check for message on receive buffer and handle it + if(m_fcp.ReceiveBufferSize()>0) { - HandleMessage(message); + message.Reset(); + message=m_fcp.ReceiveMessage(); + + if(message.GetName()!="") + { + HandleMessage(message); + lastreceivedmessage=Poco::Timestamp(); + } } - } - // let objects do their processing - for(std::vector::iterator i=m_processors.begin(); i!=m_processors.end(); i++) - { - (*i)->Process(); - } + // let objects do their processing + for(std::vector::iterator i=m_processors.begin(); i!=m_processors.end(); i++) + { + (*i)->Process(); + } + // if we haven't received any messages from the node in 10 minutes, something is wrong + now=Poco::Timestamp(); + if(lastreceivedmessage<(now-Poco::Timespan(0,0,10,0,0))) + { + m_log->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->information("FreenetMasterThread::Run Disconnected from Freenet node."); + } + + } + } + catch(Poco::Exception &e) + { + m_log->error("FreenetMasterThread::run caught exception : "+e.displayText()); } - }while(!ZThread::Thread::interrupted() && done==false); + catch(...) + { + m_log->error("FreenetMasterThread::run caught unknown exception"); + } + }while(!IsCancelled() && done==false); m_fcp.Disconnect(); Shutdown(); + m_log->debug("FreenetMasterThread::run thread exiting."); + } void FreenetMasterThread::Setup() @@ -226,8 +298,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 MessageInserter(&m_fcp)); + m_registrables.push_back(new MessageRequester(&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 FMSVersionRequester(&m_fcp)); for(std::vector::iterator i=m_registrables.begin(); i!=m_registrables.end(); i++) { @@ -238,9 +320,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 +}