diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-08-11 12:29:55 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-08-11 12:29:55 +0000 |
| commit | f2d4faad083ffb1bdf622090f63283150bd95aeb (patch) | |
| tree | dbcff240417b7879e93958a2fbbf493b83a943bc /src | |
| parent | 7ca1b43eddd1aba1c71a38dfb46b5ac5685b43d0 (diff) | |
2006-08-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add asynchronous DNS support(libares):
* src/AbstractCommand.h
(setNameResolverCheck): New function.
(disableNameResolverCheck): New function
(resolveHostname): New function.
* src/AbstractCommand.cc
(setNameResolverCheck): New function.
(disableNameResolverCheck): New function
(resolveHostname): New function.
* src/FtpInitiateConnectionCommand.h
(nameResolver): New function.
* src/FtpInitiateConnectionCommand.cc
(Util.h): Included.
(FtpInitiateConnectionCommand): Call disableReadCheckSocket,
disableWriteCheckSocket.
(~FtpInitiateConnectionCommand): Call disableNameResolverCheck.
(executeInternal): Added async DNS support.
* src/HttpInitiateConnectionCommand.h
(nameResolver): New function.
* src/HttpInitiateConnectionCommand.cc
(DlRetryEx.h): Included.
(HttpInitiateConnectionCommand): Call disableReadCheckSocket,
disableWriteCheckSocket.
(~HttpInitiateConnectionCommand): Call disableNameResolverCheck.
(executeInternal): Added async DNS support.
* src/NameResolver.h: New class. Note: #include <ares.h> is
surrounded
by extern "C" declaration.
* src/NameResolver.cc: New class.
* src/Util.h:
(isNumberAndDotsNotation): New function
* src/Util.cc
(isNumberAndDotsNotation): New function.
* src/DownloadEngine.h
(NameResolver.h): Included.
(NameResolverEntry): New class.
(NameResolverEntries): New type definition.
(addNameResolverCheck): New function.
(deleteNameResolverCheck): New function.
* src/DownloadEngine.cc
(run): Initialize cp with 0.
(SetDescriptor::operator()): Added for NameResolverEntry.
(AccumulateActiveUuid::operator()): Added for NameResolverEntry.
(waitData): Check nameResolver entries.
(updateFdSet): Update fds in nameResolver entries.
(addNameResolverCheck): New function.
(deleteNameResolverCheck): new function.
* src/PeerInteractionCommand.cc
(executeInternal): Fixed wrong socket handling.
* src/main.cc
(main): Fixed the initial value of PREF_LOWEST_SPEED_LIMIT
option to 0.
* src/Util.cc
(fileChecksum): Removed the call to ctx.digestReset().
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractCommand.cc | 31 | ||||
| -rw-r--r-- | src/AbstractCommand.h | 5 | ||||
| -rw-r--r-- | src/DownloadEngine.cc | 63 | ||||
| -rw-r--r-- | src/DownloadEngine.h | 36 | ||||
| -rw-r--r-- | src/FtpInitiateConnectionCommand.cc | 37 | ||||
| -rw-r--r-- | src/FtpInitiateConnectionCommand.h | 3 | ||||
| -rw-r--r-- | src/HttpInitiateConnectionCommand.cc | 35 | ||||
| -rw-r--r-- | src/HttpInitiateConnectionCommand.h | 3 | ||||
| -rw-r--r-- | src/Makefile.am | 9 | ||||
| -rw-r--r-- | src/Makefile.in | 48 | ||||
| -rw-r--r-- | src/NameResolver.cc | 33 | ||||
| -rw-r--r-- | src/NameResolver.h | 102 | ||||
| -rw-r--r-- | src/PeerInteractionCommand.cc | 12 | ||||
| -rw-r--r-- | src/Util.cc | 10 | ||||
| -rw-r--r-- | src/Util.h | 2 | ||||
| -rw-r--r-- | src/main.cc | 2 |
16 files changed, 390 insertions, 41 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index ffd72393..bc9f005f 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -169,3 +169,34 @@ void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) { } } } + +#ifdef HAVE_LIBARES +void AbstractCommand::setNameResolverCheck(const NameResolverHandle& resolver) { + e->addNameResolverCheck(resolver, getUuid()); +} + +void AbstractCommand::disableNameResolverCheck(const NameResolverHandle& resolver) { + e->deleteNameResolverCheck(resolver, getUuid()); +} + +bool AbstractCommand::resolveHostname(const string& hostname, + const NameResolverHandle& resolver) { + switch(resolver->getStatus()) { + case NameResolver::STATUS_READY: + logger->info("CUID#%d - Resolving hostname %s", cuid, hostname.c_str()); + resolver->resolve(hostname); + setNameResolverCheck(resolver); + return false; + case NameResolver::STATUS_SUCCESS: + logger->info("CUID#%d - Name resolution complete: %s -> %s", cuid, + hostname.c_str(), resolver->getAddrString().c_str()); + return true; + break; + case NameResolver::STATUS_ERROR: + throw new DlRetryEx("CUID#%d - Name resolution failed:%s", cuid, + resolver->getError().c_str()); + default: + return false; + } +} +#endif // HAVE_LIBARES diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h index 5289d14e..efc2e252 100644 --- a/src/AbstractCommand.h +++ b/src/AbstractCommand.h @@ -46,6 +46,11 @@ protected: void setWriteCheckSocket(const SocketHandle& socket); void disableReadCheckSocket(); void disableWriteCheckSocket(); +#ifdef HAVE_LIBARES + void setNameResolverCheck(const NameResolverHandle& resolver); + void disableNameResolverCheck(const NameResolverHandle& resolver); + bool resolveHostname(const string& hostname, const NameResolverHandle& nameResolver); +#endif // HAVE_LIBARES void setTimeout(int timeout) { this->timeout = timeout; } private: bool checkSocketIsReadable; diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 912381da..9229acd2 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -65,6 +65,7 @@ public: void DownloadEngine::run() { initStatistics(); Time cp; + cp.setTimeInSec(0); CommandUuids activeUuids; while(!commands.empty()) { if(cp.elapsed(1)) { @@ -135,6 +136,14 @@ public: *max_ptr = fd; } } +#ifdef HAVE_LIBARES + void operator()(const NameResolverEntry& entry) { + int tempFd = entry.nameResolver->getFds(rfds_ptr, wfds_ptr); + if(*max_ptr < tempFd) { + *max_ptr = tempFd; + } + } +#endif // HAVE_LIBARES }; class AccumulateActiveUuid { @@ -170,6 +179,19 @@ public: } */ } +#ifdef HAVE_LIBARES + void operator()(const NameResolverEntry& entry) { + entry.nameResolver->process(rfds_ptr, wfds_ptr); + switch(entry.nameResolver->getStatus()) { + case NameResolver::STATUS_SUCCESS: + case NameResolver::STATUS_ERROR: + activeUuids_ptr->push_back(entry.commandUuid); + break; + default: + break; + } + } +#endif // HAVE_LIBARES }; void DownloadEngine::waitData(CommandUuids& activeUuids) { @@ -187,7 +209,10 @@ void DownloadEngine::waitData(CommandUuids& activeUuids) { if(retval > 0) { for_each(socketEntries.begin(), socketEntries.end(), AccumulateActiveUuid(&activeUuids, &rfds, &wfds)); - +#ifdef HAVE_LIBARES + for_each(nameResolverEntries.begin(), nameResolverEntries.end(), + AccumulateActiveUuid(&activeUuids, &rfds, &wfds)); +#endif // HAVE_LIBARES sort(activeUuids.begin(), activeUuids.end()); activeUuids.erase(unique(activeUuids.begin(), activeUuids.end()), @@ -199,6 +224,10 @@ void DownloadEngine::updateFdSet() { fdmax = 0; FD_ZERO(&rfdset); FD_ZERO(&wfdset); +#ifdef HAVE_LIBARES + for_each(nameResolverEntries.begin(), nameResolverEntries.end(), + SetDescriptor(&fdmax, &rfdset, &wfdset)); +#endif // HAVE_LIBARES for_each(socketEntries.begin(), socketEntries.end(), SetDescriptor(&fdmax, &rfdset, &wfdset)); } @@ -250,3 +279,35 @@ bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket, SocketEntry entry(socket, commandUuid, SocketEntry::TYPE_WR); return deleteSocket(entry); } + +#ifdef HAVE_LIBARES +bool DownloadEngine::addNameResolverCheck(const NameResolverHandle& resolver, + const CommandUuid& uuid) { + NameResolverEntry entry(resolver, uuid); + NameResolverEntries::iterator itr = find(nameResolverEntries.begin(), + nameResolverEntries.end(), + entry); + if(itr == nameResolverEntries.end()) { + nameResolverEntries.push_back(entry); + updateFdSet(); + return true; + } else { + return false; + } +} + +bool DownloadEngine::deleteNameResolverCheck(const NameResolverHandle& resolver, + const CommandUuid& uuid) { + NameResolverEntry entry(resolver, uuid); + NameResolverEntries::iterator itr = find(nameResolverEntries.begin(), + nameResolverEntries.end(), + entry); + if(itr == nameResolverEntries.end()) { + return false; + } else { + nameResolverEntries.erase(itr); + updateFdSet(); + return true; + } +} +#endif // HAVE_LIBARES diff --git a/src/DownloadEngine.h b/src/DownloadEngine.h index aa118ac7..b412ce3b 100644 --- a/src/DownloadEngine.h +++ b/src/DownloadEngine.h @@ -28,6 +28,9 @@ #include "common.h" #include "Logger.h" #include "Option.h" +#ifdef HAVE_LIBARES +# include "NameResolver.h" +#endif // HAVE_LIBARES typedef deque<SocketHandle> Sockets; typedef deque<Command*> Commands; @@ -59,10 +62,34 @@ public: typedef deque<SocketEntry> SocketEntries; +#ifdef HAVE_LIBARES +class NameResolverEntry { +public: + NameResolverHandle nameResolver; + CommandUuid commandUuid; +public: + NameResolverEntry(const NameResolverHandle& nameResolver, + const CommandUuid& commandUuid): + nameResolver(nameResolver), commandUuid(commandUuid) {} + ~NameResolverEntry() {} + + bool operator==(const NameResolverEntry& entry) { + return nameResolver == entry.nameResolver && + commandUuid == entry.commandUuid; + } +}; + +typedef deque<NameResolverEntry> NameResolverEntries; +#endif // HAVE_LIBARES + + class DownloadEngine { private: void waitData(CommandUuids& activeUuids); SocketEntries socketEntries; +#ifdef HAVE_LIBARES + NameResolverEntries nameResolverEntries; +#endif // HAVE_LIBARES fd_set rfdset; fd_set wfdset; int fdmax; @@ -81,7 +108,7 @@ public: Commands commands; SegmentMan* segmentMan; const Option* option; - + DownloadEngine(); virtual ~DownloadEngine(); @@ -99,7 +126,12 @@ public: const CommandUuid& commandUuid); bool deleteSocketForWriteCheck(const SocketHandle& socket, const CommandUuid& command); - +#ifdef HAVE_LIBARES + bool addNameResolverCheck(const NameResolverHandle& resolver, + const CommandUuid& uuid); + bool deleteNameResolverCheck(const NameResolverHandle& resolver, + const CommandUuid& uuid); +#endif // HAVE_LIBARES }; #endif // _D_DOWNLOAD_ENGINE_H_ diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc index 2a67222e..2a6ce116 100644 --- a/src/FtpInitiateConnectionCommand.cc +++ b/src/FtpInitiateConnectionCommand.cc @@ -26,10 +26,22 @@ #include "DlAbortEx.h" #include "message.h" #include "prefs.h" +#include "Util.h" -FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {} +FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid, + Request* req, + DownloadEngine* e) + :AbstractCommand(cuid, req, e) +{ + disableReadCheckSocket(); + disableWriteCheckSocket(); +} -FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {} +FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() { +#ifdef HAVE_LIBARES + disableNameResolverCheck(nameResolver); +#endif // HAVE_LIBARES +} bool FtpInitiateConnectionCommand::executeInternal(Segment segment) { if(!e->segmentMan->downloadStarted) { @@ -43,13 +55,28 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) { e->segmentMan->diskWriter->initAndOpenFile(e->segmentMan->getFilePath()); } } - + string hostname; + if(useHttpProxy()) { + hostname = e->option->get(PREF_HTTP_PROXY_HOST); + } else { + hostname = req->getHost(); + } +#ifdef HAVE_LIBARES + if(!Util::isNumbersAndDotsNotation(hostname)) { + if(resolveHostname(hostname, nameResolver)) { + hostname = nameResolver->getAddrString(); + } else { + e->commands.push_back(this); + return false; + } + } +#endif // HAVE_LIBARES Command* command; if(useHttpProxy()) { logger->info(MSG_CONNECTING_TO_SERVER, cuid, e->option->get(PREF_HTTP_PROXY_HOST).c_str(), e->option->getAsInt(PREF_HTTP_PROXY_PORT)); - socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST), + socket->establishConnection(hostname, e->option->getAsInt(PREF_HTTP_PROXY_PORT)); if(useHttpProxyGet()) { @@ -63,7 +90,7 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) { } else { logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(), req->getPort()); - socket->establishConnection(req->getHost(), req->getPort()); + socket->establishConnection(hostname, req->getPort()); command = new FtpNegotiationCommand(cuid, req, e, socket); } e->commands.push_back(command); diff --git a/src/FtpInitiateConnectionCommand.h b/src/FtpInitiateConnectionCommand.h index 0f997bf8..2d3802c0 100644 --- a/src/FtpInitiateConnectionCommand.h +++ b/src/FtpInitiateConnectionCommand.h @@ -26,6 +26,9 @@ class FtpInitiateConnectionCommand : public AbstractCommand { private: +#ifdef HAVE_LIBARES + NameResolverHandle nameResolver; +#endif // HAVE_LIBARES bool useHttpProxy() const; bool useHttpProxyGet() const; bool useHttpProxyConnect() const; diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc index 73657192..cc0bc862 100644 --- a/src/HttpInitiateConnectionCommand.cc +++ b/src/HttpInitiateConnectionCommand.cc @@ -24,23 +24,48 @@ #include "HttpProxyRequestCommand.h" #include "Util.h" #include "DlAbortEx.h" +#include "DlRetryEx.h" #include "message.h" #include "prefs.h" HttpInitiateConnectionCommand::HttpInitiateConnectionCommand(int cuid, Request* req, - DownloadEngine* e):AbstractCommand(cuid, req, e) {} + DownloadEngine* e): + AbstractCommand(cuid, req, e) +{ + disableReadCheckSocket(); + disableWriteCheckSocket(); +} -HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {} +HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() { +#ifdef HAVE_LIBARES + disableNameResolverCheck(nameResolver); +#endif // HAVE_LIBARES +} bool HttpInitiateConnectionCommand::executeInternal(Segment segment) { - // socket->establishConnection(...); + string hostname; + if(useProxy()) { + hostname = e->option->get(PREF_HTTP_PROXY_HOST); + } else { + hostname = req->getHost(); + } +#ifdef HAVE_LIBARES + if(!Util::isNumbersAndDotsNotation(hostname)) { + if(resolveHostname(hostname, nameResolver)) { + hostname = nameResolver->getAddrString(); + } else { + e->commands.push_back(this); + return false; + } + } +#endif // HAVE_LIBARES Command* command; if(useProxy()) { logger->info(MSG_CONNECTING_TO_SERVER, cuid, e->option->get(PREF_HTTP_PROXY_HOST).c_str(), e->option->getAsInt(PREF_HTTP_PROXY_PORT)); - socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST), + socket->establishConnection(hostname, e->option->getAsInt(PREF_HTTP_PROXY_PORT)); if(useProxyTunnel()) { command = new HttpProxyRequestCommand(cuid, req, e, socket); @@ -53,7 +78,7 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) { } else { logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(), req->getPort()); - socket->establishConnection(req->getHost(), req->getPort()); + socket->establishConnection(hostname, req->getPort()); command = new HttpRequestCommand(cuid, req, e, socket); } e->commands.push_back(command); diff --git a/src/HttpInitiateConnectionCommand.h b/src/HttpInitiateConnectionCommand.h index e605ec1b..4e4bdc8e 100644 --- a/src/HttpInitiateConnectionCommand.h +++ b/src/HttpInitiateConnectionCommand.h @@ -26,6 +26,9 @@ class HttpInitiateConnectionCommand : public AbstractCommand { private: +#ifdef HAVE_LIBARES + NameResolverHandle nameResolver; +#endif // HAVE_LIBARES bool useProxy(); bool useProxyGet(); bool useProxyTunnel(); diff --git a/src/Makefile.am b/src/Makefile.am index 5344ccfa..0fe902f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -57,6 +57,10 @@ SRCS = Socket.h\ RequestInfo.h\ UrlRequestInfo.cc UrlRequestInfo.h +if HAVE_LIBARES +SRCS += NameResolver.cc NameResolver.h +endif # HAVE_LIBARES + if ENABLE_BITTORRENT SRCS += MetaEntry.h\ Data.cc Data.h\ @@ -127,9 +131,10 @@ endif # ENABLE_METALINK noinst_LIBRARIES = libaria2c.a libaria2c_a_SOURCES = $(SRCS) aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\ - @LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@ + @LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@ @LIBARES_LIBS@ #aria2c_LDFLAGS = -pg AM_CPPFLAGS = -Wall\ -I../lib -I../intl -I$(top_srcdir)/intl\ @LIBGNUTLS_CFLAGS@ @LIBGCRYPT_CFLAGS@ @OPENSSL_CFLAGS@ @XML_CPPFLAGS@\ - -D_FILE_OFFSET_BITS=64 -DLOCALEDIR=\"$(localedir)\" @DEFS@# -pg
\ No newline at end of file + @LIBARES_CPPFLAGS@\ + -D_FILE_OFFSET_BITS=64 -DLOCALEDIR=\"$(localedir)\" @DEFS@ # -pg
\ No newline at end of file diff --git a/src/Makefile.in b/src/Makefile.in index f542ff0c..d3706b44 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -38,7 +38,8 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ bin_PROGRAMS = aria2c$(EXEEXT) -@ENABLE_BITTORRENT_TRUE@am__append_1 = MetaEntry.h\ +@HAVE_LIBARES_TRUE@am__append_1 = NameResolver.cc NameResolver.h +@ENABLE_BITTORRENT_TRUE@am__append_2 = MetaEntry.h\ @ENABLE_BITTORRENT_TRUE@ Data.cc Data.h\ @ENABLE_BITTORRENT_TRUE@ Dictionary.cc Dictionary.h\ @ENABLE_BITTORRENT_TRUE@ List.cc List.h\ @@ -94,7 +95,7 @@ bin_PROGRAMS = aria2c$(EXEEXT) @ENABLE_BITTORRENT_TRUE@ HaveEraseCommand.cc HaveEraseCommand.h\ @ENABLE_BITTORRENT_TRUE@ TorrentRequestInfo.cc TorrentRequestInfo.h -@ENABLE_METALINK_TRUE@am__append_2 = Metalinker.cc Metalinker.h\ +@ENABLE_METALINK_TRUE@am__append_3 = Metalinker.cc Metalinker.h\ @ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\ @ENABLE_METALINK_TRUE@ MetalinkResource.cc MetalinkResource.h\ @ENABLE_METALINK_TRUE@ MetalinkProcessor.h\ @@ -110,11 +111,11 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/codeset.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 $(top_srcdir)/m4/inttypes.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ - $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/nls.m4 \ - $(top_srcdir)/m4/openssl.m4 $(top_srcdir)/m4/po.m4 \ - $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/stdint_h.m4 \ - $(top_srcdir)/m4/uintmax_t.m4 $(top_srcdir)/m4/ulonglong.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libares.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/openssl.m4 \ + $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ + $(top_srcdir)/m4/stdint_h.m4 $(top_srcdir)/m4/uintmax_t.m4 \ + $(top_srcdir)/m4/ulonglong.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -159,10 +160,11 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ LogFactory.cc LogFactory.h NullLogger.h TimeA2.cc TimeA2.h \ SharedHandle.h FeatureConfig.cc FeatureConfig.h \ DownloadEngineFactory.cc DownloadEngineFactory.h RequestInfo.h \ - UrlRequestInfo.cc UrlRequestInfo.h MetaEntry.h Data.cc Data.h \ - Dictionary.cc Dictionary.h List.cc List.h MetaFileUtil.cc \ - MetaFileUtil.h MetaEntryVisitor.h ShaVisitor.cc ShaVisitor.h \ - TorrentMan.cc TorrentMan.h PeerConnection.cc PeerConnection.h \ + UrlRequestInfo.cc UrlRequestInfo.h NameResolver.cc \ + NameResolver.h MetaEntry.h Data.cc Data.h Dictionary.cc \ + Dictionary.h List.cc List.h MetaFileUtil.cc MetaFileUtil.h \ + MetaEntryVisitor.h ShaVisitor.cc ShaVisitor.h TorrentMan.cc \ + TorrentMan.h PeerConnection.cc PeerConnection.h \ PeerMessageUtil.cc PeerMessageUtil.h PeerAbstractCommand.cc \ PeerAbstractCommand.h PeerInitiateConnectionCommand.cc \ PeerInitiateConnectionCommand.h PeerInteractionCommand.cc \ @@ -199,7 +201,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ MetalinkResource.cc MetalinkResource.h MetalinkProcessor.h \ Xml2MetalinkProcessor.cc Xml2MetalinkProcessor.h \ MetalinkRequestInfo.cc MetalinkRequestInfo.h -@ENABLE_BITTORRENT_TRUE@am__objects_1 = Data.$(OBJEXT) \ +@HAVE_LIBARES_TRUE@am__objects_1 = NameResolver.$(OBJEXT) +@ENABLE_BITTORRENT_TRUE@am__objects_2 = Data.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ Dictionary.$(OBJEXT) List.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ MetaFileUtil.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ ShaVisitor.$(OBJEXT) \ @@ -248,12 +251,12 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ @ENABLE_BITTORRENT_TRUE@ PeerMessageFactory.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ HaveEraseCommand.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ TorrentRequestInfo.$(OBJEXT) -@ENABLE_METALINK_TRUE@am__objects_2 = Metalinker.$(OBJEXT) \ +@ENABLE_METALINK_TRUE@am__objects_3 = Metalinker.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ Xml2MetalinkProcessor.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkRequestInfo.$(OBJEXT) -am__objects_3 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \ +am__objects_4 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \ AbstractCommand.$(OBJEXT) \ InitiateConnectionCommandFactory.$(OBJEXT) \ DownloadCommand.$(OBJEXT) \ @@ -277,8 +280,9 @@ am__objects_3 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \ File.$(OBJEXT) Option.$(OBJEXT) Base64.$(OBJEXT) \ CookieBox.$(OBJEXT) LogFactory.$(OBJEXT) TimeA2.$(OBJEXT) \ FeatureConfig.$(OBJEXT) DownloadEngineFactory.$(OBJEXT) \ - UrlRequestInfo.$(OBJEXT) $(am__objects_1) $(am__objects_2) -am_libaria2c_a_OBJECTS = $(am__objects_3) + UrlRequestInfo.$(OBJEXT) $(am__objects_1) $(am__objects_2) \ + $(am__objects_3) +am_libaria2c_a_OBJECTS = $(am__objects_4) libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS) am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) @@ -341,6 +345,8 @@ EXEEXT = @EXEEXT@ GENCAT = @GENCAT@ GLIBC21 = @GLIBC21@ GMSGFMT = @GMSGFMT@ +HAVE_LIBARES_FALSE = @HAVE_LIBARES_FALSE@ +HAVE_LIBARES_TRUE = @HAVE_LIBARES_TRUE@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ @@ -351,6 +357,8 @@ INTLLIBS = @INTLLIBS@ INTLOBJS = @INTLOBJS@ INTL_LIBTOOL_SUFFIX_PREFIX = @INTL_LIBTOOL_SUFFIX_PREFIX@ LDFLAGS = @LDFLAGS@ +LIBARES_CPPFLAGS = @LIBARES_CPPFLAGS@ +LIBARES_LIBS = @LIBARES_LIBS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ @@ -469,17 +477,18 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \ SharedHandle.h FeatureConfig.cc FeatureConfig.h \ DownloadEngineFactory.cc DownloadEngineFactory.h RequestInfo.h \ UrlRequestInfo.cc UrlRequestInfo.h $(am__append_1) \ - $(am__append_2) + $(am__append_2) $(am__append_3) noinst_LIBRARIES = libaria2c.a libaria2c_a_SOURCES = $(SRCS) aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\ - @LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@ + @LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@ @LIBARES_LIBS@ #aria2c_LDFLAGS = -pg AM_CPPFLAGS = -Wall\ -I../lib -I../intl -I$(top_srcdir)/intl\ @LIBGNUTLS_CFLAGS@ @LIBGCRYPT_CFLAGS@ @OPENSSL_CFLAGS@ @XML_CPPFLAGS@\ - -D_FILE_OFFSET_BITS=64 -DLOCALEDIR=\"$(localedir)\" @DEFS@# -pg + @LIBARES_CPPFLAGS@\ + -D_FILE_OFFSET_BITS=64 -DLOCALEDIR=\"$(localedir)\" @DEFS@ # -pg all: all-am @@ -611,6 +620,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Metalinker.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskAdaptor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskWriter.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameResolver.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NotInterestedMessage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Option.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Peer.Po@am__quote@ diff --git a/src/NameResolver.cc b/src/NameResolver.cc new file mode 100644 index 00000000..0406dbe1 --- /dev/null +++ b/src/NameResolver.cc @@ -0,0 +1,33 @@ +/* <!-- copyright */ +/* + * aria2 - a simple utility for downloading files faster + * + * Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* copyright --> */ +#include "NameResolver.h" + +void callback(void* arg, int status, struct hostent* host) { + NameResolver* resolverPtr = (NameResolver*)arg; + if(status != ARES_SUCCESS) { + resolverPtr->error = ares_strerror(status, 0); + resolverPtr->status = NameResolver::STATUS_ERROR; + return; + } + memcpy(&resolverPtr->addr, *host->h_addr_list, sizeof(struct in_addr)); + resolverPtr->status = NameResolver::STATUS_SUCCESS; +} diff --git a/src/NameResolver.h b/src/NameResolver.h new file mode 100644 index 00000000..42bb5414 --- /dev/null +++ b/src/NameResolver.h @@ -0,0 +1,102 @@ +/* <!-- copyright */ +/* + * aria2 - a simple utility for downloading files faster + * + * Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* copyright --> */ +#ifndef _D_NAME_RESOLVER_H_ +#define _D_NAME_RESOLVER_H_ + +#include "common.h" +#include "SharedHandle.h" +#include <netdb.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#ifdef __cplusplus +extern "C" { +#endif +#include <ares.h> +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +class NameResolver { + friend void callback(void* arg, int status, struct hostent* host); + +public: + enum STATUS { + STATUS_READY, + STATUS_QUERYING, + STATUS_SUCCESS, + STATUS_ERROR, + }; +private: + STATUS status; + ares_channel channel; + struct in_addr addr; + string error; +public: + NameResolver(): + status(STATUS_READY) + { + ares_init(&channel); + } + + ~NameResolver() { + ares_destroy(channel); + } + + void resolve(const string& name) { + status = STATUS_QUERYING; + ares_gethostbyname(channel, name.c_str(), AF_INET, callback, this); + } + + string getAddrString() const { + return inet_ntoa(addr); + } + + const struct in_addr& getAddr() const { + return addr; + } + + const string& getError() const { + return error; + } + + STATUS getStatus() const { + return status; + } + + int getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const { + return ares_fds(channel, rfdsPtr, wfdsPtr); + } + + void process(fd_set* rfdsPtr, fd_set* wfdsPtr) { + ares_process(channel, rfdsPtr, wfdsPtr); + } + + bool operator==(const NameResolver& resolver) { + return this == &resolver; + } +}; + +typedef SharedHandle<NameResolver> NameResolverHandle; + +#endif // _D_NAME_RESOLVER_H_ diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 2788026b..1b529264 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -60,17 +60,19 @@ PeerInteractionCommand::~PeerInteractionCommand() { } bool PeerInteractionCommand::executeInternal() { - if(sequence == INITIATOR_SEND_HANDSHAKE) { - socket->setBlockingMode(); - setReadCheckSocket(socket); - setTimeout(e->option->getAsInt(PREF_TIMEOUT)); - } disableWriteCheckSocket(); setUploadLimitCheck(false); setNoCheck(false); switch(sequence) { case INITIATOR_SEND_HANDSHAKE: + if(!socket->isWritable(0)) { + setWriteCheckSocket(socket); + break; + } + socket->setBlockingMode(); + setReadCheckSocket(socket); + setTimeout(e->option->getAsInt(PREF_TIMEOUT)); peerInteraction->sendHandshake(); sequence = INITIATOR_WAIT_HANDSHAKE; break; diff --git a/src/Util.cc b/src/Util.cc index 846e8976..1b34a182 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -376,7 +376,6 @@ void Util::fileChecksum(const string& filename, unsigned char* digest, MessageDigestContext::DigestAlgo algo) { MessageDigestContext ctx(algo); ctx.digestInit(); - ctx.digestReset(); int BUFLEN = 4096; char buf[BUFLEN]; @@ -531,3 +530,12 @@ string Util::toLower(const string& src) { for_each(temp.begin(), temp.end(), LowerCase()); return temp; } + +bool Util::isNumbersAndDotsNotation(const string& name) { + struct sockaddr_in sockaddr; + if(inet_aton(name.c_str(), &sockaddr.sin_addr)) { + return true; + } else { + return false; + } +} @@ -107,6 +107,8 @@ public: static string toUpper(const string& src); static string toLower(const string& src); + + static bool isNumbersAndDotsNotation(const string& name); }; #endif // _D_UTIL_H_ diff --git a/src/main.cc b/src/main.cc index 09543542..62813108 100644 --- a/src/main.cc +++ b/src/main.cc @@ -292,7 +292,7 @@ int main(int argc, char* argv[]) { op->put(PREF_AUTO_SAVE_INTERVAL, "60"); op->put(PREF_DIRECT_FILE_MAPPING, V_TRUE); op->put(PREF_UPLOAD_LIMIT, "0"); - op->put(PREF_LOWEST_SPEED_LIMIT, "4000"); + op->put(PREF_LOWEST_SPEED_LIMIT, "0"); while(1) { int optIndex = 0; int lopt; |
