aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-20 08:50:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-20 08:50:35 +0000
commit61a008c4e471cd5081d5c2871949da779246a868 (patch)
tree95f07d0579ec84330e440a3325109cca45ddb809 /src
parent0211530d9b0e02e31eecd14f8565b88de8210025 (diff)
downloadgnunet-61a008c4e471cd5081d5c2871949da779246a868.tar.gz
gnunet-61a008c4e471cd5081d5c2871949da779246a868.zip
make resolver test pass even if primary DNS is down
Diffstat (limited to 'src')
-rw-r--r--src/util/connection.c2
-rw-r--r--src/util/gnunet-service-resolver.c49
-rw-r--r--src/util/resolver_api.c30
-rw-r--r--src/util/server.c16
-rw-r--r--src/util/test_resolver_api.c38
-rw-r--r--src/util/test_resolver_api_data.conf1
6 files changed, 113 insertions, 23 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index a29237de6..80f2cae7f 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -1606,7 +1606,7 @@ SCHEDULE_WRITE:
1606 GNUNET_assert ( (sock->nth.notify_ready != NULL) || (have > 0) ); 1606 GNUNET_assert ( (sock->nth.notify_ready != NULL) || (have > 0) );
1607 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) 1607 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
1608 sock->write_task = 1608 sock->write_task =
1609 GNUNET_SCHEDULER_add_write_net ((have > 0) 1609 GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == NULL)
1610 ? GNUNET_TIME_UNIT_FOREVER_REL 1610 ? GNUNET_TIME_UNIT_FOREVER_REL
1611 : GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), 1611 : GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout),
1612 sock->sock, 1612 sock->sock,
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index ee2cfb3b8..bffe2ce26 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -23,8 +23,6 @@
23 * @brief code to do DNS resolution 23 * @brief code to do DNS resolution
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26
27#include <stdlib.h>
28#include "platform.h" 26#include "platform.h"
29#include "gnunet_disk_lib.h" 27#include "gnunet_disk_lib.h"
30#include "gnunet_getopt_lib.h" 28#include "gnunet_getopt_lib.h"
@@ -440,6 +438,7 @@ handle_get (void *cls,
440 uint16_t msize; 438 uint16_t msize;
441 const struct GNUNET_RESOLVER_GetMessage *msg; 439 const struct GNUNET_RESOLVER_GetMessage *msg;
442 const char *hostname; 440 const char *hostname;
441 const struct sockaddr *sa;
443 uint16_t size; 442 uint16_t size;
444 int direction; 443 int direction;
445 int domain; 444 int domain;
@@ -473,11 +472,51 @@ handle_get (void *cls,
473 } 472 }
474 else 473 else
475 { 474 {
476#if DEBUG_RESOLVER 475#if DEBUG_RESOLVER
476 char buf[INET6_ADDRSTRLEN] buf;
477#endif
478 sa = (const struct sockaddr*) &msg[1];
479 if (size < sizeof (struct sockaddr_in))
480 {
481 GNUNET_break (0);
482 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
483 return;
484 }
485 switch (sa->sa_family)
486 {
487 case AF_INET:
488 if (size != sizeof (struct sockaddr_in))
489 {
490 GNUNET_break (0);
491 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
492 return;
493 }
494#if DEBUG_RESOLVER
495 inet_ntop (AF_INET, sa, buf, size);
496#endif
497 break;
498 case AF_INET6:
499 if (size != sizeof (struct sockaddr_in6))
500 {
501 GNUNET_break (0);
502 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
503 return;
504 }
505#if DEBUG_RESOLVER
506 inet_ntop (AF_INET6, sa, buf, size);
507#endif
508 break;
509 default:
510 GNUNET_break (0);
511 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
512 return;
513 }
514#if DEBUG_RESOLVER
477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
478 _("Resolver asked to look up IP address.\n")); 516 _("Resolver asked to look up IP address `%s'.\n"),
517 buf);
479#endif 518#endif
480 get_ip_as_string (client, (const struct sockaddr *) &msg[1], size); 519 get_ip_as_string (client, sa, size);
481 } 520 }
482} 521}
483 522
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 5c0973f86..6127badeb 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -33,7 +33,6 @@
33#include "gnunet_server_lib.h" 33#include "gnunet_server_lib.h"
34#include "resolver.h" 34#include "resolver.h"
35 35
36
37/** 36/**
38 * Maximum supported length for a hostname 37 * Maximum supported length for a hostname
39 */ 38 */
@@ -239,6 +238,10 @@ GNUNET_RESOLVER_disconnect ()
239 GNUNET_assert (NULL == req_tail); 238 GNUNET_assert (NULL == req_tail);
240 if (NULL != client) 239 if (NULL != client)
241 { 240 {
241#if DEBUG_RESOLVER
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Disconnecting from DNS service\n");
244#endif
242 GNUNET_CLIENT_disconnect (client, GNUNET_NO); 245 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
243 client = NULL; 246 client = NULL;
244 } 247 }
@@ -339,6 +342,10 @@ handle_response (void *cls,
339 const struct sockaddr *sa; 342 const struct sockaddr *sa;
340 socklen_t salen; 343 socklen_t salen;
341 344
345#if DEBUG_RESOLVER
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
347 "Receiving response from DNS service\n");
348#endif
342 if (msg == NULL) 349 if (msg == NULL)
343 { 350 {
344 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 351 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -437,8 +444,9 @@ handle_response (void *cls,
437 { 444 {
438 char *ips = no_resolve (sa, salen); 445 char *ips = no_resolve (sa, salen);
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Resolver returns `%s' for `%s'.\n", ips, 447 "Resolver returns `%s' for `%s'.\n",
441 rh->hostname); 448 ips,
449 (const char*) &rh[1]);
442 GNUNET_free (ips); 450 GNUNET_free (ips);
443 } 451 }
444#endif 452#endif
@@ -601,7 +609,10 @@ process_requests ()
601 msg->direction = htonl (rh->direction); 609 msg->direction = htonl (rh->direction);
602 msg->domain = htonl (rh->domain); 610 msg->domain = htonl (rh->domain);
603 memcpy (&msg[1], &rh[1], rh->data_len); 611 memcpy (&msg[1], &rh[1], rh->data_len);
604 612#if DEBUG_RESOLVER
613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Transmitting DNS resolution request to DNS service\n");
615#endif
605 if (GNUNET_OK != 616 if (GNUNET_OK !=
606 GNUNET_CLIENT_transmit_and_get_response (client, 617 GNUNET_CLIENT_transmit_and_get_response (client,
607 &msg->header, 618 &msg->header,
@@ -633,9 +644,15 @@ reconnect_task (void *cls,
633 return; /* no work pending */ 644 return; /* no work pending */
634 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 645 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
635 return; 646 return;
647#if DEBUG_RESOLVER
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
649 "Trying to connect to DNS service\n");
650#endif
636 client = GNUNET_CLIENT_connect ("resolver", cfg); 651 client = GNUNET_CLIENT_connect ("resolver", cfg);
637 if (NULL == client) 652 if (NULL == client)
638 { 653 {
654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
655 "Failed to connect, will try again later\n");
639 reconnect (); 656 reconnect ();
640 return; 657 return;
641 } 658 }
@@ -677,6 +694,11 @@ reconnect ()
677 break; 694 break;
678 } 695 }
679 } 696 }
697#if DEBUG_RESOLVER
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
699 "Will try to connect to DNS service in %llu ms\n",
700 (unsigned long long) backoff.rel_value);
701#endif
680 r_task = GNUNET_SCHEDULER_add_delayed (backoff, 702 r_task = GNUNET_SCHEDULER_add_delayed (backoff,
681 &reconnect_task, 703 &reconnect_task,
682 NULL); 704 NULL);
diff --git a/src/util/server.c b/src/util/server.c
index d1d0b1aca..33a824e7c 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -375,6 +375,22 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
375 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); 375 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
376 eno = 0; 376 eno = 0;
377 } 377 }
378 else
379 {
380 if (port != 0)
381 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
382 _
383 ("`%s' failed for port %d (%s): address already in use\n"),
384 "bind", port,
385 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
386 else if (serverAddr->sa_family == AF_UNIX)
387 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
388 _
389 ("`%s' failed for `%s': address already in use\n"),
390 "bind",
391 ((const struct sockaddr_un*) serverAddr)->sun_path);
392
393 }
378 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 394 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
379 errno = eno; 395 errno = eno;
380 return NULL; 396 return NULL;
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index d1c343f82..be631e36f 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -54,6 +54,7 @@ check_hostname(void *cls, const struct sockaddr *sa, socklen_t salen)
54 GNUNET_a2s(sa, salen)); 54 GNUNET_a2s(sa, salen));
55} 55}
56 56
57
57static void 58static void
58check_localhost_num(void *cls, const char *hostname) 59check_localhost_num(void *cls, const char *hostname)
59{ 60{
@@ -78,6 +79,7 @@ check_localhost_num(void *cls, const char *hostname)
78 } 79 }
79} 80}
80 81
82
81static void 83static void
82check_localhost(void *cls, const char *hostname) 84check_localhost(void *cls, const char *hostname)
83{ 85{
@@ -223,7 +225,7 @@ run(void *cls, char * const *args,
223 int *ok = cls; 225 int *ok = cls;
224 struct sockaddr_in sa; 226 struct sockaddr_in sa;
225 struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply( 227 struct GNUNET_TIME_Relative timeout = GNUNET_TIME_relative_multiply(
226 GNUNET_TIME_UNIT_MILLISECONDS, 2500); 228 GNUNET_TIME_UNIT_SECONDS, 30);
227 int count_ips = 0; 229 int count_ips = 0;
228 char * own_fqdn; 230 char * own_fqdn;
229 231
@@ -233,15 +235,6 @@ run(void *cls, char * const *args,
233 sa.sin_len = (u_char) sizeof (sa); 235 sa.sin_len = (u_char) sizeof (sa);
234#endif 236#endif
235 sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 237 sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
236 GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127,
237 cls);
238 GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
239 sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
240 GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
241 sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
242 GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout,
243 &check_hostname, cls);
244
245 238
246 /* 239 /*
247 * Looking up our own fqdn 240 * Looking up our own fqdn
@@ -254,7 +247,6 @@ run(void *cls, char * const *args,
254 * Testing non-local DNS resolution 247 * Testing non-local DNS resolution
255 * DNS rootserver to test: a.root-servers.net - 198.41.0.4 248 * DNS rootserver to test: a.root-servers.net - 198.41.0.4
256 */ 249 */
257
258 const char * rootserver_name = ROOTSERVER_NAME; 250 const char * rootserver_name = ROOTSERVER_NAME;
259 struct hostent *rootserver; 251 struct hostent *rootserver;
260 252
@@ -340,10 +332,11 @@ run(void *cls, char * const *args,
340 } 332 }
341 333
342#if DEBUG_RESOLVER 334#if DEBUG_RESOLVER
343 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "System's own reverse name resolution is working\n"); 335 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
336 "System's own reverse name resolution is working\n");
344#endif 337#endif
345 /* Resolve the same using GNUNET */
346 338
339 /* Resolve the same using GNUNET */
347 memset(&sa, 0, sizeof(sa)); 340 memset(&sa, 0, sizeof(sa));
348 sa.sin_family = AF_INET; 341 sa.sin_family = AF_INET;
349#if HAVE_SOCKADDR_IN_SIN_LEN 342#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -356,6 +349,25 @@ run(void *cls, char * const *args,
356#endif 349#endif
357 GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa, 350 GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
358 sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls); 351 sizeof(struct sockaddr), GNUNET_YES, timeout, &check_rootserver_name, cls);
352
353 memset(&sa, 0, sizeof(sa));
354 sa.sin_family = AF_INET;
355#if HAVE_SOCKADDR_IN_SIN_LEN
356 sa.sin_len = (u_char) sizeof (sa);
357#endif
358 sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
359
360 GNUNET_RESOLVER_ip_get("localhost", AF_INET, timeout, &check_127,
361 cls);
362 fprintf (stderr, "Trying to get hostname for 127.0.0.1\n");
363 GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
364 sizeof(struct sockaddr), GNUNET_YES, timeout, &check_localhost, cls);
365
366 GNUNET_RESOLVER_hostname_get((const struct sockaddr *) &sa,
367 sizeof(struct sockaddr), GNUNET_NO, timeout, &check_localhost_num, cls);
368 GNUNET_RESOLVER_hostname_resolve(AF_UNSPEC, timeout,
369 &check_hostname, cls);
370
359} 371}
360 372
361static int 373static int
diff --git a/src/util/test_resolver_api_data.conf b/src/util/test_resolver_api_data.conf
index dde65683a..f776c0bcd 100644
--- a/src/util/test_resolver_api_data.conf
+++ b/src/util/test_resolver_api_data.conf
@@ -4,6 +4,7 @@ SERVICEHOME = /tmp/test-gnunetd-statistics/
4[resolver] 4[resolver]
5PORT = 22354 5PORT = 22354
6HOSTNAME = localhost 6HOSTNAME = localhost
7DEBUG = YES
7 8
8[dns] 9[dns]
9AUTOSTART = NO 10AUTOSTART = NO