diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-07-03 12:10:02 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-07-03 12:10:02 +0000 |
commit | 51dbce39943d78c1986a1cac14f01735b7c078d6 (patch) | |
tree | 1a8f777497760b33f5c4d322d8c8b51ab3d5b406 /src/transport | |
parent | fe757f9badda3f812f927322f603c6105c5ad28d (diff) | |
download | gnunet-51dbce39943d78c1986a1cac14f01735b7c078d6.tar.gz gnunet-51dbce39943d78c1986a1cac14f01735b7c078d6.zip |
- introducing state for put requests
- clean up shutdown
- renaming GET/PUT connections to "requests"
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 491 |
1 files changed, 260 insertions, 231 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index e996c70c5..87ad1fb60 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done | 37 | #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define VERBOSE_CURL GNUNET_YES | 40 | #define VERBOSE_CURL GNUNET_NO |
41 | 41 | ||
42 | #define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 42 | #define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
43 | 43 | ||
@@ -59,6 +59,46 @@ | |||
59 | */ | 59 | */ |
60 | struct HTTP_Client_Plugin; | 60 | struct HTTP_Client_Plugin; |
61 | 61 | ||
62 | /** | ||
63 | * State of a HTTP PUT request | ||
64 | */ | ||
65 | enum HTTP_PUT_REQUEST_STATE | ||
66 | { | ||
67 | /** | ||
68 | * Just created, not yet connected | ||
69 | */ | ||
70 | H_NOT_CONNECTED, | ||
71 | |||
72 | /** | ||
73 | * Connected | ||
74 | */ | ||
75 | H_CONNECTED, | ||
76 | |||
77 | /** | ||
78 | * Paused, nothing to send | ||
79 | */ | ||
80 | H_PAUSED, | ||
81 | |||
82 | /** | ||
83 | * Temporary disconnect in progress due to inactivity | ||
84 | */ | ||
85 | H_TMP_DISCONNECTING, | ||
86 | |||
87 | /** | ||
88 | * Send request while temporary disconnect, reconnect | ||
89 | */ | ||
90 | H_TMP_RECONNECT_REQUIRED, | ||
91 | |||
92 | /** | ||
93 | * Temporarily disconnected | ||
94 | */ | ||
95 | H_TMP_DISCONNECTED, | ||
96 | |||
97 | /** | ||
98 | * Disconnected | ||
99 | */ | ||
100 | H_DISCONNECTED | ||
101 | }; | ||
62 | 102 | ||
63 | /** | 103 | /** |
64 | * Message to send using http | 104 | * Message to send using http |
@@ -106,18 +146,23 @@ struct HTTP_Message | |||
106 | 146 | ||
107 | 147 | ||
108 | /** | 148 | /** |
109 | * Session handle for connections. | 149 | * Session handle for HTTP(S) connections. |
110 | */ | 150 | */ |
111 | struct Session; | 151 | struct Session; |
112 | 152 | ||
113 | 153 | ||
114 | /** | 154 | /** |
115 | * A connection handle | 155 | * A request handle |
116 | * | 156 | * |
117 | */ | 157 | */ |
118 | struct ConnectionHandle | 158 | struct RequestHandle |
119 | { | 159 | { |
120 | /** | 160 | /** |
161 | * Current state of this request | ||
162 | */ | ||
163 | enum HTTP_PUT_REQUEST_STATE state; | ||
164 | |||
165 | /** | ||
121 | * The curl easy handle | 166 | * The curl easy handle |
122 | */ | 167 | */ |
123 | CURL *easyhandle; | 168 | CURL *easyhandle; |
@@ -152,12 +197,12 @@ struct Session | |||
152 | /** | 197 | /** |
153 | * Handle for the HTTP PUT request. | 198 | * Handle for the HTTP PUT request. |
154 | */ | 199 | */ |
155 | struct ConnectionHandle put; | 200 | struct RequestHandle put; |
156 | 201 | ||
157 | /** | 202 | /** |
158 | * Handle for the HTTP GET request. | 203 | * Handle for the HTTP GET request. |
159 | */ | 204 | */ |
160 | struct ConnectionHandle get; | 205 | struct RequestHandle get; |
161 | 206 | ||
162 | /** | 207 | /** |
163 | * next pointer for double linked list | 208 | * next pointer for double linked list |
@@ -220,26 +265,6 @@ struct Session | |||
220 | * ATS network type in NBO | 265 | * ATS network type in NBO |
221 | */ | 266 | */ |
222 | uint32_t ats_address_network_type; | 267 | uint32_t ats_address_network_type; |
223 | |||
224 | /** | ||
225 | * Is the client PUT handle currently paused? | ||
226 | */ | ||
227 | int put_paused; | ||
228 | |||
229 | /** | ||
230 | * Is the client PUT handle disconnect in progress? | ||
231 | */ | ||
232 | int put_tmp_disconnecting; | ||
233 | |||
234 | /** | ||
235 | * Is the client PUT handle temporarily disconnected? | ||
236 | */ | ||
237 | int put_tmp_disconnected; | ||
238 | |||
239 | /** | ||
240 | * We received data to send while disconnecting, reconnect immediately | ||
241 | */ | ||
242 | int put_reconnect_required; | ||
243 | }; | 268 | }; |
244 | 269 | ||
245 | 270 | ||
@@ -328,15 +353,15 @@ struct HTTP_Client_Plugin | |||
328 | 353 | ||
329 | /** | 354 | /** |
330 | * Maximum number of sockets the plugin can use | 355 | * Maximum number of sockets the plugin can use |
331 | * Each http inbound /outbound connections are two connections | 356 | * Each http connections are two requests |
332 | */ | 357 | */ |
333 | unsigned int max_connections; | 358 | unsigned int max_requests; |
334 | 359 | ||
335 | /** | 360 | /** |
336 | * Current number of sockets the plugin can use | 361 | * Current number of sockets the plugin can use |
337 | * Each http inbound /outbound connections are two connections | 362 | * Each http connections are two requests |
338 | */ | 363 | */ |
339 | unsigned int cur_connections; | 364 | unsigned int cur_requests; |
340 | 365 | ||
341 | /** | 366 | /** |
342 | * Last used unique HTTP connection tag | 367 | * Last used unique HTTP connection tag |
@@ -359,7 +384,15 @@ struct HTTP_Client_Plugin | |||
359 | int emulate_xhr; | 384 | int emulate_xhr; |
360 | }; | 385 | }; |
361 | 386 | ||
362 | 387 | /** | |
388 | * Disconnect a session | ||
389 | * | ||
390 | * @param cls the `struct HTTP_Client_Plugin *` | ||
391 | * @param s session | ||
392 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
393 | */ | ||
394 | static int | ||
395 | http_client_plugin_session_disconnect (void *cls, struct Session *s); | ||
363 | 396 | ||
364 | /** | 397 | /** |
365 | * If a session monitor is attached, notify it about the new | 398 | * If a session monitor is attached, notify it about the new |
@@ -428,7 +461,7 @@ client_delete_session (struct Session *s) | |||
428 | if (NULL != s->put.easyhandle) | 461 | if (NULL != s->put.easyhandle) |
429 | { | 462 | { |
430 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 463 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
431 | "Session %p/connection %p: disconnecting PUT connection to peer `%s'\n", | 464 | "Session %p/request %p: disconnecting PUT request to peer `%s'\n", |
432 | s, | 465 | s, |
433 | s->put.easyhandle, | 466 | s->put.easyhandle, |
434 | GNUNET_i2s (&s->address->peer)); | 467 | GNUNET_i2s (&s->address->peer)); |
@@ -443,7 +476,7 @@ client_delete_session (struct Session *s) | |||
443 | if (NULL != s->get.easyhandle) | 476 | if (NULL != s->get.easyhandle) |
444 | { | 477 | { |
445 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 478 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
446 | "Session %p/connection %p: disconnecting GET connection to peer `%s'\n", | 479 | "Session %p/request %p: disconnecting GET request to peer `%s'\n", |
447 | s, s->get.easyhandle, | 480 | s, s->get.easyhandle, |
448 | GNUNET_i2s (&s->address->peer)); | 481 | GNUNET_i2s (&s->address->peer)); |
449 | /* remove curl handle from multi handle */ | 482 | /* remove curl handle from multi handle */ |
@@ -451,13 +484,13 @@ client_delete_session (struct Session *s) | |||
451 | s->get.easyhandle); | 484 | s->get.easyhandle); |
452 | GNUNET_break (CURLM_OK == mret); | 485 | GNUNET_break (CURLM_OK == mret); |
453 | curl_easy_cleanup (s->get.easyhandle); | 486 | curl_easy_cleanup (s->get.easyhandle); |
454 | GNUNET_assert (plugin->cur_connections > 0); | 487 | GNUNET_assert (plugin->cur_requests > 0); |
455 | plugin->cur_connections--; | 488 | plugin->cur_requests--; |
456 | s->get.easyhandle = NULL; | 489 | s->get.easyhandle = NULL; |
457 | } | 490 | } |
458 | GNUNET_STATISTICS_set (plugin->env->stats, | 491 | GNUNET_STATISTICS_set (plugin->env->stats, |
459 | HTTP_STAT_STR_CONNECTIONS, | 492 | HTTP_STAT_STR_CONNECTIONS, |
460 | plugin->cur_connections, | 493 | plugin->cur_requests, |
461 | GNUNET_NO); | 494 | GNUNET_NO); |
462 | next = s->msg_head; | 495 | next = s->msg_head; |
463 | while (NULL != (pos = next)) | 496 | while (NULL != (pos = next)) |
@@ -580,6 +613,7 @@ client_schedule (struct HTTP_Client_Plugin *plugin, | |||
580 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 613 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
581 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); | 614 | GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); |
582 | 615 | ||
616 | /* Schedule task to run when select is ready to read or write */ | ||
583 | plugin->client_perform_task = | 617 | plugin->client_perform_task = |
584 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 618 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
585 | timeout, grs, gws, | 619 | timeout, grs, gws, |
@@ -589,7 +623,7 @@ client_schedule (struct HTTP_Client_Plugin *plugin, | |||
589 | return GNUNET_OK; | 623 | return GNUNET_OK; |
590 | } | 624 | } |
591 | 625 | ||
592 | 626 | #if VERBOSE_CURL | |
593 | /** | 627 | /** |
594 | * Loggging function | 628 | * Loggging function |
595 | * | 629 | * |
@@ -607,7 +641,7 @@ client_log (CURL *curl, | |||
607 | size_t size, | 641 | size_t size, |
608 | void *cls) | 642 | void *cls) |
609 | { | 643 | { |
610 | struct ConnectionHandle *ch = cls; | 644 | struct RequestHandle *ch = cls; |
611 | const char *ttype = "UNSPECIFIED"; | 645 | const char *ttype = "UNSPECIFIED"; |
612 | char text[size + 2]; | 646 | char text[size + 2]; |
613 | 647 | ||
@@ -644,16 +678,16 @@ client_log (CURL *curl, | |||
644 | text[size + 1] = '\0'; | 678 | text[size + 1] = '\0'; |
645 | } | 679 | } |
646 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 680 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
647 | "Connection %p %s: %s", | 681 | "Request %p %s: %s", |
648 | ch->easyhandle, | 682 | ch->easyhandle, |
649 | ttype, | 683 | ttype, |
650 | text); | 684 | text); |
651 | return 0; | 685 | return 0; |
652 | } | 686 | } |
653 | 687 | #endif | |
654 | 688 | ||
655 | /** | 689 | /** |
656 | * Connect GET connection for a session | 690 | * Connect GET request |
657 | * | 691 | * |
658 | * @param s the session to connect | 692 | * @param s the session to connect |
659 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 693 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
@@ -663,7 +697,7 @@ client_connect_get (struct Session *s); | |||
663 | 697 | ||
664 | 698 | ||
665 | /** | 699 | /** |
666 | * Connect a HTTP put connection | 700 | * Connect a HTTP put request |
667 | * | 701 | * |
668 | * @param s the session to connect | 702 | * @param s the session to connect |
669 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success | 703 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success |
@@ -714,7 +748,7 @@ http_client_plugin_send (void *cls, | |||
714 | char *stat_txt; | 748 | char *stat_txt; |
715 | 749 | ||
716 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 750 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
717 | "Session %p/connection %p: Sending message with %u to peer `%s' \n", | 751 | "Session %p/request %p: Sending message with %u to peer `%s' \n", |
718 | s, s->put.easyhandle, | 752 | s, s->put.easyhandle, |
719 | msgbuf_size, GNUNET_i2s (&s->address->peer)); | 753 | msgbuf_size, GNUNET_i2s (&s->address->peer)); |
720 | 754 | ||
@@ -742,42 +776,42 @@ http_client_plugin_send (void *cls, | |||
742 | notify_session_monitor (plugin, | 776 | notify_session_monitor (plugin, |
743 | s, | 777 | s, |
744 | GNUNET_TRANSPORT_SS_UP); | 778 | GNUNET_TRANSPORT_SS_UP); |
745 | if (GNUNET_YES == s->put_tmp_disconnecting) | 779 | if (H_TMP_DISCONNECTING == s->put.state) |
746 | { | 780 | { |
747 | /* PUT connection is currently getting disconnected */ | 781 | /* PUT request is currently getting disconnected */ |
748 | s->put_reconnect_required = GNUNET_YES; | 782 | s->put.state = H_TMP_RECONNECT_REQUIRED; |
749 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 783 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
750 | "Session %p/connection %jp: currently disconnecting, reconnecting immediately\n", | 784 | "Session %p/request %p: currently disconnecting, reconnecting immediately\n", |
751 | s, | 785 | s, |
752 | s->put.easyhandle); | 786 | s->put.easyhandle); |
753 | return msgbuf_size; | 787 | return msgbuf_size; |
754 | } | 788 | } |
755 | if (GNUNET_YES == s->put_paused) | 789 | if (H_PAUSED == s->put.state) |
756 | { | 790 | { |
757 | /* PUT connection was paused, unpause */ | 791 | /* PUT request was paused, unpause */ |
758 | GNUNET_assert (s->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); | 792 | GNUNET_assert (s->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); |
759 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); | 793 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); |
760 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 794 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
761 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 795 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
762 | "Session %p/connection %p: unpausing connection\n", | 796 | "Session %p/request %p: unpausing request\n", |
763 | s, s->put.easyhandle); | 797 | s, s->put.easyhandle); |
764 | s->put_paused = GNUNET_NO; | 798 | s->put.state = H_CONNECTED; |
765 | if (NULL != s->put.easyhandle) | 799 | if (NULL != s->put.easyhandle) |
766 | curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); | 800 | curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); |
767 | } | 801 | } |
768 | else if (GNUNET_YES == s->put_tmp_disconnected) | 802 | else if (H_TMP_DISCONNECTED == s->put.state) |
769 | { | 803 | { |
770 | /* PUT connection was disconnected, reconnect */ | 804 | /* PUT request was disconnected, reconnect */ |
771 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 805 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s); |
772 | "Session %p: Reconnecting PUT connection\n", | ||
773 | s); | ||
774 | s->put_tmp_disconnected = GNUNET_NO; | ||
775 | GNUNET_break (NULL == s->put.easyhandle); | 806 | GNUNET_break (NULL == s->put.easyhandle); |
776 | if (GNUNET_SYSERR == client_connect_put (s)) | 807 | if (GNUNET_SYSERR == client_connect_put (s)) |
808 | { | ||
809 | /* Could not reconnect */ | ||
810 | http_client_plugin_session_disconnect (plugin, s); | ||
777 | return GNUNET_SYSERR; | 811 | return GNUNET_SYSERR; |
812 | } | ||
778 | } | 813 | } |
779 | client_schedule (s->plugin, | 814 | client_schedule (s->plugin, GNUNET_YES); |
780 | GNUNET_YES); | ||
781 | return msgbuf_size; | 815 | return msgbuf_size; |
782 | } | 816 | } |
783 | 817 | ||
@@ -797,9 +831,7 @@ http_client_plugin_session_disconnect (void *cls, | |||
797 | 831 | ||
798 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 832 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
799 | "Session %p: notifying transport about ending session\n",s); | 833 | "Session %p: notifying transport about ending session\n",s); |
800 | plugin->env->session_end (plugin->env->cls, | 834 | plugin->env->session_end (plugin->env->cls, s->address, s); |
801 | s->address, | ||
802 | s); | ||
803 | client_delete_session (s); | 835 | client_delete_session (s); |
804 | 836 | ||
805 | /* Re-schedule since handles have changed */ | 837 | /* Re-schedule since handles have changed */ |
@@ -867,10 +899,8 @@ http_client_plugin_peer_disconnect (void *cls, | |||
867 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 899 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
868 | "Transport tells me to disconnect `%s'\n", | 900 | "Transport tells me to disconnect `%s'\n", |
869 | GNUNET_i2s (target)); | 901 | GNUNET_i2s (target)); |
870 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, | 902 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, |
871 | target, | 903 | &destroy_session_cb, plugin); |
872 | &destroy_session_cb, | ||
873 | plugin); | ||
874 | } | 904 | } |
875 | 905 | ||
876 | 906 | ||
@@ -942,7 +972,7 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, | |||
942 | /** | 972 | /** |
943 | * When we have nothing to transmit, we pause the HTTP PUT | 973 | * When we have nothing to transmit, we pause the HTTP PUT |
944 | * after a while (so that gnurl stops asking). This task | 974 | * after a while (so that gnurl stops asking). This task |
945 | * is the delayed task that actually pauses the PUT. | 975 | * is the delayed task that actually disconnects the PUT. |
946 | * | 976 | * |
947 | * @param cls the `struct Session *` with the put | 977 | * @param cls the `struct Session *` with the put |
948 | * @param tc scheduler context | 978 | * @param tc scheduler context |
@@ -955,10 +985,9 @@ client_put_disconnect (void *cls, | |||
955 | 985 | ||
956 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 986 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
957 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 987 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
958 | "Session %p/connection %p: will be disconnected due to no activity\n", | 988 | "Session %p/request %p: will be disconnected due to no activity\n", |
959 | s, s->put.easyhandle); | 989 | s, s->put.easyhandle); |
960 | s->put_paused = GNUNET_NO; | 990 | s->put.state = H_TMP_DISCONNECTING; |
961 | s->put_tmp_disconnecting = GNUNET_YES; | ||
962 | if (NULL != s->put.easyhandle) | 991 | if (NULL != s->put.easyhandle) |
963 | curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); | 992 | curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); |
964 | client_schedule (s->plugin, GNUNET_YES); | 993 | client_schedule (s->plugin, GNUNET_YES); |
@@ -973,7 +1002,7 @@ client_put_disconnect (void *cls, | |||
973 | * @param size size of an individual element | 1002 | * @param size size of an individual element |
974 | * @param nmemb count of elements that can be written to the buffer | 1003 | * @param nmemb count of elements that can be written to the buffer |
975 | * @param cls our `struct Session` | 1004 | * @param cls our `struct Session` |
976 | * @return bytes written to stream, returning 0 will terminate connection! | 1005 | * @return bytes written to stream, returning 0 will terminate request! |
977 | */ | 1006 | */ |
978 | static size_t | 1007 | static size_t |
979 | client_send_cb (void *stream, | 1008 | client_send_cb (void *stream, |
@@ -987,10 +1016,10 @@ client_send_cb (void *stream, | |||
987 | size_t len; | 1016 | size_t len; |
988 | char *stat_txt; | 1017 | char *stat_txt; |
989 | 1018 | ||
990 | if (GNUNET_YES == s->put_tmp_disconnecting) | 1019 | if (H_TMP_DISCONNECTING == s->put.state) |
991 | { | 1020 | { |
992 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1021 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
993 | "Session %p/connection %p: disconnect due to inactivity\n", | 1022 | "Session %p/request %p: disconnect due to inactivity\n", |
994 | s, s->put.easyhandle); | 1023 | s, s->put.easyhandle); |
995 | return 0; | 1024 | return 0; |
996 | } | 1025 | } |
@@ -1000,19 +1029,19 @@ client_send_cb (void *stream, | |||
1000 | if (GNUNET_YES == plugin->emulate_xhr) | 1029 | if (GNUNET_YES == plugin->emulate_xhr) |
1001 | { | 1030 | { |
1002 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1031 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1003 | "Session %p/connection %p: PUT request finished\n", | 1032 | "Session %p/request %p: PUT request finished\n", |
1004 | s, s->put.easyhandle); | 1033 | s, s->put.easyhandle); |
1005 | s->put_tmp_disconnecting = GNUNET_YES; | 1034 | s->put.state = H_TMP_DISCONNECTING; |
1006 | return 0; | 1035 | return 0; |
1007 | } | 1036 | } |
1008 | 1037 | ||
1038 | /* We have nothing to send, so pause PUT request */ | ||
1009 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1039 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1010 | "Session %p/connection %p: nothing to send, suspending\n", | 1040 | "Session %p/request %p: nothing to send, suspending\n", |
1011 | s, s->put.easyhandle); | 1041 | s, s->put.easyhandle); |
1012 | s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, | 1042 | s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, |
1013 | &client_put_disconnect, | 1043 | &client_put_disconnect, s); |
1014 | s); | 1044 | s->put.state = H_PAUSED; |
1015 | s->put_paused = GNUNET_YES; | ||
1016 | return CURL_READFUNC_PAUSE; | 1045 | return CURL_READFUNC_PAUSE; |
1017 | } | 1046 | } |
1018 | /* data to send */ | 1047 | /* data to send */ |
@@ -1025,7 +1054,7 @@ client_send_cb (void *stream, | |||
1025 | if (msg->pos == msg->size) | 1054 | if (msg->pos == msg->size) |
1026 | { | 1055 | { |
1027 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1056 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1028 | "Session %p/connection %p: sent message with %u bytes sent, removing message from queue\n", | 1057 | "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", |
1029 | s, s->put.easyhandle, msg->size, msg->pos); | 1058 | s, s->put.easyhandle, msg->size, msg->pos); |
1030 | /* Calling transmit continuation */ | 1059 | /* Calling transmit continuation */ |
1031 | GNUNET_CONTAINER_DLL_remove (s->msg_head, | 1060 | GNUNET_CONTAINER_DLL_remove (s->msg_head, |
@@ -1083,21 +1112,20 @@ client_wake_up (void *cls, | |||
1083 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1112 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1084 | return; | 1113 | return; |
1085 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1114 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1086 | "Session %p/connection %p: Waking up GET handle\n", | 1115 | "Session %p/request %p: Waking up GET handle\n", |
1087 | s, s->get.easyhandle); | 1116 | s, s->get.easyhandle); |
1088 | if (GNUNET_YES == s->put_paused) | 1117 | if (H_PAUSED == s->put.state) |
1089 | { | 1118 | { |
1090 | /* PUT connection was paused, unpause */ | 1119 | /* PUT request was paused, unpause */ |
1091 | GNUNET_assert (s->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); | 1120 | GNUNET_assert (s->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); |
1092 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); | 1121 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); |
1093 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1122 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
1094 | s->put_paused = GNUNET_NO; | 1123 | s->put.state = H_CONNECTED; |
1095 | if (NULL != s->put.easyhandle) | 1124 | if (NULL != s->put.easyhandle) |
1096 | curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); | 1125 | curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); |
1097 | } | 1126 | } |
1098 | if (NULL != s->get.easyhandle) | 1127 | if (NULL != s->get.easyhandle) |
1099 | curl_easy_pause (s->get.easyhandle, | 1128 | curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT); |
1100 | CURLPAUSE_CONT); | ||
1101 | } | 1129 | } |
1102 | 1130 | ||
1103 | 1131 | ||
@@ -1160,7 +1188,7 @@ client_receive_mst_cb (void *cls, | |||
1160 | 1188 | ||
1161 | 1189 | ||
1162 | /** | 1190 | /** |
1163 | * Callback method used with libcurl when data for a PUT connection are | 1191 | * Callback method used with libcurl when data for a PUT request are |
1164 | * received. We do not expect data here, so we just discard it. | 1192 | * received. We do not expect data here, so we just discard it. |
1165 | * | 1193 | * |
1166 | * @param stream pointer where to write data | 1194 | * @param stream pointer where to write data |
@@ -1180,7 +1208,7 @@ client_receive_put (void *stream, | |||
1180 | 1208 | ||
1181 | 1209 | ||
1182 | /** | 1210 | /** |
1183 | * Callback method used with libcurl when data for a GET connection are | 1211 | * Callback method used with libcurl when data for a GET request are |
1184 | * received. Forward to MST | 1212 | * received. Forward to MST |
1185 | * | 1213 | * |
1186 | * @param stream pointer where to write data | 1214 | * @param stream pointer where to write data |
@@ -1200,7 +1228,7 @@ client_receive (void *stream, | |||
1200 | size_t len = size * nmemb; | 1228 | size_t len = size * nmemb; |
1201 | 1229 | ||
1202 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1230 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1203 | "Session %p / connection %p: Received %u bytes from peer `%s'\n", | 1231 | "Session %p / request %p: Received %u bytes from peer `%s'\n", |
1204 | s, s->get.easyhandle, | 1232 | s, s->get.easyhandle, |
1205 | len, GNUNET_i2s (&s->address->peer)); | 1233 | len, GNUNET_i2s (&s->address->peer)); |
1206 | now = GNUNET_TIME_absolute_get (); | 1234 | now = GNUNET_TIME_absolute_get (); |
@@ -1211,7 +1239,7 @@ client_receive (void *stream, | |||
1211 | = GNUNET_TIME_absolute_get_difference (now, s->next_receive); | 1239 | = GNUNET_TIME_absolute_get_difference (now, s->next_receive); |
1212 | 1240 | ||
1213 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1241 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1214 | "Session %p / connection %p: No inbound bandwidth available! Next read was delayed for %s\n", | 1242 | "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n", |
1215 | s, | 1243 | s, |
1216 | s->get.easyhandle, | 1244 | s->get.easyhandle, |
1217 | GNUNET_STRINGS_relative_time_to_string (delta, | 1245 | GNUNET_STRINGS_relative_time_to_string (delta, |
@@ -1255,134 +1283,136 @@ client_run (void *cls, | |||
1255 | long http_statuscode; | 1283 | long http_statuscode; |
1256 | CURLMcode mret; | 1284 | CURLMcode mret; |
1257 | CURLMsg *msg; | 1285 | CURLMsg *msg; |
1286 | int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */ | ||
1258 | int msgs_left; | 1287 | int msgs_left; |
1259 | 1288 | ||
1260 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; | 1289 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
1261 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1290 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1262 | return; | 1291 | return; |
1292 | |||
1293 | /* While data are available or timeouts occured */ | ||
1263 | do | 1294 | do |
1264 | { | 1295 | { |
1265 | running = 0; | 1296 | running = 0; |
1297 | /* Perform operations for all handles */ | ||
1266 | mret = curl_multi_perform (plugin->curl_multi_handle, &running); | 1298 | mret = curl_multi_perform (plugin->curl_multi_handle, &running); |
1267 | 1299 | ||
1268 | 1300 | /* Get additional information for all handles */ | |
1269 | while ((msg = curl_multi_info_read (plugin->curl_multi_handle, &msgs_left))) | 1301 | while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle, &msgs_left))) |
1270 | { | 1302 | { |
1271 | CURL *easy_h = msg->easy_handle; | 1303 | CURL *easy_h = msg->easy_handle; |
1272 | struct Session *s = NULL; | 1304 | struct Session *s = NULL; |
1273 | char *d = NULL; /* curl requires 'd' to be a 'char *' */ | 1305 | char *d = NULL; /* curl requires 'd' to be a 'char *' */ |
1274 | 1306 | ||
1275 | if (NULL == easy_h) | 1307 | GNUNET_assert (NULL != easy_h); |
1276 | { | ||
1277 | GNUNET_break (0); | ||
1278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1279 | "Client: connection to ended with reason %i: `%s', %i handles running\n", | ||
1280 | msg->data.result, | ||
1281 | curl_easy_strerror (msg->data.result), running); | ||
1282 | continue; | ||
1283 | } | ||
1284 | 1308 | ||
1285 | GNUNET_assert (CURLE_OK == | 1309 | /* Obtain session from easy handle */ |
1286 | curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d)); | 1310 | GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d)); |
1287 | s = (struct Session *) d; | 1311 | s = (struct Session *) d; |
1288 | GNUNET_assert (NULL != s); | 1312 | GNUNET_assert (NULL != s); |
1289 | if (msg->msg == CURLMSG_DONE) | 1313 | |
1314 | if (msg->msg != CURLMSG_DONE) | ||
1315 | continue; /* This should not happen */ | ||
1316 | |||
1317 | /* Get HTTP response code */ | ||
1318 | GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h, | ||
1319 | CURLINFO_RESPONSE_CODE, &http_statuscode)); | ||
1320 | |||
1321 | |||
1322 | if (easy_h == s->put.easyhandle) | ||
1323 | put_request = GNUNET_YES; | ||
1324 | else | ||
1325 | put_request = GNUNET_NO; | ||
1326 | |||
1327 | /* Log status of terminated request */ | ||
1328 | if ((0 != msg->data.result) || (http_statuscode != 200)) | ||
1329 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1330 | "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n", | ||
1331 | s, msg->easy_handle, | ||
1332 | (GNUNET_YES == put_request) ? "PUT" : "GET", | ||
1333 | GNUNET_i2s (&s->address->peer), | ||
1334 | http_statuscode, | ||
1335 | msg->data.result, | ||
1336 | curl_easy_strerror (msg->data.result)); | ||
1337 | else | ||
1338 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1339 | "Session %p/request %p: %s request to `%s' ended normal\n", | ||
1340 | s, msg->easy_handle, | ||
1341 | (GNUNET_YES == put_request) ? "PUT" : "GET", | ||
1342 | GNUNET_i2s (&s->address->peer)); | ||
1343 | |||
1344 | /* Remove easy handle from multi handle */ | ||
1345 | curl_multi_remove_handle (plugin->curl_multi_handle, easy_h); | ||
1346 | |||
1347 | /* Clean up easy handle */ | ||
1348 | curl_easy_cleanup (easy_h); | ||
1349 | |||
1350 | /* Remove information */ | ||
1351 | GNUNET_assert (plugin->cur_requests > 0); | ||
1352 | plugin->cur_requests--; | ||
1353 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1354 | "%s request done, number of requests decreased to %u\n", | ||
1355 | (GNUNET_YES == put_request) ? "PUT" : "GET", | ||
1356 | plugin->cur_requests); | ||
1357 | |||
1358 | if (GNUNET_YES == put_request) | ||
1290 | { | 1359 | { |
1291 | GNUNET_break (CURLE_OK == | 1360 | /* Clean up a PUT request */ |
1292 | curl_easy_getinfo (easy_h, | 1361 | s->put.easyhandle = NULL; |
1293 | CURLINFO_RESPONSE_CODE, | 1362 | s->put.s = NULL; |
1294 | &http_statuscode)); | 1363 | |
1295 | if (easy_h == s->put.easyhandle) | 1364 | switch (s->put.state) { |
1296 | { | 1365 | case H_NOT_CONNECTED: |
1297 | if ((0 != msg->data.result) || (http_statuscode != 200)) | 1366 | case H_DISCONNECTED: |
1298 | { | 1367 | case H_TMP_DISCONNECTED: |
1299 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1368 | /* This must not happen */ |
1300 | "Session %p/connection %p: PUT connection to `%s' ended with status %i reason %i: `%s'\n", | 1369 | GNUNET_break (0); |
1301 | s, msg->easy_handle, | 1370 | break; |
1302 | GNUNET_i2s (&s->address->peer), | 1371 | case H_TMP_RECONNECT_REQUIRED: |
1303 | http_statuscode, | 1372 | /* Transport called send while disconnect in progess, reconnect */ |
1304 | msg->data.result, | ||
1305 | curl_easy_strerror (msg->data.result)); | ||
1306 | } | ||
1307 | else | ||
1308 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1309 | "Session %p/connection %p: PUT connection to `%s' ended normal\n", | ||
1310 | s, msg->easy_handle, | ||
1311 | GNUNET_i2s (&s->address->peer)); | ||
1312 | if (NULL == s->get.easyhandle) | ||
1313 | { | ||
1314 | /* Disconnect other transmission direction and tell transport */ | ||
1315 | /* FIXME? */ | ||
1316 | } | ||
1317 | curl_multi_remove_handle (plugin->curl_multi_handle, | ||
1318 | easy_h); | ||
1319 | curl_easy_cleanup (easy_h); | ||
1320 | GNUNET_assert (plugin->cur_connections > 0); | ||
1321 | plugin->cur_connections--; | ||
1322 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1323 | "PUT request done, number of connections decreased to %u\n", | ||
1324 | plugin->cur_connections); | ||
1325 | s->put_tmp_disconnecting = GNUNET_NO; | ||
1326 | s->put_tmp_disconnected = GNUNET_YES; | ||
1327 | s->put.easyhandle = NULL; | ||
1328 | s->put.easyhandle = NULL; | ||
1329 | s->put.s = NULL; | ||
1330 | |||
1331 | /* | ||
1332 | * Handling a rare case: | ||
1333 | * plugin_send was called during temporary put disconnect, | ||
1334 | * reconnect required after connection was disconnected | ||
1335 | */ | ||
1336 | if (GNUNET_YES == s->put_reconnect_required) | ||
1337 | { | ||
1338 | s->put_reconnect_required = GNUNET_NO; | ||
1339 | if (GNUNET_SYSERR == client_connect_put (s)) | 1373 | if (GNUNET_SYSERR == client_connect_put (s)) |
1340 | { | 1374 | { |
1341 | GNUNET_break (s->put.easyhandle == NULL); | 1375 | /* Reconnect failed, disconnect session */ |
1342 | GNUNET_break (s->put_tmp_disconnected == GNUNET_NO); | 1376 | http_client_plugin_session_disconnect (plugin, s); |
1343 | } | 1377 | } |
1344 | } | 1378 | break; |
1379 | case H_TMP_DISCONNECTING: | ||
1380 | /* PUT gets temporarily disconnected */ | ||
1381 | s->put.state = H_TMP_DISCONNECTED; | ||
1382 | break; | ||
1383 | case H_PAUSED: | ||
1384 | case H_CONNECTED: | ||
1385 | /* PUT gets permanently disconnected */ | ||
1386 | s->put.state = H_DISCONNECTED; | ||
1387 | http_client_plugin_session_disconnect (plugin, s); | ||
1388 | break; | ||
1389 | default: | ||
1390 | GNUNET_break (0); | ||
1391 | break; | ||
1345 | } | 1392 | } |
1346 | if (easy_h == s->get.easyhandle) | 1393 | } |
1394 | else if (GNUNET_NO == put_request) | ||
1395 | { | ||
1396 | /* Clean up a GET request */ | ||
1397 | s->get.easyhandle = NULL; | ||
1398 | s->get.s = NULL; | ||
1399 | |||
1400 | /* If we are emulating an XHR client we need to make another GET | ||
1401 | * request. | ||
1402 | */ | ||
1403 | if (GNUNET_YES == plugin->emulate_xhr) | ||
1347 | { | 1404 | { |
1348 | if ((0 != msg->data.result) || (http_statuscode != 200)) | 1405 | if (GNUNET_SYSERR == client_connect_get (s)) |
1349 | { | ||
1350 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1351 | "Session %p/connection %p: GET connection to `%s' ended with status %i reason %i: `%s'\n", | ||
1352 | s, | ||
1353 | msg->easy_handle, | ||
1354 | GNUNET_i2s (&s->address->peer), | ||
1355 | http_statuscode, | ||
1356 | msg->data.result, | ||
1357 | curl_easy_strerror (msg->data.result)); | ||
1358 | |||
1359 | } | ||
1360 | else | ||
1361 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1362 | "Session %p/connection %p: GET connection to `%s' ended normal\n", | ||
1363 | s, | ||
1364 | msg->easy_handle, | ||
1365 | GNUNET_i2s (&s->address->peer)); | ||
1366 | /* Disconnect other transmission direction and tell transport */ | ||
1367 | s->get.easyhandle = NULL; | ||
1368 | s->get.s = NULL; | ||
1369 | /* FIXME: who calls curl_multi_remove on 'easy_h' now!? */ | ||
1370 | GNUNET_assert (plugin->cur_connections > 0); | ||
1371 | plugin->cur_connections--; | ||
1372 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1373 | "GET request done, number of connections decreased to %u\n", | ||
1374 | plugin->cur_connections); | ||
1375 | /* If we are emulating an XHR client we need to make another GET | ||
1376 | * request. | ||
1377 | */ | ||
1378 | if (GNUNET_YES == plugin->emulate_xhr) | ||
1379 | { | ||
1380 | if (GNUNET_SYSERR == client_connect_get (s)) | ||
1381 | http_client_plugin_session_disconnect (plugin, s); | ||
1382 | } else | ||
1383 | http_client_plugin_session_disconnect (plugin, s); | 1406 | http_client_plugin_session_disconnect (plugin, s); |
1384 | } | 1407 | } |
1408 | else | ||
1409 | { | ||
1410 | /* GET request was terminated, so disconnect session */ | ||
1411 | http_client_plugin_session_disconnect (plugin, s); | ||
1412 | } | ||
1385 | } | 1413 | } |
1414 | else | ||
1415 | GNUNET_break (0); /* Must not happen */ | ||
1386 | } | 1416 | } |
1387 | } | 1417 | } |
1388 | while (mret == CURLM_CALL_MULTI_PERFORM); | 1418 | while (mret == CURLM_CALL_MULTI_PERFORM); |
@@ -1391,7 +1421,7 @@ curl_easy_getinfo (easy_h, | |||
1391 | 1421 | ||
1392 | 1422 | ||
1393 | /** | 1423 | /** |
1394 | * Connect GET connection for a session | 1424 | * Connect GET request for a session |
1395 | * | 1425 | * |
1396 | * @param s the session to connect | 1426 | * @param s the session to connect |
1397 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 1427 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
@@ -1401,7 +1431,7 @@ client_connect_get (struct Session *s) | |||
1401 | { | 1431 | { |
1402 | CURLMcode mret; | 1432 | CURLMcode mret; |
1403 | 1433 | ||
1404 | /* create get connection */ | 1434 | /* create get request */ |
1405 | s->get.easyhandle = curl_easy_init (); | 1435 | s->get.easyhandle = curl_easy_init (); |
1406 | s->get.s = s; | 1436 | s->get.s = s; |
1407 | #if VERBOSE_CURL | 1437 | #if VERBOSE_CURL |
@@ -1492,16 +1522,16 @@ client_connect_get (struct Session *s) | |||
1492 | GNUNET_break (0); | 1522 | GNUNET_break (0); |
1493 | return GNUNET_SYSERR; | 1523 | return GNUNET_SYSERR; |
1494 | } | 1524 | } |
1495 | s->plugin->cur_connections++; | 1525 | s->plugin->cur_requests++; |
1496 | LOG (GNUNET_ERROR_TYPE_INFO, | 1526 | LOG (GNUNET_ERROR_TYPE_INFO, |
1497 | "GET request `%s' established, number of connections increased to %u\n", | 1527 | "GET request `%s' established, number of requests increased to %u\n", |
1498 | s->url, s->plugin->cur_connections); | 1528 | s->url, s->plugin->cur_requests); |
1499 | return GNUNET_OK; | 1529 | return GNUNET_OK; |
1500 | } | 1530 | } |
1501 | 1531 | ||
1502 | 1532 | ||
1503 | /** | 1533 | /** |
1504 | * Connect a HTTP put connection | 1534 | * Connect a HTTP put request |
1505 | * | 1535 | * |
1506 | * @param s the session to connect | 1536 | * @param s the session to connect |
1507 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok | 1537 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok |
@@ -1511,7 +1541,7 @@ client_connect_put (struct Session *s) | |||
1511 | { | 1541 | { |
1512 | CURLMcode mret; | 1542 | CURLMcode mret; |
1513 | 1543 | ||
1514 | /* create put connection */ | 1544 | /* create put request */ |
1515 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1545 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1516 | "Session %p: Init PUT handle\n", s); | 1546 | "Session %p: Init PUT handle\n", s); |
1517 | s->put.easyhandle = curl_easy_init (); | 1547 | s->put.easyhandle = curl_easy_init (); |
@@ -1584,26 +1614,27 @@ client_connect_put (struct Session *s) | |||
1584 | { | 1614 | { |
1585 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1615 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1586 | "Session %p : Failed to add PUT handle to multihandle: `%s'\n", | 1616 | "Session %p : Failed to add PUT handle to multihandle: `%s'\n", |
1587 | s, | 1617 | s, curl_multi_strerror (mret)); |
1588 | curl_multi_strerror (mret)); | ||
1589 | curl_easy_cleanup (s->put.easyhandle); | 1618 | curl_easy_cleanup (s->put.easyhandle); |
1590 | s->put.easyhandle = NULL; | 1619 | s->put.easyhandle = NULL; |
1591 | s->put.easyhandle = NULL; | 1620 | s->put.easyhandle = NULL; |
1592 | s->put.s = NULL; | 1621 | s->put.s = NULL; |
1593 | s->put_tmp_disconnected = GNUNET_YES; | 1622 | s->put.state = H_DISCONNECTED; |
1594 | return GNUNET_SYSERR; | 1623 | return GNUNET_SYSERR; |
1595 | } | 1624 | } |
1596 | s->put_tmp_disconnected = GNUNET_NO; | 1625 | s->put.state = H_CONNECTED; |
1597 | s->plugin->cur_connections++; | 1626 | s->plugin->cur_requests++; |
1627 | |||
1598 | LOG (GNUNET_ERROR_TYPE_INFO, | 1628 | LOG (GNUNET_ERROR_TYPE_INFO, |
1599 | "PUT request `%s' established, number of connections increased to %u\n", | 1629 | "PUT request `%s' established, number of requests increased to %u\n", |
1600 | s->url, s->plugin->cur_connections); | 1630 | s->url, s->plugin->cur_requests); |
1631 | |||
1601 | return GNUNET_OK; | 1632 | return GNUNET_OK; |
1602 | } | 1633 | } |
1603 | 1634 | ||
1604 | 1635 | ||
1605 | /** | 1636 | /** |
1606 | * Connect both PUT and GET connection for a session | 1637 | * Connect both PUT and GET request for a session |
1607 | * | 1638 | * |
1608 | * @param s the session to connect | 1639 | * @param s the session to connect |
1609 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 1640 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
@@ -1639,17 +1670,19 @@ client_connect (struct Session *s) | |||
1639 | * there is something to send. | 1670 | * there is something to send. |
1640 | */ | 1671 | */ |
1641 | if (GNUNET_YES == plugin->emulate_xhr) | 1672 | if (GNUNET_YES == plugin->emulate_xhr) |
1642 | s->put_tmp_disconnected = GNUNET_YES; | 1673 | { |
1674 | s->put.state = H_TMP_DISCONNECTED; | ||
1675 | } | ||
1643 | else if (GNUNET_SYSERR == client_connect_put (s)) | 1676 | else if (GNUNET_SYSERR == client_connect_put (s)) |
1644 | return GNUNET_SYSERR; | 1677 | return GNUNET_SYSERR; |
1645 | 1678 | ||
1646 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1679 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1647 | "Session %p: connected with connections GET %p and PUT %p\n", | 1680 | "Session %p: connected with GET %p and PUT %p\n", |
1648 | s, s->get.easyhandle, s->put.easyhandle); | 1681 | s, s->get.easyhandle, s->put.easyhandle); |
1649 | /* Perform connect */ | 1682 | /* Perform connect */ |
1650 | GNUNET_STATISTICS_set (plugin->env->stats, | 1683 | GNUNET_STATISTICS_set (plugin->env->stats, |
1651 | HTTP_STAT_STR_CONNECTIONS, | 1684 | HTTP_STAT_STR_CONNECTIONS, |
1652 | plugin->cur_connections, | 1685 | plugin->cur_requests, |
1653 | GNUNET_NO); | 1686 | GNUNET_NO); |
1654 | /* Re-schedule since handles have changed */ | 1687 | /* Re-schedule since handles have changed */ |
1655 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) | 1688 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1657,6 +1690,8 @@ client_connect (struct Session *s) | |||
1657 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); | 1690 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); |
1658 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; | 1691 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
1659 | } | 1692 | } |
1693 | |||
1694 | /* Schedule task to run immediately */ | ||
1660 | plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin); | 1695 | plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin); |
1661 | return res; | 1696 | return res; |
1662 | } | 1697 | } |
@@ -1742,12 +1777,12 @@ http_client_plugin_get_session (void *cls, | |||
1742 | return s; | 1777 | return s; |
1743 | 1778 | ||
1744 | /* create a new session */ | 1779 | /* create a new session */ |
1745 | if (plugin->max_connections <= plugin->cur_connections) | 1780 | if (plugin->max_requests <= plugin->cur_requests) |
1746 | { | 1781 | { |
1747 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1782 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1748 | "Maximum number of connections (%u) reached: " | 1783 | "Maximum number of requests (%u) reached: " |
1749 | "cannot connect to peer `%s'\n", | 1784 | "cannot connect to peer `%s'\n", |
1750 | plugin->max_connections, | 1785 | plugin->max_requests, |
1751 | GNUNET_i2s (&address->peer)); | 1786 | GNUNET_i2s (&address->peer)); |
1752 | return NULL; | 1787 | return NULL; |
1753 | } | 1788 | } |
@@ -1787,9 +1822,8 @@ http_client_plugin_get_session (void *cls, | |||
1787 | s->plugin = plugin; | 1822 | s->plugin = plugin; |
1788 | s->address = GNUNET_HELLO_address_copy (address); | 1823 | s->address = GNUNET_HELLO_address_copy (address); |
1789 | s->ats_address_network_type = ats.value; | 1824 | s->ats_address_network_type = ats.value; |
1790 | s->put_paused = GNUNET_NO; | 1825 | |
1791 | s->put_tmp_disconnecting = GNUNET_NO; | 1826 | s->put.state = H_NOT_CONNECTED; |
1792 | s->put_tmp_disconnected = GNUNET_NO; | ||
1793 | s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT); | 1827 | s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT); |
1794 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, | 1828 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, |
1795 | &client_session_timeout, | 1829 | &client_session_timeout, |
@@ -1813,15 +1847,12 @@ http_client_plugin_get_session (void *cls, | |||
1813 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1847 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1814 | "Cannot connect to peer `%s' address `%s''\n", | 1848 | "Cannot connect to peer `%s' address `%s''\n", |
1815 | http_common_plugin_address_to_string (plugin->protocol, | 1849 | http_common_plugin_address_to_string (plugin->protocol, |
1816 | s->address->address, | 1850 | s->address->address, s->address->address_length), |
1817 | s->address->address_length), | 1851 | GNUNET_i2s (&s->address->peer)); |
1818 | GNUNET_i2s (&s->address->peer)); | ||
1819 | client_delete_session (s); | 1852 | client_delete_session (s); |
1820 | return NULL; | 1853 | return NULL; |
1821 | } | 1854 | } |
1822 | notify_session_monitor (plugin, | 1855 | notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP); /* or handshake? */ |
1823 | s, | ||
1824 | GNUNET_TRANSPORT_SS_UP); /* or handshake? */ | ||
1825 | return s; | 1856 | return s; |
1826 | } | 1857 | } |
1827 | 1858 | ||
@@ -1928,7 +1959,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1928 | static int | 1959 | static int |
1929 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) | 1960 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) |
1930 | { | 1961 | { |
1931 | unsigned long long max_connections; | 1962 | unsigned long long max_requests; |
1932 | char *proxy_type; | 1963 | char *proxy_type; |
1933 | 1964 | ||
1934 | 1965 | ||
@@ -1937,13 +1968,13 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1937 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 1968 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, |
1938 | plugin->name, | 1969 | plugin->name, |
1939 | "MAX_CONNECTIONS", | 1970 | "MAX_CONNECTIONS", |
1940 | &max_connections)) | 1971 | &max_requests)) |
1941 | max_connections = 128; | 1972 | max_requests = 128; |
1942 | plugin->max_connections = max_connections; | 1973 | plugin->max_requests = max_requests; |
1943 | 1974 | ||
1944 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1975 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1945 | _("Maximum number of connections is %u\n"), | 1976 | _("Maximum number of requests is %u\n"), |
1946 | plugin->max_connections); | 1977 | plugin->max_requests); |
1947 | 1978 | ||
1948 | /* Read proxy configuration */ | 1979 | /* Read proxy configuration */ |
1949 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 1980 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -2104,10 +2135,8 @@ http_client_plugin_update_inbound_delay (void *cls, | |||
2104 | if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) | 2135 | if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) |
2105 | { | 2136 | { |
2106 | GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); | 2137 | GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); |
2107 | s->recv_wakeup_task | 2138 | s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay, |
2108 | = GNUNET_SCHEDULER_add_delayed (delay, | 2139 | &client_wake_up, s); |
2109 | &client_wake_up, | ||
2110 | s); | ||
2111 | } | 2140 | } |
2112 | } | 2141 | } |
2113 | 2142 | ||