diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-03-27 16:16:44 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-03-27 16:16:44 +0000 |
| commit | 6e6ba30c603826718b159cb1c0800b20147c23c7 (patch) | |
| tree | 80e45880d16a2a9eb468b2f673f400cc709f72f7 /src | |
| parent | 9b73454b07dc23e2aaf08baf6eff1643590e30f3 (diff) | |
2007-03-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add the command-line option which disables netrc support:
* src/OptionHandlerFactory.cc
(createOptionHandlers): Added PREF_NO_NETRC.
* src/main.cc: Added -n option.
* src/prefs.h (PREF_NO_NETRC): New definition.
* src/RequestFactory.cc: Do not use netrc in ftp if
PREF_NO_NETRC is
V_TRUE.
Note that netrc is not used in http, http proxy even if
PREF_NO_NETRC
is V_FALSE. This may get configurable in the future release.
To clear peer's error status by time basis:
* src/PeerAbstractCommand.cc
(onAbort): Call Peer::startBadCondition().
* src/Peer.h, src/Peer.cc
(error): Removed.
(_badConditionStartTime): New variable.
(_badConditionInterval): New variable. Initialized to 10
seconds.
(startBadCondition): New function.
(isGood): New function.
* src/DefaultPeerStorage.cc
(addPeer): Use Peer::isGood().
(FindFinePeer): Use Peer::isGood().
Always include port number in http request header:
* src/HttpRequest.cc (getHostText): Always include port number
in
http request header.
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractProxyRequestCommand.cc | 2 | ||||
| -rw-r--r-- | src/DefaultPeerStorage.cc | 4 | ||||
| -rw-r--r-- | src/HttpRequest.cc | 2 | ||||
| -rw-r--r-- | src/NetrcAuthResolver.h | 6 | ||||
| -rw-r--r-- | src/OptionHandlerFactory.cc | 1 | ||||
| -rw-r--r-- | src/Peer.cc | 15 | ||||
| -rw-r--r-- | src/Peer.h | 8 | ||||
| -rw-r--r-- | src/PeerAbstractCommand.cc | 6 | ||||
| -rw-r--r-- | src/RequestFactory.cc | 50 | ||||
| -rw-r--r-- | src/TimeA2.cc | 4 | ||||
| -rw-r--r-- | src/TimeA2.h | 1 | ||||
| -rw-r--r-- | src/UrlRequestInfo.cc | 4 | ||||
| -rw-r--r-- | src/main.cc | 8 | ||||
| -rw-r--r-- | src/prefs.h | 2 |
14 files changed, 82 insertions, 31 deletions
diff --git a/src/AbstractProxyRequestCommand.cc b/src/AbstractProxyRequestCommand.cc index 9c01ddbb..d4142045 100644 --- a/src/AbstractProxyRequestCommand.cc +++ b/src/AbstractProxyRequestCommand.cc @@ -34,6 +34,7 @@ /* copyright --> */ #include "AbstractProxyRequestCommand.h" #include "HttpConnection.h" +#include "prefs.h" AbstractProxyRequestCommand::AbstractProxyRequestCommand(int cuid, const RequestHandle& req, @@ -50,6 +51,7 @@ bool AbstractProxyRequestCommand::executeInternal() { socket->setBlockingMode(); HttpRequestHandle httpRequest = new HttpRequest(); + httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT)); httpRequest->setRequest(req); httpRequest->configure(e->option); diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index 39c6ae5c..e43c88d2 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -60,7 +60,7 @@ bool DefaultPeerStorage::addPeer(const PeerHandle& peer) { return true; } else { const PeerHandle& peer = *itr; - if(peer->error >= MAX_PEER_ERROR || peer->cuid != 0) { + if(!peer->isGood() || peer->cuid != 0) { return false; } else { *itr = peer; @@ -87,7 +87,7 @@ const Peers& DefaultPeerStorage::getPeers() { class FindFinePeer { public: bool operator()(const PeerHandle& peer) const { - return peer->cuid == 0 && peer->error < MAX_PEER_ERROR; + return peer->cuid == 0 && peer->isGood(); } }; diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 63b865b8..888a7f98 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -65,7 +65,7 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const string HttpRequest::getHostText(const string& host, in_port_t port) const { - return host+(port == 80 || port == 443 ? "" : ":"+Util::itos(port)); + return host+":"+Util::itos(port); } string HttpRequest::createRequest() const diff --git a/src/NetrcAuthResolver.h b/src/NetrcAuthResolver.h index 3c204adc..098b33dc 100644 --- a/src/NetrcAuthResolver.h +++ b/src/NetrcAuthResolver.h @@ -52,6 +52,12 @@ public: { _netrc = netrc; } + + NetrcHandle getNetrc() const + { + return _netrc; + } + }; typedef SharedHandle<NetrcAuthResolver> NetrcAuthResolverHandle; diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 9c889797..a3c90eb1 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -89,6 +89,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() V_NONE, V_PREALLOC)); handlers.push_back(new BooleanOptionHandler(PREF_CONTINUE)); handlers.push_back(new DefaultOptionHandler(PREF_USER_AGENT)); + handlers.push_back(new BooleanOptionHandler(PREF_NO_NETRC)); return handlers; } diff --git a/src/Peer.cc b/src/Peer.cc index 7da4120d..d4b64452 100644 --- a/src/Peer.cc +++ b/src/Peer.cc @@ -39,11 +39,12 @@ Peer::Peer(string ipaddr, int port, int pieceLength, long long int totalLength): ipaddr(ipaddr), port(port), - error(0), sessionUploadLength(0), sessionDownloadLength(0), pieceLength(pieceLength), - active(false) + active(false), + _badConditionStartTime(0), + _badConditionInterval(10) { resetStatus(); this->bitfield = BitfieldManFactory::getFactoryInstance()-> @@ -143,3 +144,13 @@ void Peer::setAllBitfield() { void Peer::updateLatency(int latency) { this->latency = (this->latency*20+latency*80)/200; } + +void Peer::startBadCondition() +{ + _badConditionStartTime.reset(); +} + +bool Peer::isGood() const +{ + return _badConditionStartTime.elapsed(_badConditionInterval); +} @@ -39,6 +39,7 @@ #include "BitfieldMan.h" #include "SharedHandle.h" #include "PeerStat.h" +#include "TimeA2.h" #include <string.h> #include <string> @@ -58,7 +59,6 @@ public: bool peerChoking; bool peerInterested; int tryCount; - int error; int cuid; bool chokingRequired; bool optUnchoking; @@ -80,6 +80,8 @@ private: int latency; bool active; string id; + Time _badConditionStartTime; + int _badConditionInterval; public: Peer(string ipaddr, int port, int pieceLength, long long int totalLength); @@ -196,6 +198,10 @@ public: const string& getId() const { return id; } + + void startBadCondition(); + + bool isGood() const; }; typedef SharedHandle<Peer> PeerHandle; diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index 11780643..3ad5f9be 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -97,11 +97,7 @@ bool PeerAbstractCommand::prepareForRetry(int wait) { } void PeerAbstractCommand::onAbort(RecoverableException* ex) { - if(peer->isSeeder()) { - peer->error++; - } else { - peer->error += MAX_PEER_ERROR; - } + peer->startBadCondition(); peer->resetStatus(); } diff --git a/src/RequestFactory.cc b/src/RequestFactory.cc index 859737ab..e1e0350c 100644 --- a/src/RequestFactory.cc +++ b/src/RequestFactory.cc @@ -34,7 +34,9 @@ /* copyright --> */ #include "RequestFactory.h" #include "prefs.h" +#include "AbstractAuthResolver.h" #include "NetrcAuthResolver.h" +#include "DefaultAuthResolver.h" RequestHandle RequestFactory::createRequest() { @@ -58,29 +60,43 @@ AuthConfigHandle RequestFactory::createAuthConfig(const string& user, const stri AuthResolverHandle RequestFactory::createHttpAuthResolver() { - NetrcAuthResolverHandle authResolver = 0; - authResolver = new NetrcAuthResolver(); - authResolver->setNetrc(_netrc); - authResolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_USER), _option->get(PREF_HTTP_PASSWD))); - return authResolver; + AbstractAuthResolverHandle resolver = 0; + if(true || _option->getAsBool(PREF_NO_NETRC)) { + resolver = new DefaultAuthResolver(); + } else { + NetrcAuthResolverHandle authResolver = new NetrcAuthResolver(); + authResolver->setNetrc(_netrc); + resolver = authResolver; + } + resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_USER), _option->get(PREF_HTTP_PASSWD))); + return resolver; } AuthResolverHandle RequestFactory::createFtpAuthResolver() { - NetrcAuthResolverHandle authResolver = 0; - authResolver = new NetrcAuthResolver(); - authResolver->setNetrc(_netrc); - authResolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_FTP_USER), _option->get(PREF_FTP_PASSWD))); - authResolver->setDefaultAuthConfig(new AuthConfig("anonymous", - "ARIA2USER@")); - return authResolver; + AbstractAuthResolverHandle resolver = 0; + if(_option->getAsBool(PREF_NO_NETRC)) { + resolver = new DefaultAuthResolver(); + } else { + NetrcAuthResolverHandle authResolver = new NetrcAuthResolver(); + authResolver->setNetrc(_netrc); + resolver = authResolver; + } + resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_FTP_USER), _option->get(PREF_FTP_PASSWD))); + resolver->setDefaultAuthConfig(new AuthConfig("anonymous", "ARIA2USER@")); + return resolver; } AuthResolverHandle RequestFactory::createHttpProxyAuthResolver() { - NetrcAuthResolverHandle authResolver = 0; - authResolver = new NetrcAuthResolver(); - authResolver->setNetrc(_netrc); - authResolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_PROXY_USER), _option->get(PREF_HTTP_PROXY_PASSWD))); - return authResolver; + AbstractAuthResolverHandle resolver = 0; + if(true || _option->getAsBool(PREF_NO_NETRC)) { + resolver = new DefaultAuthResolver(); + } else { + NetrcAuthResolverHandle authResolver = new NetrcAuthResolver(); + authResolver->setNetrc(_netrc); + resolver = authResolver; + } + resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_PROXY_USER), _option->get(PREF_HTTP_PROXY_PASSWD))); + return resolver; } diff --git a/src/TimeA2.cc b/src/TimeA2.cc index 68b9bd12..7c56ed65 100644 --- a/src/TimeA2.cc +++ b/src/TimeA2.cc @@ -43,6 +43,10 @@ Time::Time(const Time& time) { tv = time.tv; } +Time::Time(int sec) { + setTimeInSec(sec); +} + Time::~Time() {} void Time::reset() { diff --git a/src/TimeA2.h b/src/TimeA2.h index 14728c3c..da5f2d4f 100644 --- a/src/TimeA2.h +++ b/src/TimeA2.h @@ -48,6 +48,7 @@ public: // this object was created. Time(); Time(const Time& time); + Time(int sec); Time& operator=(const Time& time) { if(this != &time) { diff --git a/src/UrlRequestInfo.cc b/src/UrlRequestInfo.cc index dc677b0b..6af35555 100644 --- a/src/UrlRequestInfo.cc +++ b/src/UrlRequestInfo.cc @@ -189,9 +189,9 @@ RequestInfos UrlRequestInfo::execute() { SharedHandle<ConsoleDownloadEngine> e(DownloadEngineFactory::newConsoleEngine(op, requests, reserved)); - e->segmentMan->filename = hr->filename; - e->segmentMan->totalSize = hr->totalLength; if(hr->totalLength > 0) { + e->segmentMan->filename = hr->filename; + e->segmentMan->totalSize = hr->totalLength; e->segmentMan->downloadStarted = true; } diff --git a/src/main.cc b/src/main.cc index 3756a5df..486d4f36 100644 --- a/src/main.cc +++ b/src/main.cc @@ -202,6 +202,7 @@ void showUsage() { " Currently this option is applicable to http(s)/\n" " ftp downloads.") << endl; cout << _(" -U, --user-agent=USER_AGENT Set user agent for http(s) downloads.") << endl; + cout << _(" -n, --no-netrc Disables netrc support.") << endl; #ifdef ENABLE_BITTORRENT cout << _(" -T, --torrent-file=TORRENT_FILE The file path to .torrent file.") << endl; cout << _(" --follow-torrent=true|false Setting this option to false prevents aria2 to\n" @@ -352,6 +353,7 @@ int main(int argc, char* argv[]) { op->put(PREF_NETRC_PATH, Util::getHomeDir()+"/.netrc"); op->put(PREF_CONTINUE, V_FALSE); op->put(PREF_USER_AGENT, "aria2"); + op->put(PREF_NO_NETRC, V_FALSE); while(1) { int optIndex = 0; int lopt; @@ -386,6 +388,7 @@ int main(int argc, char* argv[]) { { "realtime-chunk-checksum", required_argument, &lopt, 204 }, { "continue", no_argument, 0, 'c' }, { "user-agent", required_argument, 0, 'U' }, + { "no-netrc", no_argument, 0, 'n' }, #ifdef ENABLE_BITTORRENT { "torrent-file", required_argument, NULL, 'T' }, { "listen-port", required_argument, &lopt, 15 }, @@ -413,7 +416,7 @@ int main(int argc, char* argv[]) { { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vhST:M:C:a:c", longOpts, &optIndex); + c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vhST:M:C:a:cU:n", longOpts, &optIndex); if(c == -1) { break; } @@ -564,6 +567,9 @@ int main(int argc, char* argv[]) { case 'U': cmdstream << PREF_USER_AGENT << "=" << optarg << "\n"; break; + case 'n': + cmdstream << PREF_NO_NETRC << "=" << V_TRUE << "\n"; + break; case 'v': showVersion(); exit(EXIT_SUCCESS); diff --git a/src/prefs.h b/src/prefs.h index b6525689..49eea67c 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -94,6 +94,8 @@ #define PREF_NETRC_PATH "netrc-path" // value: #define PREF_CONTINUE "continue" +// value: +#define PREF_NO_NETRC "no-netrc" /** * FTP related preferences |
