Rewrite backup connection handling

Now dedicated ConnectCommand handles connection establishment.  It
checks whether connection is established or not.  It also handles
backup connection. The next Command creation is abstracted using
ControlChain struct template.
pull/60/head
Tatsuhiro Tsujikawa 2013-04-01 23:51:33 +09:00
parent cf23e3e11d
commit 26972b8535
24 changed files with 664 additions and 307 deletions

View File

@ -555,6 +555,13 @@ void AbstractCommand::setWriteCheckSocketIf
} }
} }
void AbstractCommand::swapSocket(SharedHandle<SocketCore>& socket)
{
disableReadCheckSocket();
disableWriteCheckSocket();
socket_.swap(socket);
}
namespace { namespace {
// Constructs proxy URI, merging username and password if they are // Constructs proxy URI, merging username and password if they are
// defined. // defined.

View File

@ -89,7 +89,7 @@ private:
int32_t calculateMinSplitSize() const; int32_t calculateMinSplitSize() const;
void useFasterRequest(const SharedHandle<Request>& fasterRequest); void useFasterRequest(const SharedHandle<Request>& fasterRequest);
protected: public:
RequestGroup* getRequestGroup() const RequestGroup* getRequestGroup() const
{ {
return requestGroup_; return requestGroup_;
@ -151,9 +151,6 @@ protected:
(std::vector<std::string>& addrs, const std::string& hostname, uint16_t port); (std::vector<std::string>& addrs, const std::string& hostname, uint16_t port);
void tryReserved(); void tryReserved();
virtual bool prepareForRetry(time_t wait);
virtual void onAbort();
virtual bool executeInternal() = 0;
void setReadCheckSocket(const SharedHandle<SocketCore>& socket); void setReadCheckSocket(const SharedHandle<SocketCore>& socket);
void setWriteCheckSocket(const SharedHandle<SocketCore>& socket); void setWriteCheckSocket(const SharedHandle<SocketCore>& socket);
@ -171,6 +168,10 @@ protected:
*/ */
void setWriteCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred); void setWriteCheckSocketIf(const SharedHandle<SocketCore>& socket, bool pred);
// Swaps socket_ with socket. This disables current read and write
// check.
void swapSocket(SharedHandle<SocketCore>& socket);
time_t getTimeout() const time_t getTimeout() const
{ {
return timeout_; return timeout_;
@ -221,12 +222,17 @@ protected:
void checkSocketRecvBuffer(); void checkSocketRecvBuffer();
protected:
virtual bool prepareForRetry(time_t wait);
virtual void onAbort();
virtual bool executeInternal() = 0;
// Returns true if the derived class wants to execute // Returns true if the derived class wants to execute
// executeInternal() unconditionally // executeInternal() unconditionally
virtual bool noCheck() virtual bool noCheck()
{ {
return false; return false;
} }
public: public:
AbstractCommand AbstractCommand
(cuid_t cuid, const SharedHandle<Request>& req, (cuid_t cuid, const SharedHandle<Request>& req,

View File

@ -44,7 +44,6 @@
#include "SocketCore.h" #include "SocketCore.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "SocketRecvBuffer.h" #include "SocketRecvBuffer.h"
#include "BackupIPv4ConnectCommand.h"
#include "fmt.h" #include "fmt.h"
#include "LogFactory.h" #include "LogFactory.h"
@ -70,48 +69,11 @@ AbstractProxyRequestCommand::AbstractProxyRequestCommand
setWriteCheckSocket(getSocket()); setWriteCheckSocket(getSocket());
} }
AbstractProxyRequestCommand::~AbstractProxyRequestCommand() AbstractProxyRequestCommand::~AbstractProxyRequestCommand() {}
{
if(backupConnectionInfo_) {
backupConnectionInfo_->cancel = true;
}
}
bool AbstractProxyRequestCommand::noCheck() {
return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
}
bool AbstractProxyRequestCommand::executeInternal() { bool AbstractProxyRequestCommand::executeInternal() {
//socket->setBlockingMode(); //socket->setBlockingMode();
if(httpConnection_->sendBufferIsEmpty()) { 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()); SharedHandle<HttpRequest> httpRequest(new HttpRequest());
httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT)); httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT));
httpRequest->setRequest(getRequest()); httpRequest->setRequest(getRequest());
@ -131,10 +93,4 @@ bool AbstractProxyRequestCommand::executeInternal() {
} }
} }
void AbstractProxyRequestCommand::setBackupConnectInfo
(const SharedHandle<BackupConnectInfo>& info)
{
backupConnectionInfo_ = info;
}
} // namespace aria2 } // namespace aria2

View File

@ -41,18 +41,14 @@ namespace aria2 {
class HttpConnection; class HttpConnection;
class SocketCore; class SocketCore;
class BackupConnectInfo;
class AbstractProxyRequestCommand : public AbstractCommand { class AbstractProxyRequestCommand : public AbstractCommand {
private: private:
SharedHandle<Request> proxyRequest_; SharedHandle<Request> proxyRequest_;
SharedHandle<HttpConnection> httpConnection_; SharedHandle<HttpConnection> httpConnection_;
SharedHandle<BackupConnectInfo> backupConnectionInfo_;
protected: protected:
virtual bool executeInternal(); virtual bool executeInternal();
virtual bool noCheck();
const SharedHandle<HttpConnection>& getHttpConnection() const const SharedHandle<HttpConnection>& getHttpConnection() const
{ {
@ -75,8 +71,6 @@ public:
virtual ~AbstractProxyRequestCommand(); virtual ~AbstractProxyRequestCommand();
virtual Command* getNextCommand() = 0; virtual Command* getNextCommand() = 0;
virtual Command* createSelf(const SharedHandle<SocketCore>& socket) = 0;
void setBackupConnectInfo(const SharedHandle<BackupConnectInfo>& info);
}; };
} // namespace aria2 } // namespace aria2

123
src/ConnectCommand.cc Normal file
View File

@ -0,0 +1,123 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "ConnectCommand.h"
#include "BackupIPv4ConnectCommand.h"
#include "ControlChain.h"
#include "Option.h"
#include "message.h"
#include "SocketCore.h"
#include "fmt.h"
#include "LogFactory.h"
#include "DownloadEngine.h"
#include "Request.h"
#include "prefs.h"
#include "SocketRecvBuffer.h"
namespace aria2 {
ConnectCommand::ConnectCommand(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<SocketCore>& s)
: AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
proxyRequest_(proxyRequest)
{
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
disableReadCheckSocket();
setWriteCheckSocket(getSocket());
}
ConnectCommand::~ConnectCommand()
{
if(backupConnectionInfo_) {
backupConnectionInfo_->cancel = true;
}
}
void ConnectCommand::setControlChain
(const SharedHandle<ControlChain<ConnectCommand*> >& chain)
{
chain_ = chain;
}
void ConnectCommand::setBackupConnectInfo
(const SharedHandle<BackupConnectInfo>& info)
{
backupConnectionInfo_ = info;
}
const SharedHandle<Request>& ConnectCommand::getProxyRequest() const
{
return proxyRequest_;
}
bool ConnectCommand::executeInternal()
{
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());
swapSocket(backupConnectionInfo_->socket);
backupConnectionInfo_.reset();
}
if(!checkIfConnectionEstablished
(getSocket(), getRequest()->getConnectedHostname(),
getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) {
return true;
}
if(backupConnectionInfo_) {
backupConnectionInfo_->cancel = true;
backupConnectionInfo_.reset();
}
chain_->run(this, getDownloadEngine());
return true;
}
bool ConnectCommand::noCheck()
{
return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
}
} // namespace aria2

70
src/ConnectCommand.h Normal file
View File

@ -0,0 +1,70 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef CONNECT_COMMAND_H
#define CONNECT_COMMAND_H
#include "AbstractCommand.h"
#include "ControlChain.h"
namespace aria2 {
class BackupConnectInfo;
class ConnectCommand : public AbstractCommand {
public:
ConnectCommand(cuid_t cuid,
const SharedHandle<Request>& req,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<FileEntry>& fileEntry,
RequestGroup* requestGroup,
DownloadEngine* e,
const SharedHandle<SocketCore>& s);
virtual ~ConnectCommand();
void setControlChain
(const SharedHandle<ControlChain<ConnectCommand*> >& chain);
void setBackupConnectInfo(const SharedHandle<BackupConnectInfo>& info);
const SharedHandle<Request>& getProxyRequest() const;
protected:
virtual bool executeInternal();
virtual bool noCheck();
private:
SharedHandle<Request> proxyRequest_;
SharedHandle<BackupConnectInfo> backupConnectionInfo_;
SharedHandle<ControlChain<ConnectCommand*> > chain_;
};
} // namespace aria2
#endif // CONNECT_COMMAND_H

52
src/ControlChain.h Normal file
View File

@ -0,0 +1,52 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef CONTROL_CHAIN_H
#define CONTROL_CHAIN_H
namespace aria2 {
// This class template is used to transit to the next state using
// T. The main application is embed to the Command classes and get
// next Command from the previous Command.
template<typename T>
struct ControlChain {
virtual ~ControlChain() {}
// Currently, the implementation must returns 0.
virtual int run(T t, DownloadEngine* e) = 0;
};
} // namespace aria2
#endif // CONTROL_CHAIN_H

View File

@ -57,6 +57,9 @@
#include "fmt.h" #include "fmt.h"
#include "SocketRecvBuffer.h" #include "SocketRecvBuffer.h"
#include "BackupIPv4ConnectCommand.h" #include "BackupIPv4ConnectCommand.h"
#include "FtpNegotiationConnectChain.h"
#include "FtpTunnelRequestConnectChain.h"
#include "HttpRequestConnectChain.h"
namespace aria2 { namespace aria2 {
@ -98,47 +101,40 @@ Command* FtpInitiateConnectionCommand::createNextCommand
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
ConnectCommand* c = new ConnectCommand(getCuid(),
getRequest(),
proxyRequest,
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
getSocket());
if(proxyMethod == V_GET) { if(proxyMethod == V_GET) {
// Use GET for FTP via HTTP proxy. // Use GET for FTP via HTTP proxy.
getRequest()->setMethod(Request::METHOD_GET); getRequest()->setMethod(Request::METHOD_GET);
SharedHandle<SocketRecvBuffer> socketRecvBuffer SharedHandle<HttpRequestConnectChain> chain
(new SocketRecvBuffer(getSocket())); (new HttpRequestConnectChain());
SharedHandle<HttpConnection> hc c->setControlChain(chain);
(new HttpConnection(getCuid(), getSocket(), socketRecvBuffer));
HttpRequestCommand* c =
new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), hc, getDownloadEngine(),
getSocket());
c->setProxyRequest(proxyRequest);
SharedHandle<BackupConnectInfo> backupConnectInfo
= createBackupIPv4ConnectCommand(hostname, addr, port, c);
if(backupConnectInfo) {
c->setBackupConnectInfo(backupConnectInfo);
}
command = c;
} else if(proxyMethod == V_TUNNEL) { } else if(proxyMethod == V_TUNNEL) {
FtpTunnelRequestCommand* c = SharedHandle<FtpTunnelRequestConnectChain> chain
new FtpTunnelRequestCommand(getCuid(), getRequest(), getFileEntry(), (new FtpTunnelRequestConnectChain());
getRequestGroup(), getDownloadEngine(), c->setControlChain(chain);
proxyRequest, getSocket());
SharedHandle<BackupConnectInfo> backupConnectInfo
= createBackupIPv4ConnectCommand(hostname, addr, port, c);
if(backupConnectInfo) {
c->setBackupConnectInfo(backupConnectInfo);
}
command = c;
} else { } else {
// TODO // Unreachable
throw DL_ABORT_EX("ERROR"); assert(0);
} }
setupBackupConnection(hostname, addr, port, c);
command = c;
} else { } else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket); setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
if(proxyMethod == V_TUNNEL) { if(proxyMethod == V_TUNNEL) {
// options contains "baseWorkingDir" // options contains "baseWorkingDir"
command = command = new FtpNegotiationCommand
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(), (getCuid(),
getRequestGroup(), getDownloadEngine(), getRequest(),
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
pooledSocket, pooledSocket,
FtpNegotiationCommand::SEQ_SEND_CWD_PREP, FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
options); options);
@ -150,15 +146,18 @@ Command* FtpInitiateConnectionCommand::createNextCommand
SharedHandle<HttpConnection> hc SharedHandle<HttpConnection> hc
(new HttpConnection(getCuid(), pooledSocket, socketRecvBuffer)); (new HttpConnection(getCuid(), pooledSocket, socketRecvBuffer));
HttpRequestCommand* c = HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(), getRequest(),
getRequestGroup(), hc, getDownloadEngine(), getFileEntry(),
getRequestGroup(),
hc,
getDownloadEngine(),
pooledSocket); pooledSocket);
c->setProxyRequest(proxyRequest); c->setProxyRequest(proxyRequest);
command = c; command = c;
} else { } else {
// TODO // Unreachable
throw DL_ABORT_EX("ERROR"); assert(0);
} }
} }
} else { } else {
@ -175,21 +174,26 @@ Command* FtpInitiateConnectionCommand::createNextCommand
createSocket(); createSocket();
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
FtpNegotiationCommand* c = ConnectCommand* c = new ConnectCommand(getCuid(),
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(), getRequest(),
getRequestGroup(), getDownloadEngine(), proxyRequest, // must be null
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
getSocket()); getSocket());
SharedHandle<BackupConnectInfo> backupConnectInfo SharedHandle<FtpNegotiationConnectChain> chain
= createBackupIPv4ConnectCommand(hostname, addr, port, c); (new FtpNegotiationConnectChain());
if(backupConnectInfo) { c->setControlChain(chain);
c->setBackupConnectInfo(backupConnectInfo); setupBackupConnection(hostname, addr, port, c);
}
command = c; command = c;
} else { } else {
// options contains "baseWorkingDir" // options contains "baseWorkingDir"
command = command = new FtpNegotiationCommand
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(), (getCuid(),
getRequestGroup(), getDownloadEngine(), getRequest(),
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
pooledSocket, pooledSocket,
FtpNegotiationCommand::SEQ_SEND_CWD_PREP, FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
options); options);

View File

@ -74,7 +74,6 @@
#include "CheckIntegrityEntry.h" #include "CheckIntegrityEntry.h"
#include "error_code.h" #include "error_code.h"
#include "SocketRecvBuffer.h" #include "SocketRecvBuffer.h"
#include "BackupIPv4ConnectCommand.h"
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
# include "ChecksumCheckIntegrityEntry.h" # include "ChecksumCheckIntegrityEntry.h"
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
@ -102,20 +101,9 @@ FtpNegotiationCommand::FtpNegotiationCommand
if(seq == SEQ_RECV_GREETING) { if(seq == SEQ_RECV_GREETING) {
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT)); setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
} }
disableReadCheckSocket();
setWriteCheckSocket(getSocket());
} }
FtpNegotiationCommand::~FtpNegotiationCommand() FtpNegotiationCommand::~FtpNegotiationCommand() {}
{
if(backupConnectionInfo_) {
backupConnectionInfo_->cancel = true;
}
}
bool FtpNegotiationCommand::noCheck() {
return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
}
bool FtpNegotiationCommand::executeInternal() { bool FtpNegotiationCommand::executeInternal() {
while(processSequence(getSegments().front())); while(processSequence(getSegments().front()));
@ -155,38 +143,6 @@ bool FtpNegotiationCommand::executeInternal() {
} }
bool FtpNegotiationCommand::recvGreeting() { bool FtpNegotiationCommand::recvGreeting() {
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());
FtpNegotiationCommand* c =
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(),
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())) {
sequence_ = SEQ_EXIT;
return false;
}
if(backupConnectionInfo_) {
backupConnectionInfo_->cancel = true;
backupConnectionInfo_.reset();
}
setTimeout(getRequestGroup()->getTimeout()); setTimeout(getRequestGroup()->getTimeout());
//socket->setBlockingMode(); //socket->setBlockingMode();
disableWriteCheckSocket(); disableWriteCheckSocket();
@ -1009,10 +965,4 @@ void FtpNegotiationCommand::onDryRunFileFound()
sequence_ = SEQ_HEAD_OK; sequence_ = SEQ_HEAD_OK;
} }
void FtpNegotiationCommand::setBackupConnectInfo
(const SharedHandle<BackupConnectInfo>& info)
{
backupConnectionInfo_ = info;
}
} // namespace aria2 } // namespace aria2

View File

@ -44,7 +44,6 @@ namespace aria2 {
class FtpConnection; class FtpConnection;
class SocketCore; class SocketCore;
class HttpConnection; class HttpConnection;
class BackupConnectInfo;
class FtpNegotiationCommand : public AbstractCommand { class FtpNegotiationCommand : public AbstractCommand {
public: public:
@ -154,11 +153,8 @@ private:
std::string proxyAddr_; std::string proxyAddr_;
std::deque<std::string> cwdDirs_; std::deque<std::string> cwdDirs_;
SharedHandle<BackupConnectInfo> backupConnectionInfo_;
protected: protected:
virtual bool executeInternal(); virtual bool executeInternal();
virtual bool noCheck();
public: public:
FtpNegotiationCommand(cuid_t cuid, FtpNegotiationCommand(cuid_t cuid,
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
@ -169,7 +165,6 @@ public:
Seq seq = SEQ_RECV_GREETING, Seq seq = SEQ_RECV_GREETING,
const std::string& baseWorkingDir = "/"); const std::string& baseWorkingDir = "/");
virtual ~FtpNegotiationCommand(); virtual ~FtpNegotiationCommand();
void setBackupConnectInfo(const SharedHandle<BackupConnectInfo>& info);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -0,0 +1,66 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef FTP_NEGOTIATION_CONNECT_CHAIN_H
#define FTP_NEGOTIATION_CONNECT_CHAIN_H
#include "ControlChain.h"
#include "ConnectCommand.h"
#include "DownloadEngine.h"
#include "FtpNegotiationCommand.h"
namespace aria2 {
struct FtpNegotiationConnectChain : public ControlChain<ConnectCommand*> {
FtpNegotiationConnectChain() {}
virtual ~FtpNegotiationConnectChain() {}
virtual int run(ConnectCommand* t, DownloadEngine* e)
{
FtpNegotiationCommand* c = new FtpNegotiationCommand
(t->getCuid(),
t->getRequest(),
t->getFileEntry(),
t->getRequestGroup(),
t->getDownloadEngine(),
t->getSocket());
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
e->setNoWait(true);
e->addCommand(c);
return 0;
}
};
} // namespace aria2
#endif // FTP_NEGOTIATION_CONNECT_CHAIN_H

View File

@ -63,12 +63,4 @@ Command* FtpTunnelRequestCommand::getNextCommand()
getHttpConnection(), getDownloadEngine(), getSocket()); getHttpConnection(), getDownloadEngine(), getSocket());
} }
Command* FtpTunnelRequestCommand::createSelf
(const SharedHandle<SocketCore>& socket)
{
return new FtpTunnelRequestCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(),
getProxyRequest(), socket);
}
} // namespace aria2 } // namespace aria2

View File

@ -53,8 +53,6 @@ public:
virtual ~FtpTunnelRequestCommand(); virtual ~FtpTunnelRequestCommand();
virtual Command* getNextCommand(); virtual Command* getNextCommand();
virtual Command* createSelf(const SharedHandle<SocketCore>& socket);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -0,0 +1,67 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef FTP_TUNNEL_REQUEST_CONNECT_CHAIN_H
#define FTP_TUNNEL_REQUEST_CONNECT_CHAIN_H
#include "ControlChain.h"
#include "ConnectCommand.h"
#include "DownloadEngine.h"
#include "FtpTunnelRequestCommand.h"
namespace aria2 {
struct FtpTunnelRequestConnectChain : public ControlChain<ConnectCommand*> {
FtpTunnelRequestConnectChain() {}
virtual ~FtpTunnelRequestConnectChain() {}
virtual int run(ConnectCommand* t, DownloadEngine* e)
{
FtpTunnelRequestCommand* c = new FtpTunnelRequestCommand
(t->getCuid(),
t->getRequest(),
t->getFileEntry(),
t->getRequestGroup(),
t->getDownloadEngine(),
t->getProxyRequest(),
t->getSocket());
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
e->setNoWait(true);
e->addCommand(c);
return 0;
}
};
} // namespace aria2
#endif // FTP_TUNNEL_REQUEST_CONNECT_CHAIN_H

View File

@ -52,6 +52,9 @@
#include "fmt.h" #include "fmt.h"
#include "SocketRecvBuffer.h" #include "SocketRecvBuffer.h"
#include "BackupIPv4ConnectCommand.h" #include "BackupIPv4ConnectCommand.h"
#include "ConnectCommand.h"
#include "HttpRequestConnectChain.h"
#include "HttpProxyRequestConnectChain.h"
namespace aria2 { namespace aria2 {
@ -85,44 +88,27 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
if(proxyMethod == V_TUNNEL) { ConnectCommand* c = new ConnectCommand(getCuid(),
HttpProxyRequestCommand* c =
new HttpProxyRequestCommand(getCuid(),
getRequest(), getRequest(),
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
proxyRequest, proxyRequest,
getSocket());
SharedHandle<BackupConnectInfo> backupConnectionInfo
= createBackupIPv4ConnectCommand(hostname, addr, port, c);
if(backupConnectionInfo) {
c->setBackupConnectInfo(backupConnectionInfo);
}
command = c;
} else if(proxyMethod == V_GET) {
SharedHandle<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(getSocket()));
SharedHandle<HttpConnection> httpConnection
(new HttpConnection(getCuid(), getSocket(), socketRecvBuffer));
HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
getRequest(),
getFileEntry(), getFileEntry(),
getRequestGroup(), getRequestGroup(),
httpConnection,
getDownloadEngine(), getDownloadEngine(),
getSocket()); getSocket());
c->setProxyRequest(proxyRequest); if(proxyMethod == V_TUNNEL) {
SharedHandle<BackupConnectInfo> backupConnectionInfo SharedHandle<HttpProxyRequestConnectChain> chain
= createBackupIPv4ConnectCommand(hostname, addr, port, c); (new HttpProxyRequestConnectChain());
if(backupConnectionInfo) { c->setControlChain(chain);
c->setBackupConnectInfo(backupConnectionInfo); } else if(proxyMethod == V_GET) {
} SharedHandle<HttpRequestConnectChain> chain
command = c; (new HttpRequestConnectChain());
c->setControlChain(chain);
} else { } else {
// TODO // Unreachable
throw DL_ABORT_EX("ERROR"); assert(0);
} }
setupBackupConnection(hostname, addr, port, c);
command = c;
} else { } else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket); setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
SharedHandle<SocketRecvBuffer> socketRecvBuffer SharedHandle<SocketRecvBuffer> socketRecvBuffer
@ -142,7 +128,6 @@ Command* HttpInitiateConnectionCommand::createNextCommand
command = c; command = c;
} }
} else { } else {
bool connectRequired = false;
SharedHandle<SocketCore> pooledSocket = SharedHandle<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket getDownloadEngine()->popPooledSocket
(resolvedAddresses, getRequest()->getPort()); (resolvedAddresses, getRequest()->getPort());
@ -153,31 +138,35 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
connectRequired = true; ConnectCommand* c = new ConnectCommand(getCuid(),
getRequest(),
proxyRequest, // must be null
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
getSocket());
SharedHandle<HttpRequestConnectChain> chain
(new HttpRequestConnectChain());
c->setControlChain(chain);
setupBackupConnection(hostname, addr, port, c);
command = c;
} else { } else {
setSocket(pooledSocket); setSocket(pooledSocket);
setConnectedAddrInfo(getRequest(), hostname, pooledSocket); setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
}
SharedHandle<SocketRecvBuffer> socketRecvBuffer SharedHandle<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(getSocket())); (new SocketRecvBuffer(getSocket()));
SharedHandle<HttpConnection> httpConnection SharedHandle<HttpConnection> httpConnection
(new HttpConnection(getCuid(), getSocket(), socketRecvBuffer)); (new HttpConnection(getCuid(), getSocket(), socketRecvBuffer));
HttpRequestCommand* c = command = new HttpRequestCommand(getCuid(),
new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(), getRequest(),
getFileEntry(),
getRequestGroup(), getRequestGroup(),
httpConnection, httpConnection,
getDownloadEngine(), getDownloadEngine(),
getSocket()); getSocket());
if(connectRequired) {
SharedHandle<BackupConnectInfo> backupConnectInfo
= createBackupIPv4ConnectCommand(hostname, addr, port, c);
if(backupConnectInfo) {
c->setBackupConnectInfo(backupConnectInfo);
} }
} }
command = c;
}
return command; return command;
} }

View File

@ -62,16 +62,4 @@ Command* HttpProxyRequestCommand::getNextCommand()
getHttpConnection(), getDownloadEngine(), getSocket()); getHttpConnection(), getDownloadEngine(), getSocket());
} }
Command* HttpProxyRequestCommand::createSelf
(const SharedHandle<SocketCore>& socket)
{
return new HttpProxyRequestCommand(getCuid(),
getRequest(),
getFileEntry(),
getRequestGroup(),
getDownloadEngine(),
getProxyRequest(),
socket);
}
} // namespace aria2 } // namespace aria2

View File

@ -53,8 +53,6 @@ public:
virtual ~HttpProxyRequestCommand(); virtual ~HttpProxyRequestCommand();
virtual Command* getNextCommand(); virtual Command* getNextCommand();
virtual Command* createSelf(const SharedHandle<SocketCore>& socket);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -0,0 +1,67 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef HTTP_PROXY_REQUEST_CONNECT_CHAIN_H
#define HTTP_PROXY_REQUEST_CONNECT_CHAIN_H
#include "ControlChain.h"
#include "ConnectCommand.h"
#include "DownloadEngine.h"
#include "HttpProxyRequestCommand.h"
namespace aria2 {
struct HttpProxyRequestConnectChain : public ControlChain<ConnectCommand*> {
HttpProxyRequestConnectChain() {}
virtual ~HttpProxyRequestConnectChain() {}
virtual int run(ConnectCommand* t, DownloadEngine* e)
{
HttpProxyRequestCommand* c = new HttpProxyRequestCommand
(t->getCuid(),
t->getRequest(),
t->getFileEntry(),
t->getRequestGroup(),
e,
t->getProxyRequest(),
t->getSocket());
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
e->setNoWait(true);
e->addCommand(c);
return 0;
}
};
} // namespace aria2
#endif // HTTP_PROXY_REQUEST_CONNECT_CHAIN_H

View File

@ -59,7 +59,6 @@
#include "LogFactory.h" #include "LogFactory.h"
#include "fmt.h" #include "fmt.h"
#include "SocketRecvBuffer.h" #include "SocketRecvBuffer.h"
#include "BackupIPv4ConnectCommand.h"
namespace aria2 { namespace aria2 {
@ -80,12 +79,7 @@ HttpRequestCommand::HttpRequestCommand
setWriteCheckSocket(getSocket()); setWriteCheckSocket(getSocket());
} }
HttpRequestCommand::~HttpRequestCommand() HttpRequestCommand::~HttpRequestCommand() {}
{
if(backupConnectionInfo_) {
backupConnectionInfo_->cancel = true;
}
}
namespace { namespace {
SharedHandle<HttpRequest> SharedHandle<HttpRequest>
@ -128,52 +122,9 @@ createHttpRequest(const SharedHandle<Request>& req,
} }
} // namespace } // namespace
bool HttpRequestCommand::noCheck() {
return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
}
bool HttpRequestCommand::executeInternal() { bool HttpRequestCommand::executeInternal() {
//socket->setBlockingMode(); //socket->setBlockingMode();
if(httpConnection_->sendBufferIsEmpty()) { 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 #ifdef ENABLE_SSL
if(getRequest()->getProtocol() == "https") { if(getRequest()->getProtocol() == "https") {
if(!getSocket()->tlsConnect(getRequest()->getHost())) { if(!getSocket()->tlsConnect(getRequest()->getHost())) {
@ -279,10 +230,4 @@ void HttpRequestCommand::setProxyRequest
proxyRequest_ = proxyRequest; proxyRequest_ = proxyRequest;
} }
void HttpRequestCommand::setBackupConnectInfo
(const SharedHandle<BackupConnectInfo>& info)
{
backupConnectionInfo_ = info;
}
} // namespace aria2 } // namespace aria2

View File

@ -41,7 +41,6 @@ namespace aria2 {
class HttpConnection; class HttpConnection;
class SocketCore; class SocketCore;
class BackupConnectInfo;
// HttpRequestCommand sends HTTP request header to remote server. // HttpRequestCommand sends HTTP request header to remote server.
// Because network I/O is non-blocking, execute() returns false if all // Because network I/O is non-blocking, execute() returns false if all
@ -54,11 +53,8 @@ private:
SharedHandle<Request> proxyRequest_; SharedHandle<Request> proxyRequest_;
SharedHandle<HttpConnection> httpConnection_; SharedHandle<HttpConnection> httpConnection_;
SharedHandle<BackupConnectInfo> backupConnectionInfo_;
protected: protected:
virtual bool executeInternal(); virtual bool executeInternal();
virtual bool noCheck();
public: public:
HttpRequestCommand(cuid_t cuid, HttpRequestCommand(cuid_t cuid,
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
@ -70,7 +66,6 @@ public:
virtual ~HttpRequestCommand(); virtual ~HttpRequestCommand();
void setProxyRequest(const SharedHandle<Request>& proxyRequest); void setProxyRequest(const SharedHandle<Request>& proxyRequest);
void setBackupConnectInfo(const SharedHandle<BackupConnectInfo>& info);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -0,0 +1,73 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2013 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef HTTP_REQUEST_CONNECT_CHAIN_H
#define HTTP_REQUEST_CONNECT_CHAIN_H
#include "ControlChain.h"
#include "ConnectCommand.h"
#include "DownloadEngine.h"
#include "SocketRecvBuffer.h"
#include "HttpConnection.h"
#include "HttpRequestCommand.h"
namespace aria2 {
struct HttpRequestConnectChain : public ControlChain<ConnectCommand*> {
HttpRequestConnectChain() {}
virtual ~HttpRequestConnectChain() {}
virtual int run(ConnectCommand* t, DownloadEngine* e)
{
SharedHandle<SocketRecvBuffer> socketRecvBuffer
(new SocketRecvBuffer(t->getSocket()));
SharedHandle<HttpConnection> httpConnection
(new HttpConnection(t->getCuid(), t->getSocket(), socketRecvBuffer));
HttpRequestCommand* c = new HttpRequestCommand(t->getCuid(),
t->getRequest(),
t->getFileEntry(),
t->getRequestGroup(),
httpConnection,
e,
t->getSocket());
c->setProxyRequest(t->getProxyRequest());
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
e->setNoWait(true);
e->addCommand(c);
return 0;
}
};
} // namespace aria2
#endif // HTTP_REQUEST_CONNECT_CHAIN_H

View File

@ -52,6 +52,7 @@
#include "fmt.h" #include "fmt.h"
#include "SocketRecvBuffer.h" #include "SocketRecvBuffer.h"
#include "BackupIPv4ConnectCommand.h" #include "BackupIPv4ConnectCommand.h"
#include "ConnectCommand.h"
namespace aria2 { namespace aria2 {
@ -160,4 +161,15 @@ InitiateConnectionCommand::createBackupIPv4ConnectCommand
return info; return info;
} }
void InitiateConnectionCommand::setupBackupConnection
(const std::string& hostname, const std::string& addr, uint16_t port,
ConnectCommand* c)
{
SharedHandle<BackupConnectInfo> backupConnectInfo
= createBackupIPv4ConnectCommand(hostname, addr, port, c);
if(backupConnectInfo) {
c->setBackupConnectInfo(backupConnectInfo);
}
}
} // namespace aria2 } // namespace aria2

View File

@ -40,6 +40,7 @@
namespace aria2 { namespace aria2 {
class BackupConnectInfo; class BackupConnectInfo;
class ConnectCommand;
class InitiateConnectionCommand : public AbstractCommand { class InitiateConnectionCommand : public AbstractCommand {
protected: protected:
@ -70,6 +71,10 @@ protected:
SharedHandle<BackupConnectInfo> createBackupIPv4ConnectCommand SharedHandle<BackupConnectInfo> createBackupIPv4ConnectCommand
(const std::string& hostname, const std::string& ipaddr, uint16_t port, (const std::string& hostname, const std::string& ipaddr, uint16_t port,
Command* mainCommand); Command* mainCommand);
void setupBackupConnection
(const std::string& hostname, const std::string& addr, uint16_t port,
ConnectCommand* c);
public: public:
InitiateConnectionCommand(cuid_t cuid, const SharedHandle<Request>& req, InitiateConnectionCommand(cuid_t cuid, const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry, const SharedHandle<FileEntry>& fileEntry,

View File

@ -246,7 +246,12 @@ SRCS = SocketCore.cc SocketCore.h\
GroupId.cc GroupId.h\ GroupId.cc GroupId.h\
IndexedList.h\ IndexedList.h\
SaveSessionCommand.h SaveSessionCommand.cc\ SaveSessionCommand.h SaveSessionCommand.cc\
BackupIPv4ConnectCommand.h BackupIPv4ConnectCommand.cc BackupIPv4ConnectCommand.h BackupIPv4ConnectCommand.cc\
ConnectCommand.cc ConnectCommand.h\
HttpRequestConnectChain.h\
HttpProxyRequestConnectChain.h\
FtpNegotiationConnectChain.h\
FtpTunnelRequestConnectChain.h
if MINGW_BUILD if MINGW_BUILD
SRCS += WinConsoleFile.cc WinConsoleFile.h SRCS += WinConsoleFile.cc WinConsoleFile.h