/* */ #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 { logger->info("Dispatching LPD message for infohash=%s", util::toHex(_dispatcher->getInfoHash()).c_str()); if(_dispatcher->sendMessage()) { logger->info("Sending LPD message is complete."); _dispatcher->resetAnnounceTimer(); _tryCount = 0; } else { ++_tryCount; if(_tryCount >= 5) { logger->info("Sending LPD message %u times but all failed."); _dispatcher->resetAnnounceTimer(); _tryCount = 0; } else { logger->info("Could not send LPD message, retry shortly."); } } } catch(RecoverableException& e) { logger->info("Failed to send LPD message.", e); _dispatcher->resetAnnounceTimer(); _tryCount = 0; } } _e->addCommand(this); return false; } } // namespace aria2