diff options
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index a0a3f2087..bf24d97d6 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -97,7 +97,6 @@ struct HTTP_Message | |||
97 | void *transmit_cont_cls; | 97 | void *transmit_cont_cls; |
98 | }; | 98 | }; |
99 | 99 | ||
100 | |||
101 | /** | 100 | /** |
102 | * Session handle for connections. | 101 | * Session handle for connections. |
103 | */ | 102 | */ |
@@ -145,17 +144,6 @@ struct Session | |||
145 | struct HTTP_Client_Plugin *plugin; | 144 | struct HTTP_Client_Plugin *plugin; |
146 | 145 | ||
147 | /** | 146 | /** |
148 | * Is client send handle paused since there are no data to send? | ||
149 | * GNUNET_YES/NO | ||
150 | */ | ||
151 | int client_put_paused; | ||
152 | |||
153 | /** | ||
154 | * Is client send handle to be disconnected due to inactivity | ||
155 | */ | ||
156 | int client_put_disconnect; | ||
157 | |||
158 | /** | ||
159 | * Was session given to transport service? | 147 | * Was session given to transport service? |
160 | */ | 148 | */ |
161 | // int session_passed; | 149 | // int session_passed; |
@@ -165,6 +153,10 @@ struct Session | |||
165 | */ | 153 | */ |
166 | void *client_put; | 154 | void *client_put; |
167 | 155 | ||
156 | int put_paused; | ||
157 | |||
158 | int put_tmp_disconnecting; | ||
159 | |||
168 | /** | 160 | /** |
169 | * Client receive handle | 161 | * Client receive handle |
170 | */ | 162 | */ |
@@ -426,7 +418,7 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls) | |||
426 | */ | 418 | */ |
427 | static ssize_t | 419 | static ssize_t |
428 | http_client_plugin_send (void *cls, | 420 | http_client_plugin_send (void *cls, |
429 | struct Session *session, | 421 | struct Session *s, |
430 | const char *msgbuf, size_t msgbuf_size, | 422 | const char *msgbuf, size_t msgbuf_size, |
431 | unsigned int priority, | 423 | unsigned int priority, |
432 | struct GNUNET_TIME_Relative to, | 424 | struct GNUNET_TIME_Relative to, |
@@ -436,19 +428,19 @@ http_client_plugin_send (void *cls, | |||
436 | struct HTTP_Message *msg; | 428 | struct HTTP_Message *msg; |
437 | 429 | ||
438 | GNUNET_assert (plugin != NULL); | 430 | GNUNET_assert (plugin != NULL); |
439 | GNUNET_assert (session != NULL); | 431 | GNUNET_assert (s != NULL); |
440 | 432 | ||
441 | /* lookup if session is really existing */ | 433 | /* lookup if session is really existing */ |
442 | if (GNUNET_YES != client_exist_session (plugin, session)) | 434 | if (GNUNET_YES != client_exist_session (plugin, s)) |
443 | { | 435 | { |
444 | GNUNET_break (0); | 436 | GNUNET_break (0); |
445 | return GNUNET_SYSERR; | 437 | return GNUNET_SYSERR; |
446 | } | 438 | } |
447 | 439 | ||
448 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name, | 440 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
449 | "Session %p/connection %p: Sending message with %u to peer `%s' with \n", | 441 | "Session %p/connection %p: Sending message with %u to peer `%s' with \n", |
450 | session, session->client_put, | 442 | s, s->client_put, |
451 | msgbuf_size, GNUNET_i2s (&session->target)); | 443 | msgbuf_size, GNUNET_i2s (&s->target)); |
452 | 444 | ||
453 | /* create new message and schedule */ | 445 | /* create new message and schedule */ |
454 | msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); | 446 | msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); |
@@ -459,30 +451,33 @@ http_client_plugin_send (void *cls, | |||
459 | msg->transmit_cont = cont; | 451 | msg->transmit_cont = cont; |
460 | msg->transmit_cont_cls = cont_cls; | 452 | msg->transmit_cont_cls = cont_cls; |
461 | memcpy (msg->buf, msgbuf, msgbuf_size); | 453 | memcpy (msg->buf, msgbuf, msgbuf_size); |
462 | GNUNET_CONTAINER_DLL_insert_tail (session->msg_head, session->msg_tail, msg); | 454 | GNUNET_CONTAINER_DLL_insert_tail (s->msg_head, s->msg_tail, msg); |
463 | 455 | ||
464 | if (GNUNET_YES == session->client_put_disconnect) | 456 | if (GNUNET_YES == s->put_tmp_disconnecting) |
465 | { | 457 | { |
466 | session->client_put_disconnect = GNUNET_NO; | 458 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
467 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name, | ||
468 | "Session %p: Reconnecting PUT connection\n", | 459 | "Session %p: Reconnecting PUT connection\n", |
469 | session); | 460 | s); |
470 | client_connect_put (session); | 461 | s->put_tmp_disconnecting = GNUNET_NO; |
462 | if (GNUNET_SYSERR == client_connect_put (s)) | ||
463 | { | ||
464 | return GNUNET_SYSERR; | ||
465 | } | ||
471 | } | 466 | } |
472 | 467 | ||
473 | if (GNUNET_YES == session->client_put_paused) | 468 | if (GNUNET_YES == s->put_paused) |
474 | { | 469 | { |
475 | GNUNET_assert (session->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); | 470 | GNUNET_assert (s->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); |
476 | GNUNET_SCHEDULER_cancel (session->put_disconnect_task); | 471 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); |
477 | session->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 472 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
478 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, session->plugin->name, | 473 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
479 | "Session %p/connection %p: unpausing connection\n", | 474 | "Session %p/connection %p: unpausing connection\n", |
480 | session, session->client_put); | 475 | s, s->client_put); |
481 | session->client_put_paused = GNUNET_NO; | 476 | s->put_paused = GNUNET_NO; |
482 | curl_easy_pause (session->client_put, CURLPAUSE_CONT); | 477 | curl_easy_pause (s->client_put, CURLPAUSE_CONT); |
483 | } | 478 | } |
484 | client_schedule (session->plugin, GNUNET_YES); | 479 | client_schedule (s->plugin, GNUNET_YES); |
485 | client_reschedule_session_timeout (session); | 480 | client_reschedule_session_timeout (s); |
486 | return msgbuf_size; | 481 | return msgbuf_size; |
487 | } | 482 | } |
488 | 483 | ||
@@ -688,8 +683,8 @@ client_put_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
688 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 683 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
689 | "Session %p/connection %p: will be disconnected due to no activity\n", | 684 | "Session %p/connection %p: will be disconnected due to no activity\n", |
690 | s, s->client_put); | 685 | s, s->client_put); |
691 | s->client_put_disconnect = GNUNET_YES; | 686 | s->put_paused = GNUNET_NO; |
692 | s->client_put_paused = GNUNET_NO; | 687 | s->put_tmp_disconnecting = GNUNET_YES; |
693 | curl_easy_pause (s->client_put, CURLPAUSE_CONT); | 688 | curl_easy_pause (s->client_put, CURLPAUSE_CONT); |
694 | client_schedule (s->plugin, GNUNET_YES); | 689 | client_schedule (s->plugin, GNUNET_YES); |
695 | } | 690 | } |
@@ -719,8 +714,9 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) | |||
719 | GNUNET_break (0); | 714 | GNUNET_break (0); |
720 | return 0; | 715 | return 0; |
721 | } | 716 | } |
722 | if (GNUNET_YES == s->client_put_disconnect) | 717 | if (GNUNET_YES == s->put_tmp_disconnecting) |
723 | { | 718 | { |
719 | |||
724 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 720 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
725 | "Session %p/connection %p: disconnect due to inactivity\n", | 721 | "Session %p/connection %p: disconnect due to inactivity\n", |
726 | s, s->client_put); | 722 | s, s->client_put); |
@@ -733,8 +729,7 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) | |||
733 | "Session %p/connection %p: nothing to send, suspending\n", | 729 | "Session %p/connection %p: nothing to send, suspending\n", |
734 | s, s->client_put); | 730 | s, s->client_put); |
735 | s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, &client_put_disconnect, s); | 731 | s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, &client_put_disconnect, s); |
736 | s->client_put_disconnect = GNUNET_NO; | 732 | s->put_paused = GNUNET_YES; |
737 | s->client_put_paused = GNUNET_YES; | ||
738 | return CURL_READFUNC_PAUSE; | 733 | return CURL_READFUNC_PAUSE; |
739 | } | 734 | } |
740 | /* data to send */ | 735 | /* data to send */ |
@@ -1054,8 +1049,8 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1054 | { | 1049 | { |
1055 | /* Disconnect other transmission direction and tell transport */ | 1050 | /* Disconnect other transmission direction and tell transport */ |
1056 | } | 1051 | } |
1057 | curl_multi_remove_handle(plugin->curl_multi_handle, easy_h); | 1052 | curl_multi_remove_handle (plugin->curl_multi_handle, easy_h); |
1058 | curl_easy_cleanup(easy_h); | 1053 | curl_easy_cleanup (easy_h); |
1059 | s->client_put = NULL; | 1054 | s->client_put = NULL; |
1060 | } | 1055 | } |
1061 | if (easy_h == s->client_get) | 1056 | if (easy_h == s->client_get) |
@@ -1134,7 +1129,9 @@ client_connect_put (struct Session *s) | |||
1134 | CURLMcode mret; | 1129 | CURLMcode mret; |
1135 | /* create put connection */ | 1130 | /* create put connection */ |
1136 | if (NULL == s->client_put) | 1131 | if (NULL == s->client_put) |
1132 | { | ||
1137 | s->client_put = curl_easy_init (); | 1133 | s->client_put = curl_easy_init (); |
1134 | } | ||
1138 | #if VERBOSE_CURL | 1135 | #if VERBOSE_CURL |
1139 | curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L); | 1136 | curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L); |
1140 | curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log); | 1137 | curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log); |
@@ -1147,11 +1144,6 @@ client_connect_put (struct Session *s) | |||
1147 | #endif | 1144 | #endif |
1148 | curl_easy_setopt (s->client_put, CURLOPT_URL, s->url); | 1145 | curl_easy_setopt (s->client_put, CURLOPT_URL, s->url); |
1149 | curl_easy_setopt (s->client_put, CURLOPT_UPLOAD, 1L); | 1146 | curl_easy_setopt (s->client_put, CURLOPT_UPLOAD, 1L); |
1150 | /* | ||
1151 | struct curl_slist *m_headerlist; | ||
1152 | m_headerlist = NULL; | ||
1153 | m_headerlist = curl_slist_append(m_headerlist, "Transfer-Encoding: chunked"); | ||
1154 | curl_easy_setopt(s->client_put, CURLOPT_HTTPHEADER, m_headerlist);*/ | ||
1155 | //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &client_curl_header); | 1147 | //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &client_curl_header); |
1156 | //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps); | 1148 | //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps); |
1157 | curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb); | 1149 | curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb); |
@@ -1168,12 +1160,15 @@ client_connect_put (struct Session *s) | |||
1168 | #if CURL_TCP_NODELAY | 1160 | #if CURL_TCP_NODELAY |
1169 | curl_easy_setopt (s->client_put, CURLOPT_TCP_NODELAY, 1); | 1161 | curl_easy_setopt (s->client_put, CURLOPT_TCP_NODELAY, 1); |
1170 | #endif | 1162 | #endif |
1171 | |||
1172 | mret = curl_multi_add_handle (s->plugin->curl_multi_handle, s->client_put); | 1163 | mret = curl_multi_add_handle (s->plugin->curl_multi_handle, s->client_put); |
1173 | if (mret != CURLM_OK) | 1164 | if (mret != CURLM_OK) |
1174 | { | 1165 | { |
1166 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, | ||
1167 | "Failed to add curl handle to multihandle: `%s'\n", | ||
1168 | curl_multi_strerror (mret)); | ||
1169 | |||
1175 | curl_easy_cleanup (s->client_put); | 1170 | curl_easy_cleanup (s->client_put); |
1176 | GNUNET_break (0); | 1171 | s->client_put = NULL; |
1177 | return GNUNET_SYSERR; | 1172 | return GNUNET_SYSERR; |
1178 | } | 1173 | } |
1179 | return GNUNET_OK; | 1174 | return GNUNET_OK; |
@@ -1314,6 +1309,8 @@ http_client_plugin_get_session (void *cls, | |||
1314 | memcpy (s->addr, address->address, address->address_length); | 1309 | memcpy (s->addr, address->address, address->address_length); |
1315 | s->addrlen = address->address_length; | 1310 | s->addrlen = address->address_length; |
1316 | s->ats_address_network_type = ats.value; | 1311 | s->ats_address_network_type = ats.value; |
1312 | s->put_paused = GNUNET_NO; | ||
1313 | s->put_tmp_disconnecting = GNUNET_NO; | ||
1317 | 1314 | ||
1318 | client_start_session_timeout (s); | 1315 | client_start_session_timeout (s); |
1319 | 1316 | ||