diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-04-18 17:06:17 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-04-18 17:06:17 +0000 |
| commit | 19f713b99d39cc5a672e3d56eaff7b76a2a7e72c (patch) | |
| tree | fa6374a20ad36ddf4da92b08598887c54904e47f /src/TrackerUpdateCommand.cc | |
| parent | 39276dcb00b33372e1ac5fbd0de2d60c733aeb60 (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/TrackerUpdateCommand.cc')
| -rw-r--r-- | src/TrackerUpdateCommand.cc | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/TrackerUpdateCommand.cc b/src/TrackerUpdateCommand.cc deleted file mode 100644 index 6b2ed6b6..00000000 --- a/src/TrackerUpdateCommand.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* <!-- copyright */ -/* - * aria2 - a simple utility for downloading files faster - * - * Copyright (C) 2006 Tatsuhiro Tsujikawa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* copyright --> */ -#include "TrackerUpdateCommand.h" -#include "PeerInitiateConnectionCommand.h" -#include "PeerListenCommand.h" -#include "Dictionary.h" -#include "Data.h" -#include "DlAbortEx.h" -#include "message.h" -#include <netinet/in.h> - -TrackerUpdateCommand::TrackerUpdateCommand(int cuid, Request* req, - TorrentDownloadEngine* e, - MetaEntry* trackerResponse) - :Command(cuid), req(req), e(e), trackerResponse(trackerResponse) { -} - -TrackerUpdateCommand::~TrackerUpdateCommand() { - delete trackerResponse; -} - -bool TrackerUpdateCommand::execute() { - Dictionary* response = (Dictionary*)trackerResponse; - Data* failureReason = (Data*)response->get("failure reason"); - if(failureReason != NULL) { - throw new DlAbortEx("Tracker returned failure reason: %s", failureReason->toString().c_str()); - } - Data* warningMessage = (Data*)response->get("warning message"); - if(warningMessage != NULL) { - logger->warn(MSG_TRACKER_WARNING_MESSAGE, cuid, warningMessage->toString().c_str()); - } - Data* trackerId = (Data*)response->get("tracker id"); - if(trackerId != NULL) { - e->torrentMan->trackerId = trackerId->toString(); - logger->debug("CUID#%d - Tracker ID:%s", cuid, e->torrentMan->trackerId.c_str()); - } - Data* interval = (Data*)response->get("interval"); - if(interval != NULL) { - e->torrentMan->interval = interval->toInt(); - logger->debug("CUID#%d - interval:%d", cuid, e->torrentMan->interval); - } - Data* minInterval = (Data*)response->get("min interval"); - if(minInterval != NULL) { - e->torrentMan->minInterval = minInterval->toInt(); - logger->debug("CUID#%d - min interval:%d", cuid, e->torrentMan->minInterval); - } - if(e->torrentMan->minInterval > e->torrentMan->interval) { - e->torrentMan->minInterval = e->torrentMan->interval; - } - Data* complete = (Data*)response->get("complete"); - if(complete != NULL) { - e->torrentMan->complete = complete->toInt(); - logger->debug("CUID#%d - complete:%d", cuid, e->torrentMan->complete); - } - Data* incomplete = (Data*)response->get("incomplete"); - if(incomplete != NULL) { - e->torrentMan->incomplete = incomplete->toInt(); - logger->debug("CUID#%d - incomplete:%d", cuid, e->torrentMan->incomplete); - } - Data* peers = (Data*)response->get("peers"); - if(peers != NULL) { - for(int i = 0; i < peers->getLen(); i += 6) { - unsigned int ipaddr1 = (unsigned char)*(peers->getData()+i); - unsigned int ipaddr2 = (unsigned char)*(peers->getData()+i+1); - unsigned int ipaddr3 = (unsigned char)*(peers->getData()+i+2); - unsigned int ipaddr4 = (unsigned char)*(peers->getData()+i+3); - unsigned int port = ntohs(*(unsigned short int*)(peers->getData()+i+4)); - char ipaddr[16]; - - snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d", - ipaddr1, ipaddr2, ipaddr3, ipaddr4); - Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength, - e->torrentMan->getTotalLength()); - if(e->torrentMan->addPeer(peer)) { - logger->debug("CUID#%d - adding peer %s:%d", cuid, - peer->ipaddr.c_str(), peer->port); - } else { - delete peer; - } - } - } else { - logger->info("CUID#%d - no peer list received.", cuid); - } - while(e->torrentMan->isPeerAvailable() && - e->torrentMan->connections < MAX_PEER_UPDATE) { - Peer* peer = e->torrentMan->getPeer(); - int newCuid = e->torrentMan->getNewCuid(); - peer->cuid = newCuid; - PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(newCuid, peer, e); - e->commands.push(command); - logger->debug("CUID#%d - adding new command CUID#%d", cuid, newCuid); - } - if(req->getTrackerEvent() == Request::STARTED) { - req->setTrackerEvent(Request::AUTO); - } - return true; -} |
