mirror of https://github.com/aria2/aria2
2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Find pooled socket using all cached addresses. * src/DNSCache.h * src/DownloadEngine.cc * src/DownloadEngine.h * src/InitiateConnectionCommand.ccpull/1/head
parent
ffdf21b87b
commit
e3a61f0fd8
|
@ -1,3 +1,11 @@
|
||||||
|
2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Find pooled socket using all cached addresses.
|
||||||
|
* src/DNSCache.h
|
||||||
|
* src/DownloadEngine.cc
|
||||||
|
* src/DownloadEngine.h
|
||||||
|
* src/InitiateConnectionCommand.cc
|
||||||
|
|
||||||
2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Updated copyright year.
|
Updated copyright year.
|
||||||
|
|
|
@ -107,6 +107,17 @@ private:
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename OutputIterator>
|
||||||
|
void getAllGoodAddrs(OutputIterator out) const
|
||||||
|
{
|
||||||
|
for(std::vector<AddrEntry>::const_iterator i = _addrEntries.begin();
|
||||||
|
i != _addrEntries.end(); ++i) {
|
||||||
|
if((*i)._good) {
|
||||||
|
*out++ = (*i)._addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void markBad(const std::string& addr)
|
void markBad(const std::string& addr)
|
||||||
{
|
{
|
||||||
std::vector<AddrEntry>::iterator i = find(addr);
|
std::vector<AddrEntry>::iterator i = find(addr);
|
||||||
|
@ -143,6 +154,18 @@ public:
|
||||||
}
|
}
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename OutputIterator>
|
||||||
|
void findAll
|
||||||
|
(OutputIterator out, const std::string& hostname, uint16_t port) const
|
||||||
|
{
|
||||||
|
CacheEntry target(hostname, port);
|
||||||
|
std::deque<CacheEntry>::const_iterator i =
|
||||||
|
std::lower_bound(_entries.begin(), _entries.end(), target);
|
||||||
|
if(i != _entries.end() && (*i) == target) {
|
||||||
|
(*i).getAllGoodAddrs(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void put
|
void put
|
||||||
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
|
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
|
||||||
|
|
|
@ -57,7 +57,6 @@
|
||||||
#include "ServerStatMan.h"
|
#include "ServerStatMan.h"
|
||||||
#include "CookieStorage.h"
|
#include "CookieStorage.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include "DNSCache.h"
|
|
||||||
#include "AuthConfigFactory.h"
|
#include "AuthConfigFactory.h"
|
||||||
#include "AuthConfig.h"
|
#include "AuthConfig.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "CUIDCounter.h"
|
#include "CUIDCounter.h"
|
||||||
#include "FileAllocationMan.h"
|
#include "FileAllocationMan.h"
|
||||||
#include "CheckIntegrityMan.h"
|
#include "CheckIntegrityMan.h"
|
||||||
|
#include "DNSCache.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -60,7 +61,6 @@ class RequestGroupMan;
|
||||||
class StatCalc;
|
class StatCalc;
|
||||||
class SocketCore;
|
class SocketCore;
|
||||||
class CookieStorage;
|
class CookieStorage;
|
||||||
class DNSCache;
|
|
||||||
class AuthConfigFactory;
|
class AuthConfigFactory;
|
||||||
class Request;
|
class Request;
|
||||||
class EventPoll;
|
class EventPoll;
|
||||||
|
@ -251,6 +251,13 @@ public:
|
||||||
const std::string& findCachedIPAddress
|
const std::string& findCachedIPAddress
|
||||||
(const std::string& hostname, uint16_t port) const;
|
(const std::string& hostname, uint16_t port) const;
|
||||||
|
|
||||||
|
template<typename OutputIterator>
|
||||||
|
void findAllCachedIPAddresses
|
||||||
|
(OutputIterator out, const std::string& hostname, uint16_t port) const
|
||||||
|
{
|
||||||
|
_dnsCache->findAll(out, hostname, port);
|
||||||
|
}
|
||||||
|
|
||||||
void cacheIPAddress
|
void cacheIPAddress
|
||||||
(const std::string& hostname, const std::string& ipaddr, uint16_t port);
|
(const std::string& hostname, const std::string& ipaddr, uint16_t port);
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,9 @@ bool InitiateConnectionCommand::executeInternal() {
|
||||||
port = proxyRequest->getPort();
|
port = proxyRequest->getPort();
|
||||||
}
|
}
|
||||||
std::deque<std::string> addrs;
|
std::deque<std::string> addrs;
|
||||||
std::string ipaddr = e->findCachedIPAddress(hostname, port);
|
e->findAllCachedIPAddresses(std::back_inserter(addrs), hostname, port);
|
||||||
if(ipaddr.empty()) {
|
std::string ipaddr;
|
||||||
|
if(addrs.empty()) {
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
if(getOption()->getAsBool(PREF_ASYNC_DNS)) {
|
if(getOption()->getAsBool(PREF_ASYNC_DNS)) {
|
||||||
if(!isAsyncNameResolverInitialized()) {
|
if(!isAsyncNameResolverInitialized()) {
|
||||||
|
@ -105,15 +106,16 @@ bool InitiateConnectionCommand::executeInternal() {
|
||||||
}
|
}
|
||||||
logger->info(MSG_NAME_RESOLUTION_COMPLETE, cuid,
|
logger->info(MSG_NAME_RESOLUTION_COMPLETE, cuid,
|
||||||
hostname.c_str(),
|
hostname.c_str(),
|
||||||
strjoin(addrs.begin(), addrs.end(), ",").c_str());
|
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||||
for(std::deque<std::string>::const_iterator i = addrs.begin();
|
for(std::deque<std::string>::const_iterator i = addrs.begin();
|
||||||
i != addrs.end(); ++i) {
|
i != addrs.end(); ++i) {
|
||||||
e->cacheIPAddress(hostname, *i, port);
|
e->cacheIPAddress(hostname, *i, port);
|
||||||
}
|
}
|
||||||
ipaddr = e->findCachedIPAddress(hostname, port);
|
ipaddr = e->findCachedIPAddress(hostname, port);
|
||||||
} else {
|
} else {
|
||||||
logger->info(MSG_DNS_CACHE_HIT, cuid, hostname.c_str(), ipaddr.c_str());
|
ipaddr = addrs.front();
|
||||||
addrs.push_back(ipaddr);
|
logger->info(MSG_DNS_CACHE_HIT, cuid, hostname.c_str(),
|
||||||
|
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Command* command = createNextCommand(hostname, ipaddr, port,
|
Command* command = createNextCommand(hostname, ipaddr, port,
|
||||||
|
@ -123,6 +125,8 @@ bool InitiateConnectionCommand::executeInternal() {
|
||||||
} catch(RecoverableException& ex) {
|
} catch(RecoverableException& ex) {
|
||||||
// Catch exception and retry another address.
|
// Catch exception and retry another address.
|
||||||
// See also AbstractCommand::checkIfConnectionEstablished
|
// See also AbstractCommand::checkIfConnectionEstablished
|
||||||
|
|
||||||
|
// TODO ipaddr might not be used if pooled sockt was found.
|
||||||
e->markBadIPAddress(hostname, ipaddr, port);
|
e->markBadIPAddress(hostname, ipaddr, port);
|
||||||
if(!e->findCachedIPAddress(hostname, port).empty()) {
|
if(!e->findCachedIPAddress(hostname, port).empty()) {
|
||||||
logger->info(EX_EXCEPTION_CAUGHT, ex);
|
logger->info(EX_EXCEPTION_CAUGHT, ex);
|
||||||
|
|
Loading…
Reference in New Issue