/* */ #include "TrackerWatcherCommand.h" #include "InitiateConnectionCommandFactory.h" #include "Util.h" #include "SleepCommand.h" #include "prefs.h" TrackerWatcherCommand::TrackerWatcherCommand(int cuid, TorrentDownloadEngine* e, const BtContextHandle& btContext): BtContextAwareCommand(cuid, btContext), e(e) { } TrackerWatcherCommand::~TrackerWatcherCommand() {} bool TrackerWatcherCommand::execute() { if(btRuntime->isHalt() && e->segmentMan->errors > 0 && btAnnounce->isAllAnnounceFailed() || btAnnounce->noMoreAnnounce()) { return true; } Command* command = createCommand(); if(command) { e->commands.push_back(command); } e->commands.push_back(this); return false; } Command* TrackerWatcherCommand::createCommand() { Command* command = 0; if(btAnnounce->isAnnounceReady()) { command = createRequestCommand(btAnnounce->getAnnounceUrl()); btAnnounce->announceStart(); // inside it, trackers++. } else if(e->segmentMan->errors > 0) { btAnnounce->announceFailure(); // inside it, trackers = 0. e->segmentMan->init(); if(btAnnounce->isAllAnnounceFailed()) { btAnnounce->resetAnnounce(); // sleep a few seconds. command = new SleepCommand(cuid, e, createRequestCommand(btAnnounce->getAnnounceUrl()), e->option->getAsInt(PREF_RETRY_WAIT)); } } return command; } Command* TrackerWatcherCommand::createRequestCommand(const string& url) { RequestHandle req; req->setUrl(url); req->isTorrent = true; Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(btRuntime->getNewCuid(), req, e); logger->info("CUID#%d - Creating new tracker request command #%d", cuid, command->getCuid()); return command; }