diff options
Diffstat (limited to 'src/util/connection.c')
-rw-r--r-- | src/util/connection.c | 218 |
1 files changed, 129 insertions, 89 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index b3ea3b5af..95fbb13f8 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -217,7 +217,7 @@ struct GNUNET_CONNECTION_Handle | |||
217 | struct GNUNET_RESOLVER_RequestHandle *dns_active; | 217 | struct GNUNET_RESOLVER_RequestHandle *dns_active; |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * The handle we return for GNUNET_CONNECTION_notify_transmit_ready. | 220 | * The handle we return for #GNUNET_CONNECTION_notify_transmit_ready(). |
221 | */ | 221 | */ |
222 | struct GNUNET_CONNECTION_TransmitHandle nth; | 222 | struct GNUNET_CONNECTION_TransmitHandle nth; |
223 | 223 | ||
@@ -344,7 +344,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
344 | 344 | ||
345 | addrlen = sizeof (addr); | 345 | addrlen = sizeof (addr); |
346 | sock = | 346 | sock = |
347 | GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); | 347 | GNUNET_NETWORK_socket_accept (lsock, |
348 | (struct sockaddr *) &addr, | ||
349 | &addrlen); | ||
348 | if (NULL == sock) | 350 | if (NULL == sock) |
349 | { | 351 | { |
350 | if (EAGAIN != errno) | 352 | if (EAGAIN != errno) |
@@ -360,7 +362,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
360 | 362 | ||
361 | sa = (struct sockaddr *) addr; | 363 | sa = (struct sockaddr *) addr; |
362 | v6 = (struct sockaddr_in6 *) addr; | 364 | v6 = (struct sockaddr_in6 *) addr; |
363 | if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) | 365 | if ( (AF_INET6 == sa->sa_family) && |
366 | (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) ) | ||
364 | { | 367 | { |
365 | /* convert to V4 address */ | 368 | /* convert to V4 address */ |
366 | v4 = GNUNET_new (struct sockaddr_in); | 369 | v4 = GNUNET_new (struct sockaddr_in); |
@@ -389,15 +392,21 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
389 | { | 392 | { |
390 | #if HAVE_GETPEEREID | 393 | #if HAVE_GETPEEREID |
391 | /* most BSDs */ | 394 | /* most BSDs */ |
392 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) | 395 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), |
396 | &gc.uid, | ||
397 | &gc.gid)) | ||
393 | gcp = &gc; | 398 | gcp = &gc; |
394 | #else | 399 | #else |
395 | #ifdef SO_PEERCRED | 400 | #ifdef SO_PEERCRED |
396 | /* largely traditional GNU/Linux */ | 401 | /* largely traditional GNU/Linux */ |
397 | olen = sizeof (uc); | 402 | olen = sizeof (uc); |
398 | if ((0 == | 403 | if ( (0 == |
399 | getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc, | 404 | getsockopt (GNUNET_NETWORK_get_fd (sock), |
400 | &olen)) && (olen == sizeof (uc))) | 405 | SOL_SOCKET, |
406 | SO_PEERCRED, | ||
407 | &uc, | ||
408 | &olen)) && | ||
409 | (olen == sizeof (uc)) ) | ||
401 | { | 410 | { |
402 | gc.uid = uc.uid; | 411 | gc.uid = uc.uid; |
403 | gc.gid = uc.gid; | 412 | gc.gid = uc.gid; |
@@ -421,8 +430,11 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
421 | #endif | 430 | #endif |
422 | } | 431 | } |
423 | 432 | ||
424 | if ((NULL != access_cb) && | 433 | if ( (NULL != access_cb) && |
425 | (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen)))) | 434 | (GNUNET_YES != (aret = access_cb (access_cb_cls, |
435 | gcp, | ||
436 | uaddr, | ||
437 | addrlen))) ) | ||
426 | { | 438 | { |
427 | if (GNUNET_NO == aret) | 439 | if (GNUNET_NO == aret) |
428 | LOG (GNUNET_ERROR_TYPE_INFO, | 440 | LOG (GNUNET_ERROR_TYPE_INFO, |
@@ -444,7 +456,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
444 | connection->sock = sock; | 456 | connection->sock = sock; |
445 | LOG (GNUNET_ERROR_TYPE_INFO, | 457 | LOG (GNUNET_ERROR_TYPE_INFO, |
446 | _("Accepting connection from `%s': %p\n"), | 458 | _("Accepting connection from `%s': %p\n"), |
447 | GNUNET_a2s (uaddr, addrlen), connection); | 459 | GNUNET_a2s (uaddr, |
460 | addrlen), | ||
461 | connection); | ||
448 | return connection; | 462 | return connection; |
449 | } | 463 | } |
450 | 464 | ||
@@ -554,7 +568,9 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | |||
554 | return; /* nobody to tell about it */ | 568 | return; /* nobody to tell about it */ |
555 | notify = connection->nth.notify_ready; | 569 | notify = connection->nth.notify_ready; |
556 | connection->nth.notify_ready = NULL; | 570 | connection->nth.notify_ready = NULL; |
557 | notify (connection->nth.notify_ready_cls, 0, NULL); | 571 | notify (connection->nth.notify_ready_cls, |
572 | 0, | ||
573 | NULL); | ||
558 | } | 574 | } |
559 | 575 | ||
560 | 576 | ||
@@ -631,7 +647,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
631 | { | 647 | { |
632 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 648 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
633 | "Connection to `%s' succeeded! (%p)\n", | 649 | "Connection to `%s' succeeded! (%p)\n", |
634 | GNUNET_a2s (connection->addr, connection->addrlen), | 650 | GNUNET_a2s (connection->addr, |
651 | connection->addrlen), | ||
635 | connection); | 652 | connection); |
636 | /* trigger jobs that waited for the connection */ | 653 | /* trigger jobs that waited for the connection */ |
637 | if (NULL != connection->receiver) | 654 | if (NULL != connection->receiver) |
@@ -642,7 +659,8 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
642 | GNUNET_assert (NULL == connection->read_task); | 659 | GNUNET_assert (NULL == connection->read_task); |
643 | connection->read_task = | 660 | connection->read_task = |
644 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 661 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining |
645 | (connection->receive_timeout), connection->sock, | 662 | (connection->receive_timeout), |
663 | connection->sock, | ||
646 | &receive_ready, connection); | 664 | &receive_ready, connection); |
647 | } | 665 | } |
648 | if (NULL != connection->nth.notify_ready) | 666 | if (NULL != connection->nth.notify_ready) |
@@ -679,21 +697,28 @@ connect_probe_continuation (void *cls) | |||
679 | socklen_t len; | 697 | socklen_t len; |
680 | 698 | ||
681 | GNUNET_assert (NULL != ap->sock); | 699 | GNUNET_assert (NULL != ap->sock); |
682 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); | 700 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, |
701 | connection->ap_tail, | ||
702 | ap); | ||
683 | len = sizeof (error); | 703 | len = sizeof (error); |
684 | errno = 0; | 704 | errno = 0; |
685 | error = 0; | 705 | error = 0; |
686 | tc = GNUNET_SCHEDULER_get_task_context (); | 706 | tc = GNUNET_SCHEDULER_get_task_context (); |
687 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || | 707 | if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || |
688 | (GNUNET_OK != | 708 | (GNUNET_OK != |
689 | GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error, | 709 | GNUNET_NETWORK_socket_getsockopt (ap->sock, |
690 | &len)) || (0 != error)) | 710 | SOL_SOCKET, |
711 | SO_ERROR, | ||
712 | &error, | ||
713 | &len)) || | ||
714 | (0 != error) ) | ||
691 | { | 715 | { |
692 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); | 716 | GNUNET_break (GNUNET_OK == |
717 | GNUNET_NETWORK_socket_close (ap->sock)); | ||
693 | GNUNET_free (ap); | 718 | GNUNET_free (ap); |
694 | if ((NULL == connection->ap_head) && | 719 | if ( (NULL == connection->ap_head) && |
695 | (GNUNET_NO == connection->dns_active) && | 720 | (GNUNET_NO == connection->dns_active) && |
696 | (NULL == connection->proxy_handshake)) | 721 | (NULL == connection->proxy_handshake) ) |
697 | connect_fail_continuation (connection); | 722 | connect_fail_continuation (connection); |
698 | return; | 723 | return; |
699 | } | 724 | } |
@@ -709,7 +734,9 @@ connect_probe_continuation (void *cls) | |||
709 | { | 734 | { |
710 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 735 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
711 | GNUNET_SCHEDULER_cancel (pos->task); | 736 | GNUNET_SCHEDULER_cancel (pos->task); |
712 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); | 737 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, |
738 | connection->ap_tail, | ||
739 | pos); | ||
713 | GNUNET_free (pos); | 740 | GNUNET_free (pos); |
714 | } | 741 | } |
715 | connect_success_continuation (connection); | 742 | connect_success_continuation (connection); |
@@ -771,7 +798,8 @@ try_connect_using_address (void *cls, | |||
771 | GNUNET_free (ap); | 798 | GNUNET_free (ap); |
772 | return; /* not supported by us */ | 799 | return; /* not supported by us */ |
773 | } | 800 | } |
774 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); | 801 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, |
802 | SOCK_STREAM, 0); | ||
775 | if (NULL == ap->sock) | 803 | if (NULL == ap->sock) |
776 | { | 804 | { |
777 | GNUNET_free (ap); | 805 | GNUNET_free (ap); |
@@ -782,7 +810,9 @@ try_connect_using_address (void *cls, | |||
782 | GNUNET_a2s (ap->addr, ap->addrlen), | 810 | GNUNET_a2s (ap->addr, ap->addrlen), |
783 | connection); | 811 | connection); |
784 | if ((GNUNET_OK != | 812 | if ((GNUNET_OK != |
785 | GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && | 813 | GNUNET_NETWORK_socket_connect (ap->sock, |
814 | ap->addr, | ||
815 | ap->addrlen)) && | ||
786 | (EINPROGRESS != errno)) | 816 | (EINPROGRESS != errno)) |
787 | { | 817 | { |
788 | /* maybe refused / unsupported address, try next */ | 818 | /* maybe refused / unsupported address, try next */ |
@@ -794,17 +824,15 @@ try_connect_using_address (void *cls, | |||
794 | GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); | 824 | GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); |
795 | delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; | 825 | delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; |
796 | if (NULL != connection->nth.notify_ready) | 826 | if (NULL != connection->nth.notify_ready) |
797 | delay = | 827 | delay = GNUNET_TIME_relative_min (delay, |
798 | GNUNET_TIME_relative_min (delay, | 828 | GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); |
799 | GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); | ||
800 | if (NULL != connection->receiver) | 829 | if (NULL != connection->receiver) |
801 | delay = | 830 | delay = GNUNET_TIME_relative_min (delay, |
802 | GNUNET_TIME_relative_min (delay, | 831 | GNUNET_TIME_absolute_get_remaining (connection->receive_timeout)); |
803 | GNUNET_TIME_absolute_get_remaining | 832 | ap->task = GNUNET_SCHEDULER_add_write_net (delay, |
804 | (connection->receive_timeout)); | 833 | ap->sock, |
805 | ap->task = | 834 | &connect_probe_continuation, |
806 | GNUNET_SCHEDULER_add_write_net (delay, ap->sock, | 835 | ap); |
807 | &connect_probe_continuation, ap); | ||
808 | } | 836 | } |
809 | 837 | ||
810 | 838 | ||
@@ -833,9 +861,11 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | |||
833 | connection->port = port; | 861 | connection->port = port; |
834 | connection->hostname = GNUNET_strdup (hostname); | 862 | connection->hostname = GNUNET_strdup (hostname); |
835 | connection->dns_active = | 863 | connection->dns_active = |
836 | GNUNET_RESOLVER_ip_get (connection->hostname, AF_UNSPEC, | 864 | GNUNET_RESOLVER_ip_get (connection->hostname, |
865 | AF_UNSPEC, | ||
837 | GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, | 866 | GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, |
838 | &try_connect_using_address, connection); | 867 | &try_connect_using_address, |
868 | connection); | ||
839 | return connection; | 869 | return connection; |
840 | } | 870 | } |
841 | 871 | ||
@@ -865,7 +895,8 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
865 | { | 895 | { |
866 | int abstract; | 896 | int abstract; |
867 | 897 | ||
868 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", | 898 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
899 | "TESTING", | ||
869 | "USE_ABSTRACT_SOCKETS"); | 900 | "USE_ABSTRACT_SOCKETS"); |
870 | if (GNUNET_YES == abstract) | 901 | if (GNUNET_YES == abstract) |
871 | un->sun_path[0] = '\0'; | 902 | un->sun_path[0] = '\0'; |
@@ -882,7 +913,9 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
882 | connection->hostname = NULL; | 913 | connection->hostname = NULL; |
883 | connection->addr = (struct sockaddr *) un; | 914 | connection->addr = (struct sockaddr *) un; |
884 | connection->addrlen = sizeof (struct sockaddr_un); | 915 | connection->addrlen = sizeof (struct sockaddr_un); |
885 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 916 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, |
917 | SOCK_STREAM, | ||
918 | 0); | ||
886 | if (NULL == connection->sock) | 919 | if (NULL == connection->sock) |
887 | { | 920 | { |
888 | GNUNET_free (connection->addr); | 921 | GNUNET_free (connection->addr); |
@@ -891,11 +924,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
891 | return NULL; | 924 | return NULL; |
892 | } | 925 | } |
893 | if ( (GNUNET_OK != | 926 | if ( (GNUNET_OK != |
894 | GNUNET_NETWORK_socket_connect (connection->sock, connection->addr, connection->addrlen)) && | 927 | GNUNET_NETWORK_socket_connect (connection->sock, |
928 | connection->addr, | ||
929 | connection->addrlen)) && | ||
895 | (EINPROGRESS != errno) ) | 930 | (EINPROGRESS != errno) ) |
896 | { | 931 | { |
897 | /* Just return; we expect everything to work eventually so don't fail HARD */ | 932 | /* Just return; we expect everything to work eventually so don't fail HARD */ |
898 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); | 933 | GNUNET_break (GNUNET_OK == |
934 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
899 | connection->sock = NULL; | 935 | connection->sock = NULL; |
900 | return connection; | 936 | return connection; |
901 | } | 937 | } |
@@ -971,10 +1007,13 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
971 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); | 1007 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); |
972 | if (NULL == s) | 1008 | if (NULL == s) |
973 | { | 1009 | { |
974 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); | 1010 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
1011 | "socket"); | ||
975 | return NULL; | 1012 | return NULL; |
976 | } | 1013 | } |
977 | return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen); | 1014 | return GNUNET_CONNECTION_connect_socket (s, |
1015 | serv_addr, | ||
1016 | addrlen); | ||
978 | } | 1017 | } |
979 | 1018 | ||
980 | 1019 | ||
@@ -1054,7 +1093,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1054 | { | 1093 | { |
1055 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 1094 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
1056 | GNUNET_SCHEDULER_cancel (pos->task); | 1095 | GNUNET_SCHEDULER_cancel (pos->task); |
1057 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); | 1096 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, |
1097 | connection->ap_tail, | ||
1098 | pos); | ||
1058 | GNUNET_free (pos); | 1099 | GNUNET_free (pos); |
1059 | } | 1100 | } |
1060 | if ( (NULL != connection->sock) && | 1101 | if ( (NULL != connection->sock) && |
@@ -1105,21 +1146,14 @@ receive_ready (void *cls) | |||
1105 | 1146 | ||
1106 | connection->read_task = NULL; | 1147 | connection->read_task = NULL; |
1107 | tc = GNUNET_SCHEDULER_get_task_context (); | 1148 | tc = GNUNET_SCHEDULER_get_task_context (); |
1108 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1109 | { | ||
1110 | /* ignore shutdown request, go again immediately */ | ||
1111 | connection->read_task = | ||
1112 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | ||
1113 | (connection->receive_timeout), connection->sock, | ||
1114 | &receive_ready, connection); | ||
1115 | return; | ||
1116 | } | ||
1117 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 1149 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
1118 | { | 1150 | { |
1119 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1151 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1120 | "Receive from `%s' encounters error: timeout (%s, %p)\n", | 1152 | "Receive from `%s' encounters error: timeout (%s, %p)\n", |
1121 | GNUNET_a2s (connection->addr, connection->addrlen), | 1153 | GNUNET_a2s (connection->addr, |
1122 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), GNUNET_YES), | 1154 | connection->addrlen), |
1155 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), | ||
1156 | GNUNET_YES), | ||
1123 | connection); | 1157 | connection); |
1124 | signal_receive_timeout (connection); | 1158 | signal_receive_timeout (connection); |
1125 | return; | 1159 | return; |
@@ -1130,7 +1164,8 @@ receive_ready (void *cls) | |||
1130 | signal_receive_error (connection, ECONNREFUSED); | 1164 | signal_receive_error (connection, ECONNREFUSED); |
1131 | return; | 1165 | return; |
1132 | } | 1166 | } |
1133 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); | 1167 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, |
1168 | connection->sock)); | ||
1134 | RETRY: | 1169 | RETRY: |
1135 | ret = GNUNET_NETWORK_socket_recv (connection->sock, | 1170 | ret = GNUNET_NETWORK_socket_recv (connection->sock, |
1136 | buffer, | 1171 | buffer, |
@@ -1161,8 +1196,8 @@ RETRY: | |||
1161 | 1196 | ||
1162 | 1197 | ||
1163 | /** | 1198 | /** |
1164 | * Receive data from the given connection. Note that this function will | 1199 | * Receive data from the given connection. Note that this function |
1165 | * call @a receiver asynchronously using the scheduler. It will | 1200 | * will call @a receiver asynchronously using the scheduler. It will |
1166 | * "immediately" return. Note that there MUST only be one active | 1201 | * "immediately" return. Note that there MUST only be one active |
1167 | * receive call per connection at any given point in time (so do not | 1202 | * receive call per connection at any given point in time (so do not |
1168 | * call receive again until the receiver callback has been invoked). | 1203 | * call receive again until the receiver callback has been invoked). |
@@ -1202,7 +1237,10 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, | |||
1202 | (NULL == connection->proxy_handshake)) | 1237 | (NULL == connection->proxy_handshake)) |
1203 | { | 1238 | { |
1204 | connection->receiver = NULL; | 1239 | connection->receiver = NULL; |
1205 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); | 1240 | receiver (receiver_cls, |
1241 | NULL, 0, | ||
1242 | NULL, 0, | ||
1243 | ETIMEDOUT); | ||
1206 | return; | 1244 | return; |
1207 | } | 1245 | } |
1208 | } | 1246 | } |
@@ -1312,7 +1350,9 @@ transmit_timeout (void *cls) | |||
1312 | notify = connection->nth.notify_ready; | 1350 | notify = connection->nth.notify_ready; |
1313 | GNUNET_assert (NULL != notify); | 1351 | GNUNET_assert (NULL != notify); |
1314 | connection->nth.notify_ready = NULL; | 1352 | connection->nth.notify_ready = NULL; |
1315 | notify (connection->nth.notify_ready_cls, 0, NULL); | 1353 | notify (connection->nth.notify_ready_cls, |
1354 | 0, | ||
1355 | NULL); | ||
1316 | } | 1356 | } |
1317 | 1357 | ||
1318 | 1358 | ||
@@ -1339,7 +1379,9 @@ connect_error (void *cls) | |||
1339 | connection->write_task = NULL; | 1379 | connection->write_task = NULL; |
1340 | notify = connection->nth.notify_ready; | 1380 | notify = connection->nth.notify_ready; |
1341 | connection->nth.notify_ready = NULL; | 1381 | connection->nth.notify_ready = NULL; |
1342 | notify (connection->nth.notify_ready_cls, 0, NULL); | 1382 | notify (connection->nth.notify_ready_cls, |
1383 | 0, | ||
1384 | NULL); | ||
1343 | } | 1385 | } |
1344 | 1386 | ||
1345 | 1387 | ||
@@ -1364,21 +1406,6 @@ transmit_ready (void *cls) | |||
1364 | connection->write_task = NULL; | 1406 | connection->write_task = NULL; |
1365 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1407 | GNUNET_assert (NULL == connection->nth.timeout_task); |
1366 | tc = GNUNET_SCHEDULER_get_task_context (); | 1408 | tc = GNUNET_SCHEDULER_get_task_context (); |
1367 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1368 | { | ||
1369 | if (NULL != connection->sock) | ||
1370 | goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ | ||
1371 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1372 | "Transmit to `%s' fails, shutdown happened (%p).\n", | ||
1373 | GNUNET_a2s (connection->addr, connection->addrlen), connection); | ||
1374 | notify = connection->nth.notify_ready; | ||
1375 | if (NULL != notify) | ||
1376 | { | ||
1377 | connection->nth.notify_ready = NULL; | ||
1378 | notify (connection->nth.notify_ready_cls, 0, NULL); | ||
1379 | } | ||
1380 | return; | ||
1381 | } | ||
1382 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 1409 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
1383 | { | 1410 | { |
1384 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1400,7 +1427,8 @@ transmit_ready (void *cls) | |||
1400 | * Hence retry. */ | 1427 | * Hence retry. */ |
1401 | goto SCHEDULE_WRITE; | 1428 | goto SCHEDULE_WRITE; |
1402 | } | 1429 | } |
1403 | if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) | 1430 | if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, |
1431 | connection->sock)) | ||
1404 | { | 1432 | { |
1405 | GNUNET_assert (NULL == connection->write_task); | 1433 | GNUNET_assert (NULL == connection->write_task); |
1406 | /* special circumstances (in particular, shutdown): not yet ready | 1434 | /* special circumstances (in particular, shutdown): not yet ready |
@@ -1444,7 +1472,11 @@ RETRY: | |||
1444 | } | 1472 | } |
1445 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1473 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1446 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", | 1474 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", |
1447 | (unsigned int) ret, have, GNUNET_a2s (connection->addr, connection->addrlen), connection); | 1475 | (unsigned int) ret, |
1476 | have, | ||
1477 | GNUNET_a2s (connection->addr, | ||
1478 | connection->addrlen), | ||
1479 | connection); | ||
1448 | connection->write_buffer_pos += ret; | 1480 | connection->write_buffer_pos += ret; |
1449 | if (connection->write_buffer_pos == connection->write_buffer_off) | 1481 | if (connection->write_buffer_pos == connection->write_buffer_off) |
1450 | { | 1482 | { |
@@ -1452,21 +1484,25 @@ RETRY: | |||
1452 | connection->write_buffer_pos = 0; | 1484 | connection->write_buffer_pos = 0; |
1453 | connection->write_buffer_off = 0; | 1485 | connection->write_buffer_off = 0; |
1454 | } | 1486 | } |
1455 | if ((0 == connection->write_buffer_off) && (NULL == connection->nth.notify_ready)) | 1487 | if ( (0 == connection->write_buffer_off) && |
1488 | (NULL == connection->nth.notify_ready) ) | ||
1456 | return; /* all data sent! */ | 1489 | return; /* all data sent! */ |
1457 | /* not done writing, schedule more */ | 1490 | /* not done writing, schedule more */ |
1458 | SCHEDULE_WRITE: | 1491 | SCHEDULE_WRITE: |
1459 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1492 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1460 | "Re-scheduling transmit_ready (more to do) (%p).\n", connection); | 1493 | "Re-scheduling transmit_ready (more to do) (%p).\n", |
1494 | connection); | ||
1461 | have = connection->write_buffer_off - connection->write_buffer_pos; | 1495 | have = connection->write_buffer_off - connection->write_buffer_pos; |
1462 | GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); | 1496 | GNUNET_assert ( (NULL != connection->nth.notify_ready) || |
1497 | (have > 0) ); | ||
1463 | if (NULL == connection->write_task) | 1498 | if (NULL == connection->write_task) |
1464 | connection->write_task = | 1499 | connection->write_task = |
1465 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == | 1500 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == |
1466 | NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : | 1501 | NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : |
1467 | GNUNET_TIME_absolute_get_remaining | 1502 | GNUNET_TIME_absolute_get_remaining |
1468 | (connection->nth.transmit_timeout), | 1503 | (connection->nth.transmit_timeout), |
1469 | connection->sock, &transmit_ready, connection); | 1504 | connection->sock, |
1505 | &transmit_ready, connection); | ||
1470 | } | 1506 | } |
1471 | 1507 | ||
1472 | 1508 | ||
@@ -1488,8 +1524,8 @@ struct GNUNET_CONNECTION_TransmitHandle * | |||
1488 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, | 1524 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, |
1489 | size_t size, | 1525 | size_t size, |
1490 | struct GNUNET_TIME_Relative timeout, | 1526 | struct GNUNET_TIME_Relative timeout, |
1491 | GNUNET_CONNECTION_TransmitReadyNotify | 1527 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
1492 | notify, void *notify_cls) | 1528 | void *notify_cls) |
1493 | { | 1529 | { |
1494 | if (NULL != connection->nth.notify_ready) | 1530 | if (NULL != connection->nth.notify_ready) |
1495 | { | 1531 | { |
@@ -1529,7 +1565,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1529 | connection->write_task = | 1565 | connection->write_task = |
1530 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 1566 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining |
1531 | (connection->nth.transmit_timeout), | 1567 | (connection->nth.transmit_timeout), |
1532 | connection->sock, &transmit_ready, connection); | 1568 | connection->sock, |
1569 | &transmit_ready, connection); | ||
1533 | return &connection->nth; | 1570 | return &connection->nth; |
1534 | } | 1571 | } |
1535 | /* not yet connected, wait for connection */ | 1572 | /* not yet connected, wait for connection */ |
@@ -1538,7 +1575,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1538 | connection); | 1575 | connection); |
1539 | connection->nth.timeout_task = | 1576 | connection->nth.timeout_task = |
1540 | GNUNET_SCHEDULER_add_delayed (timeout, | 1577 | GNUNET_SCHEDULER_add_delayed (timeout, |
1541 | &transmit_timeout, connection); | 1578 | &transmit_timeout, |
1579 | connection); | ||
1542 | return &connection->nth; | 1580 | return &connection->nth; |
1543 | } | 1581 | } |
1544 | 1582 | ||
@@ -1575,7 +1613,8 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi | |||
1575 | struct GNUNET_CONNECTION_Handle * | 1613 | struct GNUNET_CONNECTION_Handle * |
1576 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) | 1614 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) |
1577 | { | 1615 | { |
1578 | struct GNUNET_CONNECTION_Handle * proxied = GNUNET_CONNECTION_create_from_existing(NULL); | 1616 | struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL); |
1617 | |||
1579 | proxied->proxy_handshake = cph; | 1618 | proxied->proxy_handshake = cph; |
1580 | return proxied; | 1619 | return proxied; |
1581 | } | 1620 | } |
@@ -1592,11 +1631,12 @@ void | |||
1592 | GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) | 1631 | GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) |
1593 | { | 1632 | { |
1594 | struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; | 1633 | struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; |
1634 | |||
1595 | GNUNET_assert (NULL != cph); | 1635 | GNUNET_assert (NULL != cph); |
1596 | GNUNET_assert (NULL == proxied->sock); | 1636 | GNUNET_assert (NULL == proxied->sock); |
1597 | GNUNET_assert (NULL != cph->sock); | 1637 | GNUNET_assert (NULL != cph->sock); |
1598 | proxied->sock=cph->sock; | 1638 | proxied->sock = cph->sock; |
1599 | cph->sock=NULL; | 1639 | cph->sock = NULL; |
1600 | GNUNET_CONNECTION_destroy (cph); | 1640 | GNUNET_CONNECTION_destroy (cph); |
1601 | connect_success_continuation (proxied); | 1641 | connect_success_continuation (proxied); |
1602 | } | 1642 | } |