2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/resolver_api.c
23 * @brief resolver for writing a tool
24 * @author Christian Grothoff
27 #include "gnunet_getopt_lib.h"
28 #include "gnunet_os_lib.h"
29 #include "gnunet_client_lib.h"
30 #include "gnunet_container_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_resolver_service.h"
33 #include "gnunet_server_lib.h"
36 #define LOG(kind,...) GNUNET_log_from (kind, "resolver-api", __VA_ARGS__)
38 #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "resolver-api", syscall)
41 * Maximum supported length for a hostname
43 #define MAX_HOSTNAME 1024
47 * Possible hostnames for "loopback".
49 static const char *loopback[] = {
59 static const struct GNUNET_CONFIGURATION_Handle *resolver_cfg;
62 * Our connection to the resolver service, created on-demand, but then
63 * persists until error or shutdown.
65 static struct GNUNET_CLIENT_Connection *client;
68 * Head of DLL of requests.
70 static struct GNUNET_RESOLVER_RequestHandle *req_head;
73 * Tail of DLL of requests.
75 static struct GNUNET_RESOLVER_RequestHandle *req_tail;
78 * How long should we wait to reconnect?
80 static struct GNUNET_TIME_Relative backoff;
83 * Task for reconnecting.
85 static GNUNET_SCHEDULER_TaskIdentifier r_task;
88 * Task ID of shutdown task; only present while we have a
89 * connection to the resolver service.
91 static GNUNET_SCHEDULER_TaskIdentifier s_task;
95 * Handle to a request given to the resolver. Can be used to cancel
96 * the request prior to the timeout or successful execution. Also
97 * used to track our internal state for the request.
99 struct GNUNET_RESOLVER_RequestHandle
103 * Next entry in DLL of requests.
105 struct GNUNET_RESOLVER_RequestHandle *next;
108 * Previous entry in DLL of requests.
110 struct GNUNET_RESOLVER_RequestHandle *prev;
113 * Callback if this is an name resolution request,
116 GNUNET_RESOLVER_AddressCallback addr_callback;
119 * Callback if this is a reverse lookup request,
122 GNUNET_RESOLVER_HostnameCallback name_callback;
125 * Closure for the respective "callback".
130 * When should this request time out?
132 struct GNUNET_TIME_Absolute timeout;
135 * Task handle for numeric lookups.
137 GNUNET_SCHEDULER_TaskIdentifier task;
140 * Desired address family.
145 * Has this request been transmitted to the service?
146 * GNUNET_YES if transmitted
147 * GNUNET_YES if not transmitted
148 * GNUNET_SYSERR when request was canceled
153 * Did we add this request to the queue?
158 * Desired direction (IP to name or name to IP)
163 * GNUNET_YES if a response was received
165 int received_response;
168 * Length of the data that follows this struct.
175 * Check that the resolver service runs on localhost
183 struct sockaddr_in v4;
184 struct sockaddr_in6 v6;
186 memset (&v4, 0, sizeof (v4));
187 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
188 v4.sin_family = AF_INET;
189 #if HAVE_SOCKADDR_IN_SIN_LEN
190 v4.sin_len = sizeof (v4);
192 memset (&v6, 0, sizeof (v6));
193 v6.sin6_family = AF_INET6;
194 #if HAVE_SOCKADDR_IN_SIN_LEN
195 v6.sin6_len = sizeof (v6);
198 GNUNET_CONFIGURATION_get_value_string (resolver_cfg, "resolver",
199 "HOSTNAME", &hostname))
201 LOG (GNUNET_ERROR_TYPE_ERROR,
202 _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
206 if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
207 (1 != inet_pton (AF_INET6, hostname, &v6)))
209 GNUNET_free (hostname);
213 while (loopback[i] != NULL)
214 if (0 == strcasecmp (loopback[i++], hostname))
216 GNUNET_free (hostname);
219 LOG (GNUNET_ERROR_TYPE_ERROR,
221 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
222 "localhost", "HOSTNAME", "resolver");
223 GNUNET_free (hostname);
229 * Create the connection to the resolver service.
231 * @param cfg configuration to use
234 GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
236 GNUNET_assert (NULL != cfg);
237 backoff = GNUNET_TIME_UNIT_MILLISECONDS;
244 * Destroy the connection to the resolver service.
247 GNUNET_RESOLVER_disconnect ()
249 GNUNET_assert (NULL == req_head);
250 GNUNET_assert (NULL == req_tail);
254 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n");
256 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
259 if (r_task != GNUNET_SCHEDULER_NO_TASK)
261 GNUNET_SCHEDULER_cancel (r_task);
262 r_task = GNUNET_SCHEDULER_NO_TASK;
264 if (s_task != GNUNET_SCHEDULER_NO_TASK)
266 GNUNET_SCHEDULER_cancel (s_task);
267 s_task = GNUNET_SCHEDULER_NO_TASK;
273 * Convert IP address to string without DNS resolution.
275 * @param sa the address
276 * @param salen number of bytes in sa
277 * @return address as a string, NULL on error
280 no_resolve (const struct sockaddr *sa, socklen_t salen)
283 char inet4[INET_ADDRSTRLEN];
284 char inet6[INET6_ADDRSTRLEN];
286 if (salen < sizeof (struct sockaddr))
288 switch (sa->sa_family)
291 if (salen != sizeof (struct sockaddr_in))
294 inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
297 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
300 ret = GNUNET_strdup (inet4);
303 if (salen != sizeof (struct sockaddr_in6))
306 inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr,
307 inet6, INET6_ADDRSTRLEN))
309 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
312 ret = GNUNET_strdup (inet6);
323 * Adjust exponential back-off and reconnect to the service.
325 static void reconnect ();
329 * Process pending requests to the resolver.
331 static void process_requests ();
335 * Process response with a hostname for a DNS lookup.
337 * @param cls our "struct GNUNET_RESOLVER_RequestHandle" context
338 * @param msg message with the hostname, NULL on error
341 handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
343 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
345 const char *hostname;
346 const struct sockaddr *sa;
350 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n");
354 if (NULL != rh->name_callback)
355 LOG (GNUNET_ERROR_TYPE_INFO,
356 _("Timeout trying to resolve IP address `%s'.\n"),
357 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
359 LOG (GNUNET_ERROR_TYPE_INFO,
360 _("Timeout trying to resolve hostname `%s'.\n"),
361 (const char *) &rh[1]);
362 /* check if request was canceled */
363 if (rh->was_transmitted != GNUNET_SYSERR)
365 if (NULL != rh->name_callback)
367 /* no reverse lookup was successful, return ip as string */
368 if (rh->received_response == GNUNET_NO)
369 rh->name_callback (rh->cls,
370 no_resolve ((const struct sockaddr *)
371 &rh[1], rh->data_len));
372 /* at least one reverse lookup was successful */
374 rh->name_callback (rh->cls, NULL);
376 if (NULL != rh->addr_callback)
377 rh->addr_callback (rh->cls, NULL, 0);
379 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
381 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
386 if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
389 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
394 size = ntohs (msg->size);
395 /* message contains not data, just header */
396 if (size == sizeof (struct GNUNET_MessageHeader))
398 /* check if request was canceled */
399 if (rh->was_transmitted != GNUNET_SYSERR)
401 if (NULL != rh->name_callback)
402 rh->name_callback (rh->cls, NULL);
403 if (NULL != rh->addr_callback)
404 rh->addr_callback (rh->cls, NULL, 0);
406 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
411 /* return reverse lookup results to caller */
412 if (NULL != rh->name_callback)
414 hostname = (const char *) &msg[1];
415 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
418 if (rh->was_transmitted != GNUNET_SYSERR)
419 rh->name_callback (rh->cls, NULL);
420 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
422 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
428 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s' for IP `%s'.\n"),
429 hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len));
431 if (rh->was_transmitted != GNUNET_SYSERR)
432 rh->name_callback (rh->cls, hostname);
433 rh->received_response = GNUNET_YES;
434 GNUNET_CLIENT_receive (client, &handle_response, rh,
435 GNUNET_TIME_absolute_get_remaining
438 /* return lookup results to caller */
439 if (NULL != rh->addr_callback)
441 sa = (const struct sockaddr *) &msg[1];
442 salen = size - sizeof (struct GNUNET_MessageHeader);
443 if (salen < sizeof (struct sockaddr))
446 if (rh->was_transmitted != GNUNET_SYSERR)
447 rh->addr_callback (rh->cls, NULL, 0);
448 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
450 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
457 char *ips = no_resolve (sa, salen);
459 LOG (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n",
460 ips, (const char *) &rh[1]);
464 rh->addr_callback (rh->cls, sa, salen);
465 GNUNET_CLIENT_receive (client, &handle_response, rh,
466 GNUNET_TIME_absolute_get_remaining
473 * We've been asked to lookup the address for a hostname and were
474 * given a valid numeric string. Perform the callbacks for the
477 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
478 * @param tc unused scheduler context
481 numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
483 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
484 struct sockaddr_in v4;
485 struct sockaddr_in6 v6;
486 const char *hostname;
488 memset (&v4, 0, sizeof (v4));
489 v4.sin_family = AF_INET;
490 #if HAVE_SOCKADDR_IN_SIN_LEN
491 v4.sin_len = sizeof (v4);
493 memset (&v6, 0, sizeof (v6));
494 v6.sin6_family = AF_INET6;
495 #if HAVE_SOCKADDR_IN_SIN_LEN
496 v6.sin6_len = sizeof (v6);
498 hostname = (const char *) &rh[1];
499 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
500 (1 == inet_pton (AF_INET, hostname, &v4.sin_addr)))
502 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
503 if ((rh->domain == AF_UNSPEC) &&
504 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
506 /* this can happen on some systems IF "hostname" is "localhost" */
507 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6,
510 rh->addr_callback (rh->cls, NULL, 0);
514 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
515 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
517 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
518 rh->addr_callback (rh->cls, NULL, 0);
522 /* why are we here? this task should not have been scheduled! */
529 * We've been asked to lookup the address for a hostname and were
530 * given a variant of "loopback". Perform the callbacks for the
531 * respective loopback numeric addresses.
533 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
534 * @param tc unused scheduler context
537 loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
539 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
540 struct sockaddr_in v4;
541 struct sockaddr_in6 v6;
543 memset (&v4, 0, sizeof (v4));
544 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
545 v4.sin_family = AF_INET;
546 #if HAVE_SOCKADDR_IN_SIN_LEN
547 v4.sin_len = sizeof (v4);
549 memset (&v6, 0, sizeof (v6));
550 v6.sin6_family = AF_INET6;
551 #if HAVE_SOCKADDR_IN_SIN_LEN
552 v6.sin6_len = sizeof (v6);
554 v6.sin6_addr = in6addr_loopback;
558 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
561 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
564 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
565 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
571 rh->addr_callback (rh->cls, NULL, 0);
577 * Task executed on system shutdown.
580 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
582 s_task = GNUNET_SCHEDULER_NO_TASK;
583 GNUNET_RESOLVER_disconnect ();
588 * Process pending requests to the resolver.
593 struct GNUNET_RESOLVER_GetMessage *msg;
594 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
595 struct GNUNET_RESOLVER_RequestHandle *rh;
605 /* nothing to do, release socket really soon if there is nothing
606 * else happening... */
608 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
609 &shutdown_task, NULL);
612 if (GNUNET_YES == rh->was_transmitted)
613 return; /* waiting for reply */
614 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
616 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
617 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
618 msg->direction = htonl (rh->direction);
619 msg->domain = htonl (rh->domain);
620 memcpy (&msg[1], &rh[1], rh->data_len);
622 LOG (GNUNET_ERROR_TYPE_DEBUG,
623 "Transmitting DNS resolution request to DNS service\n");
626 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
627 GNUNET_TIME_absolute_get_remaining
628 (rh->timeout), GNUNET_YES,
629 &handle_response, rh))
631 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
636 rh->was_transmitted = GNUNET_YES;
641 * Now try to reconnect to the resolver service.
644 * @param tc scheduler context
647 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
649 r_task = GNUNET_SCHEDULER_NO_TASK;
650 if (NULL == req_head)
651 return; /* no work pending */
652 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
655 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to DNS service\n");
657 client = GNUNET_CLIENT_connect ("resolver", resolver_cfg);
660 LOG (GNUNET_ERROR_TYPE_DEBUG,
661 "Failed to connect, will try again later\n");
670 * Adjust exponential back-off and reconnect to the service.
675 struct GNUNET_RESOLVER_RequestHandle *rh;
677 if (GNUNET_SCHEDULER_NO_TASK != r_task)
679 GNUNET_assert (NULL == client);
680 if (NULL != (rh = req_head))
682 switch (rh->was_transmitted)
685 /* nothing more to do */
688 /* disconnected, transmit again! */
689 rh->was_transmitted = GNUNET_NO;
692 /* request was cancelled, remove entirely */
693 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
702 LOG (GNUNET_ERROR_TYPE_DEBUG,
703 "Will try to connect to DNS service in %llu ms\n",
704 (unsigned long long) backoff.rel_value);
706 GNUNET_assert (NULL != resolver_cfg);
707 r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL);
708 backoff = GNUNET_TIME_relative_multiply (backoff, 2);
713 * Convert a string to one or more IP addresses.
715 * @param hostname the hostname to resolve
716 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
717 * @param callback function to call with addresses
718 * @param callback_cls closure for callback
719 * @param timeout how long to try resolving
720 * @return handle that can be used to cancel the request, NULL on error
722 struct GNUNET_RESOLVER_RequestHandle *
723 GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
724 struct GNUNET_TIME_Relative timeout,
725 GNUNET_RESOLVER_AddressCallback callback,
728 struct GNUNET_RESOLVER_RequestHandle *rh;
734 slen = strlen (hostname) + 1;
735 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
736 GNUNET_SERVER_MAX_MESSAGE_SIZE)
741 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
743 rh->addr_callback = callback;
744 rh->cls = callback_cls;
745 memcpy (&rh[1], hostname, slen);
747 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
748 rh->direction = GNUNET_NO;
749 /* first, check if this is a numeric address */
750 if (((1 == inet_pton (AF_INET, hostname, &v4)) &&
751 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
752 ((1 == inet_pton (AF_INET6, hostname, &v6)) &&
753 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
755 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
758 /* then, check if this is a loopback address */
760 while (loopback[i] != NULL)
761 if (0 == strcasecmp (loopback[i++], hostname))
763 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
766 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
767 rh->was_queued = GNUNET_YES;
768 if (s_task != GNUNET_SCHEDULER_NO_TASK)
770 GNUNET_SCHEDULER_cancel (s_task);
771 s_task = GNUNET_SCHEDULER_NO_TASK;
779 * We've been asked to convert an address to a string without
780 * a reverse lookup. Do it.
782 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
783 * @param tc unused scheduler context
786 numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
788 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
791 result = no_resolve ((const struct sockaddr *) &rh[1], rh->data_len);
793 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
797 rh->name_callback (rh->cls, result);
798 GNUNET_free (result);
800 rh->name_callback (rh->cls, NULL);
806 * Get an IP address as a string.
808 * @param sa host address
809 * @param salen length of host address
810 * @param do_resolve use GNUNET_NO to return numeric hostname
811 * @param timeout how long to try resolving
812 * @param callback function to call with hostnames
813 * last callback is NULL when finished
814 * @param cls closure for callback
815 * @return handle that can be used to cancel the request
817 struct GNUNET_RESOLVER_RequestHandle *
818 GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
820 struct GNUNET_TIME_Relative timeout,
821 GNUNET_RESOLVER_HostnameCallback callback,
824 struct GNUNET_RESOLVER_RequestHandle *rh;
827 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
828 rh->name_callback = callback;
830 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
831 memcpy (&rh[1], sa, salen);
832 rh->data_len = salen;
833 rh->direction = GNUNET_YES;
834 rh->received_response = GNUNET_NO;
835 if (GNUNET_NO == do_resolve)
837 rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
840 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
841 GNUNET_SERVER_MAX_MESSAGE_SIZE)
847 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
848 rh->was_queued = GNUNET_YES;
849 if (s_task != GNUNET_SCHEDULER_NO_TASK)
851 GNUNET_SCHEDULER_cancel (s_task);
852 s_task = GNUNET_SCHEDULER_NO_TASK;
860 * Get local fully qualified domain name
865 GNUNET_RESOLVER_local_fqdn_get ()
867 struct hostent *host;
868 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
870 if (0 != gethostname (hostname, sizeof (hostname) - 1))
872 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
877 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"), hostname);
879 host = gethostbyname (hostname);
882 LOG (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
883 hstrerror (h_errno));
886 return GNUNET_strdup (host->h_name);
891 * Looking our own hostname.
893 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
894 * @param callback function to call with addresses
895 * @param cls closure for callback
896 * @param timeout how long to try resolving
897 * @return handle that can be used to cancel the request, NULL on error
899 struct GNUNET_RESOLVER_RequestHandle *
900 GNUNET_RESOLVER_hostname_resolve (int domain,
901 struct GNUNET_TIME_Relative timeout,
902 GNUNET_RESOLVER_AddressCallback callback,
905 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
907 if (0 != gethostname (hostname, sizeof (hostname) - 1))
909 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
914 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"), hostname);
916 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls);
921 * Cancel a request that is still pending with the resolver.
922 * Note that a client MUST NOT cancel a request that has
923 * been completed (i.e, the callback has been called to
924 * signal timeout or the final result).
926 * @param rh handle of request to cancel
929 GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
931 if (rh->task != GNUNET_SCHEDULER_NO_TASK)
933 GNUNET_SCHEDULER_cancel (rh->task);
934 rh->task = GNUNET_SCHEDULER_NO_TASK;
936 if (rh->was_transmitted == GNUNET_NO)
938 if (rh->was_queued == GNUNET_YES)
939 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
943 GNUNET_assert (rh->was_transmitted == GNUNET_YES);
944 rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
948 /* end of resolver_api.c */