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,
195 "resolver", "HOSTNAME", &hostname))
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 _("Must specify `%s' for `%s' in configuration!\n"),
199 "HOSTNAME", "resolver");
202 if ((1 != inet_pton (AF_INET,
204 &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6)))
206 GNUNET_free (hostname);
210 while (loopback[i] != NULL)
211 if (0 == strcasecmp (loopback[i++], hostname))
213 GNUNET_free (hostname);
216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
218 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
219 "localhost", "HOSTNAME", "resolver");
220 GNUNET_free (hostname);
226 * Create the connection to the resolver service.
228 * @param c configuration to use
231 GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *c)
233 GNUNET_assert (NULL != c);
235 backoff = GNUNET_TIME_UNIT_MILLISECONDS;
241 * Destroy the connection to the resolver service.
244 GNUNET_RESOLVER_disconnect ()
246 GNUNET_assert (NULL == req_head);
247 GNUNET_assert (NULL == req_tail);
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from DNS service\n");
253 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
256 if (r_task != GNUNET_SCHEDULER_NO_TASK)
258 GNUNET_SCHEDULER_cancel (r_task);
259 r_task = GNUNET_SCHEDULER_NO_TASK;
261 if (s_task != GNUNET_SCHEDULER_NO_TASK)
263 GNUNET_SCHEDULER_cancel (s_task);
264 s_task = GNUNET_SCHEDULER_NO_TASK;
270 * Convert IP address to string without DNS resolution.
272 * @param sa the address
273 * @param salen number of bytes in sa
274 * @return address as a string, NULL on error
277 no_resolve (const struct sockaddr *sa, socklen_t salen)
280 char inet4[INET_ADDRSTRLEN];
281 char inet6[INET6_ADDRSTRLEN];
283 if (salen < sizeof (struct sockaddr))
285 switch (sa->sa_family)
288 if (salen != sizeof (struct sockaddr_in))
292 &((struct sockaddr_in *) sa)->sin_addr,
293 inet4, INET_ADDRSTRLEN))
295 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
298 ret = GNUNET_strdup (inet4);
301 if (salen != sizeof (struct sockaddr_in6))
305 &((struct sockaddr_in6 *) sa)->sin6_addr,
306 inet6, INET6_ADDRSTRLEN))
308 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
311 ret = GNUNET_strdup (inet6);
322 * Adjust exponential back-off and reconnect to the service.
324 static void reconnect ();
328 * Process pending requests to the resolver.
330 * @param h handle to the resolver
332 static void process_requests ();
336 * Process response with a hostname for a DNS lookup.
338 * @param cls our "struct GNUNET_RESOLVER_RequestHandle" context
339 * @param msg message with the hostname, NULL on error
342 handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
344 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
346 const char *hostname;
347 const struct sockaddr *sa;
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving response from DNS service\n");
355 if (NULL != rh->name_callback)
356 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
357 _("Timeout trying to resolve IP address `%s'.\n"),
358 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
360 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
361 _("Timeout trying to resolve hostname `%s'.\n"),
362 (const char *) &rh[1]);
363 /* check if request was canceled */
364 if (rh->was_transmitted != GNUNET_SYSERR)
366 if (NULL != rh->name_callback)
368 /* no reverse lookup was successful, return ip as string */
369 if (rh->received_response == GNUNET_NO)
370 rh->name_callback (rh->cls,
371 no_resolve ((const struct sockaddr *) &rh[1],
373 /* at least one reverse lookup was successful */
375 rh->name_callback (rh->cls, NULL);
377 if (NULL != rh->addr_callback)
378 rh->addr_callback (rh->cls, NULL, 0);
380 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
382 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
387 if (GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE != ntohs (msg->type))
390 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
395 size = ntohs (msg->size);
396 /* message contains not data, just header */
397 if (size == sizeof (struct GNUNET_MessageHeader))
399 /* check if request was canceled */
400 if (rh->was_transmitted != GNUNET_SYSERR)
402 if (NULL != rh->name_callback)
403 rh->name_callback (rh->cls, NULL);
404 if (NULL != rh->addr_callback)
405 rh->addr_callback (rh->cls, NULL, 0);
407 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
412 /* return reverse lookup results to caller */
413 if (NULL != rh->name_callback)
415 hostname = (const char *) &msg[1];
416 if (hostname[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
419 if (rh->was_transmitted != GNUNET_SYSERR)
420 rh->name_callback (rh->cls, NULL);
421 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
423 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 _("Resolver returns `%s' for IP `%s'.\n"),
431 hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len));
433 if (rh->was_transmitted != GNUNET_SYSERR)
434 rh->name_callback (rh->cls, hostname);
435 rh->received_response = GNUNET_YES;
436 GNUNET_CLIENT_receive (client,
439 GNUNET_TIME_absolute_get_remaining (rh->timeout));
441 /* return lookup results to caller */
442 if (NULL != rh->addr_callback)
444 sa = (const struct sockaddr *) &msg[1];
445 salen = size - sizeof (struct GNUNET_MessageHeader);
446 if (salen < sizeof (struct sockaddr))
449 if (rh->was_transmitted != GNUNET_SYSERR)
450 rh->addr_callback (rh->cls, NULL, 0);
451 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
453 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
460 char *ips = no_resolve (sa, salen);
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Resolver returns `%s' for `%s'.\n",
464 ips, (const char *) &rh[1]);
468 rh->addr_callback (rh->cls, sa, salen);
469 GNUNET_CLIENT_receive (client,
472 GNUNET_TIME_absolute_get_remaining (rh->timeout));
478 * We've been asked to lookup the address for a hostname and were
479 * given a valid numeric string. Perform the callbacks for the
482 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
483 * @param tc unused scheduler context
486 numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
488 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
489 struct sockaddr_in v4;
490 struct sockaddr_in6 v6;
491 const char *hostname;
493 memset (&v4, 0, sizeof (v4));
494 v4.sin_family = AF_INET;
495 #if HAVE_SOCKADDR_IN_SIN_LEN
496 v4.sin_len = sizeof (v4);
498 memset (&v6, 0, sizeof (v6));
499 v6.sin6_family = AF_INET6;
500 #if HAVE_SOCKADDR_IN_SIN_LEN
501 v6.sin6_len = sizeof (v6);
503 hostname = (const char *) &rh[1];
504 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
505 (1 == inet_pton (AF_INET, hostname, &v4.sin_addr)))
507 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
508 if ((rh->domain == AF_UNSPEC) &&
509 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
511 /* this can happen on some systems IF "hostname" is "localhost" */
512 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
514 rh->addr_callback (rh->cls, NULL, 0);
518 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
519 (1 == inet_pton (AF_INET6, hostname, &v6.sin6_addr)))
521 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
522 rh->addr_callback (rh->cls, NULL, 0);
526 /* why are we here? this task should not have been scheduled! */
533 * We've been asked to lookup the address for a hostname and were
534 * given a variant of "loopback". Perform the callbacks for the
535 * respective loopback numeric addresses.
537 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
538 * @param tc unused scheduler context
541 loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
543 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
544 struct sockaddr_in v4;
545 struct sockaddr_in6 v6;
547 memset (&v4, 0, sizeof (v4));
548 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
549 v4.sin_family = AF_INET;
550 #if HAVE_SOCKADDR_IN_SIN_LEN
551 v4.sin_len = sizeof (v4);
553 memset (&v6, 0, sizeof (v6));
554 v6.sin6_family = AF_INET6;
555 #if HAVE_SOCKADDR_IN_SIN_LEN
556 v6.sin6_len = sizeof (v6);
558 v6.sin6_addr = in6addr_loopback;
562 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
565 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
568 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
569 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
575 rh->addr_callback (rh->cls, NULL, 0);
581 * Task executed on system shutdown.
584 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
586 s_task = GNUNET_SCHEDULER_NO_TASK;
587 GNUNET_RESOLVER_disconnect ();
592 * Process pending requests to the resolver.
594 * @param h handle to the resolver
599 struct GNUNET_RESOLVER_GetMessage *msg;
600 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
601 struct GNUNET_RESOLVER_RequestHandle *rh;
611 /* nothing to do, release socket really soon if there is nothing
612 * else happening... */
613 s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
614 &shutdown_task, NULL);
617 if (GNUNET_YES == rh->was_transmitted)
618 return; /* waiting for reply */
619 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
621 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + rh->data_len);
622 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
623 msg->direction = htonl (rh->direction);
624 msg->domain = htonl (rh->domain);
625 memcpy (&msg[1], &rh[1], rh->data_len);
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628 "Transmitting DNS resolution request to DNS service\n");
631 GNUNET_CLIENT_transmit_and_get_response (client,
633 GNUNET_TIME_absolute_get_remaining
634 (rh->timeout), GNUNET_YES,
635 &handle_response, rh))
637 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
642 rh->was_transmitted = GNUNET_YES;
647 * Now try to reconnect to the resolver service.
650 * @param tc scheduler context
653 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
655 r_task = GNUNET_SCHEDULER_NO_TASK;
656 if (NULL == req_head)
657 return; /* no work pending */
658 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to DNS service\n");
663 client = GNUNET_CLIENT_connect ("resolver", cfg);
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 "Failed to connect, will try again later\n");
676 * Adjust exponential back-off and reconnect to the service.
681 struct GNUNET_RESOLVER_RequestHandle *rh;
683 if (GNUNET_SCHEDULER_NO_TASK != r_task)
685 GNUNET_assert (NULL == client);
686 if (NULL != (rh = req_head))
688 switch (rh->was_transmitted)
691 /* nothing more to do */
694 /* disconnected, transmit again! */
695 rh->was_transmitted = GNUNET_NO;
698 /* request was cancelled, remove entirely */
699 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
709 "Will try to connect to DNS service in %llu ms\n",
710 (unsigned long long) backoff.rel_value);
712 GNUNET_assert (NULL != cfg);
713 r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL);
714 backoff = GNUNET_TIME_relative_multiply (backoff, 2);
719 * Convert a string to one or more IP addresses.
721 * @param hostname the hostname to resolve
722 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
723 * @param callback function to call with addresses
724 * @param callback_cls closure for callback
725 * @param timeout how long to try resolving
726 * @return handle that can be used to cancel the request, NULL on error
728 struct GNUNET_RESOLVER_RequestHandle *
729 GNUNET_RESOLVER_ip_get (const char *hostname,
731 struct GNUNET_TIME_Relative timeout,
732 GNUNET_RESOLVER_AddressCallback callback,
735 struct GNUNET_RESOLVER_RequestHandle *rh;
741 slen = strlen (hostname) + 1;
742 if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
743 GNUNET_SERVER_MAX_MESSAGE_SIZE)
748 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
750 rh->addr_callback = callback;
751 rh->cls = callback_cls;
752 memcpy (&rh[1], hostname, slen);
754 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
755 rh->direction = GNUNET_NO;
756 /* first, check if this is a numeric address */
757 if (((1 == inet_pton (AF_INET,
760 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
761 ((1 == inet_pton (AF_INET6,
764 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
766 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
769 /* then, check if this is a loopback address */
771 while (loopback[i] != NULL)
772 if (0 == strcasecmp (loopback[i++], hostname))
774 rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh);
777 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
778 rh->was_queued = GNUNET_YES;
779 if (s_task != GNUNET_SCHEDULER_NO_TASK)
781 GNUNET_SCHEDULER_cancel (s_task);
782 s_task = GNUNET_SCHEDULER_NO_TASK;
790 * We've been asked to convert an address to a string without
791 * a reverse lookup. Do it.
793 * @param cls struct GNUNET_RESOLVER_RequestHandle for the request
794 * @param tc unused scheduler context
797 numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
799 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
802 result = no_resolve ((const struct sockaddr *) &rh[1], rh->data_len);
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
808 rh->name_callback (rh->cls, result);
809 GNUNET_free (result);
811 rh->name_callback (rh->cls, NULL);
817 * Get an IP address as a string.
819 * @param sa host address
820 * @param salen length of host address
821 * @param do_resolve use GNUNET_NO to return numeric hostname
822 * @param timeout how long to try resolving
823 * @param callback function to call with hostnames
824 * last callback is NULL when finished
825 * @param cls closure for callback
826 * @return handle that can be used to cancel the request
828 struct GNUNET_RESOLVER_RequestHandle *
829 GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa,
832 struct GNUNET_TIME_Relative timeout,
833 GNUNET_RESOLVER_HostnameCallback callback,
836 struct GNUNET_RESOLVER_RequestHandle *rh;
839 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
840 rh->name_callback = callback;
842 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
843 memcpy (&rh[1], sa, salen);
844 rh->data_len = salen;
845 rh->direction = GNUNET_YES;
846 rh->received_response = GNUNET_NO;
847 if (GNUNET_NO == do_resolve)
849 rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh);
852 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
853 GNUNET_SERVER_MAX_MESSAGE_SIZE)
859 GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh);
860 rh->was_queued = GNUNET_YES;
861 if (s_task != GNUNET_SCHEDULER_NO_TASK)
863 GNUNET_SCHEDULER_cancel (s_task);
864 s_task = GNUNET_SCHEDULER_NO_TASK;
872 * Get local fully qualified domain name
877 GNUNET_RESOLVER_local_fqdn_get ()
879 struct hostent *host;
880 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
882 if (0 != gethostname (hostname, sizeof (hostname) - 1))
884 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
885 GNUNET_ERROR_TYPE_BULK, "gethostname");
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 _("Resolving our FQDN `%s'\n"), hostname);
892 host = gethostbyname (hostname);
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
896 _("Could not resolve our FQDN : %s\n"), hstrerror (h_errno));
899 return GNUNET_strdup (host->h_name);
904 * Looking our own hostname.
906 * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any"
907 * @param callback function to call with addresses
908 * @param cls closure for callback
909 * @param timeout how long to try resolving
910 * @return handle that can be used to cancel the request, NULL on error
912 struct GNUNET_RESOLVER_RequestHandle *
913 GNUNET_RESOLVER_hostname_resolve (int domain,
914 struct GNUNET_TIME_Relative timeout,
915 GNUNET_RESOLVER_AddressCallback callback,
918 char hostname[GNUNET_OS_get_hostname_max_length () + 1];
920 if (0 != gethostname (hostname, sizeof (hostname) - 1))
922 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR |
923 GNUNET_ERROR_TYPE_BULK, "gethostname");
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
928 _("Resolving our hostname `%s'\n"), hostname);
930 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls);
935 * Cancel a request that is still pending with the resolver.
936 * Note that a client MUST NOT cancel a request that has
937 * been completed (i.e, the callback has been called to
938 * signal timeout or the final result).
940 * @param rh handle of request to cancel
943 GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
945 if (rh->task != GNUNET_SCHEDULER_NO_TASK)
947 GNUNET_SCHEDULER_cancel (rh->task);
948 rh->task = GNUNET_SCHEDULER_NO_TASK;
950 if (rh->was_transmitted == GNUNET_NO)
952 if (rh->was_queued == GNUNET_YES)
953 GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
957 GNUNET_assert (rh->was_transmitted == GNUNET_YES);
958 rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
962 /* end of resolver_api.c */