/* */ #include "LpdDispatchMessageCommand.h" #include "LpdMessageDispatcher.h" #include "DownloadEngine.h" #include "BtRuntime.h" #include "Logger.h" #include "RecoverableException.h" #include "SocketCore.h" #include "util.h" #include "RequestGroupMan.h" #include "FileAllocationEntry.h" #include "CheckIntegrityEntry.h" #include "ServerStatMan.h" #include "FileEntry.h" namespace aria2 { LpdDispatchMessageCommand::LpdDispatchMessageCommand (cuid_t cuid, const SharedHandle& dispatcher, DownloadEngine* e): Command(cuid), dispatcher_(dispatcher), e_(e), tryCount_(0) {} bool LpdDispatchMessageCommand::execute() { if(btRuntime_->isHalt()) { return true; } if(dispatcher_->isAnnounceReady()) { try { getLogger()->info("Dispatching LPD message for infohash=%s", util::toHex(dispatcher_->getInfoHash()).c_str()); if(dispatcher_->sendMessage()) { getLogger()->info("Sending LPD message is complete."); dispatcher_->resetAnnounceTimer(); tryCount_ = 0; } else { ++tryCount_; if(tryCount_ >= 5) { getLogger()->info("Sending LPD message %u times but all failed."); dispatcher_->resetAnnounceTimer(); tryCount_ = 0; } else { getLogger()->info("Could not send LPD message, retry shortly."); } } } catch(RecoverableException& e) { getLogger()->info("Failed to send LPD message.", e); dispatcher_->resetAnnounceTimer(); tryCount_ = 0; } } e_->addCommand(this); return false; } } // namespace aria2