2010-09-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Moved connectedHostname, connectedAddr and connectedPort to
	Request object. Mark cached IP address bad on timeout to allow
	aria2 to renew IP address cache.
	* src/AbstractCommand.cc
	* src/AbstractProxyRequestCommand.cc
	* src/AbstractProxyRequestCommand.h
	* src/FtpInitiateConnectionCommand.cc
	* src/FtpNegotiationCommand.cc
	* src/FtpNegotiationCommand.h
	* src/HttpInitiateConnectionCommand.cc
	* src/HttpRequestCommand.cc
	* src/HttpRequestCommand.h
	* src/InitiateConnectionCommand.cc
	* src/InitiateConnectionCommand.h
	* src/Request.cc
	* src/Request.h
pull/1/head
Tatsuhiro Tsujikawa 2010-09-09 12:00:42 +00:00
parent 420500f6bf
commit d687886c24
14 changed files with 99 additions and 50 deletions

View File

@ -1,3 +1,22 @@
2010-09-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved connectedHostname, connectedAddr and connectedPort to
Request object. Mark cached IP address bad on timeout to allow
aria2 to renew IP address cache.
* src/AbstractCommand.cc
* src/AbstractProxyRequestCommand.cc
* src/AbstractProxyRequestCommand.h
* src/FtpInitiateConnectionCommand.cc
* src/FtpNegotiationCommand.cc
* src/FtpNegotiationCommand.h
* src/HttpInitiateConnectionCommand.cc
* src/HttpRequestCommand.cc
* src/HttpRequestCommand.h
* src/InitiateConnectionCommand.cc
* src/InitiateConnectionCommand.h
* src/Request.cc
* src/Request.h
2010-09-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Call RequestGroupMan::fillRequestGroupFromReserver() repeatedly

View File

@ -242,12 +242,29 @@ bool AbstractCommand::execute() {
} else {
if(checkPoint_.difference(global::wallclock) >= timeout_) {
// timeout triggers ServerStat error state.
SharedHandle<ServerStat> ss =
e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(),
req_->getProtocol());
ss->setError();
// Purging IP address cache to renew IP address.
if(getLogger()->debug()) {
getLogger()->debug("CUID#%s - Marking IP address %s as bad",
util::itos(getCuid()).c_str(),
req_->getConnectedAddr().c_str());
}
e_->markBadIPAddress(req_->getConnectedHostname(),
req_->getConnectedAddr(),
req_->getConnectedPort());
if(e_->findCachedIPAddress
(req_->getConnectedHostname(), req_->getConnectedPort()).empty()) {
if(getLogger()->debug()) {
getLogger()->debug("CUID#%s - All IP addresses were marked bad."
" Removing Entry.",
util::itos(getCuid()).c_str());
}
e_->removeCachedIPAddress
(req_->getConnectedHostname(), req_->getConnectedPort());
}
throw DL_RETRY_EX2(EX_TIME_OUT, downloadresultcode::TIME_OUT);
}
e_->addCommand(this);

View File

@ -77,7 +77,8 @@ bool AbstractProxyRequestCommand::executeInternal() {
//socket->setBlockingMode();
if(httpConnection_->sendBufferIsEmpty()) {
if(!checkIfConnectionEstablished
(getSocket(), connectedHostname_, connectedAddr_, connectedPort_)) {
(getSocket(), getRequest()->getConnectedHostname(),
getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) {
return true;
}
SharedHandle<HttpRequest> httpRequest(new HttpRequest());

View File

@ -47,10 +47,6 @@ private:
SharedHandle<Request> proxyRequest_;
SharedHandle<HttpConnection> httpConnection_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
protected:
virtual bool executeInternal();
@ -70,14 +66,6 @@ public:
virtual ~AbstractProxyRequestCommand();
virtual Command* getNextCommand() = 0;
void setConnectedAddr
(const std::string& hostname, const std::string& addr, uint16_t port)
{
connectedHostname_ = hostname;
connectedAddr_ = addr;
connectedPort_ = port;
}
};
} // namespace aria2

View File

@ -100,6 +100,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
createSocket();
getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port);
if(proxyMethod == V_GET) {
// Use GET for FTP via HTTP proxy.
getRequest()->setMethod(Request::METHOD_GET);
@ -110,7 +111,6 @@ Command* FtpInitiateConnectionCommand::createNextCommand
new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), hc, getDownloadEngine(),
getSocket());
c->setConnectedAddr(hostname, addr, port);
c->setProxyRequest(proxyRequest);
command = c;
} else if(proxyMethod == V_TUNNEL) {
@ -118,13 +118,13 @@ Command* FtpInitiateConnectionCommand::createNextCommand
new FtpTunnelRequestCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(),
proxyRequest, getSocket());
c->setConnectedAddr(hostname, addr, port);
command = c;
} else {
// TODO
throw DL_ABORT_EX("ERROR");
}
} else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
if(proxyMethod == V_TUNNEL) {
command =
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
@ -168,7 +168,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(),
getSocket());
c->setConnectedAddr(hostname, addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port);
command = c;
} else {
command =
@ -177,6 +177,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
pooledSocket,
FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
options["baseWorkingDir"]);
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
}
}
return command;

View File

@ -141,7 +141,8 @@ bool FtpNegotiationCommand::executeInternal() {
bool FtpNegotiationCommand::recvGreeting() {
if(!checkIfConnectionEstablished
(getSocket(), connectedHostname_, connectedAddr_, connectedPort_)) {
(getSocket(), getRequest()->getConnectedHostname(),
getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) {
sequence_ = SEQ_EXIT;
return false;
}

View File

@ -150,10 +150,6 @@ private:
// Resolved address for proxy
std::string proxyAddr_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
std::deque<std::string> cwdDirs_;
protected:
virtual bool executeInternal();
@ -167,14 +163,6 @@ public:
Seq seq = SEQ_RECV_GREETING,
const std::string& baseWorkingDir = "/");
virtual ~FtpNegotiationCommand();
void setConnectedAddr
(const std::string& hostname, const std::string& addr, uint16_t port)
{
connectedHostname_ = hostname;
connectedAddr_ = addr;
connectedPort_ = port;
}
};
} // namespace aria2

View File

@ -85,6 +85,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
createSocket();
getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port);
if(proxyMethod == V_TUNNEL) {
HttpProxyRequestCommand* c =
new HttpProxyRequestCommand(getCuid(),
@ -94,7 +95,6 @@ Command* HttpInitiateConnectionCommand::createNextCommand
getDownloadEngine(),
proxyRequest,
getSocket());
c->setConnectedAddr(hostname, addr, port);
command = c;
} else if(proxyMethod == V_GET) {
SharedHandle<HttpConnection> httpConnection
@ -106,7 +106,6 @@ Command* HttpInitiateConnectionCommand::createNextCommand
httpConnection,
getDownloadEngine(),
getSocket());
c->setConnectedAddr(hostname, addr, port);
c->setProxyRequest(proxyRequest);
command = c;
} else {
@ -114,6 +113,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
throw DL_ABORT_EX("ERROR");
}
} else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
SharedHandle<HttpConnection> httpConnection
(new HttpConnection(getCuid(), pooledSocket));
HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
@ -139,8 +139,10 @@ Command* HttpInitiateConnectionCommand::createNextCommand
}
createSocket();
getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port);
} else {
setSocket(pooledSocket);
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
}
SharedHandle<HttpConnection> httpConnection
(new HttpConnection(getCuid(), getSocket()));
@ -150,9 +152,6 @@ Command* HttpInitiateConnectionCommand::createNextCommand
httpConnection,
getDownloadEngine(),
getSocket());
if(pooledSocket.isNull()) {
c->setConnectedAddr(hostname, addr, port);
}
command = c;
}
return command;

View File

@ -131,7 +131,8 @@ bool HttpRequestCommand::executeInternal() {
}
if(httpConnection_->sendBufferIsEmpty()) {
if(!checkIfConnectionEstablished
(getSocket(), connectedHostname_, connectedAddr_, connectedPort_)) {
(getSocket(), getRequest()->getConnectedHostname(),
getRequest()->getConnectedAddr(), getRequest()->getConnectedPort())) {
return true;
}

View File

@ -47,10 +47,6 @@ private:
SharedHandle<Request> proxyRequest_;
SharedHandle<HttpConnection> httpConnection_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
protected:
virtual bool executeInternal();
public:
@ -64,14 +60,6 @@ public:
virtual ~HttpRequestCommand();
void setProxyRequest(const SharedHandle<Request>& proxyRequest);
void setConnectedAddr
(const std::string& hostname, const std::string& addr, uint16_t port)
{
connectedHostname_ = hostname;
connectedAddr_ = addr;
connectedPort_ = port;
}
};
} // namespace aria2

View File

@ -120,4 +120,14 @@ bool InitiateConnectionCommand::executeInternal() {
}
}
void InitiateConnectionCommand::setConnectedAddrInfo
(const SharedHandle<Request>& req,
const std::string& hostname,
const SharedHandle<SocketCore>& socket)
{
std::pair<std::string, uint16_t> peerAddr;
socket->getPeerInfo(peerAddr);
req->setConnectedAddrInfo(hostname, peerAddr.first, peerAddr.second);
}
} // namespace aria2

View File

@ -59,6 +59,11 @@ protected:
(const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest) = 0;
void setConnectedAddrInfo
(const SharedHandle<Request>& req,
const std::string& hostname,
const SharedHandle<SocketCore>& socket);
public:
InitiateConnectionCommand(cuid_t cuid, const SharedHandle<Request>& req,
const SharedHandle<FileEntry>& fileEntry,

View File

@ -64,7 +64,8 @@ Request::Request():
method_(METHOD_GET),
hasPassword_(false),
ipv6LiteralAddress_(false),
removalRequested_(false)
removalRequested_(false),
connectedPort_(0)
{}
static std::string removeFragment(const std::string& uri)
@ -116,6 +117,7 @@ bool Request::setUri(const std::string& uri) {
bool Request::resetUri() {
previousUri_ = referer_;
supportsPersistentConnection_ = true;
setConnectedAddrInfo(A2STR::NIL, A2STR::NIL, 0);
return parseUri(uri_);
}

View File

@ -90,6 +90,12 @@ private:
bool removalRequested_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
bool parseUri(const std::string& uri);
public:
Request();
@ -216,6 +222,29 @@ public:
return removalRequested_;
}
void setConnectedAddrInfo
(const std::string& hostname, const std::string& addr, uint16_t port)
{
connectedHostname_ = hostname;
connectedAddr_ = addr;
connectedPort_ = port;
}
const std::string& getConnectedHostname() const
{
return connectedHostname_;
}
const std::string& getConnectedAddr() const
{
return connectedAddr_;
}
uint16_t getConnectedPort() const
{
return connectedPort_;
}
static const std::string METHOD_GET;
static const std::string METHOD_HEAD;