X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Ffreenetmasterthread.cpp;h=01db50c6b72006babdc13aecfd8d7a24b11f0808;hb=c0ebc7b53a977885ebc2d3a679c586ae20c0bc4a;hp=4d16043326041a26271a60df1d0c936b90fe18dd;hpb=76805933f794915a72b7f0a21b12af6654759f4f;p=fms.git diff --git a/src/freenet/freenetmasterthread.cpp b/src/freenet/freenetmasterthread.cpp index 4d16043..01db50c 100644 --- a/src/freenet/freenetmasterthread.cpp +++ b/src/freenet/freenetmasterthread.cpp @@ -34,24 +34,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; @@ -123,6 +123,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()) { @@ -200,70 +201,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);