diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-04 08:51:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-04 08:51:00 +0000 |
commit | b91546a3de767292e6472c6b1927480adba43d88 (patch) | |
tree | e0e73428a12587a9b6a0ad838f49b78e70610178 /src | |
parent | 7c11ff30adc1cd8c2987eafaaa6bf5f11475b8ca (diff) | |
download | gnunet-b91546a3de767292e6472c6b1927480adba43d88.tar.gz gnunet-b91546a3de767292e6472c6b1927480adba43d88.zip |
cleaner cleanup of DNS request code
Diffstat (limited to 'src')
-rw-r--r-- | src/util/connection.c | 65 |
1 files changed, 20 insertions, 45 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index daf0cbf03..066b81bbe 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -245,6 +245,11 @@ struct GNUNET_CONNECTION_Handle | |||
245 | GNUNET_SCHEDULER_TaskIdentifier write_task; | 245 | GNUNET_SCHEDULER_TaskIdentifier write_task; |
246 | 246 | ||
247 | /** | 247 | /** |
248 | * Handle to a pending DNS lookup request. | ||
249 | */ | ||
250 | struct GNUNET_RESOLVER_RequestHandle *dns_active; | ||
251 | |||
252 | /** | ||
248 | * The handle we return for GNUNET_CONNECTION_notify_transmit_ready. | 253 | * The handle we return for GNUNET_CONNECTION_notify_transmit_ready. |
249 | */ | 254 | */ |
250 | struct GNUNET_CONNECTION_TransmitHandle nth; | 255 | struct GNUNET_CONNECTION_TransmitHandle nth; |
@@ -265,14 +270,6 @@ struct GNUNET_CONNECTION_Handle | |||
265 | size_t max; | 270 | size_t max; |
266 | 271 | ||
267 | /** | 272 | /** |
268 | * Are we still waiting for DNS replies (on connect)? | ||
269 | * GNUNET_YES if we are, GNUNET_NO if we are not waiting for DNS, | ||
270 | * GNUNET_SYSERR if destroying the handle was deferred due to | ||
271 | * a pending DNS lookup. | ||
272 | */ | ||
273 | int dns_active; | ||
274 | |||
275 | /** | ||
276 | * Port to connect to. | 273 | * Port to connect to. |
277 | */ | 274 | */ |
278 | uint16_t port; | 275 | uint16_t port; |
@@ -462,11 +459,7 @@ destroy_continuation (void *cls, | |||
462 | struct GNUNET_CONNECTION_Handle *sock = cls; | 459 | struct GNUNET_CONNECTION_Handle *sock = cls; |
463 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 460 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
464 | 461 | ||
465 | if (sock->dns_active == GNUNET_YES) | 462 | GNUNET_assert (sock->dns_active == NULL); |
466 | { | ||
467 | sock->dns_active = GNUNET_SYSERR; | ||
468 | return; | ||
469 | } | ||
470 | if (0 != (sock->ccs & COCO_TRANSMIT_READY)) | 463 | if (0 != (sock->ccs & COCO_TRANSMIT_READY)) |
471 | { | 464 | { |
472 | #if DEBUG_CONNECTION | 465 | #if DEBUG_CONNECTION |
@@ -748,30 +741,13 @@ try_connect_using_address (void *cls, | |||
748 | 741 | ||
749 | if (addr == NULL) | 742 | if (addr == NULL) |
750 | { | 743 | { |
751 | if (h->dns_active == GNUNET_SYSERR) | 744 | h->dns_active = NULL; |
752 | { | ||
753 | h->dns_active = GNUNET_NO; | ||
754 | GNUNET_SCHEDULER_add_after (h->sched, | ||
755 | GNUNET_YES, | ||
756 | GNUNET_SCHEDULER_PRIORITY_KEEP, | ||
757 | h->read_task, &destroy_continuation, h); | ||
758 | return; | ||
759 | } | ||
760 | h->dns_active = GNUNET_NO; | ||
761 | if (NULL == h->ap_head) | 745 | if (NULL == h->ap_head) |
762 | connect_fail_continuation (h); | 746 | connect_fail_continuation (h); |
763 | return; | 747 | return; |
764 | } | 748 | } |
765 | if (h->sock != NULL) | 749 | if (h->sock != NULL) |
766 | return; /* already connected */ | 750 | return; /* already connected */ |
767 | if (h->dns_active == GNUNET_SYSERR) | ||
768 | { | ||
769 | #if DEBUG_CONNECTION | ||
770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
771 | "Connection %p has already been destroyed.\n", h); | ||
772 | #endif | ||
773 | return; /* already destroyed */ | ||
774 | } | ||
775 | /* try to connect */ | 751 | /* try to connect */ |
776 | #if DEBUG_CONNECTION | 752 | #if DEBUG_CONNECTION |
777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -851,13 +827,13 @@ retry_connect_continuation (void *cls, | |||
851 | { | 827 | { |
852 | struct GNUNET_CONNECTION_Handle *sock = cls; | 828 | struct GNUNET_CONNECTION_Handle *sock = cls; |
853 | 829 | ||
854 | sock->dns_active = GNUNET_YES; | 830 | GNUNET_assert (sock->dns_active == NULL); |
855 | GNUNET_RESOLVER_ip_get (sock->sched, | 831 | sock->dns_active = GNUNET_RESOLVER_ip_get (sock->sched, |
856 | sock->cfg, | 832 | sock->cfg, |
857 | sock->hostname, | 833 | sock->hostname, |
858 | AF_UNSPEC, | 834 | AF_UNSPEC, |
859 | GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, | 835 | GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, |
860 | &try_connect_using_address, sock); | 836 | &try_connect_using_address, sock); |
861 | } | 837 | } |
862 | 838 | ||
863 | 839 | ||
@@ -957,7 +933,7 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle | |||
957 | int | 933 | int |
958 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) | 934 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) |
959 | { | 935 | { |
960 | if ((sock->ap_head != NULL) || (sock->dns_active == GNUNET_YES)) | 936 | if ((sock->ap_head != NULL) || (sock->dns_active != NULL)) |
961 | return GNUNET_YES; /* still trying to connect */ | 937 | return GNUNET_YES; /* still trying to connect */ |
962 | return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; | 938 | return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; |
963 | } | 939 | } |
@@ -973,11 +949,10 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) | |||
973 | void | 949 | void |
974 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) | 950 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) |
975 | { | 951 | { |
976 | if ((sock->write_buffer_off == 0) && (sock->dns_active == GNUNET_YES)) | 952 | if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) |
977 | { | 953 | { |
978 | sock->dns_active = GNUNET_SYSERR; /* if we're still trying to connect and have | 954 | GNUNET_RESOLVER_request_cancel (sock->dns_active); |
979 | no message pending, stop trying! */ | 955 | sock->dns_active = NULL; |
980 | return; | ||
981 | } | 956 | } |
982 | GNUNET_assert (sock->sched != NULL); | 957 | GNUNET_assert (sock->sched != NULL); |
983 | GNUNET_SCHEDULER_add_after (sock->sched, | 958 | GNUNET_SCHEDULER_add_after (sock->sched, |
@@ -1173,7 +1148,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, | |||
1173 | receive_again (sock, &tc); | 1148 | receive_again (sock, &tc); |
1174 | return; | 1149 | return; |
1175 | } | 1150 | } |
1176 | if ((sock->dns_active != GNUNET_YES) && (sock->ap_head == NULL)) | 1151 | if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) |
1177 | { | 1152 | { |
1178 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); | 1153 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); |
1179 | return; | 1154 | return; |
@@ -1475,7 +1450,7 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle | |||
1475 | sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1450 | sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1476 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); | 1451 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); |
1477 | if ((sock->sock == NULL) && | 1452 | if ((sock->sock == NULL) && |
1478 | (sock->ap_head == NULL) && (sock->dns_active != GNUNET_YES)) | 1453 | (sock->ap_head == NULL) && (sock->dns_active == NULL)) |
1479 | { | 1454 | { |
1480 | sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched, | 1455 | sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched, |
1481 | GNUNET_NO, | 1456 | GNUNET_NO, |