Explorar o código

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

	Added --enable-async-dns6 option. This option enables IPv6 name
	resolution in asynchronous DNS resolver. This option will be
	ignored when --async-dns=false.
	* doc/aria2c.1.txt
	* src/AbstractCommand.cc
	* src/AsyncNameResolver.cc
	* src/AsyncNameResolver.h
	* src/DHTEntryPointNameResolveCommand.cc
	* src/OptionHandlerFactory.cc
	* src/download_helper.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa %!s(int64=15) %!d(string=hai) anos
pai
achega
939a372727

+ 16 - 0
ChangeLog

@@ -1,3 +1,19 @@
+2010-08-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added --enable-async-dns6 option. This option enables IPv6 name
+	resolution in asynchronous DNS resolver. This option will be
+	ignored when --async-dns=false.
+	* doc/aria2c.1.txt
+	* src/AbstractCommand.cc
+	* src/AsyncNameResolver.cc
+	* src/AsyncNameResolver.h
+	* src/DHTEntryPointNameResolveCommand.cc
+	* src/OptionHandlerFactory.cc
+	* src/download_helper.cc
+	* src/prefs.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2010-07-31  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 2010-07-31  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 
 	Use hostname of original URI when counting hostname in
 	Use hostname of original URI when counting hostname in

+ 20 - 2
doc/aria2c.1

@@ -2,12 +2,12 @@
 .\"     Title: aria2c
 .\"     Title: aria2c
 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
 .\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
 .\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
 .\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\"      Date: 07/19/2010
+.\"      Date: 08/01/2010
 .\"    Manual: Aria2 Manual
 .\"    Manual: Aria2 Manual
 .\"    Source: Aria2 1.10.0
 .\"    Source: Aria2 1.10.0
 .\"  Language: English
 .\"  Language: English
 .\"
 .\"
-.TH "ARIA2C" "1" "07/19/2010" "Aria2 1\&.10\&.0" "Aria2 Manual"
+.TH "ARIA2C" "1" "08/01/2010" "Aria2 1\&.10\&.0" "Aria2 Manual"
 .\" -----------------------------------------------------------------
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
 .\" -----------------------------------------------------------------
@@ -1127,6 +1127,13 @@ Disable IPv6\&. This is useful if you have to use broken DNS and want to avoid t
 \fIfalse\fR
 \fIfalse\fR
 .RE
 .RE
 .PP
 .PP
+\fB\-\-enable\-async\-dns6\fR[=\fItrue\fR|\fIfalse\fR]
+.RS 4
+Enable IPv6 name resolution in asynchronous DNS resolver\&. This option will be ignored when
+\fB\-\-async\-dns\fR=\fIfalse\fR\&. Default:
+\fIfalse\fR
+.RE
+.PP
 \fB\-\-enable\-direct\-io\fR[=\fItrue\fR|\fIfalse\fR]
 \fB\-\-enable\-direct\-io\fR[=\fItrue\fR|\fIfalse\fR]
 .RS 4
 .RS 4
 Enable directI/O, which lowers cpu usage while allocating/checking files\&. Turn off if you encounter any error\&. Default:
 Enable directI/O, which lowers cpu usage while allocating/checking files\&. Turn off if you encounter any error\&. Default:
@@ -2612,6 +2619,17 @@ min\-split\-size
 conditional\-get
 conditional\-get
 .RE
 .RE
 .sp
 .sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+enable\-async\-dns6
+.RE
+.sp
 These options have exactly same meaning of the ones in the command\-line options, but it just applies to the URIs it belongs to\&.
 These options have exactly same meaning of the ones in the command\-line options, but it just applies to the URIs it belongs to\&.
 .sp
 .sp
 For example, the content of uri\&.txt is
 For example, the content of uri\&.txt is

+ 16 - 1
doc/aria2c.1.html

@@ -1955,6 +1955,16 @@ writes the piece to the appropriate files.</td>
 </p>
 </p>
 </dd>
 </dd>
 <dt class="hdlist1">
 <dt class="hdlist1">
+<strong>--enable-async-dns6</strong>[=<em>true</em>|<em>false</em>]
+</dt>
+<dd>
+<p>
+  Enable IPv6 name resolution in asynchronous DNS resolver. This
+  option will be ignored when <strong>--async-dns</strong>=<em>false</em>.
+  Default: <em>false</em>
+</p>
+</dd>
+<dt class="hdlist1">
 <strong>--enable-direct-io</strong>[=<em>true</em>|<em>false</em>]
 <strong>--enable-direct-io</strong>[=<em>true</em>|<em>false</em>]
 </dt>
 </dt>
 <dd>
 <dd>
@@ -3003,6 +3013,11 @@ min-split-size
 conditional-get
 conditional-get
 </p>
 </p>
 </li>
 </li>
+<li>
+<p>
+enable-async-dns6
+</p>
+</li>
 </ul></div>
 </ul></div>
 <div class="paragraph"><p>These options have exactly same meaning of the ones in the
 <div class="paragraph"><p>These options have exactly same meaning of the ones in the
 command-line options, but it just applies to the URIs it belongs to.</p></div>
 command-line options, but it just applies to the URIs it belongs to.</p></div>
@@ -4258,7 +4273,7 @@ files in the program, then also delete it here.</p></div>
 <div id="footnotes"><hr /></div>
 <div id="footnotes"><hr /></div>
 <div id="footer">
 <div id="footer">
 <div id="footer-text">
 <div id="footer-text">
-Last updated 2010-07-19 13:48:41 JST
+Last updated 2010-08-01 14:56:58 JST
 </div>
 </div>
 </div>
 </div>
 </body>
 </body>

+ 7 - 0
doc/aria2c.1.txt

@@ -774,6 +774,12 @@ Advanced Options
   Disable IPv6. This is useful if you have to use broken DNS and want
   Disable IPv6. This is useful if you have to use broken DNS and want
   to avoid terribly slow AAAA record lookup. Default: 'false'
   to avoid terribly slow AAAA record lookup. Default: 'false'
 
 
+*--enable-async-dns6*[='true'|'false']::
+
+  Enable IPv6 name resolution in asynchronous DNS resolver. This
+  option will be ignored when *--async-dns*='false'.
+  Default: 'false'
+
 *--enable-direct-io*[='true'|'false']::
 *--enable-direct-io*[='true'|'false']::
   Enable directI/O, which lowers cpu usage while allocating/checking files.
   Enable directI/O, which lowers cpu usage while allocating/checking files.
   Turn off if you encounter any error.
   Turn off if you encounter any error.
@@ -1265,6 +1271,7 @@ of URIs. These optional lines must start with white space(s).
 * max-connection-per-server
 * max-connection-per-server
 * min-split-size
 * min-split-size
 * conditional-get
 * conditional-get
+* enable-async-dns6
 
 
 These options have exactly same meaning of the ones in the
 These options have exactly same meaning of the ones in the
 command-line options, but it just applies to the URIs it belongs to.
 command-line options, but it just applies to the URIs it belongs to.

+ 7 - 1
src/AbstractCommand.cc

@@ -638,7 +638,13 @@ bool AbstractCommand::isAsyncNameResolverInitialized() const
 
 
 void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
 void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
 {
 {
-  asyncNameResolver_.reset(new AsyncNameResolver());
+  int family;
+  if(getOption()->getAsBool(PREF_ENABLE_ASYNC_DNS6)) {
+    family = AF_UNSPEC;
+  } else {
+    family = AF_INET;
+  }
+  asyncNameResolver_.reset(new AsyncNameResolver(family));
   if(getLogger()->info()) {
   if(getLogger()->info()) {
     getLogger()->info(MSG_RESOLVING_HOSTNAME,
     getLogger()->info(MSG_RESOLVING_HOSTNAME,
                       util::itos(getCuid()).c_str(), hostname.c_str());
                       util::itos(getCuid()).c_str(), hostname.c_str());

+ 16 - 7
src/AsyncNameResolver.cc

@@ -53,15 +53,24 @@ void callback(void* arg, int status, int timeouts, struct hostent* host)
     return;
     return;
   }
   }
   for(char** ap = host->h_addr_list; *ap; ++ap) {
   for(char** ap = host->h_addr_list; *ap; ++ap) {
-    struct in_addr addr;
-    memcpy(&addr, *ap, sizeof(in_addr));
-    resolverPtr->resolvedAddresses_.push_back(inet_ntoa(addr));
+    char addrstring[INET6_ADDRSTRLEN];
+    const char* dst =
+      inet_ntop(host->h_addrtype, *ap, addrstring, sizeof(addrstring));
+    if(dst) {
+      resolverPtr->resolvedAddresses_.push_back(dst);
+    }
+  }
+  if(resolverPtr->resolvedAddresses_.empty()) {
+    resolverPtr->error_ = "inet_ntop failed";
+    resolverPtr->status_ = AsyncNameResolver::STATUS_ERROR;
+  } else {
+    resolverPtr->status_ = AsyncNameResolver::STATUS_SUCCESS;
   }
   }
-  resolverPtr->status_ = AsyncNameResolver::STATUS_SUCCESS;
 }
 }
 
 
-AsyncNameResolver::AsyncNameResolver():
-  status_(STATUS_READY)
+AsyncNameResolver::AsyncNameResolver(int family):
+  status_(STATUS_READY),
+  family_(family)
 {
 {
   // TODO evaluate return value
   // TODO evaluate return value
   ares_init(&channel_);
   ares_init(&channel_);
@@ -76,7 +85,7 @@ void AsyncNameResolver::resolve(const std::string& name)
 {
 {
   hostname_ = name;
   hostname_ = name;
   status_ = STATUS_QUERYING;
   status_ = STATUS_QUERYING;
-  ares_gethostbyname(channel_, name.c_str(), AF_INET, callback, this);
+  ares_gethostbyname(channel_, name.c_str(), family_, callback, this);
 }
 }
 
 
 int AsyncNameResolver::getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const
 int AsyncNameResolver::getFds(fd_set* rfdsPtr, fd_set* wfdsPtr) const

+ 2 - 1
src/AsyncNameResolver.h

@@ -63,13 +63,14 @@ public:
   };
   };
 private:
 private:
   STATUS status_;
   STATUS status_;
+  int family_;
   ares_channel channel_;
   ares_channel channel_;
 
 
   std::vector<std::string> resolvedAddresses_;
   std::vector<std::string> resolvedAddresses_;
   std::string error_;
   std::string error_;
   std::string hostname_;
   std::string hostname_;
 public:
 public:
-  AsyncNameResolver();
+  AsyncNameResolver(int family);
 
 
   ~AsyncNameResolver();
   ~AsyncNameResolver();
 
 

+ 7 - 1
src/DHTEntryPointNameResolveCommand.cc

@@ -81,7 +81,13 @@ bool DHTEntryPointNameResolveCommand::execute()
   }
   }
 #ifdef ENABLE_ASYNC_DNS
 #ifdef ENABLE_ASYNC_DNS
   if(resolver_.isNull()) {
   if(resolver_.isNull()) {
-    resolver_.reset(new AsyncNameResolver());
+    int family;
+    if(e_->getOption()->getAsBool(PREF_ENABLE_ASYNC_DNS6)) {
+      family = AF_UNSPEC;
+    } else {
+      family = AF_INET;
+    }
+    resolver_.reset(new AsyncNameResolver(family));
   }
   }
 #endif // ENABLE_ASYNC_DNS
 #endif // ENABLE_ASYNC_DNS
   try {
   try {

+ 11 - 0
src/OptionHandlerFactory.cc

@@ -192,6 +192,17 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->hide();
     op->hide();
     handlers.push_back(op);
     handlers.push_back(op);
   }
   }
+#ifdef ENABLE_ASYNC_DNS
+  {
+    SharedHandle<OptionHandler> op(new BooleanOptionHandler
+                                   (PREF_ENABLE_ASYNC_DNS6,
+                                    TEXT_ENABLE_ASYNC_DNS6,
+                                    V_FALSE,
+                                    OptionHandler::OPT_ARG));
+    op->addTag(TAG_ADVANCED);
+    handlers.push_back(op);
+  }
+#endif // ENABLE_ASYNC_DNS
 #ifdef ENABLE_DIRECT_IO
 #ifdef ENABLE_DIRECT_IO
   {
   {
     SharedHandle<OptionHandler> op(new BooleanOptionHandler
     SharedHandle<OptionHandler> op(new BooleanOptionHandler

+ 2 - 1
src/download_helper.cc

@@ -162,7 +162,8 @@ const std::set<std::string>& listRequestOptions()
     PREF_HTTP_ACCEPT_GZIP,
     PREF_HTTP_ACCEPT_GZIP,
     PREF_MAX_CONNECTION_PER_SERVER,
     PREF_MAX_CONNECTION_PER_SERVER,
     PREF_MIN_SPLIT_SIZE,
     PREF_MIN_SPLIT_SIZE,
-    PREF_CONDITIONAL_GET
+    PREF_CONDITIONAL_GET,
+    PREF_ENABLE_ASYNC_DNS6
   };
   };
   static std::set<std::string> requestOptions
   static std::set<std::string> requestOptions
     (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS));
     (vbegin(REQUEST_OPTIONS), vend(REQUEST_OPTIONS));

+ 2 - 0
src/prefs.cc

@@ -198,6 +198,8 @@ const std::string PREF_MIN_SPLIT_SIZE("min-split-size");
 const std::string PREF_CONDITIONAL_GET("conditional-get");
 const std::string PREF_CONDITIONAL_GET("conditional-get");
 // value: true | false
 // value: true | false
 const std::string PREF_SELECT_LEAST_USED_HOST("select-least-used-host");
 const std::string PREF_SELECT_LEAST_USED_HOST("select-least-used-host");
+// value: true | false
+const std::string PREF_ENABLE_ASYNC_DNS6("enable-async-dns6");
 
 
 /**
 /**
  * FTP related preferences
  * FTP related preferences

+ 2 - 0
src/prefs.h

@@ -202,6 +202,8 @@ extern const std::string PREF_MIN_SPLIT_SIZE;
 extern const std::string PREF_CONDITIONAL_GET;
 extern const std::string PREF_CONDITIONAL_GET;
 // value: true | false
 // value: true | false
 extern const std::string PREF_SELECT_LEAST_USED_HOST;
 extern const std::string PREF_SELECT_LEAST_USED_HOST;
+// value: true | false
+extern const std::string PREF_ENABLE_ASYNC_DNS6;
 
 
 /**
 /**
  * FTP related preferences
  * FTP related preferences

+ 4 - 0
src/usage_text.h

@@ -710,3 +710,7 @@
     "                              download completes but before seeding.\n" \
     "                              download completes but before seeding.\n" \
     "                              See --on-download-start option for the\n" \
     "                              See --on-download-start option for the\n" \
     "                              requirement of COMMAND.")
     "                              requirement of COMMAND.")
+#define TEXT_ENABLE_ASYNC_DNS6                  \
+  _(" --enable-async-dns6[=true|false] Enable IPv6 name resolution in asynchronous\n" \
+    "                              DNS resolver. This option will be ignored when\n" \
+    "                              --async-dns=false.")