summaryrefslogtreecommitdiff
path: root/src/HttpRequestCommand.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/HttpRequestCommand.cc')
-rw-r--r--src/HttpRequestCommand.cc52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc
index f393125f..6fc083c6 100644
--- a/src/HttpRequestCommand.cc
+++ b/src/HttpRequestCommand.cc
@@ -59,6 +59,7 @@
#include "LogFactory.h"
#include "fmt.h"
#include "SocketRecvBuffer.h"
+#include "BackupIPv4ConnectCommand.h"
namespace aria2 {
@@ -79,7 +80,12 @@ HttpRequestCommand::HttpRequestCommand
setWriteCheckSocket(getSocket());
}
-HttpRequestCommand::~HttpRequestCommand() {}
+HttpRequestCommand::~HttpRequestCommand()
+{
+ if(backupConnectionInfo_) {
+ backupConnectionInfo_->cancel = true;
+ }
+}
namespace {
SharedHandle<HttpRequest>
@@ -122,14 +128,52 @@ createHttpRequest(const SharedHandle<Request>& req,
}
} // namespace
+bool HttpRequestCommand::noCheck() {
+ return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
+}
+
bool HttpRequestCommand::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());
+
+ SharedHandle<SocketRecvBuffer> socketRecvBuffer
+ (new SocketRecvBuffer(backupConnectionInfo_->socket));
+ SharedHandle<HttpConnection> httpConnection
+ (new HttpConnection(getCuid(), backupConnectionInfo_->socket,
+ socketRecvBuffer));
+ HttpRequestCommand* c =
+ new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(),
+ getRequestGroup(),
+ httpConnection,
+ getDownloadEngine(),
+ backupConnectionInfo_->socket);
+ c->setProxyRequest(proxyRequest_);
+ 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();
+ }
#ifdef ENABLE_SSL
if(getRequest()->getProtocol() == "https") {
if(!getSocket()->tlsConnect(getRequest()->getHost())) {
@@ -235,4 +279,10 @@ void HttpRequestCommand::setProxyRequest
proxyRequest_ = proxyRequest;
}
+void HttpRequestCommand::setBackupConnectInfo
+(const SharedHandle<BackupConnectInfo>& info)
+{
+ backupConnectionInfo_ = info;
+}
+
} // namespace aria2