X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ffreenetmasterthread.cpp;h=c0feb6a691789fea40f2e183bb22cf58aada445c;hb=e662ea47fba8715474851ceebacba400984ee433;hp=9e0670cc77448b543fe05af5429f9dd72fec91de;hpb=dec33c63afafabf83c3039e916725cac6faef9b3;p=fms.git diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index 9e0670c..c0feb6a 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -4,6 +4,7 @@ #include "../../include/freenet/unkeyedidcreator.h" #include "../../include/freenet/identityinserter.h" #include "../../include/freenet/identityrequester.h" +#include "../../include/freenet/unknownidentityrequester.h" #include "../../include/freenet/introductionpuzzleinserter.h" #include "../../include/freenet/identityintroductionrequester.h" #include "../../include/freenet/introductionpuzzlerequester.h" @@ -11,6 +12,7 @@ #include "../../include/freenet/trustlistinserter.h" #include "../../include/freenet/trustlistrequester.h" #include "../../include/freenet/messagelistrequester.h" +#include "../../include/freenet/inactivemessagelistrequester.h" #include "../../include/freenet/messagelistinserter.h" #include "../../include/freenet/messagerequester.h" #include "../../include/freenet/messageinserter.h" @@ -18,6 +20,7 @@ #include "../../include/freenet/boardlistrequester.h" #include "../../include/freenet/siteinserter.h" #include "../../include/freenet/fileinserter.h" +#include "../../include/freenet/fmsversionrequester.h" #include #include @@ -33,24 +36,24 @@ FreenetMasterThread::FreenetMasterThread() { - std::string fcpport; if(Option::Instance()->Get("FCPHost",m_fcphost)==false) { m_fcphost="localhost"; 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; @@ -122,6 +125,7 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) if(m_receivednodehello==true) { bool handled=false; + std::vector::iterator i=m_fcpmessagehandlers.begin(); while(handled==false && i!=m_fcpmessagehandlers.end()) { @@ -147,7 +151,7 @@ const bool FreenetMasterThread::HandleMessage(FCPMessage &message) { m_fcp.Update(1); } - if(m_fcp.Connected()) + if(m_fcp.Connected() && length>0) { char *data=new char[length]; m_fcp.ReceiveRaw(data,length); @@ -199,70 +203,81 @@ void FreenetMasterThread::run() do { - if(m_fcp.Connected()==false) + try { - // wait at least 1 minute since last successful connect - now=Poco::Timestamp(); - if(lastconnected<=(now-Poco::Timespan(0,0,1,0,0))) + if(m_fcp.Connected()==false) { - if(FCPConnect()==false) + // wait at least 1 minute since last successful connect + now=Poco::Timestamp(); + if(lastconnected<=(now-Poco::Timespan(0,0,1,0,0))) { + if(FCPConnect()==false) + { - m_log->error("FreenetMasterThread::run could not connect to node. Waiting 60 seconds."); + m_log->error("FreenetMasterThread::run could not connect to node. Waiting 60 seconds."); - for(int i=0; i<60 && !IsCancelled(); i++) + for(int i=0; i<60 && !IsCancelled(); i++) + { + Poco::Thread::sleep(1000); + } + } + else { - Poco::Thread::sleep(1000); + lastreceivedmessage=Poco::Timestamp(); + lastconnected=Poco::Timestamp(); } } else { - lastreceivedmessage=Poco::Timestamp(); - lastconnected=Poco::Timestamp(); + Poco::Thread::sleep(1000); } } + // fcp is connected else { - Poco::Thread::sleep(1000); - } - } - // fcp is connected - else - { - m_fcp.Update(1); + m_fcp.Update(1); - // check for message on receive buffer and handle it - if(m_fcp.ReceiveBufferSize()>0) - { - message.Reset(); - message=m_fcp.ReceiveMessage(); + // check for message on receive buffer and handle it + if(m_fcp.ReceiveBufferSize()>0) + { + message.Reset(); + message=m_fcp.ReceiveMessage(); - if(message.GetName()!="") + 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++) { - HandleMessage(message); - lastreceivedmessage=Poco::Timestamp(); + (*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 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."); + } - 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()); + } + catch(...) + { + m_log->error("FreenetMasterThread::run caught unknown exception"); } }while(!IsCancelled() && done==false); @@ -283,6 +298,7 @@ void FreenetMasterThread::Setup() m_registrables.push_back(new UnkeyedIDCreator(&m_fcp)); m_registrables.push_back(new IdentityInserter(&m_fcp)); m_registrables.push_back(new IdentityRequester(&m_fcp)); + m_registrables.push_back(new UnknownIdentityRequester(&m_fcp)); m_registrables.push_back(new IntroductionPuzzleInserter(&m_fcp)); m_registrables.push_back(new IdentityIntroductionRequester(&m_fcp)); m_registrables.push_back(new IntroductionPuzzleRequester(&m_fcp)); @@ -291,12 +307,14 @@ void FreenetMasterThread::Setup() 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 InactiveMessageListRequester(&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++) {