[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r15718 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r15718 - gnunet/src/util |
Date: |
Mon, 20 Jun 2011 10:50:35 +0200 |
Author: grothoff
Date: 2011-06-20 10:50:35 +0200 (Mon, 20 Jun 2011)
New Revision: 15718
Modified:
gnunet/src/util/connection.c
gnunet/src/util/gnunet-service-resolver.c
gnunet/src/util/resolver_api.c
gnunet/src/util/server.c
gnunet/src/util/test_resolver_api.c
gnunet/src/util/test_resolver_api_data.conf
Log:
make resolver test pass even if primary DNS is down
Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c 2011-06-20 07:47:16 UTC (rev 15717)
+++ gnunet/src/util/connection.c 2011-06-20 08:50:35 UTC (rev 15718)
@@ -1606,7 +1606,7 @@
GNUNET_assert ( (sock->nth.notify_ready != NULL) || (have > 0) );
if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
sock->write_task =
- GNUNET_SCHEDULER_add_write_net ((have > 0)
+ GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == NULL)
? GNUNET_TIME_UNIT_FOREVER_REL
: GNUNET_TIME_absolute_get_remaining
(sock->nth.transmit_timeout),
sock->sock,
Modified: gnunet/src/util/gnunet-service-resolver.c
===================================================================
--- gnunet/src/util/gnunet-service-resolver.c 2011-06-20 07:47:16 UTC (rev
15717)
+++ gnunet/src/util/gnunet-service-resolver.c 2011-06-20 08:50:35 UTC (rev
15718)
@@ -23,8 +23,6 @@
* @brief code to do DNS resolution
* @author Christian Grothoff
*/
-
-#include <stdlib.h>
#include "platform.h"
#include "gnunet_disk_lib.h"
#include "gnunet_getopt_lib.h"
@@ -440,6 +438,7 @@
uint16_t msize;
const struct GNUNET_RESOLVER_GetMessage *msg;
const char *hostname;
+ const struct sockaddr *sa;
uint16_t size;
int direction;
int domain;
@@ -473,11 +472,51 @@
}
else
{
-#if DEBUG_RESOLVER
+#if DEBUG_RESOLVER
+ char buf[INET6_ADDRSTRLEN] buf;
+#endif
+ sa = (const struct sockaddr*) &msg[1];
+ if (size < sizeof (struct sockaddr_in))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ if (size != sizeof (struct sockaddr_in))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+#if DEBUG_RESOLVER
+ inet_ntop (AF_INET, sa, buf, size);
+#endif
+ break;
+ case AF_INET6:
+ if (size != sizeof (struct sockaddr_in6))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+#if DEBUG_RESOLVER
+ inet_ntop (AF_INET6, sa, buf, size);
+#endif
+ break;
+ default:
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+#if DEBUG_RESOLVER
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Resolver asked to look up IP address.\n"));
+ _("Resolver asked to look up IP address `%s'.\n"),
+ buf);
#endif
- get_ip_as_string (client, (const struct sockaddr *) &msg[1], size);
+ get_ip_as_string (client, sa, size);
}
}
Modified: gnunet/src/util/resolver_api.c
===================================================================
--- gnunet/src/util/resolver_api.c 2011-06-20 07:47:16 UTC (rev 15717)
+++ gnunet/src/util/resolver_api.c 2011-06-20 08:50:35 UTC (rev 15718)
@@ -33,7 +33,6 @@
#include "gnunet_server_lib.h"
#include "resolver.h"
-
/**
* Maximum supported length for a hostname
*/
@@ -239,6 +238,10 @@
GNUNET_assert (NULL == req_tail);
if (NULL != client)
{
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting from DNS service\n");
+#endif
GNUNET_CLIENT_disconnect (client, GNUNET_NO);
client = NULL;
}
@@ -339,6 +342,10 @@
const struct sockaddr *sa;
socklen_t salen;
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receiving response from DNS service\n");
+#endif
if (msg == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -437,8 +444,9 @@
{
char *ips = no_resolve (sa, salen);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Resolver returns `%s' for `%s'.\n", ips,
- rh->hostname);
+ "Resolver returns `%s' for `%s'.\n",
+ ips,
+ (const char*) &rh[1]);
GNUNET_free (ips);
}
#endif
@@ -601,7 +609,10 @@
msg->direction = htonl (rh->direction);
msg->domain = htonl (rh->domain);
memcpy (&msg[1], &rh[1], rh->data_len);
-
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting DNS resolution request to DNS service\n");
+#endif
if (GNUNET_OK !=
GNUNET_CLIENT_transmit_and_get_response (client,
&msg->header,
@@ -633,9 +644,15 @@
return; /* no work pending */
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Trying to connect to DNS service\n");
+#endif
client = GNUNET_CLIENT_connect ("resolver", cfg);
if (NULL == client)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to connect, will try again later\n");
reconnect ();
return;
}
@@ -677,6 +694,11 @@
break;
}
}
+#if DEBUG_RESOLVER
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will try to connect to DNS service in %llu ms\n",
+ (unsigned long long) backoff.rel_value);
+#endif
r_task = GNUNET_SCHEDULER_add_delayed (backoff,
&reconnect_task,
NULL);
Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c 2011-06-20 07:47:16 UTC (rev 15717)
+++ gnunet/src/util/server.c 2011-06-20 08:50:35 UTC (rev 15718)
@@ -375,6 +375,22 @@
(serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
eno = 0;
}
+ else
+ {
+ if (port != 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("`%s' failed for port %d (%s): address already in
use\n"),
+ "bind", port,
+ (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
+ else if (serverAddr->sa_family == AF_UNIX)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("`%s' failed for `%s': address already in use\n"),
+ "bind",
+ ((const struct sockaddr_un*) serverAddr)->sun_path);
+
+ }
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = eno;
return NULL;
Modified: gnunet/src/util/test_resolver_api.c
===================================================================
--- gnunet/src/util/test_resolver_api.c 2011-06-20 07:47:16 UTC (rev 15717)
+++ gnunet/src/util/test_resolver_api.c 2011-06-20 08:50:35 UTC (rev 15718)
@@ -54,6 +54,7 @@
GNUNET_a2s(sa, salen));
}
+
static void
check_localhost_num(void *cls, const char *hostname)
{
@@ -78,6 +79,7 @@
}
}
+
static void
check_localhost(void *cls, const char *hostname)
{
@@ -223,7 +225,7 @@
int *ok = cls;
struct sockaddr_in sa;
struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_MILLISECONDS, 2500);
+ GNUNET_TIME_UNIT_SECONDS, 30);
int count_ips = 0;
char * own_fqdn;
@@ -233,16 +235,7 @@
sa.sin_len = (u_char) sizeof (sa);
#endif
sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127,
- cls);
- GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
- sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
- GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
- sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
- GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout,
- &check_hostname, cls);
-
/*
* Looking up our own fqdn
*/
@@ -254,7 +247,6 @@
* Testing non-local DNS resolution
* DNS rootserver to test: a.root-servers.net - 198.41.0.4
*/
-
const char * rootserver_name = ROOTSERVER_NAME;
struct hostent *rootserver;
@@ -340,10 +332,11 @@
}
#if DEBUG_RESOLVER
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own reverse name resolution is
working\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "System's own reverse name resolution is working\n");
#endif
+
/* Resolve the same using GNUNET */
-
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -356,6 +349,25 @@
#endif
GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name,
cls);
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sin_family = AF_INET;
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ sa.sin_len = (u_char) sizeof (sa);
+#endif
+ sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127,
+ cls);
+ fprintf (stderr, "Trying to get hostname for 127.0.0.1\n");
+ GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
+ sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
+
+ GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
+ sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
+ GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout,
+ &check_hostname, cls);
+
}
static int
Modified: gnunet/src/util/test_resolver_api_data.conf
===================================================================
--- gnunet/src/util/test_resolver_api_data.conf 2011-06-20 07:47:16 UTC (rev
15717)
+++ gnunet/src/util/test_resolver_api_data.conf 2011-06-20 08:50:35 UTC (rev
15718)
@@ -4,6 +4,7 @@
[resolver]
PORT = 22354
HOSTNAME = localhost
+DEBUG = YES
[dns]
AUTOSTART = NO
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r15718 - gnunet/src/util,
gnunet <=