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> 2010-09-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Call RequestGroupMan::fillRequestGroupFromReserver() repeatedly Call RequestGroupMan::fillRequestGroupFromReserver() repeatedly

View File

@ -242,12 +242,29 @@ bool AbstractCommand::execute() {
} else { } else {
if(checkPoint_.difference(global::wallclock) >= timeout_) { if(checkPoint_.difference(global::wallclock) >= timeout_) {
// timeout triggers ServerStat error state. // timeout triggers ServerStat error state.
SharedHandle<ServerStat> ss = SharedHandle<ServerStat> ss =
e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(), e_->getRequestGroupMan()->getOrCreateServerStat(req_->getHost(),
req_->getProtocol()); req_->getProtocol());
ss->setError(); 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); throw DL_RETRY_EX2(EX_TIME_OUT, downloadresultcode::TIME_OUT);
} }
e_->addCommand(this); e_->addCommand(this);

View File

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

View File

@ -47,10 +47,6 @@ private:
SharedHandle<Request> proxyRequest_; SharedHandle<Request> proxyRequest_;
SharedHandle<HttpConnection> httpConnection_; SharedHandle<HttpConnection> httpConnection_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
protected: protected:
virtual bool executeInternal(); virtual bool executeInternal();
@ -70,14 +66,6 @@ public:
virtual ~AbstractProxyRequestCommand(); virtual ~AbstractProxyRequestCommand();
virtual Command* getNextCommand() = 0; 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 } // namespace aria2

View File

@ -100,6 +100,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
createSocket(); createSocket();
getSocket()->establishConnection(addr, port); getSocket()->establishConnection(addr, port);
getRequest()->setConnectedAddrInfo(hostname, addr, port);
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);
@ -110,7 +111,6 @@ Command* FtpInitiateConnectionCommand::createNextCommand
new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(), new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), hc, getDownloadEngine(), getRequestGroup(), hc, getDownloadEngine(),
getSocket()); getSocket());
c->setConnectedAddr(hostname, addr, port);
c->setProxyRequest(proxyRequest); c->setProxyRequest(proxyRequest);
command = c; command = c;
} else if(proxyMethod == V_TUNNEL) { } else if(proxyMethod == V_TUNNEL) {
@ -118,13 +118,13 @@ Command* FtpInitiateConnectionCommand::createNextCommand
new FtpTunnelRequestCommand(getCuid(), getRequest(), getFileEntry(), new FtpTunnelRequestCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(), getRequestGroup(), getDownloadEngine(),
proxyRequest, getSocket()); proxyRequest, getSocket());
c->setConnectedAddr(hostname, addr, port);
command = c; command = c;
} else { } else {
// TODO // TODO
throw DL_ABORT_EX("ERROR"); throw DL_ABORT_EX("ERROR");
} }
} else { } else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
if(proxyMethod == V_TUNNEL) { if(proxyMethod == V_TUNNEL) {
command = command =
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(), new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
@ -168,7 +168,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(), new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(), getRequestGroup(), getDownloadEngine(),
getSocket()); getSocket());
c->setConnectedAddr(hostname, addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port);
command = c; command = c;
} else { } else {
command = command =
@ -177,6 +177,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
pooledSocket, pooledSocket,
FtpNegotiationCommand::SEQ_SEND_CWD_PREP, FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
options["baseWorkingDir"]); options["baseWorkingDir"]);
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
} }
} }
return command; return command;

View File

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

View File

@ -150,10 +150,6 @@ private:
// Resolved address for proxy // Resolved address for proxy
std::string proxyAddr_; std::string proxyAddr_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
std::deque<std::string> cwdDirs_; std::deque<std::string> cwdDirs_;
protected: protected:
virtual bool executeInternal(); virtual bool executeInternal();
@ -167,14 +163,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 setConnectedAddr
(const std::string& hostname, const std::string& addr, uint16_t port)
{
connectedHostname_ = hostname;
connectedAddr_ = addr;
connectedPort_ = port;
}
}; };
} // namespace aria2 } // namespace aria2

View File

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

View File

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

View File

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

View File

@ -59,6 +59,11 @@ protected:
(const std::string& hostname, const std::string& addr, uint16_t port, (const std::string& hostname, const std::string& addr, uint16_t port,
const std::vector<std::string>& resolvedAddresses, const std::vector<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest) = 0; const SharedHandle<Request>& proxyRequest) = 0;
void setConnectedAddrInfo
(const SharedHandle<Request>& req,
const std::string& hostname,
const SharedHandle<SocketCore>& socket);
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

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

View File

@ -90,6 +90,12 @@ private:
bool removalRequested_; bool removalRequested_;
std::string connectedHostname_;
std::string connectedAddr_;
uint16_t connectedPort_;
bool parseUri(const std::string& uri); bool parseUri(const std::string& uri);
public: public:
Request(); Request();
@ -216,6 +222,29 @@ public:
return removalRequested_; 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_GET;
static const std::string METHOD_HEAD; static const std::string METHOD_HEAD;