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,
* @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"
uint16_t msize;
const struct GNUNET_RESOLVER_GetMessage *msg;
const char *hostname;
+ const struct sockaddr *sa;
uint16_t size;
int direction;
int domain;
}
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);
}
}
#include "gnunet_server_lib.h"
#include "resolver.h"
-
/**
* Maximum supported length for a hostname
*/
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;
}
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,
{
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
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,
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;
}
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);
(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;
GNUNET_a2s(sa, salen));
}
+
static void
check_localhost_num(void *cls, const char *hostname)
{
}
}
+
static void
check_localhost(void *cls, const char *hostname)
{
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;
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
* 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;
}
#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 */
+ /* Resolve the same using GNUNET */
memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
#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
[resolver]
PORT = 22354
HOSTNAME = localhost
+DEBUG = YES
[dns]
AUTOSTART = NO