summaryrefslogtreecommitdiff
path: root/src/TrackerWatcherCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-04-18 17:06:17 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-04-18 17:06:17 +0000
commit19f713b99d39cc5a672e3d56eaff7b76a2a7e72c (patch)
treefa6374a20ad36ddf4da92b08598887c54904e47f /src/TrackerWatcherCommand.cc
parent39276dcb00b33372e1ac5fbd0de2d60c733aeb60 (diff)
2006-04-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add a readout of estimated remaining time to normal HTTP/FTP downloads: * src/ConsoleDownloadEngine.h (startup): New variable. (startupLength): New variable. (isStartupLengthSet): New variable. (avgSpeed): New variable. (eta): New variable. * src/ConsoleDownloadEngine.cc (sendStatistics): Added a readout of estimated remaining time. (initStatistics): Initialized newly added variables. (calculateStatistics): Calculate average speed and estimated remaining time. To decouple TorrentDownloadEngine from HttpResponseCommand: * src/TrackerDownloadCommand.h: Removed. * src/TrackerDownloadCommand.cc: Removed. * src/TrackerInitCommand.h: Removed. * src/TrackerInitCommand.cc: Removed. * src/TrackerUpdateCommand.h: Removed. * src/TrackerUpdateCommand.cc: Removed. * src/TrackerWatcherCommand.cc (execute): The construction of request url written in TrackerInitCommand was moved here. Do not create tracker request command if torretnMan->trackers != 0. * src/CompactTrackerResponseProcessor.h: New class. * src/CompactTrackerResponseProcessor.cc: New class. * src/message.h (MSG_TRACKER_WARNING_MESSAGE): Updated. * src/HttpResponseCommand.cc (createHttpDownloadCommand): Decoupled TorrentDownloadEngine from this. * src/SegmentMan.h (init): New function. * src/SegmentMan.cc (init): New function. * src/TorrentMan.h (responseProcessor): New variable. (trackers): New variable. (setTrackerResponseProcessor): New function. (getTrackerResponseProcessor): New function. (processTrackerResponse): New function. * src/TorrentMan.cc (Constructor): Initialized new variable trackers. (processTrackerResponse): New function. * src/main.cc (main): Use ByteArrayDiskWriter and CompactTrackerResponseProcessor. * src/TorrentDownloadEngine.cc (afterEachIteration): Call torrentMan-> processTrackerResponse(). * src/TorrentConsoleDownloadEngine.cc (printStatistics): Updated a readout. * src/TorrentDownloadEngine.cc (afterEachIteration): Added log message which indicates download has completed. * src/AbstractDiskWriter.cc (Destructor): fd >= 0, not fd >0 (closeFile): fd >= 0, not fd > 0 * src/main.cc (main): Added short cut for show-files. Added short cut for torrent-file. Added new command-line option listen-port. Updated i18n messages.
Diffstat (limited to 'src/TrackerWatcherCommand.cc')
-rw-r--r--src/TrackerWatcherCommand.cc60
1 files changed, 51 insertions, 9 deletions
diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc
index f622a52a..7ff43ee4 100644
--- a/src/TrackerWatcherCommand.cc
+++ b/src/TrackerWatcherCommand.cc
@@ -21,7 +21,8 @@
/* copyright --> */
#include "TrackerWatcherCommand.h"
#include "SleepCommand.h"
-#include "TrackerInitCommand.h"
+#include "InitiateConnectionCommandFactory.h"
+#include "Util.h"
TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
TorrentDownloadEngine* e):
@@ -31,14 +32,55 @@ TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
TrackerWatcherCommand::~TrackerWatcherCommand() {}
bool TrackerWatcherCommand::execute() {
- req->resetTryCount();
- Command* command = new TrackerInitCommand(e->torrentMan->getNewCuid(),
- req,
- e);
- logger->info("CUID#%d - creating new tracker request command #%d", cuid,
- command->getCuid());
- e->commands.push(command);
-
+ if(e->torrentMan->trackers == 0) {
+ req->resetTryCount();
+
+ if(e->torrentMan->downloadComplete()) {
+ if(req->getTrackerEvent() == Request::COMPLETED) {
+ req->setTrackerEvent(Request::AFTER_COMPLETED);
+ } else {
+ if(req->getTrackerEvent() == Request::STARTED) {
+ req->setTrackerEvent(Request::AFTER_COMPLETED);
+ } else if(req->getTrackerEvent() != Request::AFTER_COMPLETED) {
+ req->setTrackerEvent(Request::COMPLETED);
+ }
+ }
+ }
+ string event;
+ switch(req->getTrackerEvent()) {
+ case Request::STARTED:
+ event = "started";
+ break;
+ case Request::STOPPED:
+ event = "stopped";
+ break;
+ case Request::COMPLETED:
+ event = "completed";
+ break;
+ }
+ string url = e->torrentMan->announce+"?"+
+ "info_hash="+Util::urlencode(e->torrentMan->getInfoHash(), 20)+"&"+
+ "peer_id="+e->torrentMan->peerId+"&"+
+ "port="+Util::itos(e->torrentMan->getPort())+"&"+
+ "uploaded="+Util::llitos(e->torrentMan->getSessionUploadLength())+"&"+
+ "downloaded="+Util::llitos(e->torrentMan->getSessionDownloadLength())+"&"+
+ "left="+(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength() <= 0
+ ? "0" : Util::llitos(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength()))+"&"+
+ "compact=1"+"&"+
+ "key="+e->torrentMan->peerId;
+ if(!event.empty()) {
+ url += string("&")+"event="+event;
+ }
+ if(!e->torrentMan->trackerId.empty()) {
+ url += string("&")+"trackerid="+e->torrentMan->trackerId;
+ }
+ req->setUrl(url);
+ Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(e->torrentMan->getNewCuid(), req, e);
+ e->commands.push(command);
+ e->torrentMan->trackers++;
+ logger->info("CUID#%d - creating new tracker request command #%d", cuid,
+ command->getCuid());
+ }
SleepCommand* slpCommand = new SleepCommand(cuid, e, this,
e->torrentMan->minInterval);
e->commands.push(slpCommand);