diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-11-05 18:21:50 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-11-05 18:21:50 +0000 |
commit | 75a33a1499cf60ea4364c9aa673816629a6c1413 (patch) | |
tree | 0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/util/resolver_api.c | |
parent | 7217c601ad30760872823193d62307e7a335d226 (diff) | |
download | gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip |
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r-- | src/util/resolver_api.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index f4832ed9c..7daaaf1cc 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -80,11 +80,6 @@ struct GNUNET_RESOLVER_RequestHandle | |||
80 | struct GNUNET_CLIENT_Connection *client; | 80 | struct GNUNET_CLIENT_Connection *client; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Our scheduler. | ||
84 | */ | ||
85 | struct GNUNET_SCHEDULER_Handle *sched; | ||
86 | |||
87 | /** | ||
88 | * Name of the host that we are resolving. | 83 | * Name of the host that we are resolving. |
89 | */ | 84 | */ |
90 | const char *hostname; | 85 | const char *hostname; |
@@ -401,7 +396,6 @@ loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
401 | /** | 396 | /** |
402 | * Convert a string to one or more IP addresses. | 397 | * Convert a string to one or more IP addresses. |
403 | * | 398 | * |
404 | * @param sched scheduler to use | ||
405 | * @param cfg configuration to use | 399 | * @param cfg configuration to use |
406 | * @param hostname the hostname to resolve | 400 | * @param hostname the hostname to resolve |
407 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" | 401 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" |
@@ -411,8 +405,7 @@ loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
411 | * @return handle that can be used to cancel the request, NULL on error | 405 | * @return handle that can be used to cancel the request, NULL on error |
412 | */ | 406 | */ |
413 | struct GNUNET_RESOLVER_RequestHandle * | 407 | struct GNUNET_RESOLVER_RequestHandle * |
414 | GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | 408 | GNUNET_RESOLVER_ip_get (const struct GNUNET_CONFIGURATION_Handle *cfg, |
415 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
416 | const char *hostname, | 409 | const char *hostname, |
417 | int domain, | 410 | int domain, |
418 | struct GNUNET_TIME_Relative timeout, | 411 | struct GNUNET_TIME_Relative timeout, |
@@ -436,7 +429,6 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
436 | return NULL; | 429 | return NULL; |
437 | } | 430 | } |
438 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); | 431 | rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen); |
439 | rh->sched = sched; | ||
440 | rh->domain = domain; | 432 | rh->domain = domain; |
441 | rh->addr_callback = callback; | 433 | rh->addr_callback = callback; |
442 | rh->cls = callback_cls; | 434 | rh->cls = callback_cls; |
@@ -454,8 +446,7 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
454 | &v6)) && | 446 | &v6)) && |
455 | ((domain == AF_INET6) || (domain == AF_UNSPEC)))) | 447 | ((domain == AF_INET6) || (domain == AF_UNSPEC)))) |
456 | { | 448 | { |
457 | rh->task = GNUNET_SCHEDULER_add_now (sched, | 449 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_resolution, rh); |
458 | &numeric_resolution, rh); | ||
459 | return rh; | 450 | return rh; |
460 | } | 451 | } |
461 | /* then, check if this is a loopback address */ | 452 | /* then, check if this is a loopback address */ |
@@ -463,12 +454,11 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
463 | while (loopback[i] != NULL) | 454 | while (loopback[i] != NULL) |
464 | if (0 == strcasecmp (loopback[i++], hostname)) | 455 | if (0 == strcasecmp (loopback[i++], hostname)) |
465 | { | 456 | { |
466 | rh->task = GNUNET_SCHEDULER_add_now (sched, | 457 | rh->task = GNUNET_SCHEDULER_add_now (&loopback_resolution, rh); |
467 | &loopback_resolution, rh); | ||
468 | return rh; | 458 | return rh; |
469 | } | 459 | } |
470 | 460 | ||
471 | client = GNUNET_CLIENT_connect (sched, "resolver", cfg); | 461 | client = GNUNET_CLIENT_connect ("resolver", cfg); |
472 | if (client == NULL) | 462 | if (client == NULL) |
473 | { | 463 | { |
474 | GNUNET_free (rh); | 464 | GNUNET_free (rh); |
@@ -595,7 +585,6 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
595 | /** | 585 | /** |
596 | * Get an IP address as a string. | 586 | * Get an IP address as a string. |
597 | * | 587 | * |
598 | * @param sched scheduler to use | ||
599 | * @param cfg configuration to use | 588 | * @param cfg configuration to use |
600 | * @param sa host address | 589 | * @param sa host address |
601 | * @param salen length of host address | 590 | * @param salen length of host address |
@@ -606,8 +595,7 @@ numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
606 | * @return handle that can be used to cancel the request | 595 | * @return handle that can be used to cancel the request |
607 | */ | 596 | */ |
608 | struct GNUNET_RESOLVER_RequestHandle * | 597 | struct GNUNET_RESOLVER_RequestHandle * |
609 | GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, | 598 | GNUNET_RESOLVER_hostname_get (const struct GNUNET_CONFIGURATION_Handle *cfg, |
610 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
611 | const struct sockaddr *sa, | 599 | const struct sockaddr *sa, |
612 | socklen_t salen, | 600 | socklen_t salen, |
613 | int do_resolve, | 601 | int do_resolve, |
@@ -625,14 +613,12 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
625 | rh->name_callback = callback; | 613 | rh->name_callback = callback; |
626 | rh->cls = cls; | 614 | rh->cls = cls; |
627 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 615 | rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
628 | rh->sched = sched; | ||
629 | rh->salen = salen; | 616 | rh->salen = salen; |
630 | memcpy (&rh[1], sa, salen); | 617 | memcpy (&rh[1], sa, salen); |
631 | 618 | ||
632 | if (GNUNET_NO == do_resolve) | 619 | if (GNUNET_NO == do_resolve) |
633 | { | 620 | { |
634 | rh->task = GNUNET_SCHEDULER_add_now (sched, | 621 | rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); |
635 | &numeric_reverse, rh); | ||
636 | return rh; | 622 | return rh; |
637 | } | 623 | } |
638 | if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 624 | if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -641,7 +627,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
641 | GNUNET_free (rh); | 627 | GNUNET_free (rh); |
642 | return NULL; | 628 | return NULL; |
643 | } | 629 | } |
644 | client = GNUNET_CLIENT_connect (sched, "resolver", cfg); | 630 | client = GNUNET_CLIENT_connect ("resolver", cfg); |
645 | if (client == NULL) | 631 | if (client == NULL) |
646 | { | 632 | { |
647 | GNUNET_free (rh); | 633 | GNUNET_free (rh); |
@@ -710,7 +696,6 @@ GNUNET_RESOLVER_local_fqdn_get ( void ) | |||
710 | /** | 696 | /** |
711 | * Looking our own hostname. | 697 | * Looking our own hostname. |
712 | * | 698 | * |
713 | * @param sched scheduler to use | ||
714 | * @param cfg configuration to use | 699 | * @param cfg configuration to use |
715 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" | 700 | * @param domain AF_INET or AF_INET6; use AF_UNSPEC for "any" |
716 | * @param callback function to call with addresses | 701 | * @param callback function to call with addresses |
@@ -719,8 +704,7 @@ GNUNET_RESOLVER_local_fqdn_get ( void ) | |||
719 | * @return handle that can be used to cancel the request, NULL on error | 704 | * @return handle that can be used to cancel the request, NULL on error |
720 | */ | 705 | */ |
721 | struct GNUNET_RESOLVER_RequestHandle * | 706 | struct GNUNET_RESOLVER_RequestHandle * |
722 | GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, | 707 | GNUNET_RESOLVER_hostname_resolve (const struct GNUNET_CONFIGURATION_Handle |
723 | const struct GNUNET_CONFIGURATION_Handle | ||
724 | *cfg, int domain, | 708 | *cfg, int domain, |
725 | struct GNUNET_TIME_Relative timeout, | 709 | struct GNUNET_TIME_Relative timeout, |
726 | GNUNET_RESOLVER_AddressCallback callback, | 710 | GNUNET_RESOLVER_AddressCallback callback, |
@@ -739,8 +723,7 @@ GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, | |||
739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
740 | _("Resolving our hostname `%s'\n"), hostname); | 724 | _("Resolving our hostname `%s'\n"), hostname); |
741 | #endif | 725 | #endif |
742 | return GNUNET_RESOLVER_ip_get (sched, | 726 | return GNUNET_RESOLVER_ip_get (cfg, hostname, domain, timeout, callback, |
743 | cfg, hostname, domain, timeout, callback, | ||
744 | cls); | 727 | cls); |
745 | } | 728 | } |
746 | 729 | ||
@@ -759,7 +742,7 @@ GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *h) | |||
759 | if (h->client != NULL) | 742 | if (h->client != NULL) |
760 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | 743 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
761 | if (h->task != GNUNET_SCHEDULER_NO_TASK) | 744 | if (h->task != GNUNET_SCHEDULER_NO_TASK) |
762 | GNUNET_SCHEDULER_cancel (h->sched, h->task); | 745 | GNUNET_SCHEDULER_cancel (h->task); |
763 | GNUNET_free (h); | 746 | GNUNET_free (h); |
764 | } | 747 | } |
765 | 748 | ||