aboutsummaryrefslogtreecommitdiff
path: root/src/util/resolver_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/util/resolver_api.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r--src/util/resolver_api.c80
1 files changed, 33 insertions, 47 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index ef48faf59..3aa8bff9c 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -191,17 +191,16 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg)
191 v6.sin6_len = sizeof (v6); 191 v6.sin6_len = sizeof (v6);
192#endif 192#endif
193 if (GNUNET_OK != 193 if (GNUNET_OK !=
194 GNUNET_CONFIGURATION_get_value_string (cfg, 194 GNUNET_CONFIGURATION_get_value_string (cfg, "resolver", "HOSTNAME",
195 "resolver", "HOSTNAME", &hostname)) 195 &hostname))
196 { 196 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 _("Must specify `%s' for `%s' in configuration!\n"), 198 _("Must specify `%s' for `%s' in configuration!\n"), "HOSTNAME",
199 "HOSTNAME", "resolver"); 199 "resolver");
200 GNUNET_assert (0); 200 GNUNET_assert (0);
201 } 201 }
202 if ((1 != inet_pton (AF_INET, 202 if ((1 != inet_pton (AF_INET, hostname, &v4)) ||
203 hostname, 203 (1 != inet_pton (AF_INET6, hostname, &v6)))
204 &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6)))
205 { 204 {
206 GNUNET_free (hostname); 205 GNUNET_free (hostname);
207 return; 206 return;
@@ -288,9 +287,8 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
288 if (salen != sizeof (struct sockaddr_in)) 287 if (salen != sizeof (struct sockaddr_in))
289 return NULL; 288 return NULL;
290 if (NULL == 289 if (NULL ==
291 inet_ntop (AF_INET, 290 inet_ntop (AF_INET, &((struct sockaddr_in *) sa)->sin_addr, inet4,
292 &((struct sockaddr_in *) sa)->sin_addr, 291 INET_ADDRSTRLEN))
293 inet4, INET_ADDRSTRLEN))
294 { 292 {
295 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 293 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
296 return NULL; 294 return NULL;
@@ -301,9 +299,8 @@ no_resolve (const struct sockaddr *sa, socklen_t salen)
301 if (salen != sizeof (struct sockaddr_in6)) 299 if (salen != sizeof (struct sockaddr_in6))
302 return NULL; 300 return NULL;
303 if (NULL == 301 if (NULL ==
304 inet_ntop (AF_INET6, 302 inet_ntop (AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, inet6,
305 &((struct sockaddr_in6 *) sa)->sin6_addr, 303 INET6_ADDRSTRLEN))
306 inet6, INET6_ADDRSTRLEN))
307 { 304 {
308 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 305 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
309 return NULL; 306 return NULL;
@@ -427,15 +424,13 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
427 } 424 }
428#if DEBUG_RESOLVER 425#if DEBUG_RESOLVER
429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
430 _("Resolver returns `%s' for IP `%s'.\n"), 427 _("Resolver returns `%s' for IP `%s'.\n"), hostname,
431 hostname, GNUNET_a2s ((const void *) &rh[1], rh->data_len)); 428 GNUNET_a2s ((const void *) &rh[1], rh->data_len));
432#endif 429#endif
433 if (rh->was_transmitted != GNUNET_SYSERR) 430 if (rh->was_transmitted != GNUNET_SYSERR)
434 rh->name_callback (rh->cls, hostname); 431 rh->name_callback (rh->cls, hostname);
435 rh->received_response = GNUNET_YES; 432 rh->received_response = GNUNET_YES;
436 GNUNET_CLIENT_receive (client, 433 GNUNET_CLIENT_receive (client, &handle_response, rh,
437 &handle_response,
438 rh,
439 GNUNET_TIME_absolute_get_remaining (rh->timeout)); 434 GNUNET_TIME_absolute_get_remaining (rh->timeout));
440 } 435 }
441 /* return lookup results to caller */ 436 /* return lookup results to caller */
@@ -459,16 +454,13 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg)
459 { 454 {
460 char *ips = no_resolve (sa, salen); 455 char *ips = no_resolve (sa, salen);
461 456
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s' for `%s'.\n",
463 "Resolver returns `%s' for `%s'.\n",
464 ips, (const char *) &rh[1]); 458 ips, (const char *) &rh[1]);
465 GNUNET_free (ips); 459 GNUNET_free (ips);
466 } 460 }
467#endif 461#endif
468 rh->addr_callback (rh->cls, sa, salen); 462 rh->addr_callback (rh->cls, sa, salen);
469 GNUNET_CLIENT_receive (client, 463 GNUNET_CLIENT_receive (client, &handle_response, rh,
470 &handle_response,
471 rh,
472 GNUNET_TIME_absolute_get_remaining (rh->timeout)); 464 GNUNET_TIME_absolute_get_remaining (rh->timeout));
473 } 465 }
474} 466}
@@ -610,8 +602,9 @@ process_requests ()
610 { 602 {
611 /* nothing to do, release socket really soon if there is nothing 603 /* nothing to do, release socket really soon if there is nothing
612 * else happening... */ 604 * else happening... */
613 s_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, 605 s_task =
614 &shutdown_task, NULL); 606 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
607 &shutdown_task, NULL);
615 return; 608 return;
616 } 609 }
617 if (GNUNET_YES == rh->was_transmitted) 610 if (GNUNET_YES == rh->was_transmitted)
@@ -628,8 +621,7 @@ process_requests ()
628 "Transmitting DNS resolution request to DNS service\n"); 621 "Transmitting DNS resolution request to DNS service\n");
629#endif 622#endif
630 if (GNUNET_OK != 623 if (GNUNET_OK !=
631 GNUNET_CLIENT_transmit_and_get_response (client, 624 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
632 &msg->header,
633 GNUNET_TIME_absolute_get_remaining 625 GNUNET_TIME_absolute_get_remaining
634 (rh->timeout), GNUNET_YES, 626 (rh->timeout), GNUNET_YES,
635 &handle_response, rh)) 627 &handle_response, rh))
@@ -726,8 +718,7 @@ reconnect ()
726 * @return handle that can be used to cancel the request, NULL on error 718 * @return handle that can be used to cancel the request, NULL on error
727 */ 719 */
728struct GNUNET_RESOLVER_RequestHandle * 720struct GNUNET_RESOLVER_RequestHandle *
729GNUNET_RESOLVER_ip_get (const char *hostname, 721GNUNET_RESOLVER_ip_get (const char *hostname, int domain,
730 int domain,
731 struct GNUNET_TIME_Relative timeout, 722 struct GNUNET_TIME_Relative timeout,
732 GNUNET_RESOLVER_AddressCallback callback, 723 GNUNET_RESOLVER_AddressCallback callback,
733 void *callback_cls) 724 void *callback_cls)
@@ -754,13 +745,9 @@ GNUNET_RESOLVER_ip_get (const char *hostname,
754 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 745 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
755 rh->direction = GNUNET_NO; 746 rh->direction = GNUNET_NO;
756 /* first, check if this is a numeric address */ 747 /* first, check if this is a numeric address */
757 if (((1 == inet_pton (AF_INET, 748 if (((1 == inet_pton (AF_INET, hostname, &v4)) &&
758 hostname,
759 &v4)) &&
760 ((domain == AF_INET) || (domain == AF_UNSPEC))) || 749 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
761 ((1 == inet_pton (AF_INET6, 750 ((1 == inet_pton (AF_INET6, hostname, &v6)) &&
762 hostname,
763 &v6)) &&
764 ((domain == AF_INET6) || (domain == AF_UNSPEC)))) 751 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
765 { 752 {
766 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); 753 rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh);
@@ -826,8 +813,7 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
826 * @return handle that can be used to cancel the request 813 * @return handle that can be used to cancel the request
827 */ 814 */
828struct GNUNET_RESOLVER_RequestHandle * 815struct GNUNET_RESOLVER_RequestHandle *
829GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, 816GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen,
830 socklen_t salen,
831 int do_resolve, 817 int do_resolve,
832 struct GNUNET_TIME_Relative timeout, 818 struct GNUNET_TIME_Relative timeout,
833 GNUNET_RESOLVER_HostnameCallback callback, 819 GNUNET_RESOLVER_HostnameCallback callback,
@@ -881,19 +867,19 @@ GNUNET_RESOLVER_local_fqdn_get ()
881 867
882 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 868 if (0 != gethostname (hostname, sizeof (hostname) - 1))
883 { 869 {
884 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 870 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
885 GNUNET_ERROR_TYPE_BULK, "gethostname"); 871 "gethostname");
886 return NULL; 872 return NULL;
887 } 873 }
888#if DEBUG_RESOLVER 874#if DEBUG_RESOLVER
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our FQDN `%s'\n"),
890 _("Resolving our FQDN `%s'\n"), hostname); 876 hostname);
891#endif 877#endif
892 host = gethostbyname (hostname); 878 host = gethostbyname (hostname);
893 if (NULL == host) 879 if (NULL == host)
894 { 880 {
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 881 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not resolve our FQDN : %s\n"),
896 _("Could not resolve our FQDN : %s\n"), hstrerror (h_errno)); 882 hstrerror (h_errno));
897 return NULL; 883 return NULL;
898 } 884 }
899 return GNUNET_strdup (host->h_name); 885 return GNUNET_strdup (host->h_name);
@@ -919,13 +905,13 @@ GNUNET_RESOLVER_hostname_resolve (int domain,
919 905
920 if (0 != gethostname (hostname, sizeof (hostname) - 1)) 906 if (0 != gethostname (hostname, sizeof (hostname) - 1))
921 { 907 {
922 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | 908 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
923 GNUNET_ERROR_TYPE_BULK, "gethostname"); 909 "gethostname");
924 return NULL; 910 return NULL;
925 } 911 }
926#if DEBUG_RESOLVER 912#if DEBUG_RESOLVER
927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolving our hostname `%s'\n"),
928 _("Resolving our hostname `%s'\n"), hostname); 914 hostname);
929#endif 915#endif
930 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls); 916 return GNUNET_RESOLVER_ip_get (hostname, domain, timeout, callback, cls);
931} 917}