AbstractCommand.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "AbstractCommand.h"
  36. #include <algorithm>
  37. #include "Request.h"
  38. #include "DownloadEngine.h"
  39. #include "Option.h"
  40. #include "PeerStat.h"
  41. #include "SegmentMan.h"
  42. #include "Logger.h"
  43. #include "Segment.h"
  44. #include "DlAbortEx.h"
  45. #include "DlRetryEx.h"
  46. #include "DownloadFailureException.h"
  47. #include "CreateRequestCommand.h"
  48. #include "InitiateConnectionCommandFactory.h"
  49. #include "SleepCommand.h"
  50. #ifdef ENABLE_ASYNC_DNS
  51. #include "AsyncNameResolver.h"
  52. #endif // ENABLE_ASYNC_DNS
  53. #include "StreamCheckIntegrityEntry.h"
  54. #include "PieceStorage.h"
  55. #include "Socket.h"
  56. #include "message.h"
  57. #include "prefs.h"
  58. #include "StringFormat.h"
  59. #include "ServerStat.h"
  60. #include "RequestGroupMan.h"
  61. #include "A2STR.h"
  62. #include "util.h"
  63. #include "LogFactory.h"
  64. #include "DownloadContext.h"
  65. #include "wallclock.h"
  66. namespace aria2 {
  67. AbstractCommand::AbstractCommand(int32_t cuid,
  68. const SharedHandle<Request>& req,
  69. const SharedHandle<FileEntry>& fileEntry,
  70. RequestGroup* requestGroup,
  71. DownloadEngine* e,
  72. const SocketHandle& s):
  73. Command(cuid), _requestGroup(requestGroup),
  74. req(req), _fileEntry(fileEntry), e(e), socket(s),
  75. checkSocketIsReadable(false), checkSocketIsWritable(false),
  76. nameResolverCheck(false)
  77. {
  78. if(!socket.isNull() && socket->isOpen()) {
  79. setReadCheckSocket(socket);
  80. }
  81. timeout = _requestGroup->getTimeout();
  82. _requestGroup->increaseStreamConnection();
  83. _requestGroup->increaseNumCommand();
  84. }
  85. AbstractCommand::~AbstractCommand() {
  86. disableReadCheckSocket();
  87. disableWriteCheckSocket();
  88. #ifdef ENABLE_ASYNC_DNS
  89. disableNameResolverCheck(_asyncNameResolver);
  90. #endif // ENABLE_ASYNC_DNS
  91. _requestGroup->decreaseNumCommand();
  92. _requestGroup->decreaseStreamConnection();
  93. }
  94. bool AbstractCommand::execute() {
  95. if(logger->debug()) {
  96. logger->debug("CUID#%d - socket: read:%d, write:%d, hup:%d, err:%d",
  97. cuid, _readEvent, _writeEvent, _hupEvent, _errorEvent);
  98. }
  99. try {
  100. if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) {
  101. //logger->debug("CUID#%d - finished.", cuid);
  102. return true;
  103. }
  104. if(!req.isNull() && req->removalRequested()) {
  105. if(logger->debug()) {
  106. logger->debug
  107. ("CUID#%d - Discard original URI=%s because it is requested.",
  108. cuid, req->getUrl().c_str());
  109. }
  110. return prepareForRetry(0);
  111. }
  112. // TODO it is not needed to check other PeerStats every time.
  113. // Find faster Request when no segment is available.
  114. if(!req.isNull() && _fileEntry->countPooledRequest() > 0 &&
  115. !_requestGroup->getPieceStorage()->hasMissingUnusedPiece()) {
  116. SharedHandle<Request> fasterRequest = _fileEntry->findFasterRequest(req);
  117. if(!fasterRequest.isNull()) {
  118. logger->info("CUID#%d - Use faster Request hostname=%s, port=%u",
  119. cuid,
  120. fasterRequest->getHost().c_str(),
  121. fasterRequest->getPort());
  122. // Cancel current Request object and use faster one.
  123. _fileEntry->removeRequest(req);
  124. Command* command =
  125. InitiateConnectionCommandFactory::createInitiateConnectionCommand
  126. (cuid, fasterRequest, _fileEntry, _requestGroup, e);
  127. e->setNoWait(true);
  128. e->commands.push_back(command);
  129. return true;
  130. }
  131. }
  132. if((checkSocketIsReadable && _readEvent) ||
  133. (checkSocketIsWritable && _writeEvent) ||
  134. _hupEvent ||
  135. #ifdef ENABLE_ASYNC_DNS
  136. (nameResolverCheck && nameResolveFinished()) ||
  137. #endif // ENABLE_ASYNC_DNS
  138. (!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck)) {
  139. checkPoint = global::wallclock;
  140. if(!_requestGroup->getPieceStorage().isNull()) {
  141. _segments.clear();
  142. _requestGroup->getSegmentMan()->getInFlightSegment(_segments, cuid);
  143. if(req.isNull() || req->getMaxPipelinedRequest() == 1 ||
  144. _requestGroup->getDownloadContext()->getFileEntries().size() == 1) {
  145. if(_segments.empty()) {
  146. SharedHandle<Segment> segment =
  147. _requestGroup->getSegmentMan()->getSegment(cuid);
  148. if(!segment.isNull()) {
  149. _segments.push_back(segment);
  150. }
  151. }
  152. if(_segments.empty()) {
  153. // TODO socket could be pooled here if pipelining is enabled...
  154. logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid);
  155. // When all segments are ignored in SegmentMan, there are
  156. // no URIs available, so don't retry.
  157. if(_requestGroup->getSegmentMan()->allSegmentsIgnored()) {
  158. return true;
  159. } else {
  160. return prepareForRetry(1);
  161. }
  162. }
  163. } else {
  164. size_t maxSegments = req->getMaxPipelinedRequest();
  165. if(_segments.size() < maxSegments) {
  166. _requestGroup->getSegmentMan()->getSegment
  167. (_segments, cuid, _fileEntry, maxSegments);
  168. }
  169. if(_segments.empty()) {
  170. return prepareForRetry(0);
  171. }
  172. }
  173. }
  174. return executeInternal();
  175. } else if(_errorEvent) {
  176. throw DL_RETRY_EX
  177. (StringFormat(MSG_NETWORK_PROBLEM,
  178. socket->getSocketError().c_str()).str());
  179. } else {
  180. if(checkPoint.difference(global::wallclock) >= timeout) {
  181. // timeout triggers ServerStat error state.
  182. SharedHandle<ServerStat> ss =
  183. e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
  184. req->getProtocol());
  185. ss->setError();
  186. throw DL_RETRY_EX2(EX_TIME_OUT, downloadresultcode::TIME_OUT);
  187. }
  188. e->commands.push_back(this);
  189. return false;
  190. }
  191. } catch(DlAbortEx& err) {
  192. if(req.isNull()) {
  193. if(logger->debug()) {
  194. logger->debug(EX_EXCEPTION_CAUGHT, err);
  195. }
  196. } else {
  197. logger->error(MSG_DOWNLOAD_ABORTED,
  198. DL_ABORT_EX2(StringFormat
  199. ("URI=%s", req->getCurrentUrl().c_str()).str(),err),
  200. cuid, req->getUrl().c_str());
  201. _fileEntry->addURIResult(req->getUrl(), err.getCode());
  202. _requestGroup->setLastUriResult(req->getUrl(), err.getCode());
  203. }
  204. onAbort();
  205. tryReserved();
  206. return true;
  207. } catch(DlRetryEx& err) {
  208. assert(!req.isNull());
  209. logger->info(MSG_RESTARTING_DOWNLOAD,
  210. DL_RETRY_EX2(StringFormat
  211. ("URI=%s", req->getCurrentUrl().c_str()).str(),err),
  212. cuid, req->getUrl().c_str());
  213. req->addTryCount();
  214. req->resetRedirectCount();
  215. const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES);
  216. bool isAbort = maxTries != 0 && req->getTryCount() >= maxTries;
  217. if(isAbort) {
  218. onAbort();
  219. logger->info(MSG_MAX_TRY, cuid, req->getTryCount());
  220. logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
  221. _fileEntry->addURIResult(req->getUrl(), err.getCode());
  222. _requestGroup->setLastUriResult(req->getUrl(), err.getCode());
  223. tryReserved();
  224. return true;
  225. } else {
  226. return prepareForRetry(0);
  227. }
  228. } catch(DownloadFailureException& err) {
  229. logger->error(EX_EXCEPTION_CAUGHT, err);
  230. if(!req.isNull()) {
  231. _fileEntry->addURIResult(req->getUrl(), err.getCode());
  232. _requestGroup->setLastUriResult(req->getUrl(), err.getCode());
  233. }
  234. _requestGroup->setHaltRequested(true);
  235. return true;
  236. }
  237. }
  238. void AbstractCommand::tryReserved() {
  239. if(_requestGroup->getDownloadContext()->getFileEntries().size() == 1) {
  240. const SharedHandle<FileEntry>& entry =
  241. _requestGroup->getDownloadContext()->getFirstFileEntry();
  242. // Don't create new command if currently file length is unknown
  243. // and there are no URI left. Because file length is unknown, we
  244. // can assume that there are no in-flight request object.
  245. if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
  246. if(logger->debug()) {
  247. logger->debug("CUID#%d - Not trying next request."
  248. " No reserved/pooled request is remaining and"
  249. " total length is still unknown.", cuid);
  250. }
  251. return;
  252. }
  253. }
  254. if(logger->debug()) {
  255. logger->debug("CUID#%d - Trying reserved/pooled request.", cuid);
  256. }
  257. std::vector<Command*> commands;
  258. _requestGroup->createNextCommand(commands, e, 1);
  259. e->setNoWait(true);
  260. e->addCommand(commands);
  261. }
  262. bool AbstractCommand::prepareForRetry(time_t wait) {
  263. if(!_requestGroup->getPieceStorage().isNull()) {
  264. _requestGroup->getSegmentMan()->cancelSegment(cuid);
  265. }
  266. if(!req.isNull()) {
  267. _fileEntry->poolRequest(req);
  268. if(logger->debug()) {
  269. logger->debug("CUID#%d - Pooling request URI=%s",
  270. cuid, req->getUrl().c_str());
  271. }
  272. if(!_requestGroup->getSegmentMan().isNull()) {
  273. _requestGroup->getSegmentMan()->recognizeSegmentFor(_fileEntry);
  274. }
  275. }
  276. Command* command = new CreateRequestCommand(cuid, _requestGroup, e);
  277. if(wait == 0) {
  278. e->setNoWait(true);
  279. e->commands.push_back(command);
  280. } else {
  281. SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup,
  282. command, wait);
  283. e->commands.push_back(scom);
  284. }
  285. return true;
  286. }
  287. void AbstractCommand::onAbort() {
  288. if(!req.isNull()) {
  289. // TODO This might be a problem if the failure is caused by proxy.
  290. e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
  291. req->getProtocol())->setError();
  292. _fileEntry->removeIdenticalURI(req->getUrl());
  293. _fileEntry->removeRequest(req);
  294. }
  295. if(logger->debug()) {
  296. logger->debug("CUID#%d - Aborting download", cuid);
  297. }
  298. if(!_requestGroup->getPieceStorage().isNull()) {
  299. _requestGroup->getSegmentMan()->cancelSegment(cuid);
  300. }
  301. }
  302. void AbstractCommand::disableReadCheckSocket() {
  303. if(checkSocketIsReadable) {
  304. e->deleteSocketForReadCheck(readCheckTarget, this);
  305. checkSocketIsReadable = false;
  306. readCheckTarget = SocketHandle();
  307. }
  308. }
  309. void AbstractCommand::setReadCheckSocket(const SocketHandle& socket) {
  310. if(!socket->isOpen()) {
  311. disableReadCheckSocket();
  312. } else {
  313. if(checkSocketIsReadable) {
  314. if(readCheckTarget != socket) {
  315. e->deleteSocketForReadCheck(readCheckTarget, this);
  316. e->addSocketForReadCheck(socket, this);
  317. readCheckTarget = socket;
  318. }
  319. } else {
  320. e->addSocketForReadCheck(socket, this);
  321. checkSocketIsReadable = true;
  322. readCheckTarget = socket;
  323. }
  324. }
  325. }
  326. void AbstractCommand::setReadCheckSocketIf
  327. (const SharedHandle<SocketCore>& socket, bool pred)
  328. {
  329. if(pred) {
  330. setReadCheckSocket(socket);
  331. } else {
  332. disableReadCheckSocket();
  333. }
  334. }
  335. void AbstractCommand::disableWriteCheckSocket() {
  336. if(checkSocketIsWritable) {
  337. e->deleteSocketForWriteCheck(writeCheckTarget, this);
  338. checkSocketIsWritable = false;
  339. writeCheckTarget = SocketHandle();
  340. }
  341. }
  342. void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
  343. if(!socket->isOpen()) {
  344. disableWriteCheckSocket();
  345. } else {
  346. if(checkSocketIsWritable) {
  347. if(writeCheckTarget != socket) {
  348. e->deleteSocketForWriteCheck(writeCheckTarget, this);
  349. e->addSocketForWriteCheck(socket, this);
  350. writeCheckTarget = socket;
  351. }
  352. } else {
  353. e->addSocketForWriteCheck(socket, this);
  354. checkSocketIsWritable = true;
  355. writeCheckTarget = socket;
  356. }
  357. }
  358. }
  359. void AbstractCommand::setWriteCheckSocketIf
  360. (const SharedHandle<SocketCore>& socket, bool pred)
  361. {
  362. if(pred) {
  363. setWriteCheckSocket(socket);
  364. } else {
  365. disableWriteCheckSocket();
  366. }
  367. }
  368. // Returns proxy option value for the given protocol.
  369. static const std::string& getProxyOptionFor
  370. (const std::string& proxyPref, const SharedHandle<Option>& option)
  371. {
  372. if(option->defined(proxyPref)) {
  373. return option->get(proxyPref);
  374. } else {
  375. return option->get(PREF_ALL_PROXY);
  376. }
  377. }
  378. // Returns proxy URI for given protocol. If no proxy URI is defined,
  379. // then returns an empty string.
  380. static const std::string& getProxyUri
  381. (const std::string& protocol, const SharedHandle<Option>& option)
  382. {
  383. if(protocol == Request::PROTO_HTTP) {
  384. return getProxyOptionFor(PREF_HTTP_PROXY, option);
  385. } else if(protocol == Request::PROTO_HTTPS) {
  386. return getProxyOptionFor(PREF_HTTPS_PROXY, option);
  387. } else if(protocol == Request::PROTO_FTP) {
  388. return getProxyOptionFor(PREF_FTP_PROXY, option);
  389. } else {
  390. return A2STR::NIL;
  391. }
  392. }
  393. // Returns true if proxy is defined for the given protocol. Otherwise
  394. // returns false.
  395. static bool isProxyRequest
  396. (const std::string& protocol, const SharedHandle<Option>& option)
  397. {
  398. const std::string& proxyUri = getProxyUri(protocol, option);
  399. return !proxyUri.empty() && Request().setUrl(proxyUri);
  400. }
  401. class DomainMatch {
  402. private:
  403. std::string _hostname;
  404. public:
  405. DomainMatch(const std::string& hostname):_hostname(hostname) {}
  406. bool operator()(const std::string& domain) const
  407. {
  408. if(util::startsWith(domain, A2STR::DOT_C)) {
  409. return util::endsWith(_hostname, domain);
  410. } else {
  411. return util::endsWith(_hostname, A2STR::DOT_C+domain);
  412. }
  413. }
  414. };
  415. static bool inNoProxy(const SharedHandle<Request>& req,
  416. const std::string& noProxy)
  417. {
  418. std::vector<std::string> entries;
  419. util::split(noProxy, std::back_inserter(entries), ",", true);
  420. if(entries.empty()) {
  421. return false;
  422. }
  423. return
  424. std::find_if(entries.begin(), entries.end(),
  425. DomainMatch(A2STR::DOT_C+req->getHost())) != entries.end();
  426. }
  427. bool AbstractCommand::isProxyDefined() const
  428. {
  429. return isProxyRequest(req->getProtocol(), getOption()) &&
  430. !inNoProxy(req, getOption()->get(PREF_NO_PROXY));
  431. }
  432. SharedHandle<Request> AbstractCommand::createProxyRequest() const
  433. {
  434. SharedHandle<Request> proxyRequest;
  435. if(inNoProxy(req, getOption()->get(PREF_NO_PROXY))) {
  436. return proxyRequest;
  437. }
  438. std::string proxy = getProxyUri(req->getProtocol(), getOption());
  439. if(!proxy.empty()) {
  440. proxyRequest.reset(new Request());
  441. if(proxyRequest->setUrl(proxy)) {
  442. if(logger->debug()) {
  443. logger->debug("CUID#%d - Using proxy", cuid);
  444. }
  445. } else {
  446. if(logger->debug()) {
  447. logger->debug("CUID#%d - Failed to parse proxy string", cuid);
  448. }
  449. proxyRequest.reset();
  450. }
  451. }
  452. return proxyRequest;
  453. }
  454. #ifdef ENABLE_ASYNC_DNS
  455. bool AbstractCommand::isAsyncNameResolverInitialized() const
  456. {
  457. return !_asyncNameResolver.isNull();
  458. }
  459. void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
  460. {
  461. _asyncNameResolver.reset(new AsyncNameResolver());
  462. logger->info(MSG_RESOLVING_HOSTNAME, cuid, hostname.c_str());
  463. _asyncNameResolver->resolve(hostname);
  464. setNameResolverCheck(_asyncNameResolver);
  465. }
  466. bool AbstractCommand::asyncResolveHostname()
  467. {
  468. switch(_asyncNameResolver->getStatus()) {
  469. case AsyncNameResolver::STATUS_SUCCESS:
  470. return true;
  471. case AsyncNameResolver::STATUS_ERROR:
  472. if(!isProxyRequest(req->getProtocol(), getOption())) {
  473. e->_requestGroupMan->getOrCreateServerStat
  474. (req->getHost(), req->getProtocol())->setError();
  475. }
  476. throw DL_ABORT_EX(StringFormat(MSG_NAME_RESOLUTION_FAILED, cuid,
  477. _asyncNameResolver->getHostname().c_str(),
  478. _asyncNameResolver->getError().c_str()).str());
  479. default:
  480. return false;
  481. }
  482. }
  483. const std::vector<std::string>& AbstractCommand::getResolvedAddresses()
  484. {
  485. return _asyncNameResolver->getResolvedAddresses();
  486. }
  487. void AbstractCommand::setNameResolverCheck
  488. (const SharedHandle<AsyncNameResolver>& resolver) {
  489. if(!resolver.isNull()) {
  490. nameResolverCheck = true;
  491. e->addNameResolverCheck(resolver, this);
  492. }
  493. }
  494. void AbstractCommand::disableNameResolverCheck
  495. (const SharedHandle<AsyncNameResolver>& resolver) {
  496. if(!resolver.isNull()) {
  497. nameResolverCheck = false;
  498. e->deleteNameResolverCheck(resolver, this);
  499. }
  500. }
  501. bool AbstractCommand::nameResolveFinished() const {
  502. return
  503. _asyncNameResolver->getStatus() == AsyncNameResolver::STATUS_SUCCESS ||
  504. _asyncNameResolver->getStatus() == AsyncNameResolver::STATUS_ERROR;
  505. }
  506. #endif // ENABLE_ASYNC_DNS
  507. void AbstractCommand::prepareForNextAction(Command* nextCommand)
  508. {
  509. SharedHandle<CheckIntegrityEntry> entry
  510. (new StreamCheckIntegrityEntry(_requestGroup, nextCommand));
  511. std::vector<Command*> commands;
  512. try {
  513. _requestGroup->processCheckIntegrityEntry(commands, entry, e);
  514. } catch(RecoverableException& e) {
  515. std::for_each(commands.begin(), commands.end(), Deleter());
  516. throw;
  517. }
  518. e->addCommand(commands);
  519. e->setNoWait(true);
  520. }
  521. bool AbstractCommand::checkIfConnectionEstablished
  522. (const SharedHandle<SocketCore>& socket,
  523. const std::string& connectedHostname,
  524. const std::string& connectedAddr,
  525. uint16_t connectedPort)
  526. {
  527. if(socket->isReadable(0)) {
  528. std::string error = socket->getSocketError();
  529. if(!error.empty()) {
  530. // See also InitiateConnectionCommand::executeInternal()
  531. e->markBadIPAddress(connectedHostname, connectedAddr, connectedPort);
  532. if(!e->findCachedIPAddress(connectedHostname, connectedPort).empty()) {
  533. logger->info(MSG_CONNECT_FAILED_AND_RETRY,
  534. cuid, connectedAddr.c_str(), connectedPort);
  535. Command* command =
  536. InitiateConnectionCommandFactory::createInitiateConnectionCommand
  537. (cuid, req, _fileEntry, _requestGroup, e);
  538. e->setNoWait(true);
  539. e->commands.push_back(command);
  540. return false;
  541. }
  542. e->removeCachedIPAddress(connectedHostname, connectedPort);
  543. // Don't set error if proxy server is used and its method is GET.
  544. if(resolveProxyMethod(req->getProtocol()) != V_GET ||
  545. !isProxyRequest(req->getProtocol(), getOption())) {
  546. e->_requestGroupMan->getOrCreateServerStat
  547. (req->getHost(), req->getProtocol())->setError();
  548. }
  549. throw DL_RETRY_EX
  550. (StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED, error.c_str()).str());
  551. }
  552. }
  553. return true;
  554. }
  555. const std::string& AbstractCommand::resolveProxyMethod
  556. (const std::string& protocol) const
  557. {
  558. if(getOption()->get(PREF_PROXY_METHOD) == V_TUNNEL ||
  559. Request::PROTO_HTTPS == protocol) {
  560. return V_TUNNEL;
  561. } else {
  562. return V_GET;
  563. }
  564. }
  565. const SharedHandle<Option>& AbstractCommand::getOption() const
  566. {
  567. return _requestGroup->getOption();
  568. }
  569. } // namespace aria2