diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-10-18 14:57:00 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-10-18 14:57:00 +0000 |
| commit | c0fd1fff2a6d78d3157790bbef6f98d54f31d0fc (patch) | |
| tree | de5f55ca5926df5dbd3fa83f28437d34e19c4f07 /src/AnnounceList.h | |
| parent | c35b68082519bcb4400d23d694bdaad9ffba6679 (diff) | |
2006-10-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Request -> RequestHandle:
* src/HttpResponseCommand.h: Request->RequestHandle
* src/AbstractCommand.cc: Request->RequestHandle
* src/HttpDownloadCommand.cc: Request->RequestHandle
* src/HttpRequestCommand.cc: Request->RequestHandle
* src/FtpInitiateConnectionCommand.h: Request->RequestHandle
* src/AbstractCommand.h: Request->RequestHandle
* src/HttpProxyRequestCommand.h: Request->RequestHandle
* src/HttpResponseCommand.cc: Request->RequestHandle
* src/HttpInitiateConnectionCommand.h: Request->RequestHandle
* src/FtpNegotiateCommand.cc: Request->RequestHandle
* src/FtpTunnelResponseCommand.h: Request->RequestHandle
* src/HttpConnection.h: Request->RequestHandle
* src/HttpProxyResponseCommand.cc: Request->RequestHandle
* src/InitiateConnectionCommandFactory.h: Request->RequestHandle
* src/FtpTunnelResponseCommand.cc: Request->RequestHandle
* src/DownloadCommand.h: Request->RequestHandle
* src/FtpDowndloadCommand.cc: Request->RequestHandle
* src/HttpInitiateConnectionCommand.cc: Request->RequestHandle
* src/HttpRequestCommand.h: Request->RequestHandle
* src/FtpNegotiateCommand.h: Request->RequestHandle
* src/FtpTunnelResponseCommand.cc: Request->RequestHandle
* src/FtpInitiateConnectionCommand.cc: Request->RequestHandle
* src/HttpDownloadCommand.h: Request->RequestHandle
* src/FtpConnection.cc: Request->RequestHandle
* src/InitiateConnectionCommandFactory.cc:
Request->RequestHandle
* src/UrlRequestInfo.cc: Request->RequestHandle
* src/HttpProxyResponseCommand.h: Request->RequestHandle
* src/HttpConnection.h: Request->RequestHandle
* src/DownloadCommand.cc: Request->RequestHandle
* src/FtpConnection.h: Request->RequestHandle
* src/FtpDowndloadCommand.h: Request->RequestHandle
* src/HttpProxyRequestCommand.cc: Request->RequestHandle
* src/FtpTunnelRequestCommand.h: Request->RequestHandle
* src/Request.h
(SharedHandle.h): New include.
(RequestHandle): New type definition.
(Requests): Redefined.
To add MULTITRACKER support:
* src/TrackerWatcherCommand.h
(createRequestCommand): New function.
* src/DownloadEngineFactory.cc
(newTorrentConsoleEngine): Removed req.
* src/prefs.h
(PREF_TRACKER_MAX_TRIES): New definition.
* src/TorrentMan.cc
(TorrentMan): Removed req. Added trackerNumTry.
(~TorrentMan): Removed req.
(setupInternal1): Added announceList.
* src/TorrentRequestInfo.cc
(execute): Set PREF_MAX_TIRES to 1. The max number of tries for
announces is now specified by PREF_TRACKER_MAX_TRIES.
* src/main.cc
(main): Added PREF_TRACKER_MAX_TRIES.
* src/TorrentMan.h
(Request.h): Removed.
(AnnounceList.h): New include.
(trackerNumTry): New variable.
(req): Removed.
(announceList): New variable.
* src/TrackerWatcherCommand.cc
(execute): Rewritten.
(createRequestCommand): New function.
* src/TrackerUpdateCommand.cc
(execute): Updated with the use of AnnounceList.
* src/AnnounceList.cc: New class.
* src/AnnounceList.h: New class.
To fix typo:
* src/prefs.h
(PREF_MAX_TRIES): max_try->max_tries
To not to decode "+" as space in URL decode:
* src/Util.cc
(urldecode): Removed "+"->space decoding rule. Test case was
updated.
Diffstat (limited to 'src/AnnounceList.h')
| -rw-r--r-- | src/AnnounceList.h | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/src/AnnounceList.h b/src/AnnounceList.h new file mode 100644 index 00000000..d2ecb3d8 --- /dev/null +++ b/src/AnnounceList.h @@ -0,0 +1,158 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_ANNOUNCE_LIST_H_ +#define _D_ANNOUNCE_LIST_H_ + +#include "common.h" +#include "MetaEntry.h" + +class AnnounceTier { +public: + enum AnnounceEvent { + STARTED, + STARTED_AFTER_COMPLETION, + DOWNLOADING, + STOPPED, + COMPLETED, + SEEDING, + HALTED + }; + + AnnounceEvent event; + Strings urls; + + AnnounceTier(const Strings& urls):event(STARTED), urls(urls) {} + + void nextEvent() { + switch(event) { + case STARTED: + event = DOWNLOADING; + break; + case STARTED_AFTER_COMPLETION: + event = SEEDING; + break; + case STOPPED: + event = HALTED; + break; + case COMPLETED: + event = SEEDING; + break; + default: + break; + } + } +}; + +typedef deque<AnnounceTier> AnnounceTiers; + +class AnnounceList { +public: +private: + AnnounceTiers tiers; + AnnounceTiers::iterator currentTier; + Strings::iterator currentTracker; + bool currentTrackerInitialized; + + void resetIterator(); + void setCurrentTier(const AnnounceTiers::iterator& itr); +public: + AnnounceList():currentTrackerInitialized(false) {} + AnnounceList(const MetaEntry* announceListEntry); + AnnounceList(const AnnounceTiers& tiers); + + void reconfigure(const MetaEntry* announceListEntry); + void reconfigure(const string& url); + + int countTier() const { + return tiers.size(); + } + + /** + * Shuffles all the URLs in each group. + */ + void shuffle(); + + /** + * Returns announce URL. + */ + string getAnnounce() const; + + /** + * Returns announce event, such as started, stopped, completed, etc. + */ + string getEventString() const; + + AnnounceTier::AnnounceEvent getEvent() const; + + void setEvent(AnnounceTier::AnnounceEvent event); + + /** + * Removes current announce URL from its group and inserts it before the + * first element of the group. + * The internal announce group pointer points to the first element of the + * first group after this call. + */ + void announceSuccess(); + + /** + * The internal announce URL pointer points to next URL. + * If the current URL is the last element of its group, then the first + * element of the next group is pointed. + */ + void announceFailure(); + + /** + * Counts the number of tiers to which the "stopped" event can be sent. + */ + int countStoppedAllowedTier() const; + + /** + * Counts the number of tiers to which the "completed" event can be sent. + */ + int countCompletedAllowedTier() const; + + /** + * Moves current tier pointer to the tier to which the "stopped" event can + * be sent. + * 2-stage search operation is made. + * The first search operation is performed from current pointer position + * to the end. If no such tier is found, the second search is performed from + * the first to the current pointer position. + */ + void moveToStoppedAllowedTier(); + void moveToCompletedAllowedTier(); +}; + +#endif // _D_ANNOUNCE_LIST_H_ |
