diff options
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 04a985906..3b3a4705b 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | #include "plugin_transport_http.h" | 27 | #include "plugin_transport_http.h" |
28 | 28 | ||
29 | #if VERBOSE_CLIENT | 29 | #if VERBOSE_CURL |
30 | /** | 30 | /** |
31 | * Function to log curl debug messages with GNUNET_log | 31 | * Function to log curl debug messages with GNUNET_log |
32 | * @param curl handle | 32 | * @param curl handle |
@@ -58,8 +58,9 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls) | |||
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | int | 60 | int |
61 | client_send (struct Session *s, const char *msgbuf, size_t msgbuf_size) | 61 | client_send (struct Session *s, struct HTTP_Message *msg) |
62 | { | 62 | { |
63 | GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg); | ||
63 | return GNUNET_OK; | 64 | return GNUNET_OK; |
64 | } | 65 | } |
65 | 66 | ||
@@ -183,7 +184,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
183 | "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), http_plugin_address_to_string(plugin, s->addr, s->addrlen)); | 184 | "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), http_plugin_address_to_string(plugin, s->addr, s->addrlen)); |
184 | #endif | 185 | #endif |
185 | client_disconnect(s); | 186 | client_disconnect(s); |
186 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); | 187 | //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen)); |
187 | if (s->msg_tk != NULL) | 188 | if (s->msg_tk != NULL) |
188 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 189 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
189 | notify_session_end (plugin, &s->target, s); | 190 | notify_session_end (plugin, &s->target, s); |
@@ -202,6 +203,8 @@ client_disconnect (struct Session *s) | |||
202 | int res = GNUNET_OK; | 203 | int res = GNUNET_OK; |
203 | CURLMcode mret; | 204 | CURLMcode mret; |
204 | struct Plugin *plugin = s->plugin; | 205 | struct Plugin *plugin = s->plugin; |
206 | struct HTTP_Message * msg; | ||
207 | struct HTTP_Message * t; | ||
205 | 208 | ||
206 | #if 0 | 209 | #if 0 |
207 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 210 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
@@ -241,6 +244,17 @@ client_disconnect (struct Session *s) | |||
241 | s->client_get = NULL; | 244 | s->client_get = NULL; |
242 | } | 245 | } |
243 | 246 | ||
247 | msg = s->msg_head; | ||
248 | while (msg != NULL) | ||
249 | { | ||
250 | t = msg->next; | ||
251 | if (NULL != msg->transmit_cont) | ||
252 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR); | ||
253 | GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); | ||
254 | GNUNET_free (msg); | ||
255 | msg = t; | ||
256 | } | ||
257 | |||
244 | plugin->cur_connections -= 2; | 258 | plugin->cur_connections -= 2; |
245 | /* Re-schedule since handles have changed */ | 259 | /* Re-schedule since handles have changed */ |
246 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) | 260 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -255,20 +269,15 @@ client_disconnect (struct Session *s) | |||
255 | } | 269 | } |
256 | 270 | ||
257 | static void | 271 | static void |
258 | curl_receive_mst_cb (void *cls, void *client, | 272 | client_receive_mst_cb (void *cls, void *client, |
259 | const struct GNUNET_MessageHeader *message) | 273 | const struct GNUNET_MessageHeader *message) |
260 | { | 274 | { |
261 | struct Session *s = cls; | 275 | struct Session *s = cls; |
262 | struct Plugin *plugin = s->plugin; | 276 | struct Plugin *plugin = s->plugin; |
263 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; | ||
264 | struct GNUNET_TIME_Relative delay; | 277 | struct GNUNET_TIME_Relative delay; |
265 | 278 | ||
266 | distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); | 279 | delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen); |
267 | distance[0].value = htonl (1); | ||
268 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | ||
269 | distance[1].value = htonl (0); | ||
270 | 280 | ||
271 | delay = plugin->env->receive (plugin->env->cls, &s->target, message, (const struct GNUNET_TRANSPORT_ATS_Information*) &distance, 2, s, s->addr, s->addrlen); | ||
272 | s->delay = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); | 281 | s->delay = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay); |
273 | 282 | ||
274 | if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value) | 283 | if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value) |
@@ -290,23 +299,23 @@ curl_receive_mst_cb (void *cls, void *client, | |||
290 | * @return bytes read from stream | 299 | * @return bytes read from stream |
291 | */ | 300 | */ |
292 | static size_t | 301 | static size_t |
293 | curl_receive_cb (void *stream, size_t size, size_t nmemb, void *cls) | 302 | client_receive (void *stream, size_t size, size_t nmemb, void *cls) |
294 | { | 303 | { |
295 | struct Session *s = cls; | 304 | struct Session *s = cls; |
296 | struct Plugin *plugin = s->plugin; | 305 | struct Plugin *plugin = s->plugin; |
297 | 306 | ||
298 | if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value) | 307 | if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value) |
299 | { | 308 | { |
300 | #if DEBUG_HTTP | 309 | #if DEBUG_CLIENT |
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
302 | "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", | 311 | "no inbound bandwidth available! Next read was delayed for %llu ms\n", |
303 | s, GNUNET_TIME_absolute_get_difference(s->delay, GNUNET_TIME_absolute_get()).rel_value); | 312 | s, GNUNET_TIME_absolute_get_difference(s->delay, GNUNET_TIME_absolute_get()).rel_value); |
304 | #endif | 313 | #endif |
305 | return 0; | 314 | return 0; |
306 | } | 315 | } |
307 | 316 | ||
308 | if (s->msg_tk == NULL) | 317 | if (s->msg_tk == NULL) |
309 | s->msg_tk = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, s); | 318 | s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); |
310 | 319 | ||
311 | GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, size * nmemb, GNUNET_NO, | 320 | GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, size * nmemb, GNUNET_NO, |
312 | GNUNET_NO); | 321 | GNUNET_NO); |
@@ -329,30 +338,30 @@ curl_receive_cb (void *stream, size_t size, size_t nmemb, void *cls) | |||
329 | * @return bytes written to stream | 338 | * @return bytes written to stream |
330 | */ | 339 | */ |
331 | static size_t | 340 | static size_t |
332 | curl_send_cb (void *stream, size_t size, size_t nmemb, void *ptr) | 341 | client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) |
333 | { | 342 | { |
343 | struct Session *s = cls; | ||
344 | //struct Plugin *plugin = s->plugin; | ||
334 | size_t bytes_sent = 0; | 345 | size_t bytes_sent = 0; |
335 | |||
336 | #if 0 | ||
337 | struct Session *ps = ptr; | ||
338 | struct HTTP_Message *msg = ps->pending_msgs_tail; | ||
339 | |||
340 | size_t len; | 346 | size_t len; |
341 | 347 | ||
342 | if (ps->send_active == GNUNET_NO) | 348 | struct HTTP_Message *msg = s->msg_head; |
349 | /* | ||
350 | if (s->put_paused == GNUNET_NO) | ||
343 | return CURL_READFUNC_PAUSE; | 351 | return CURL_READFUNC_PAUSE; |
344 | if ((ps->pending_msgs_tail == NULL) && (ps->send_active == GNUNET_YES)) | 352 | if ((s->msg_head == NULL) && (s->put_paused == GNUNET_YES)) |
345 | { | 353 | { |
346 | #if DEBUG_CONNECTIONS | 354 | #if VERBOSE_CLIENT |
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 355 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Suspending handle `%s' `%s'\n", |
348 | "Connection %X: No Message to send, pausing connection\n", ps); | 356 | GNUNET_i2s (&s->target),GNUNET_a2s (s->addr, s->addrlen)); |
349 | #endif | 357 | #endif |
350 | ps->send_active = GNUNET_NO; | 358 | s->put_paused = GNUNET_NO; |
351 | return CURL_READFUNC_PAUSE; | 359 | return CURL_READFUNC_PAUSE; |
352 | } | 360 | } |
353 | 361 | */ | |
362 | if (msg == NULL) | ||
363 | return bytes_sent; | ||
354 | GNUNET_assert (msg != NULL); | 364 | GNUNET_assert (msg != NULL); |
355 | |||
356 | /* data to send */ | 365 | /* data to send */ |
357 | if (msg->pos < msg->size) | 366 | if (msg->pos < msg->size) |
358 | { | 367 | { |
@@ -383,17 +392,14 @@ curl_send_cb (void *stream, size_t size, size_t nmemb, void *ptr) | |||
383 | #if DEBUG_CONNECTIONS | 392 | #if DEBUG_CONNECTIONS |
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
385 | "Connection %X: Message with %u bytes sent, removing message from queue\n", | 394 | "Connection %X: Message with %u bytes sent, removing message from queue\n", |
386 | ps, msg->pos); | 395 | s, msg->pos); |
387 | #endif | 396 | #endif |
388 | /* Calling transmit continuation */ | 397 | /* Calling transmit continuation */ |
389 | if (NULL != ps->pending_msgs_tail->transmit_cont) | 398 | if (NULL != msg->transmit_cont) |
390 | msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls, | 399 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK); |
391 | &(ps->peercontext)->identity, GNUNET_OK); | 400 | GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg); |
392 | ps->queue_length_cur -= msg->size; | 401 | GNUNET_free (msg); |
393 | remove_http_message (ps, msg); | ||
394 | } | 402 | } |
395 | |||
396 | #endif | ||
397 | return bytes_sent; | 403 | return bytes_sent; |
398 | } | 404 | } |
399 | 405 | ||
@@ -423,7 +429,7 @@ client_connect (struct Session *s) | |||
423 | #endif | 429 | #endif |
424 | /* create get connection */ | 430 | /* create get connection */ |
425 | s->client_get = curl_easy_init (); | 431 | s->client_get = curl_easy_init (); |
426 | #if VERBOSE_CLIENT | 432 | #if VERBOSE_CURL |
427 | curl_easy_setopt (s->client_get, CURLOPT_VERBOSE, 1L); | 433 | curl_easy_setopt (s->client_get, CURLOPT_VERBOSE, 1L); |
428 | curl_easy_setopt (s->client_get, CURLOPT_DEBUGFUNCTION, &client_log); | 434 | curl_easy_setopt (s->client_get, CURLOPT_DEBUGFUNCTION, &client_log); |
429 | curl_easy_setopt (s->client_get, CURLOPT_DEBUGDATA, s->client_get); | 435 | curl_easy_setopt (s->client_get, CURLOPT_DEBUGDATA, s->client_get); |
@@ -436,9 +442,9 @@ client_connect (struct Session *s) | |||
436 | curl_easy_setopt (s->client_get, CURLOPT_URL, url); | 442 | curl_easy_setopt (s->client_get, CURLOPT_URL, url); |
437 | //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); | 443 | //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); |
438 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps); | 444 | //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps); |
439 | curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, curl_send_cb); | 445 | curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb); |
440 | curl_easy_setopt (s->client_get, CURLOPT_READDATA, s); | 446 | curl_easy_setopt (s->client_get, CURLOPT_READDATA, s); |
441 | curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, curl_receive_cb); | 447 | curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, client_receive); |
442 | curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s); | 448 | curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s); |
443 | curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, | 449 | curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS, |
444 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); | 450 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); |
@@ -453,7 +459,7 @@ client_connect (struct Session *s) | |||
453 | 459 | ||
454 | /* create put connection */ | 460 | /* create put connection */ |
455 | s->client_put = curl_easy_init (); | 461 | s->client_put = curl_easy_init (); |
456 | #if VERBOSE_CLIENT | 462 | #if VERBOSE_CURL |
457 | curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L); | 463 | curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L); |
458 | curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log); | 464 | curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log); |
459 | curl_easy_setopt (s->client_put, CURLOPT_DEBUGDATA, s->client_put); | 465 | curl_easy_setopt (s->client_put, CURLOPT_DEBUGDATA, s->client_put); |
@@ -467,9 +473,9 @@ client_connect (struct Session *s) | |||
467 | curl_easy_setopt (s->client_put, CURLOPT_PUT, 1L); | 473 | curl_easy_setopt (s->client_put, CURLOPT_PUT, 1L); |
468 | //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &curl_put_header_cb); | 474 | //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &curl_put_header_cb); |
469 | //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps); | 475 | //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps); |
470 | curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, curl_send_cb); | 476 | curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb); |
471 | curl_easy_setopt (s->client_put, CURLOPT_READDATA, s); | 477 | curl_easy_setopt (s->client_put, CURLOPT_READDATA, s); |
472 | curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, curl_receive_cb); | 478 | curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive); |
473 | curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s); | 479 | curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s); |
474 | curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, | 480 | curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS, |
475 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); | 481 | (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); |