From 597e1a5c1b10aa3668f91bcae02a864dcd0c045b Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 1 Apr 2013 00:12:27 +0900 Subject: Implement simple Happy Eyeballs for HTTP/FTP downloads --- src/AbstractProxyRequestCommand.cc | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'src/AbstractProxyRequestCommand.cc') diff --git a/src/AbstractProxyRequestCommand.cc b/src/AbstractProxyRequestCommand.cc index 22bce921..1f9fe1ba 100644 --- a/src/AbstractProxyRequestCommand.cc +++ b/src/AbstractProxyRequestCommand.cc @@ -44,6 +44,9 @@ #include "SocketCore.h" #include "DownloadContext.h" #include "SocketRecvBuffer.h" +#include "BackupIPv4ConnectCommand.h" +#include "fmt.h" +#include "LogFactory.h" namespace aria2 { @@ -67,16 +70,48 @@ AbstractProxyRequestCommand::AbstractProxyRequestCommand setWriteCheckSocket(getSocket()); } -AbstractProxyRequestCommand::~AbstractProxyRequestCommand() {} +AbstractProxyRequestCommand::~AbstractProxyRequestCommand() +{ + if(backupConnectionInfo_) { + backupConnectionInfo_->cancel = true; + } +} + +bool AbstractProxyRequestCommand::noCheck() { + return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty(); +} bool AbstractProxyRequestCommand::executeInternal() { //socket->setBlockingMode(); if(httpConnection_->sendBufferIsEmpty()) { + if(backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty()) { + A2_LOG_INFO(fmt("CUID#%"PRId64" - Use backup connection address %s", + getCuid(), backupConnectionInfo_->ipaddr.c_str())); + getDownloadEngine()->markBadIPAddress + (getRequest()->getConnectedHostname(), + getRequest()->getConnectedAddr(), + getRequest()->getConnectedPort()); + + getRequest()->setConnectedAddrInfo(getRequest()->getConnectedHostname(), + backupConnectionInfo_->ipaddr, + getRequest()->getConnectedPort()); + + Command* c = createSelf(backupConnectionInfo_->socket); + c->setStatus(STATUS_ONESHOT_REALTIME); + getDownloadEngine()->setNoWait(true); + getDownloadEngine()->addCommand(c); + backupConnectionInfo_.reset(); + return true; + } if(!checkIfConnectionEstablished (getSocket(), getRequest()->getConnectedHostname(), getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) { return true; } + if(backupConnectionInfo_) { + backupConnectionInfo_->cancel = true; + backupConnectionInfo_.reset(); + } SharedHandle httpRequest(new HttpRequest()); httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT)); httpRequest->setRequest(getRequest()); @@ -96,4 +131,10 @@ bool AbstractProxyRequestCommand::executeInternal() { } } +void AbstractProxyRequestCommand::setBackupConnectInfo +(const SharedHandle& info) +{ + backupConnectionInfo_ = info; +} + } // namespace aria2 -- cgit