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 *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
175 check_config (const struct GNUNET_CONFIGURATION_Handle *cfg)
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 (cfg,
196 "HOSTNAME", &hostname))
198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
199 _("Must specify `%s' for `%s' in configuration!\n"),
200 "HOSTNAME", "resolver");
203 if ((1 != inet_pton (AF_INET,
205 &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6)))
207 GNUNET_free (hostname);
211 while (loopback[i] != NULL)
212 if (0 == strcasecmp (loopback[i++], hostname))
214 GNUNET_free (hostname);
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
219 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
220 "localhost", "HOSTNAME", "resolver");
221 GNUNET_free (hostname);
227 * Create the connection to the resolver service.
229 * @param c configuration to use
232 GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *c)
234 GNUNET_assert (NULL != c);
236 backoff = GNUNET_TIME_UNIT_MILLISECONDS;
242 * Destroy the connection to the resolver service.
245 GNUNET_RESOLVER_disconnect ()
247 GNUNET_assert (NULL == req_head);
248 GNUNET_assert (NULL == req_tail);
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 "Disconnecting from DNS service\n");
255 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
258 if (r_task != GNUNET_SCHEDULER_NO_TASK)
260 GNUNET_SCHEDULER_cancel (r_task);
261 r_task = GNUNET_SCHEDULER_NO_TASK;
263 if (s_task != GNUNET_SCHEDULER_NO_TASK)
265 GNUNET_SCHEDULER_cancel (s_task);
266 s_task = GNUNET_SCHEDULER_NO_TASK;
272 * Convert IP address to string without DNS resolution.
274 * @param sa the address
275 * @param salen number of bytes in sa
276 * @return address as a string, NULL on error
279 no_resolve (const struct sockaddr *sa, socklen_t salen)
282 char inet4[INET_ADDRSTRLEN];
283 char inet6[INET6_ADDRSTRLEN];
285 if (salen < sizeof (struct sockaddr))
287 switch (sa->sa_family)
290 if (salen != sizeof (struct sockaddr_in))
294 &((struct sockaddr_in *) sa)->sin_addr,
295 inet4, INET_ADDRSTRLEN))
297 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
300 ret = GNUNET_strdup (inet4);
303 if (salen != sizeof (struct sockaddr_in6))
307 &((struct sockaddr_in6 *) sa)->sin6_addr,
308 inet6, INET6_ADDRSTRLEN))
310 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
313 ret = GNUNET_strdup (inet6);
324 * Adjust exponential back-off and reconnect to the service.
331 * Process pending requests to the resolver.
333 * @param h handle to the resolver
340 * Process response with a hostname for a DNS lookup.
342 * @param cls our "struct GNUNET_RESOLVER_RequestHandle" context
343 * @param msg message with the hostname, NULL on error
346 handle_response (void *cls,
347 const struct GNUNET_MessageHeader *msg)
349 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
351 const char *hostname;
352 const struct sockaddr *sa;
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
357 "Receiving response from DNS service\n");
361 if (NULL != rh->name_callback)
362 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
363 _("Timeout trying to resolve IP address `%s'.\n"),
364 GNUNET_a2s ((const void*) &rh[1], rh->data_len));
366 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
367 _("Timeout trying to resolve hostname `%s'.\n"),
368 (const char *) &rh[1]);
369 /* check if request was canceled */
370 if (rh->was_transmitted != GNUNET_SYSERR)
372 if (NULL != rh->name_callback)
374 /* no reverse lookup was successful, return ip as string */
375 if (rh->received_response == GNUNET_NO)
376 rh->name_callback (rh->cls,
377 no_resolve ((const struct sockaddr *) &rh[1], rh->data_len));
378 /* at least one reverse lookup was successful */
380 rh->name_callback (rh->cls, NULL);
382 if (NULL != rh->addr_callback)
383 rh->addr_callback (rh->cls, NULL, 0);
385 GNUNET_CONTAINER_DLL_remove (req_head,
389 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
394 if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
397 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
402 size = ntohs (msg->size);
403 /* message contains not data, just header */
404 if (size == sizeof (struct GNUNET_MessageHeader))
406 /* check if request was canceled */
407 if (rh->was_transmitted != GNUNET_SYSERR)
409 if (NULL != rh->name_callback)
410 rh->name_callback (rh->cls, NULL);
411 if (NULL != rh->addr_callback)
412 rh->addr_callback (rh->cls, NULL, 0);
414 GNUNET_CONTAINER_DLL_remove (req_head,
421 /* return reverse lookup results to caller */
422 if (NULL != rh->name_callback)
424 hostname = (const char *) &msg[1];
425 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
428 if (rh->was_transmitted != GNUNET_SYSERR)
429 rh->name_callback (rh->cls, NULL);
430 GNUNET_CONTAINER_DLL_remove (req_head,
434 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 _("Resolver returns `%s' for IP `%s'.\n"),
443 GNUNET_a2s ((const void*) &rh[1], rh->data_len));
445 if (rh->was_transmitted != GNUNET_SYSERR)
446 rh->name_callback (rh->cls, hostname);
447 rh->received_response = GNUNET_YES;
448 GNUNET_CLIENT_receive (client,
451 GNUNET_TIME_absolute_get_remaining (rh->timeout));
453 /* return lookup results to caller */
454 if (NULL != rh->addr_callback)
456 sa = (const struct sockaddr *) &msg[1];
457 salen = size - sizeof (struct GNUNET_MessageHeader);
458 if (salen < sizeof (struct sockaddr))
461 if (rh->was_transmitted != GNUNET_SYSERR)
462 rh->addr_callback (rh->cls, NULL, 0);
463 GNUNET_CONTAINER_DLL_remove (req_head,
467 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
474 char *ips = no_resolve (sa, salen);
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Resolver returns `%s' for `%s'.\n",
478 (const char*) &rh[1]);
482 rh->addr_callback (rh->cls, sa, salen);
483 GNUNET_CLIENT_receive (client,
486 GNUNET_TIME_absolute_get_remaining (rh->timeout));
492 * We've been asked to lookup the address for a hostname and were
493 * given a valid numeric string. Perform the callbacks for the
496 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
497 * @param tc unused scheduler context
500 numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
502 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
503 struct sockaddr_in v4;
504 struct sockaddr_in6 v6;
505 const char *hostname;
507 memset (&v4, 0, sizeof (v4));
508 v4.sin_family = AF_INET;
509 #if HAVE_SOCKADDR_IN_SIN_LEN
510 v4.sin_len = sizeof (v4);
512 memset (&v6, 0, sizeof (v6));
513 v6.sin6_family = AF_INET6;
514 #if HAVE_SOCKADDR_IN_SIN_LEN
515 v6.sin6_len = sizeof (v6);
517 hostname = (const char*) &rh[1];
518 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
519 (1 == inet_pton (AF_INET, hostname, &v4.sin_addr)))
521 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
522 if ((rh->domain == AF_UNSPEC) &&
523 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
525 /* this can happen on some systems IF "hostname" is "localhost" */
526 rh->addr_callback (rh->cls,
527 (const struct sockaddr *) &v6, sizeof (v6));
529 rh->addr_callback (rh->cls, NULL, 0);
533 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
534 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
536 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
537 rh->addr_callback (rh->cls, NULL, 0);
541 /* why are we here? this task should not have been scheduled! */
548 * We've been asked to lookup the address for a hostname and were
549 * given a variant of "loopback". Perform the callbacks for the
550 * respective loopback numeric addresses.
552 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
553 * @param tc unused scheduler context
556 loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
558 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
559 struct sockaddr_in v4;
560 struct sockaddr_in6 v6;
562 memset (&v4, 0, sizeof (v4));
563 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
564 v4.sin_family = AF_INET;
565 #if HAVE_SOCKADDR_IN_SIN_LEN
566 v4.sin_len = sizeof (v4);
568 memset (&v6, 0, sizeof (v6));
569 v6.sin6_family = AF_INET6;
570 #if HAVE_SOCKADDR_IN_SIN_LEN
571 v6.sin6_len = sizeof (v6);
573 v6.sin6_addr = in6addr_loopback;
577 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
580 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
583 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
584 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
590 rh->addr_callback (rh->cls, NULL, 0);
596 * Task executed on system shutdown.
599 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
601 s_task = GNUNET_SCHEDULER_NO_TASK;
602 GNUNET_RESOLVER_disconnect ();
607 * Process pending requests to the resolver.
609 * @param h handle to the resolver
614 struct GNUNET_RESOLVER_GetMessage *msg;
615 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
616 struct GNUNET_RESOLVER_RequestHandle *rh;
626 /* nothing to do, release socket really soon if there is nothing
628 s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
629 &shutdown_task, NULL);
632 if (GNUNET_YES == rh->was_transmitted)
633 return; /* waiting for reply */
634 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
636 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
637 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
638 msg->direction = htonl (rh->direction);
639 msg->domain = htonl (rh->domain);
640 memcpy (&msg[1], &rh[1], rh->data_len);
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
643 "Transmitting DNS resolution request to DNS service\n");
646 GNUNET_CLIENT_transmit_and_get_response (client,
648 GNUNET_TIME_absolute_get_remaining (rh->timeout),
650 &handle_response, rh))
652 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
657 rh->was_transmitted = GNUNET_YES;
662 * Now try to reconnect to the resolver service.
665 * @param tc scheduler context
668 reconnect_task (void *cls,
669 const struct GNUNET_SCHEDULER_TaskContext *tc)
671 r_task = GNUNET_SCHEDULER_NO_TASK;
672 if (NULL == req_head)
673 return; /* no work pending */
674 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 "Trying to connect to DNS service\n");
680 client = GNUNET_CLIENT_connect ("resolver", cfg);
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
684 "Failed to connect, will try again later\n");
693 * Adjust exponential back-off and reconnect to the service.
698 struct GNUNET_RESOLVER_RequestHandle *rh;
700 if (GNUNET_SCHEDULER_NO_TASK != r_task)
702 GNUNET_assert (NULL == client);
703 if (NULL != (rh = req_head))
705 switch (rh->was_transmitted)
708 /* nothing more to do */
711 /* disconnected, transmit again! */
712 rh->was_transmitted = GNUNET_NO;
715 /* request was cancelled, remove entirely */
716 GNUNET_CONTAINER_DLL_remove (req_head,
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
728 "Will try to connect to DNS service in %llu ms\n",
729 (unsigned long long) backoff.rel_value);
731 GNUNET_assert (NULL != cfg);
732 r_task = GNUNET_SCHEDULER_add_delayed (backoff,
735 backoff = GNUNET_TIME_relative_multiply (backoff, 2);
740 * Convert a string to one or more IP addresses.
742 * @param hostname the hostname to resolve
743 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
744 * @param callback function to call with addresses
745 * @param callback_cls closure for callback
746 * @param timeout how long to try resolving
747 * @return handle that can be used to cancel the request, NULL on error
749 struct GNUNET_RESOLVER_RequestHandle *
750 GNUNET_RESOLVER_ip_get (const char *hostname,
752 struct GNUNET_TIME_Relative timeout,
753 GNUNET_RESOLVER_AddressCallback callback,
756 struct GNUNET_RESOLVER_RequestHandle *rh;
762 slen = strlen (hostname) + 1;
763 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
768 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
770 rh->addr_callback = callback;
771 rh->cls = callback_cls;
772 memcpy (&rh[1], hostname, slen);
774 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
775 rh->direction = GNUNET_NO;
776 /* first, check if this is a numeric address */
777 if (((1 == inet_pton (AF_INET,
780 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
781 ((1 == inet_pton (AF_INET6,
784 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
786 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
789 /* then, check if this is a loopback address */
791 while (loopback[i] != NULL)
792 if (0 == strcasecmp (loopback[i++], hostname))
794 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
797 GNUNET_CONTAINER_DLL_insert_tail (req_head,
800 rh->was_queued = GNUNET_YES;
801 if (s_task != GNUNET_SCHEDULER_NO_TASK)
803 GNUNET_SCHEDULER_cancel (s_task);
804 s_task = GNUNET_SCHEDULER_NO_TASK;
812 * We've been asked to convert an address to a string without
813 * a reverse lookup. Do it.
815 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
816 * @param tc unused scheduler context
819 numeric_reverse (void *cls,
820 const struct GNUNET_SCHEDULER_TaskContext *tc)
822 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
825 result = no_resolve ((const struct sockaddr *) &rh[1], rh->data_len);
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
831 rh->name_callback (rh->cls, result);
832 GNUNET_free (result);
834 rh->name_callback (rh->cls, NULL);
840 * Get an IP address as a string.
842 * @param sa host address
843 * @param salen length of host address
844 * @param do_resolve use GNUNET_NO to return numeric hostname
845 * @param timeout how long to try resolving
846 * @param callback function to call with hostnames
847 * last callback is NULL when finished
848 * @param cls closure for callback
849 * @return handle that can be used to cancel the request
851 struct GNUNET_RESOLVER_RequestHandle *
852 GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
855 struct GNUNET_TIME_Relative timeout,
856 GNUNET_RESOLVER_HostnameCallback callback,
859 struct GNUNET_RESOLVER_RequestHandle *rh;
862 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
863 rh->name_callback = callback;
865 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
866 memcpy (&rh[1], sa, salen);
867 rh->data_len = salen;
868 rh->direction = GNUNET_YES;
869 rh->received_response = GNUNET_NO;
870 if (GNUNET_NO == do_resolve)
872 rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
875 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
881 GNUNET_CONTAINER_DLL_insert_tail (req_head,
884 rh->was_queued = GNUNET_YES;
885 if (s_task != GNUNET_SCHEDULER_NO_TASK)
887 GNUNET_SCHEDULER_cancel (s_task);
888 s_task = GNUNET_SCHEDULER_NO_TASK;
896 * Get local fully qualified domain name
901 GNUNET_RESOLVER_local_fqdn_get ()
903 struct hostent *host;
904 char hostname[GNUNET_OS_get_hostname_max_length() + 1];
906 if (0 != gethostname (hostname, sizeof (hostname) - 1))
908 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
909 GNUNET_ERROR_TYPE_BULK, "gethostname");
913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
914 _("Resolving our FQDN `%s'\n"), hostname);
916 host = gethostbyname (hostname);
919 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
920 _("Could not resolve our FQDN : %s\n"),
921 hstrerror (h_errno));
924 return GNUNET_strdup (host->h_name);
929 * Looking our own hostname.
931 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
932 * @param callback function to call with addresses
933 * @param cls closure for callback
934 * @param timeout how long to try resolving
935 * @return handle that can be used to cancel the request, NULL on error
937 struct GNUNET_RESOLVER_RequestHandle *
938 GNUNET_RESOLVER_hostname_resolve (int domain,
939 struct GNUNET_TIME_Relative timeout,
940 GNUNET_RESOLVER_AddressCallback callback,
943 char hostname[GNUNET_OS_get_hostname_max_length() + 1];
945 if (0 != gethostname (hostname, sizeof (hostname) - 1))
947 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
948 GNUNET_ERROR_TYPE_BULK, "gethostname");
952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
953 _("Resolving our hostname `%s'\n"), hostname);
955 return GNUNET_RESOLVER_ip_get (hostname,
963 * Cancel a request that is still pending with the resolver.
964 * Note that a client MUST NOT cancel a request that has
965 * been completed (i.e, the callback has been called to
966 * signal timeout or the final result).
968 * @param rh handle of request to cancel
971 GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
973 if (rh->task != GNUNET_SCHEDULER_NO_TASK)
975 GNUNET_SCHEDULER_cancel (rh->task);
976 rh->task = GNUNET_SCHEDULER_NO_TASK;
978 if (rh->was_transmitted == GNUNET_NO)
980 if (rh->was_queued == GNUNET_YES)
981 GNUNET_CONTAINER_DLL_remove (req_head,
987 GNUNET_assert (rh->was_transmitted == GNUNET_YES);
988 rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
992 /* end of resolver_api.c */