[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r7786 - in GNUnet: . src/util/network
From: |
gnunet |
Subject: |
[GNUnet-SVN] r7786 - in GNUnet: . src/util/network |
Date: |
Wed, 15 Oct 2008 07:20:06 -0600 (MDT) |
Author: holindho
Date: 2008-10-15 07:20:02 -0600 (Wed, 15 Oct 2008)
New Revision: 7786
Modified:
GNUnet/configure.ac
GNUnet/src/util/network/Makefile.am
GNUnet/src/util/network/dns.c
Log:
c-ares support
Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2008-10-15 05:58:23 UTC (rev 7785)
+++ GNUnet/configure.ac 2008-10-15 13:20:02 UTC (rev 7786)
@@ -701,10 +701,42 @@
# restore LIBS
LIBS=$SAVE_LIBS
+# c-ares (asynch dns)
+c_ares=0
+AC_MSG_CHECKING([for c-ares])
+AC_ARG_WITH(c-ares,
+ [ --with-c-ares=PFX Base of c-ares installation],
+ [AC_MSG_RESULT([$with_c_ares])
+ case $with_c_ares in
+ no)
+ ;;
+ yes)
+ AC_CHECK_HEADERS(ares.h,
+ AC_CHECK_LIB([cares], [ares_process_fd],
+ c_ares=1))
+ ;;
+ *)
+ LDFLAGS="-L$with_c_ares/lib $LDFLAGS"
+ CPPFLAGS="-I$with_c_ares/include $CPPFLAGS"
+ AC_CHECK_HEADERS(ares.h,
+ AC_CHECK_LIB([cares], [ares_process_fd],
+ EXT_LIB_PATH="-L$with_c_ares/lib $EXT_LIB_PATH"
+ c_ares=1))
+ ;;
+ esac
+ ],
+ [AC_MSG_RESULT([--with-c-ares not specified])
+ AC_CHECK_HEADERS(ares.h,
+ AC_CHECK_LIB([cares], [ares_process_fd],
+ c_ares=1))])
+AM_CONDITIONAL(HAVE_C_ARES, test x$c_ares = x1)
+AC_DEFINE_UNQUOTED([HAVE_C_ARES], $c_ares, [We have c-ares])
+# restore LIBS
+LIBS=$SAVE_LIBS
+
# GNU adns
adns=0
-AC_CHECK_LIB([adns],[adns_init])
AC_MSG_CHECKING([for GNU adns])
AC_ARG_WITH(adns,
[ --with-adns=PFX Base of GNU adns installation],
@@ -998,9 +1030,9 @@
AC_MSG_NOTICE([WARNING: Guile not found, gnunet-setup will not be installed.])
fi
-if test "$adns" != 1
+if test "$adns" != 1 -a "$c_ares" != 1
then
- AC_MSG_NOTICE([WARNING: GNU adns not found, will use synchronous DNS
resolution.])
+ AC_MSG_NOTICE([WARNING: Asynchronous resolver (adns or c-ares) not found,
will use synchronous DNS resolution.])
fi
AC_MSG_NOTICE([********************************************
Modified: GNUnet/src/util/network/Makefile.am
===================================================================
--- GNUnet/src/util/network/Makefile.am 2008-10-15 05:58:23 UTC (rev 7785)
+++ GNUnet/src/util/network/Makefile.am 2008-10-15 13:20:02 UTC (rev 7786)
@@ -5,9 +5,13 @@
noinst_LTLIBRARIES = \
libnetwork.la
+if HAVE_C_ARES
+AR_LINK=-lcares
+else
if HAVE_ADNS
-ADNS_LINK=-ladns
+AR_LINK=-ladns
endif
+endif
libnetwork_la_SOURCES = \
dns.c \
@@ -16,7 +20,7 @@
ip.c \
ipcheck.c \
select.c
-libnetwork_la_LIBADD = $(ADNS_LINK)
+libnetwork_la_LIBADD = $(AR_LINK)
check_PROGRAMS = \
ipchecktest \
Modified: GNUnet/src/util/network/dns.c
===================================================================
--- GNUnet/src/util/network/dns.c 2008-10-15 05:58:23 UTC (rev 7785)
+++ GNUnet/src/util/network/dns.c 2008-10-15 13:20:02 UTC (rev 7786)
@@ -28,7 +28,9 @@
#include "platform.h"
#include "gnunet_util_network.h"
-#if HAVE_ADNS
+#if HAVE_C_ARES
+#include <ares.h>
+#elif HAVE_ADNS
#include <adns.h>
#endif
@@ -41,8 +43,10 @@
GNUNET_CronTime last_refresh;
GNUNET_CronTime last_request;
unsigned int salen;
-#if HAVE_ADNS
+#if HAVE_C_ARES
int posted;
+#elif HAVE_ADNS
+ int posted;
adns_query query;
#endif
};
@@ -51,14 +55,96 @@
static struct GNUNET_Mutex *lock;
-#if HAVE_ADNS
+#if HAVE_C_ARES
+static int ar_init;
+
+static ares_channel ar_channel;
+#elif HAVE_ADNS
static int a_init;
static adns_state a_state;
#endif
-#if HAVE_ADNS
+#if HAVE_C_ARES
+static void ar_callback(void *arg, int status, int timeouts,
+ struct hostent *ent)
+{
+ struct IPCache *cache = (struct IPCache *)arg;
+
+ if (cache == NULL)
+ return;
+
+ if (status == ARES_SUCCESS && ent != NULL)
+ cache->addr = GNUNET_strdup (ent->h_name);
+
+ cache->posted = GNUNET_NO;
+}
+
static void
+ar_resolve (struct IPCache *cache)
+{
+ int socks[ARES_GETSOCK_MAXNUM];
+ int sockmask;
+ int i;
+ int c;
+
+ if (ar_init == 0)
+ {
+ ar_init = 1;
+ ares_init (&ar_channel);
+ }
+
+ if (cache->posted == GNUNET_NO)
+ {
+ switch (cache->sa->sa_family)
+ {
+ case AF_INET:
+ ares_gethostbyaddr (ar_channel,
+ &((struct sockaddr_in *) cache->sa)->sin_addr,
+ sizeof (struct in_addr), AF_INET,
+ ar_callback, cache);
+ cache->posted = GNUNET_YES;
+ break;
+ case AF_INET6:
+ ares_gethostbyaddr (ar_channel,
+ &((struct sockaddr_in6 *) cache->sa)->sin6_addr,
+ sizeof (struct in6_addr), AF_INET6,
+ ar_callback, cache);
+ cache->posted = GNUNET_YES;
+ break;
+ default:
+ break;
+ }
+ }
+
+ sockmask = ares_getsock(ar_channel, socks, ARES_GETSOCK_MAXNUM);
+ c = 0;
+ for(i = 0; i < ARES_GETSOCK_MAXNUM; i++)
+ {
+ int r, w;
+
+ r = w = 0;
+ if(ARES_GETSOCK_READABLE(sockmask, i))
+ r = 1;
+ if(ARES_GETSOCK_WRITABLE(sockmask, i))
+ w = 1;
+ if(r != 0 || w != 0)
+ {
+ ares_process_fd(ar_channel,
+ r != 0 ? socks[i] : ARES_SOCKET_BAD,
+ w != 0 ? socks[i] : ARES_SOCKET_BAD);
+ c++;
+ }
+ else
+ break;
+ }
+
+ /* if ares_process_fd wasn't called above, call here to process time-outs */
+ if (c == 0)
+ ares_process_fd(ar_channel, ARES_SOCKET_BAD,ARES_SOCKET_BAD);
+}
+#elif HAVE_ADNS
+static void
adns_resolve (struct IPCache *cache)
{
adns_answer *answer;
@@ -137,7 +223,13 @@
static void
cache_resolve (struct IPCache *cache)
{
-#if HAVE_ADNS
+#if HAVE_C_ARES
+ if (cache->sa->sa_family == AF_INET || cache->sa->sa_family == AF_INET6)
+ {
+ ar_resolve (cache);
+ return;
+ }
+#elif HAVE_ADNS
if (cache->sa->sa_family == AF_INET)
{
adns_resolve (cache);
@@ -160,7 +252,7 @@
struct IPCache *ret;
ret = GNUNET_malloc (sizeof (struct IPCache));
-#if HAVE_ADNS
+#if HAVE_ADNS | HAVE_C_ARES
ret->posted = GNUNET_NO;
#endif
ret->next = head;
@@ -239,7 +331,10 @@
{
if (cache->last_request + 60 * GNUNET_CRON_MINUTES < now)
{
-#if HAVE_ADNS
+#if HAVE_C_ARES
+ if (cache->posted == GNUNET_YES) /* ares can't cancel single reqs */
+ continue;
+#elif HAVE_ADNS
if (cache->posted == GNUNET_YES)
{
adns_cancel (cache->query);
@@ -277,7 +372,7 @@
cache->salen = 0;
cache_resolve (cache);
}
-#if HAVE_ADNS
+#if HAVE_ADNS | HAVE_C_ARES
if (cache->posted == GNUNET_YES)
{
cache_resolve (cache);
@@ -578,10 +673,18 @@
void __attribute__ ((destructor)) GNUNET_dns_ltdl_fini ()
{
struct IPCache *pos;
+
+#if HAVE_C_ARES
+ if (ar_init != 0)
+ {
+ ar_init = 0;
+ ares_destroy (ar_channel);
+ }
+#endif
while (head != NULL)
{
pos = head->next;
-#if HAVE_ADNS
+#if HAVE_ADNS & !HAVE_C_ARES
if (head->posted == GNUNET_YES)
{
adns_cancel (head->query);
@@ -593,7 +696,7 @@
GNUNET_free (head);
head = pos;
}
-#if HAVE_ADNS
+#if HAVE_ADNS & !HAVE_C_ARES
if (a_init != 0)
{
a_init = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r7786 - in GNUnet: . src/util/network,
gnunet <=