summaryrefslogtreecommitdiff
path: root/src/AbstractProxyRequestCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-04-01 00:12:27 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-04-01 00:12:27 +0900
commit597e1a5c1b10aa3668f91bcae02a864dcd0c045b (patch)
tree4437c2896b410b441013452b7385dfa303441772 /src/AbstractProxyRequestCommand.cc
parentd671d8bf3672cbefc06f3727f82b77872abe6120 (diff)
Implement simple Happy Eyeballs for HTTP/FTP downloads
Diffstat (limited to 'src/AbstractProxyRequestCommand.cc')
-rw-r--r--src/AbstractProxyRequestCommand.cc43
1 files changed, 42 insertions, 1 deletions
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> 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<BackupConnectInfo>& info)
+{
+ backupConnectionInfo_ = info;
+}
+
} // namespace aria2