/*
This file is part of GNUnet.
- Copyright (C) 2009-2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009-2015 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
GNUNET_RESOLVER_HostnameCallback name_callback;
/**
- * Closure for the respective "callback".
+ * Closure for the callbacks.
*/
void *cls;
* Task handle for making reply callbacks in numeric lookups
* asynchronous, and for timeout handling.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Desired address family.
/**
* Check that the resolver service runs on localhost
* (or equivalent).
+ *
+ * @return #GNUNET_OK if the resolver is properly configured,
+ * #GNUNET_SYSERR otherwise.
*/
-static void
+static int
check_config ()
{
char *hostname;
"HOSTNAME",
&hostname))
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Must specify `%s' for `%s' in configuration!\n"),
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Missing `%s' for `%s' in configuration, DNS resolution will be unavailable.\n"),
"HOSTNAME",
"resolver");
- GNUNET_assert (0);
+ return GNUNET_SYSERR;
}
- if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
- (1 != inet_pton (AF_INET6, hostname, &v6)))
+ if ((1 == inet_pton (AF_INET, hostname, &v4)) ||
+ (1 == inet_pton (AF_INET6, hostname, &v6)))
{
GNUNET_free (hostname);
- return;
+ return GNUNET_OK;
}
i = 0;
while (NULL != loopback[i])
if (0 == strcasecmp (loopback[i++], hostname))
{
GNUNET_free (hostname);
- return;
+ return GNUNET_OK;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Missing `%s' or numeric IP address for `%s' of `%s' in configuration, DNS resolution will be unavailable.\n"),
"localhost",
"HOSTNAME",
"resolver");
GNUNET_free (hostname);
- GNUNET_assert (0);
+ return GNUNET_SYSERR;
}
GNUNET_assert (NULL != cfg);
backoff = GNUNET_TIME_UNIT_MILLISECONDS;
resolver_cfg = cfg;
- check_config ();
+ (void) check_config ();
}
* numeric addresses.
*
* @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request
- * @param tc unused scheduler context
*/
static void
-numeric_resolution (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+numeric_resolution (void *cls)
{
struct GNUNET_RESOLVER_RequestHandle *rh = cls;
struct sockaddr_in v4;
* respective loopback numeric addresses.
*
* @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request
- * @param tc unused scheduler context
*/
static void
-loopback_resolution (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+loopback_resolution (void *cls)
{
struct GNUNET_RESOLVER_RequestHandle *rh = cls;
struct sockaddr_in v4;
rh->addr_callback (rh->cls,
(const struct sockaddr *) &v4,
sizeof (v4));
+
break;
default:
GNUNET_break (0);
* Task executed on system shutdown.
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
s_task = NULL;
GNUNET_RESOLVER_disconnect ();
/* nothing to do, release socket really soon if there is nothing
* else happening... */
s_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&shutdown_task,
NULL);
return;
* Now try to reconnect to the resolver service.
*
* @param cls NULL
- * @param tc scheduler context
*/
static void
-reconnect_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect_task (void *cls)
{
r_task = NULL;
if (NULL == req_head)
return; /* no work pending */
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Trying to connect to DNS service\n");
client = GNUNET_CLIENT_connect ("resolver",
break;
case GNUNET_SYSERR:
/* request was cancelled, remove entirely */
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_CONTAINER_DLL_remove (req_head,
+ req_tail,
+ rh);
GNUNET_free (rh);
break;
default:
* A DNS resolution timed out. Notify the application.
*
* @param cls the `struct GNUNET_RESOLVER_RequestHandle *`
- * @param tc scheduler context
*/
static void
-handle_lookup_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+handle_lookup_timeout (void *cls)
{
struct GNUNET_RESOLVER_RequestHandle *rh = cls;
* conversion and invoke the callback.
*
* @param cls `struct GNUNET_RESOLVER_RequestHandle` for the request
- * @param tc unused scheduler context
*/
static void
-numeric_reverse (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+numeric_reverse (void *cls)
{
struct GNUNET_RESOLVER_RequestHandle *rh = cls;
char *result;
size_t ip_len;
const void *ip;
- check_config ();
+ if (GNUNET_OK != check_config ())
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Resolver not configured correctly.\n"));
+ return NULL;
+ }
+
switch (sa->sa_family)
{
case AF_INET:
gai_strerror (ret));
return NULL;
}
- rval = GNUNET_strdup (ai->ai_canonname);
+ if (NULL != ai->ai_canonname)
+ rval = GNUNET_strdup (ai->ai_canonname);
+ else
+ rval = GNUNET_strdup (hostname);
freeaddrinfo (ai);
return rval;
}