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"
37 * Maximum supported length for a hostname
39 #define MAX_HOSTNAME 1024
43 * Possible hostnames for "loopback".
45 static const char *loopback[] = {
55 static const struct GNUNET_CONFIGURATION_Handle *resolver_cfg;
58 * Our connection to the resolver service, created on-demand, but then
59 * persists until error or shutdown.
61 static struct GNUNET_CLIENT_Connection *client;
64 * Head of DLL of requests.
66 static struct GNUNET_RESOLVER_RequestHandle *req_head;
69 * Tail of DLL of requests.
71 static struct GNUNET_RESOLVER_RequestHandle *req_tail;
74 * How long should we wait to reconnect?
76 static struct GNUNET_TIME_Relative backoff;
79 * Task for reconnecting.
81 static GNUNET_SCHEDULER_TaskIdentifier r_task;
84 * Task ID of shutdown task; only present while we have a
85 * connection to the resolver service.
87 static GNUNET_SCHEDULER_TaskIdentifier s_task;
91 * Handle to a request given to the resolver. Can be used to cancel
92 * the request prior to the timeout or successful execution. Also
93 * used to track our internal state for the request.
95 struct GNUNET_RESOLVER_RequestHandle
99 * Next entry in DLL of requests.
101 struct GNUNET_RESOLVER_RequestHandle *next;
104 * Previous entry in DLL of requests.
106 struct GNUNET_RESOLVER_RequestHandle *prev;
109 * Callback if this is an name resolution request,
112 GNUNET_RESOLVER_AddressCallback addr_callback;
115 * Callback if this is a reverse lookup request,
118 GNUNET_RESOLVER_HostnameCallback name_callback;
121 * Closure for the respective "callback".
126 * When should this request time out?
128 struct GNUNET_TIME_Absolute timeout;
131 * Task handle for numeric lookups.
133 GNUNET_SCHEDULER_TaskIdentifier task;
136 * Desired address family.
141 * Has this request been transmitted to the service?
142 * GNUNET_YES if transmitted
143 * GNUNET_YES if not transmitted
144 * GNUNET_SYSERR when request was canceled
149 * Did we add this request to the queue?
154 * Desired direction (IP to name or name to IP)
159 * GNUNET_YES if a response was received
161 int received_response;
164 * Length of the data that follows this struct.
171 * Check that the resolver service runs on localhost
179 struct sockaddr_in v4;
180 struct sockaddr_in6 v6;
182 memset (&v4, 0, sizeof (v4));
183 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
184 v4.sin_family = AF_INET;
185 #if HAVE_SOCKADDR_IN_SIN_LEN
186 v4.sin_len = sizeof (v4);
188 memset (&v6, 0, sizeof (v6));
189 v6.sin6_family = AF_INET6;
190 #if HAVE_SOCKADDR_IN_SIN_LEN
191 v6.sin6_len = sizeof (v6);
194 GNUNET_CONFIGURATION_get_value_string (resolver_cfg, "resolver",
195 "HOSTNAME", &hostname))
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
202 if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
203 (1 != inet_pton (AF_INET6, hostname, &v6)))
205 GNUNET_free (hostname);
209 while (loopback[i] != NULL)
210 if (0 == strcasecmp (loopback[i++], hostname))
212 GNUNET_free (hostname);
215 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
218 "localhost", "HOSTNAME", "resolver");
219 GNUNET_free (hostname);
225 * Create the connection to the resolver service.
227 * @param cfg configuration to use
230 GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
232 GNUNET_assert (NULL != cfg);
233 backoff = GNUNET_TIME_UNIT_MILLISECONDS;
240 * Destroy the connection to the resolver service.
243 GNUNET_RESOLVER_disconnect ()
245 GNUNET_assert (NULL == req_head);
246 GNUNET_assert (NULL == req_tail);
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n");
252 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
255 if (r_task != GNUNET_SCHEDULER_NO_TASK)
257 GNUNET_SCHEDULER_cancel (r_task);
258 r_task = GNUNET_SCHEDULER_NO_TASK;
260 if (s_task != GNUNET_SCHEDULER_NO_TASK)
262 GNUNET_SCHEDULER_cancel (s_task);
263 s_task = GNUNET_SCHEDULER_NO_TASK;
269 * Convert IP address to string without DNS resolution.
271 * @param sa the address
272 * @param salen number of bytes in sa
273 * @return address as a string, NULL on error
276 no_resolve (const struct sockaddr *sa, socklen_t salen)
279 char inet4[INET_ADDRSTRLEN];
280 char inet6[INET6_ADDRSTRLEN];
282 if (salen < sizeof (struct sockaddr))
284 switch (sa->sa_family)
287 if (salen != sizeof (struct sockaddr_in))
290 inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
293 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
296 ret = GNUNET_strdup (inet4);
299 if (salen != sizeof (struct sockaddr_in6))
302 inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, inet6,
305 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
308 ret = GNUNET_strdup (inet6);
319 * Adjust exponential back-off and reconnect to the service.
326 * Process pending requests to the resolver.
333 * Process response with a hostname for a DNS lookup.
335 * @param cls our "struct GNUNET_RESOLVER_RequestHandle" context
336 * @param msg message with the hostname, NULL on error
339 handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
341 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
343 const char *hostname;
344 const struct sockaddr *sa;
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n");
352 if (NULL != rh->name_callback)
353 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
354 _("Timeout trying to resolve IP address `%s'.\n"),
355 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
357 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
358 _("Timeout trying to resolve hostname `%s'.\n"),
359 (const char *) &rh[1]);
360 /* check if request was canceled */
361 if (rh->was_transmitted != GNUNET_SYSERR)
363 if (NULL != rh->name_callback)
365 /* no reverse lookup was successful, return ip as string */
366 if (rh->received_response == GNUNET_NO)
367 rh->name_callback (rh->cls,
368 no_resolve ((const struct sockaddr *) &rh[1],
370 /* at least one reverse lookup was successful */
372 rh->name_callback (rh->cls, NULL);
374 if (NULL != rh->addr_callback)
375 rh->addr_callback (rh->cls, NULL, 0);
377 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
379 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
384 if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
387 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
392 size = ntohs (msg->size);
393 /* message contains not data, just header */
394 if (size == sizeof (struct GNUNET_MessageHeader))
396 /* check if request was canceled */
397 if (rh->was_transmitted != GNUNET_SYSERR)
399 if (NULL != rh->name_callback)
400 rh->name_callback (rh->cls, NULL);
401 if (NULL != rh->addr_callback)
402 rh->addr_callback (rh->cls, NULL, 0);
404 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
409 /* return reverse lookup results to caller */
410 if (NULL != rh->name_callback)
412 hostname = (const char *) &msg[1];
413 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
416 if (rh->was_transmitted != GNUNET_SYSERR)
417 rh->name_callback (rh->cls, NULL);
418 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
420 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 _("Resolver returns `%s' for IP `%s'.\n"), hostname,
428 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
430 if (rh->was_transmitted != GNUNET_SYSERR)
431 rh->name_callback (rh->cls, hostname);
432 rh->received_response = GNUNET_YES;
433 GNUNET_CLIENT_receive (client, &handle_response, rh,
434 GNUNET_TIME_absolute_get_remaining (rh->timeout));
436 /* return lookup results to caller */
437 if (NULL != rh->addr_callback)
439 sa = (const struct sockaddr *) &msg[1];
440 salen = size - sizeof (struct GNUNET_MessageHeader);
441 if (salen < sizeof (struct sockaddr))
444 if (rh->was_transmitted != GNUNET_SYSERR)
445 rh->addr_callback (rh->cls, NULL, 0);
446 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
448 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
455 char *ips = no_resolve (sa, salen);
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n",
458 ips, (const char *) &rh[1]);
462 rh->addr_callback (rh->cls, sa, salen);
463 GNUNET_CLIENT_receive (client, &handle_response, rh,
464 GNUNET_TIME_absolute_get_remaining (rh->timeout));
470 * We've been asked to lookup the address for a hostname and were
471 * given a valid numeric string. Perform the callbacks for the
474 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
475 * @param tc unused scheduler context
478 numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
480 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
481 struct sockaddr_in v4;
482 struct sockaddr_in6 v6;
483 const char *hostname;
485 memset (&v4, 0, sizeof (v4));
486 v4.sin_family = AF_INET;
487 #if HAVE_SOCKADDR_IN_SIN_LEN
488 v4.sin_len = sizeof (v4);
490 memset (&v6, 0, sizeof (v6));
491 v6.sin6_family = AF_INET6;
492 #if HAVE_SOCKADDR_IN_SIN_LEN
493 v6.sin6_len = sizeof (v6);
495 hostname = (const char *) &rh[1];
496 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
497 (1 == inet_pton (AF_INET, hostname, &v4.sin_addr)))
499 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
500 if ((rh->domain == AF_UNSPEC) &&
501 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
503 /* this can happen on some systems IF "hostname" is "localhost" */
504 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
506 rh->addr_callback (rh->cls, NULL, 0);
510 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
511 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
513 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
514 rh->addr_callback (rh->cls, NULL, 0);
518 /* why are we here? this task should not have been scheduled! */
525 * We've been asked to lookup the address for a hostname and were
526 * given a variant of "loopback". Perform the callbacks for the
527 * respective loopback numeric addresses.
529 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
530 * @param tc unused scheduler context
533 loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
535 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
536 struct sockaddr_in v4;
537 struct sockaddr_in6 v6;
539 memset (&v4, 0, sizeof (v4));
540 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
541 v4.sin_family = AF_INET;
542 #if HAVE_SOCKADDR_IN_SIN_LEN
543 v4.sin_len = sizeof (v4);
545 memset (&v6, 0, sizeof (v6));
546 v6.sin6_family = AF_INET6;
547 #if HAVE_SOCKADDR_IN_SIN_LEN
548 v6.sin6_len = sizeof (v6);
550 v6.sin6_addr = in6addr_loopback;
554 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
557 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
560 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
561 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
567 rh->addr_callback (rh->cls, NULL, 0);
573 * Task executed on system shutdown.
576 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
578 s_task = GNUNET_SCHEDULER_NO_TASK;
579 GNUNET_RESOLVER_disconnect ();
584 * Process pending requests to the resolver.
589 struct GNUNET_RESOLVER_GetMessage *msg;
590 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
591 struct GNUNET_RESOLVER_RequestHandle *rh;
601 /* nothing to do, release socket really soon if there is nothing
602 * else happening... */
604 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
605 &shutdown_task, NULL);
608 if (GNUNET_YES == rh->was_transmitted)
609 return; /* waiting for reply */
610 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
612 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
613 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
614 msg->direction = htonl (rh->direction);
615 msg->domain = htonl (rh->domain);
616 memcpy (&msg[1], &rh[1], rh->data_len);
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "Transmitting DNS resolution request to DNS service\n");
622 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
623 GNUNET_TIME_absolute_get_remaining
624 (rh->timeout), GNUNET_YES,
625 &handle_response, rh))
627 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
632 rh->was_transmitted = GNUNET_YES;
637 * Now try to reconnect to the resolver service.
640 * @param tc scheduler context
643 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
645 r_task = GNUNET_SCHEDULER_NO_TASK;
646 if (NULL == req_head)
647 return; /* no work pending */
648 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to DNS service\n");
653 client = GNUNET_CLIENT_connect ("resolver", resolver_cfg);
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Failed to connect, will try again later\n");
666 * Adjust exponential back-off and reconnect to the service.
671 struct GNUNET_RESOLVER_RequestHandle *rh;
673 if (GNUNET_SCHEDULER_NO_TASK != r_task)
675 GNUNET_assert (NULL == client);
676 if (NULL != (rh = req_head))
678 switch (rh->was_transmitted)
681 /* nothing more to do */
684 /* disconnected, transmit again! */
685 rh->was_transmitted = GNUNET_NO;
688 /* request was cancelled, remove entirely */
689 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
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);
702 GNUNET_assert (NULL != resolver_cfg);
703 r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL);
704 backoff = GNUNET_TIME_relative_multiply (backoff, 2);
709 * Convert a string to one or more IP addresses.
711 * @param hostname the hostname to resolve
712 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
713 * @param callback function to call with addresses
714 * @param callback_cls closure for callback
715 * @param timeout how long to try resolving
716 * @return handle that can be used to cancel the request, NULL on error
718 struct GNUNET_RESOLVER_RequestHandle *
719 GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
720 struct GNUNET_TIME_Relative timeout,
721 GNUNET_RESOLVER_AddressCallback callback,
724 struct GNUNET_RESOLVER_RequestHandle *rh;
730 slen = strlen (hostname) + 1;
731 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
732 GNUNET_SERVER_MAX_MESSAGE_SIZE)
737 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
739 rh->addr_callback = callback;
740 rh->cls = callback_cls;
741 memcpy (&rh[1], hostname, slen);
743 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
744 rh->direction = GNUNET_NO;
745 /* first, check if this is a numeric address */
746 if (((1 == inet_pton (AF_INET, hostname, &v4)) &&
747 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
748 ((1 == inet_pton (AF_INET6, hostname, &v6)) &&
749 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
751 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
754 /* then, check if this is a loopback address */
756 while (loopback[i] != NULL)
757 if (0 == strcasecmp (loopback[i++], hostname))
759 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
762 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
763 rh->was_queued = GNUNET_YES;
764 if (s_task != GNUNET_SCHEDULER_NO_TASK)
766 GNUNET_SCHEDULER_cancel (s_task);
767 s_task = GNUNET_SCHEDULER_NO_TASK;
775 * We've been asked to convert an address to a string without
776 * a reverse lookup. Do it.
778 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
779 * @param tc unused scheduler context
782 numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
784 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
787 result = no_resolve ((const struct sockaddr *) &rh[1], rh->data_len);
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
793 rh->name_callback (rh->cls, result);
794 GNUNET_free (result);
796 rh->name_callback (rh->cls, NULL);
802 * Get an IP address as a string.
804 * @param sa host address
805 * @param salen length of host address
806 * @param do_resolve use GNUNET_NO to return numeric hostname
807 * @param timeout how long to try resolving
808 * @param callback function to call with hostnames
809 * last callback is NULL when finished
810 * @param cls closure for callback
811 * @return handle that can be used to cancel the request
813 struct GNUNET_RESOLVER_RequestHandle *
814 GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
816 struct GNUNET_TIME_Relative timeout,
817 GNUNET_RESOLVER_HostnameCallback callback,
820 struct GNUNET_RESOLVER_RequestHandle *rh;
823 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
824 rh->name_callback = callback;
826 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
827 memcpy (&rh[1], sa, salen);
828 rh->data_len = salen;
829 rh->direction = GNUNET_YES;
830 rh->received_response = GNUNET_NO;
831 if (GNUNET_NO == do_resolve)
833 rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
836 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
837 GNUNET_SERVER_MAX_MESSAGE_SIZE)
843 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
844 rh->was_queued = GNUNET_YES;
845 if (s_task != GNUNET_SCHEDULER_NO_TASK)
847 GNUNET_SCHEDULER_cancel (s_task);
848 s_task = GNUNET_SCHEDULER_NO_TASK;
856 * Get local fully qualified domain name
861 GNUNET_RESOLVER_local_fqdn_get ()
863 struct hostent *host;
864 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
866 if (0 != gethostname (hostname, sizeof (hostname) - 1))
868 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
876 host = gethostbyname (hostname);
879 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
880 hstrerror (h_errno));
883 return GNUNET_strdup (host->h_name);
888 * Looking our own hostname.
890 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
891 * @param callback function to call with addresses
892 * @param cls closure for callback
893 * @param timeout how long to try resolving
894 * @return handle that can be used to cancel the request, NULL on error
896 struct GNUNET_RESOLVER_RequestHandle *
897 GNUNET_RESOLVER_hostname_resolve (int domain,
898 struct GNUNET_TIME_Relative timeout,
899 GNUNET_RESOLVER_AddressCallback callback,
902 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
904 if (0 != gethostname (hostname, sizeof (hostname) - 1))
906 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"),
914 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls);
919 * Cancel a request that is still pending with the resolver.
920 * Note that a client MUST NOT cancel a request that has
921 * been completed (i.e, the callback has been called to
922 * signal timeout or the final result).
924 * @param rh handle of request to cancel
927 GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
929 if (rh->task != GNUNET_SCHEDULER_NO_TASK)
931 GNUNET_SCHEDULER_cancel (rh->task);
932 rh->task = GNUNET_SCHEDULER_NO_TASK;
934 if (rh->was_transmitted == GNUNET_NO)
936 if (rh->was_queued == GNUNET_YES)
937 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
941 GNUNET_assert (rh->was_transmitted == GNUNET_YES);
942 rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
946 /* end of resolver_api.c */