aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_client.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/plugin_transport_http_client.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r--src/transport/plugin_transport_http_client.c2473
1 files changed, 1248 insertions, 1225 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 6148e9a44..98ab6544f 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -28,18 +28,23 @@
28#if BUILD_HTTPS 28#if BUILD_HTTPS
29#define PLUGIN_NAME "https_client" 29#define PLUGIN_NAME "https_client"
30#define HTTP_STAT_STR_CONNECTIONS "# HTTPS client connections" 30#define HTTP_STAT_STR_CONNECTIONS "# HTTPS client connections"
31#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_client_init 31#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
32#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_client_done 32 libgnunet_plugin_transport_https_client_init
33#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
34 libgnunet_plugin_transport_https_client_done
33#else 35#else
34#define PLUGIN_NAME "http_client" 36#define PLUGIN_NAME "http_client"
35#define HTTP_STAT_STR_CONNECTIONS "# HTTP client connections" 37#define HTTP_STAT_STR_CONNECTIONS "# HTTP client connections"
36#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_client_init 38#define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
37#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done 39 libgnunet_plugin_transport_http_client_init
40#define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
41 libgnunet_plugin_transport_http_client_done
38#endif 42#endif
39 43
40#define VERBOSE_CURL GNUNET_NO 44#define VERBOSE_CURL GNUNET_NO
41 45
42#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 46#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply ( \
47 GNUNET_TIME_UNIT_SECONDS, 1)
43 48
44#define ENABLE_PUT GNUNET_YES 49#define ENABLE_PUT GNUNET_YES
45#define ENABLE_GET GNUNET_YES 50#define ENABLE_GET GNUNET_YES
@@ -53,7 +58,7 @@
53#include "gnunet_curl_lib.h" 58#include "gnunet_curl_lib.h"
54 59
55 60
56#define LOG(kind, ...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__) 61#define LOG(kind, ...) GNUNET_log_from (kind, PLUGIN_NAME, __VA_ARGS__)
57 62
58/** 63/**
59 * Encapsulation of all of the state of the plugin. 64 * Encapsulation of all of the state of the plugin.
@@ -63,7 +68,8 @@ struct HTTP_Client_Plugin;
63/** 68/**
64 * State of a HTTP PUT request 69 * State of a HTTP PUT request
65 */ 70 */
66enum HTTP_PUT_REQUEST_STATE { 71enum HTTP_PUT_REQUEST_STATE
72{
67 /** 73 /**
68 * Just created, not yet connected 74 * Just created, not yet connected
69 */ 75 */
@@ -103,7 +109,8 @@ enum HTTP_PUT_REQUEST_STATE {
103/** 109/**
104 * Message to send using http 110 * Message to send using http
105 */ 111 */
106struct HTTP_Message { 112struct HTTP_Message
113{
107 /** 114 /**
108 * next pointer for double linked list 115 * next pointer for double linked list
109 */ 116 */
@@ -153,7 +160,8 @@ struct GNUNET_ATS_Session;
153 * A request handle 160 * A request handle
154 * 161 *
155 */ 162 */
156struct RequestHandle { 163struct RequestHandle
164{
157 /** 165 /**
158 * Current state of this request 166 * Current state of this request
159 */ 167 */
@@ -174,7 +182,8 @@ struct RequestHandle {
174/** 182/**
175 * Session handle for connections. 183 * Session handle for connections.
176 */ 184 */
177struct GNUNET_ATS_Session { 185struct GNUNET_ATS_Session
186{
178 /** 187 /**
179 * The URL to connect to 188 * The URL to connect to
180 */ 189 */
@@ -267,7 +276,8 @@ struct GNUNET_ATS_Session {
267/** 276/**
268 * Encapsulation of all of the state of the plugin. 277 * Encapsulation of all of the state of the plugin.
269 */ 278 */
270struct HTTP_Client_Plugin { 279struct HTTP_Client_Plugin
280{
271 /** 281 /**
272 * Our environment. 282 * Our environment.
273 */ 283 */
@@ -321,7 +331,7 @@ struct HTTP_Client_Plugin {
321 /** 331 /**
322 * curl perform task 332 * curl perform task
323 */ 333 */
324 struct GNUNET_SCHEDULER_Task * client_perform_task; 334 struct GNUNET_SCHEDULER_Task *client_perform_task;
325 335
326 /** 336 /**
327 * Type of proxy server: 337 * Type of proxy server:
@@ -388,7 +398,7 @@ struct HTTP_Client_Plugin {
388 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 398 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
389 */ 399 */
390static int 400static int
391http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s); 401http_client_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *s);
392 402
393 403
394/** 404/**
@@ -400,15 +410,15 @@ http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s);
400 * @param state new state of the session 410 * @param state new state of the session
401 */ 411 */
402static void 412static void
403notify_session_monitor(struct HTTP_Client_Plugin *plugin, 413notify_session_monitor (struct HTTP_Client_Plugin *plugin,
404 struct GNUNET_ATS_Session *session, 414 struct GNUNET_ATS_Session *session,
405 enum GNUNET_TRANSPORT_SessionState state) 415 enum GNUNET_TRANSPORT_SessionState state)
406{ 416{
407 struct GNUNET_TRANSPORT_SessionInfo info; 417 struct GNUNET_TRANSPORT_SessionInfo info;
408 418
409 if (NULL == plugin->sic) 419 if (NULL == plugin->sic)
410 return; 420 return;
411 memset(&info, 0, sizeof(info)); 421 memset (&info, 0, sizeof(info));
412 info.state = state; 422 info.state = state;
413 info.is_inbound = GNUNET_NO; 423 info.is_inbound = GNUNET_NO;
414 info.num_msg_pending = session->msgs_in_queue; 424 info.num_msg_pending = session->msgs_in_queue;
@@ -416,9 +426,9 @@ notify_session_monitor(struct HTTP_Client_Plugin *plugin,
416 info.receive_delay = session->next_receive; 426 info.receive_delay = session->next_receive;
417 info.session_timeout = session->timeout; 427 info.session_timeout = session->timeout;
418 info.address = session->address; 428 info.address = session->address;
419 plugin->sic(plugin->sic_cls, 429 plugin->sic (plugin->sic_cls,
420 session, 430 session,
421 &info); 431 &info);
422} 432}
423 433
424 434
@@ -428,7 +438,7 @@ notify_session_monitor(struct HTTP_Client_Plugin *plugin,
428 * @param s the session to delete 438 * @param s the session to delete
429 */ 439 */
430static void 440static void
431client_delete_session(struct GNUNET_ATS_Session *s) 441client_delete_session (struct GNUNET_ATS_Session *s)
432{ 442{
433 struct HTTP_Client_Plugin *plugin = s->plugin; 443 struct HTTP_Client_Plugin *plugin = s->plugin;
434 struct HTTP_Message *pos; 444 struct HTTP_Message *pos;
@@ -436,95 +446,95 @@ client_delete_session(struct GNUNET_ATS_Session *s)
436 CURLMcode mret; 446 CURLMcode mret;
437 447
438 if (NULL != s->timeout_task) 448 if (NULL != s->timeout_task)
439 { 449 {
440 GNUNET_SCHEDULER_cancel(s->timeout_task); 450 GNUNET_SCHEDULER_cancel (s->timeout_task);
441 s->timeout_task = NULL; 451 s->timeout_task = NULL;
442 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 452 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
443 } 453 }
444 if (NULL != s->put_disconnect_task) 454 if (NULL != s->put_disconnect_task)
445 { 455 {
446 GNUNET_SCHEDULER_cancel(s->put_disconnect_task); 456 GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
447 s->put_disconnect_task = NULL; 457 s->put_disconnect_task = NULL;
448 } 458 }
449 if (NULL != s->recv_wakeup_task) 459 if (NULL != s->recv_wakeup_task)
450 { 460 {
451 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 461 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
452 s->recv_wakeup_task = NULL; 462 s->recv_wakeup_task = NULL;
453 } 463 }
454 GNUNET_assert(GNUNET_OK == 464 GNUNET_assert (GNUNET_OK ==
455 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, 465 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions,
456 &s->address->peer, 466 &s->address->peer,
457 s)); 467 s));
458 if (NULL != s->put.easyhandle) 468 if (NULL != s->put.easyhandle)
459 { 469 {
460 LOG(GNUNET_ERROR_TYPE_DEBUG, 470 LOG (GNUNET_ERROR_TYPE_DEBUG,
461 "Session %p/request %p: disconnecting PUT request to peer `%s'\n", 471 "Session %p/request %p: disconnecting PUT request to peer `%s'\n",
462 s, 472 s,
463 s->put.easyhandle, 473 s->put.easyhandle,
464 GNUNET_i2s(&s->address->peer)); 474 GNUNET_i2s (&s->address->peer));
465 475
466 /* remove curl handle from multi handle */ 476 /* remove curl handle from multi handle */
467 mret = curl_multi_remove_handle(plugin->curl_multi_handle, 477 mret = curl_multi_remove_handle (plugin->curl_multi_handle,
468 s->put.easyhandle); 478 s->put.easyhandle);
469 GNUNET_break(CURLM_OK == mret); 479 GNUNET_break (CURLM_OK == mret);
470 curl_easy_cleanup(s->put.easyhandle); 480 curl_easy_cleanup (s->put.easyhandle);
471 GNUNET_assert(plugin->cur_requests > 0); 481 GNUNET_assert (plugin->cur_requests > 0);
472 plugin->cur_requests--; 482 plugin->cur_requests--;
473 s->put.easyhandle = NULL; 483 s->put.easyhandle = NULL;
474 } 484 }
475 if (NULL != s->get.easyhandle) 485 if (NULL != s->get.easyhandle)
476 { 486 {
477 LOG(GNUNET_ERROR_TYPE_DEBUG, 487 LOG (GNUNET_ERROR_TYPE_DEBUG,
478 "Session %p/request %p: disconnecting GET request to peer `%s'\n", 488 "Session %p/request %p: disconnecting GET request to peer `%s'\n",
479 s, s->get.easyhandle, 489 s, s->get.easyhandle,
480 GNUNET_i2s(&s->address->peer)); 490 GNUNET_i2s (&s->address->peer));
481 /* remove curl handle from multi handle */ 491 /* remove curl handle from multi handle */
482 mret = curl_multi_remove_handle(plugin->curl_multi_handle, 492 mret = curl_multi_remove_handle (plugin->curl_multi_handle,
483 s->get.easyhandle); 493 s->get.easyhandle);
484 GNUNET_break(CURLM_OK == mret); 494 GNUNET_break (CURLM_OK == mret);
485 curl_easy_cleanup(s->get.easyhandle); 495 curl_easy_cleanup (s->get.easyhandle);
486 GNUNET_assert(plugin->cur_requests > 0); 496 GNUNET_assert (plugin->cur_requests > 0);
487 plugin->cur_requests--; 497 plugin->cur_requests--;
488 s->get.easyhandle = NULL; 498 s->get.easyhandle = NULL;
489 } 499 }
490 500
491 GNUNET_STATISTICS_set(plugin->env->stats, 501 GNUNET_STATISTICS_set (plugin->env->stats,
492 HTTP_STAT_STR_CONNECTIONS, 502 HTTP_STAT_STR_CONNECTIONS,
493 plugin->cur_requests, 503 plugin->cur_requests,
494 GNUNET_NO); 504 GNUNET_NO);
495 next = s->msg_head; 505 next = s->msg_head;
496 while (NULL != (pos = next)) 506 while (NULL != (pos = next))
497 { 507 {
498 next = pos->next; 508 next = pos->next;
499 GNUNET_CONTAINER_DLL_remove(s->msg_head, 509 GNUNET_CONTAINER_DLL_remove (s->msg_head,
500 s->msg_tail, 510 s->msg_tail,
501 pos); 511 pos);
502 GNUNET_assert(0 < s->msgs_in_queue); 512 GNUNET_assert (0 < s->msgs_in_queue);
503 s->msgs_in_queue--; 513 s->msgs_in_queue--;
504 GNUNET_assert(pos->size <= s->bytes_in_queue); 514 GNUNET_assert (pos->size <= s->bytes_in_queue);
505 s->bytes_in_queue -= pos->size; 515 s->bytes_in_queue -= pos->size;
506 if (NULL != pos->transmit_cont) 516 if (NULL != pos->transmit_cont)
507 pos->transmit_cont(pos->transmit_cont_cls, 517 pos->transmit_cont (pos->transmit_cont_cls,
508 &s->address->peer, 518 &s->address->peer,
509 GNUNET_SYSERR, 519 GNUNET_SYSERR,
510 pos->size, 520 pos->size,
511 pos->pos + s->overhead); 521 pos->pos + s->overhead);
512 s->overhead = 0; 522 s->overhead = 0;
513 GNUNET_free(pos); 523 GNUNET_free (pos);
514 } 524 }
515 GNUNET_assert(0 == s->msgs_in_queue); 525 GNUNET_assert (0 == s->msgs_in_queue);
516 GNUNET_assert(0 == s->bytes_in_queue); 526 GNUNET_assert (0 == s->bytes_in_queue);
517 notify_session_monitor(plugin, 527 notify_session_monitor (plugin,
518 s, 528 s,
519 GNUNET_TRANSPORT_SS_DONE); 529 GNUNET_TRANSPORT_SS_DONE);
520 if (NULL != s->msg_tk) 530 if (NULL != s->msg_tk)
521 { 531 {
522 GNUNET_MST_destroy(s->msg_tk); 532 GNUNET_MST_destroy (s->msg_tk);
523 s->msg_tk = NULL; 533 s->msg_tk = NULL;
524 } 534 }
525 GNUNET_HELLO_address_free(s->address); 535 GNUNET_HELLO_address_free (s->address);
526 GNUNET_free(s->url); 536 GNUNET_free (s->url);
527 GNUNET_free(s); 537 GNUNET_free (s);
528} 538}
529 539
530 540
@@ -534,10 +544,11 @@ client_delete_session(struct GNUNET_ATS_Session *s)
534 * @param s the session 544 * @param s the session
535 */ 545 */
536static void 546static void
537client_reschedule_session_timeout(struct GNUNET_ATS_Session *s) 547client_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
538{ 548{
539 GNUNET_assert(NULL != s->timeout_task); 549 GNUNET_assert (NULL != s->timeout_task);
540 s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 550 s->timeout = GNUNET_TIME_relative_to_absolute (
551 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
541} 552}
542 553
543 554
@@ -548,7 +559,7 @@ client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
548 * @param tc gnunet scheduler task context 559 * @param tc gnunet scheduler task context
549 */ 560 */
550static void 561static void
551client_run(void *cls); 562client_run (void *cls);
552 563
553 564
554/** 565/**
@@ -559,8 +570,8 @@ client_run(void *cls);
559 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok 570 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
560 */ 571 */
561static int 572static int
562client_schedule(struct HTTP_Client_Plugin *plugin, 573client_schedule (struct HTTP_Client_Plugin *plugin,
563 int now) 574 int now)
564{ 575{
565 fd_set rs; 576 fd_set rs;
566 fd_set ws; 577 fd_set ws;
@@ -574,54 +585,54 @@ client_schedule(struct HTTP_Client_Plugin *plugin,
574 585
575 /* Cancel previous scheduled task */ 586 /* Cancel previous scheduled task */
576 if (plugin->client_perform_task != NULL) 587 if (plugin->client_perform_task != NULL)
577 { 588 {
578 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 589 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
579 plugin->client_perform_task = NULL; 590 plugin->client_perform_task = NULL;
580 } 591 }
581 max = -1; 592 max = -1;
582 FD_ZERO(&rs); 593 FD_ZERO (&rs);
583 FD_ZERO(&ws); 594 FD_ZERO (&ws);
584 FD_ZERO(&es); 595 FD_ZERO (&es);
585 mret = curl_multi_fdset(plugin->curl_multi_handle, &rs, &ws, &es, &max); 596 mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
586 if (mret != CURLM_OK) 597 if (mret != CURLM_OK)
587 { 598 {
588 LOG(GNUNET_ERROR_TYPE_ERROR, 599 LOG (GNUNET_ERROR_TYPE_ERROR,
589 _("%s failed at %s:%d: `%s'\n"), 600 _ ("%s failed at %s:%d: `%s'\n"),
590 "curl_multi_fdset", 601 "curl_multi_fdset",
591 __FILE__, 602 __FILE__,
592 __LINE__, 603 __LINE__,
593 curl_multi_strerror(mret)); 604 curl_multi_strerror (mret));
594 return GNUNET_SYSERR; 605 return GNUNET_SYSERR;
595 } 606 }
596 mret = curl_multi_timeout(plugin->curl_multi_handle, &to); 607 mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
597 if (-1 == to) 608 if (-1 == to)
598 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1); 609 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1);
599 else 610 else
600 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, to); 611 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
601 if (now == GNUNET_YES) 612 if (now == GNUNET_YES)
602 timeout = GNUNET_TIME_UNIT_MILLISECONDS; 613 timeout = GNUNET_TIME_UNIT_MILLISECONDS;
603 614
604 if (CURLM_OK != mret) 615 if (CURLM_OK != mret)
605 { 616 {
606 LOG(GNUNET_ERROR_TYPE_ERROR, 617 LOG (GNUNET_ERROR_TYPE_ERROR,
607 _("%s failed at %s:%d: `%s'\n"), 618 _ ("%s failed at %s:%d: `%s'\n"),
608 "curl_multi_timeout", __FILE__, __LINE__, 619 "curl_multi_timeout", __FILE__, __LINE__,
609 curl_multi_strerror(mret)); 620 curl_multi_strerror (mret));
610 return GNUNET_SYSERR; 621 return GNUNET_SYSERR;
611 } 622 }
612 623
613 grs = GNUNET_NETWORK_fdset_create(); 624 grs = GNUNET_NETWORK_fdset_create ();
614 gws = GNUNET_NETWORK_fdset_create(); 625 gws = GNUNET_NETWORK_fdset_create ();
615 GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1); 626 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
616 GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1); 627 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
617 628
618 /* Schedule task to run when select is ready to read or write */ 629 /* Schedule task to run when select is ready to read or write */
619 plugin->client_perform_task = 630 plugin->client_perform_task =
620 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, 631 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
621 timeout, grs, gws, 632 timeout, grs, gws,
622 &client_run, plugin); 633 &client_run, plugin);
623 GNUNET_NETWORK_fdset_destroy(gws); 634 GNUNET_NETWORK_fdset_destroy (gws);
624 GNUNET_NETWORK_fdset_destroy(grs); 635 GNUNET_NETWORK_fdset_destroy (grs);
625 return GNUNET_OK; 636 return GNUNET_OK;
626} 637}
627 638
@@ -638,58 +649,58 @@ client_schedule(struct HTTP_Client_Plugin *plugin,
638 * @return always 0 649 * @return always 0
639 */ 650 */
640static int 651static int
641client_log(CURL *curl, 652client_log (CURL *curl,
642 curl_infotype type, 653 curl_infotype type,
643 const char *data, 654 const char *data,
644 size_t size, 655 size_t size,
645 void *cls) 656 void *cls)
646{ 657{
647 struct RequestHandle *ch = cls; 658 struct RequestHandle *ch = cls;
648 const char *ttype = "UNSPECIFIED"; 659 const char *ttype = "UNSPECIFIED";
649 char text[size + 2]; 660 char text[size + 2];
650 661
651 if (!((CURLINFO_TEXT == type) || 662 if (! ((CURLINFO_TEXT == type) ||
652 (CURLINFO_HEADER_IN == type) || 663 (CURLINFO_HEADER_IN == type) ||
653 (CURLINFO_HEADER_OUT == type))) 664 (CURLINFO_HEADER_OUT == type)))
654 return 0; 665 return 0;
655 switch (type) 666 switch (type)
656 { 667 {
657 case CURLINFO_TEXT: 668 case CURLINFO_TEXT:
658 ttype = "TEXT"; 669 ttype = "TEXT";
659 break; 670 break;
660 671
661 case CURLINFO_HEADER_IN: 672 case CURLINFO_HEADER_IN:
662 ttype = "HEADER_IN"; 673 ttype = "HEADER_IN";
663 break; 674 break;
664 675
665 case CURLINFO_HEADER_OUT: 676 case CURLINFO_HEADER_OUT:
666 ttype = "HEADER_OUT"; 677 ttype = "HEADER_OUT";
667 /* Overhead*/ 678 /* Overhead*/
668 GNUNET_assert(NULL != ch); 679 GNUNET_assert (NULL != ch);
669 GNUNET_assert(NULL != ch->easyhandle); 680 GNUNET_assert (NULL != ch->easyhandle);
670 GNUNET_assert(NULL != ch->s); 681 GNUNET_assert (NULL != ch->s);
671 ch->s->overhead += size; 682 ch->s->overhead += size;
672 break; 683 break;
673 684
674 default: 685 default:
675 ttype = "UNSPECIFIED"; 686 ttype = "UNSPECIFIED";
676 break; 687 break;
677 } 688 }
678 GNUNET_memcpy(text, data, size); 689 GNUNET_memcpy (text, data, size);
679 if (text[size - 1] == '\n') 690 if (text[size - 1] == '\n')
680 { 691 {
681 text[size] = '\0'; 692 text[size] = '\0';
682 } 693 }
683 else 694 else
684 { 695 {
685 text[size] = '\n'; 696 text[size] = '\n';
686 text[size + 1] = '\0'; 697 text[size + 1] = '\0';
687 } 698 }
688 LOG(GNUNET_ERROR_TYPE_DEBUG, 699 LOG (GNUNET_ERROR_TYPE_DEBUG,
689 "Request %p %s: %s", 700 "Request %p %s: %s",
690 ch->easyhandle, 701 ch->easyhandle,
691 ttype, 702 ttype,
692 text); 703 text);
693 return 0; 704 return 0;
694} 705}
695#endif 706#endif
@@ -701,7 +712,7 @@ client_log(CURL *curl,
701 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 712 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
702 */ 713 */
703static int 714static int
704client_connect_get(struct GNUNET_ATS_Session *s); 715client_connect_get (struct GNUNET_ATS_Session *s);
705 716
706 717
707/** 718/**
@@ -711,7 +722,7 @@ client_connect_get(struct GNUNET_ATS_Session *s);
711 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success 722 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success
712 */ 723 */
713static int 724static int
714client_connect_put(struct GNUNET_ATS_Session *s); 725client_connect_put (struct GNUNET_ATS_Session *s);
715 726
716 727
717/** 728/**
@@ -742,86 +753,86 @@ client_connect_put(struct GNUNET_ATS_Session *s);
742 * and does NOT mean that the message was not transmitted (DV) 753 * and does NOT mean that the message was not transmitted (DV)
743 */ 754 */
744static ssize_t 755static ssize_t
745http_client_plugin_send(void *cls, 756http_client_plugin_send (void *cls,
746 struct GNUNET_ATS_Session *s, 757 struct GNUNET_ATS_Session *s,
747 const char *msgbuf, 758 const char *msgbuf,
748 size_t msgbuf_size, 759 size_t msgbuf_size,
749 unsigned int priority, 760 unsigned int priority,
750 struct GNUNET_TIME_Relative to, 761 struct GNUNET_TIME_Relative to,
751 GNUNET_TRANSPORT_TransmitContinuation cont, 762 GNUNET_TRANSPORT_TransmitContinuation cont,
752 void *cont_cls) 763 void *cont_cls)
753{ 764{
754 struct HTTP_Client_Plugin *plugin = cls; 765 struct HTTP_Client_Plugin *plugin = cls;
755 struct HTTP_Message *msg; 766 struct HTTP_Message *msg;
756 char *stat_txt; 767 char *stat_txt;
757 768
758 LOG(GNUNET_ERROR_TYPE_DEBUG, 769 LOG (GNUNET_ERROR_TYPE_DEBUG,
759 "Session %p/request %p: Sending message with %u to peer `%s' \n", 770 "Session %p/request %p: Sending message with %u to peer `%s' \n",
760 s, 771 s,
761 s->put.easyhandle, 772 s->put.easyhandle,
762 msgbuf_size, 773 msgbuf_size,
763 GNUNET_i2s(&s->address->peer)); 774 GNUNET_i2s (&s->address->peer));
764 775
765 /* create new message and schedule */ 776 /* create new message and schedule */
766 msg = GNUNET_malloc(sizeof(struct HTTP_Message) + msgbuf_size); 777 msg = GNUNET_malloc (sizeof(struct HTTP_Message) + msgbuf_size);
767 msg->size = msgbuf_size; 778 msg->size = msgbuf_size;
768 msg->buf = (char *)&msg[1]; 779 msg->buf = (char *) &msg[1];
769 msg->transmit_cont = cont; 780 msg->transmit_cont = cont;
770 msg->transmit_cont_cls = cont_cls; 781 msg->transmit_cont_cls = cont_cls;
771 GNUNET_memcpy(msg->buf, 782 GNUNET_memcpy (msg->buf,
772 msgbuf, 783 msgbuf,
773 msgbuf_size); 784 msgbuf_size);
774 GNUNET_CONTAINER_DLL_insert_tail(s->msg_head, 785 GNUNET_CONTAINER_DLL_insert_tail (s->msg_head,
775 s->msg_tail, 786 s->msg_tail,
776 msg); 787 msg);
777 s->msgs_in_queue++; 788 s->msgs_in_queue++;
778 s->bytes_in_queue += msg->size; 789 s->bytes_in_queue += msg->size;
779 790
780 GNUNET_asprintf(&stat_txt, 791 GNUNET_asprintf (&stat_txt,
781 "# bytes currently in %s_client buffers", 792 "# bytes currently in %s_client buffers",
782 plugin->protocol); 793 plugin->protocol);
783 GNUNET_STATISTICS_update(plugin->env->stats, 794 GNUNET_STATISTICS_update (plugin->env->stats,
784 stat_txt, msgbuf_size, GNUNET_NO); 795 stat_txt, msgbuf_size, GNUNET_NO);
785 GNUNET_free(stat_txt); 796 GNUNET_free (stat_txt);
786 notify_session_monitor(plugin, 797 notify_session_monitor (plugin,
787 s, 798 s,
788 GNUNET_TRANSPORT_SS_UPDATE); 799 GNUNET_TRANSPORT_SS_UPDATE);
789 if (H_TMP_DISCONNECTING == s->put.state) 800 if (H_TMP_DISCONNECTING == s->put.state)
790 { 801 {
791 /* PUT request is currently getting disconnected */ 802 /* PUT request is currently getting disconnected */
792 s->put.state = H_TMP_RECONNECT_REQUIRED; 803 s->put.state = H_TMP_RECONNECT_REQUIRED;
793 LOG(GNUNET_ERROR_TYPE_DEBUG, 804 LOG (GNUNET_ERROR_TYPE_DEBUG,
794 "Session %p/request %p: currently disconnecting, reconnecting immediately\n", 805 "Session %p/request %p: currently disconnecting, reconnecting immediately\n",
795 s, 806 s,
796 s->put.easyhandle); 807 s->put.easyhandle);
797 return msgbuf_size; 808 return msgbuf_size;
798 } 809 }
799 if (H_PAUSED == s->put.state) 810 if (H_PAUSED == s->put.state)
800 { 811 {
801 /* PUT request was paused, unpause */ 812 /* PUT request was paused, unpause */
802 GNUNET_assert(s->put_disconnect_task != NULL); 813 GNUNET_assert (s->put_disconnect_task != NULL);
803 GNUNET_SCHEDULER_cancel(s->put_disconnect_task); 814 GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
804 s->put_disconnect_task = NULL; 815 s->put_disconnect_task = NULL;
805 LOG(GNUNET_ERROR_TYPE_DEBUG, 816 LOG (GNUNET_ERROR_TYPE_DEBUG,
806 "Session %p/request %p: unpausing request\n", 817 "Session %p/request %p: unpausing request\n",
807 s, s->put.easyhandle); 818 s, s->put.easyhandle);
808 s->put.state = H_CONNECTED; 819 s->put.state = H_CONNECTED;
809 if (NULL != s->put.easyhandle) 820 if (NULL != s->put.easyhandle)
810 curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT); 821 curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
811 } 822 }
812 else if (H_TMP_DISCONNECTED == s->put.state) 823 else if (H_TMP_DISCONNECTED == s->put.state)
824 {
825 /* PUT request was disconnected, reconnect */
826 LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
827 GNUNET_break (NULL == s->put.easyhandle);
828 if (GNUNET_SYSERR == client_connect_put (s))
813 { 829 {
814 /* PUT request was disconnected, reconnect */ 830 /* Could not reconnect */
815 LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s); 831 http_client_plugin_session_disconnect (plugin, s);
816 GNUNET_break(NULL == s->put.easyhandle); 832 return GNUNET_SYSERR;
817 if (GNUNET_SYSERR == client_connect_put(s))
818 {
819 /* Could not reconnect */
820 http_client_plugin_session_disconnect(plugin, s);
821 return GNUNET_SYSERR;
822 }
823 } 833 }
824 client_schedule(s->plugin, GNUNET_YES); 834 }
835 client_schedule (s->plugin, GNUNET_YES);
825 return msgbuf_size; 836 return msgbuf_size;
826} 837}
827 838
@@ -834,26 +845,26 @@ http_client_plugin_send(void *cls,
834 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 845 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
835 */ 846 */
836static int 847static int
837http_client_plugin_session_disconnect(void *cls, 848http_client_plugin_session_disconnect (void *cls,
838 struct GNUNET_ATS_Session *s) 849 struct GNUNET_ATS_Session *s)
839{ 850{
840 struct HTTP_Client_Plugin *plugin = cls; 851 struct HTTP_Client_Plugin *plugin = cls;
841 852
842 LOG(GNUNET_ERROR_TYPE_DEBUG, 853 LOG (GNUNET_ERROR_TYPE_DEBUG,
843 "Session %p: notifying transport about ending session\n", 854 "Session %p: notifying transport about ending session\n",
844 s); 855 s);
845 plugin->env->session_end(plugin->env->cls, 856 plugin->env->session_end (plugin->env->cls,
846 s->address, 857 s->address,
847 s); 858 s);
848 client_delete_session(s); 859 client_delete_session (s);
849 860
850 /* Re-schedule since handles have changed */ 861 /* Re-schedule since handles have changed */
851 if (NULL != plugin->client_perform_task) 862 if (NULL != plugin->client_perform_task)
852 { 863 {
853 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 864 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
854 plugin->client_perform_task = NULL; 865 plugin->client_perform_task = NULL;
855 } 866 }
856 client_schedule(plugin, GNUNET_YES); 867 client_schedule (plugin, GNUNET_YES);
857 868
858 return GNUNET_OK; 869 return GNUNET_OK;
859} 870}
@@ -868,7 +879,7 @@ http_client_plugin_session_disconnect(void *cls,
868 * @return keepalive factor 879 * @return keepalive factor
869 */ 880 */
870static unsigned int 881static unsigned int
871http_client_query_keepalive_factor(void *cls) 882http_client_query_keepalive_factor (void *cls)
872{ 883{
873 return 3; 884 return 3;
874} 885}
@@ -883,14 +894,14 @@ http_client_query_keepalive_factor(void *cls)
883 * @return #GNUNET_OK (continue iterating) 894 * @return #GNUNET_OK (continue iterating)
884 */ 895 */
885static int 896static int
886destroy_session_cb(void *cls, 897destroy_session_cb (void *cls,
887 const struct GNUNET_PeerIdentity *peer, 898 const struct GNUNET_PeerIdentity *peer,
888 void *value) 899 void *value)
889{ 900{
890 struct HTTP_Client_Plugin *plugin = cls; 901 struct HTTP_Client_Plugin *plugin = cls;
891 struct GNUNET_ATS_Session *session = value; 902 struct GNUNET_ATS_Session *session = value;
892 903
893 http_client_plugin_session_disconnect(plugin, session); 904 http_client_plugin_session_disconnect (plugin, session);
894 return GNUNET_OK; 905 return GNUNET_OK;
895} 906}
896 907
@@ -904,25 +915,26 @@ destroy_session_cb(void *cls,
904 * @param target peer from which to disconnect 915 * @param target peer from which to disconnect
905 */ 916 */
906static void 917static void
907http_client_plugin_peer_disconnect(void *cls, 918http_client_plugin_peer_disconnect (void *cls,
908 const struct GNUNET_PeerIdentity *target) 919 const struct GNUNET_PeerIdentity *target)
909{ 920{
910 struct HTTP_Client_Plugin *plugin = cls; 921 struct HTTP_Client_Plugin *plugin = cls;
911 922
912 LOG(GNUNET_ERROR_TYPE_DEBUG, 923 LOG (GNUNET_ERROR_TYPE_DEBUG,
913 "Transport tells me to disconnect `%s'\n", 924 "Transport tells me to disconnect `%s'\n",
914 GNUNET_i2s(target)); 925 GNUNET_i2s (target));
915 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, 926 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions,
916 target, 927 target,
917 &destroy_session_cb, 928 &destroy_session_cb,
918 plugin); 929 plugin);
919} 930}
920 931
921 932
922/** 933/**
923 * Closure for #session_lookup_client_by_address(). 934 * Closure for #session_lookup_client_by_address().
924 */ 935 */
925struct GNUNET_ATS_SessionClientCtx { 936struct GNUNET_ATS_SessionClientCtx
937{
926 /** 938 /**
927 * Address we are looking for. 939 * Address we are looking for.
928 */ 940 */
@@ -944,19 +956,19 @@ struct GNUNET_ATS_SessionClientCtx {
944 * @return #GNUNET_NO if found, #GNUNET_OK if not 956 * @return #GNUNET_NO if found, #GNUNET_OK if not
945 */ 957 */
946static int 958static int
947session_lookup_client_by_address(void *cls, 959session_lookup_client_by_address (void *cls,
948 const struct GNUNET_PeerIdentity *key, 960 const struct GNUNET_PeerIdentity *key,
949 void *value) 961 void *value)
950{ 962{
951 struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls; 963 struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls;
952 struct GNUNET_ATS_Session *s = value; 964 struct GNUNET_ATS_Session *s = value;
953 965
954 if (0 == GNUNET_HELLO_address_cmp(sc_ctx->address, 966 if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address,
955 s->address)) 967 s->address))
956 { 968 {
957 sc_ctx->ret = s; 969 sc_ctx->ret = s;
958 return GNUNET_NO; 970 return GNUNET_NO;
959 } 971 }
960 return GNUNET_YES; 972 return GNUNET_YES;
961} 973}
962 974
@@ -969,16 +981,16 @@ session_lookup_client_by_address(void *cls,
969 * @return the session or NULL 981 * @return the session or NULL
970 */ 982 */
971static struct GNUNET_ATS_Session * 983static struct GNUNET_ATS_Session *
972client_lookup_session(struct HTTP_Client_Plugin *plugin, 984client_lookup_session (struct HTTP_Client_Plugin *plugin,
973 const struct GNUNET_HELLO_Address *address) 985 const struct GNUNET_HELLO_Address *address)
974{ 986{
975 struct GNUNET_ATS_SessionClientCtx sc_ctx; 987 struct GNUNET_ATS_SessionClientCtx sc_ctx;
976 988
977 sc_ctx.address = address; 989 sc_ctx.address = address;
978 sc_ctx.ret = NULL; 990 sc_ctx.ret = NULL;
979 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 991 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
980 &session_lookup_client_by_address, 992 &session_lookup_client_by_address,
981 &sc_ctx); 993 &sc_ctx);
982 return sc_ctx.ret; 994 return sc_ctx.ret;
983} 995}
984 996
@@ -991,19 +1003,19 @@ client_lookup_session(struct HTTP_Client_Plugin *plugin,
991 * @param cls the `struct GNUNET_ATS_Session *` with the put 1003 * @param cls the `struct GNUNET_ATS_Session *` with the put
992 */ 1004 */
993static void 1005static void
994client_put_disconnect(void *cls) 1006client_put_disconnect (void *cls)
995{ 1007{
996 struct GNUNET_ATS_Session *s = cls; 1008 struct GNUNET_ATS_Session *s = cls;
997 1009
998 s->put_disconnect_task = NULL; 1010 s->put_disconnect_task = NULL;
999 LOG(GNUNET_ERROR_TYPE_DEBUG, 1011 LOG (GNUNET_ERROR_TYPE_DEBUG,
1000 "Session %p/request %p: will be disconnected due to no activity\n", 1012 "Session %p/request %p: will be disconnected due to no activity\n",
1001 s, s->put.easyhandle); 1013 s, s->put.easyhandle);
1002 s->put.state = H_TMP_DISCONNECTING; 1014 s->put.state = H_TMP_DISCONNECTING;
1003 if (NULL != s->put.easyhandle) 1015 if (NULL != s->put.easyhandle)
1004 curl_easy_pause(s->put.easyhandle, 1016 curl_easy_pause (s->put.easyhandle,
1005 CURLPAUSE_CONT); 1017 CURLPAUSE_CONT);
1006 client_schedule(s->plugin, GNUNET_YES); 1018 client_schedule (s->plugin, GNUNET_YES);
1007} 1019}
1008 1020
1009 1021
@@ -1018,10 +1030,10 @@ client_put_disconnect(void *cls)
1018 * @return bytes written to stream, returning 0 will terminate request! 1030 * @return bytes written to stream, returning 0 will terminate request!
1019 */ 1031 */
1020static size_t 1032static size_t
1021client_send_cb(void *stream, 1033client_send_cb (void *stream,
1022 size_t size, 1034 size_t size,
1023 size_t nmemb, 1035 size_t nmemb,
1024 void *cls) 1036 void *cls)
1025{ 1037{
1026 struct GNUNET_ATS_Session *s = cls; 1038 struct GNUNET_ATS_Session *s = cls;
1027 struct HTTP_Client_Plugin *plugin = s->plugin; 1039 struct HTTP_Client_Plugin *plugin = s->plugin;
@@ -1030,90 +1042,90 @@ client_send_cb(void *stream,
1030 char *stat_txt; 1042 char *stat_txt;
1031 1043
1032 if (H_TMP_DISCONNECTING == s->put.state) 1044 if (H_TMP_DISCONNECTING == s->put.state)
1033 { 1045 {
1034 LOG(GNUNET_ERROR_TYPE_DEBUG, 1046 LOG (GNUNET_ERROR_TYPE_DEBUG,
1035 "Session %p/request %p: disconnect due to inactivity\n", 1047 "Session %p/request %p: disconnect due to inactivity\n",
1036 s, s->put.easyhandle); 1048 s, s->put.easyhandle);
1037 return 0; 1049 return 0;
1038 } 1050 }
1039 1051
1040 if (NULL == msg) 1052 if (NULL == msg)
1053 {
1054 if (GNUNET_YES == plugin->emulate_xhr)
1041 { 1055 {
1042 if (GNUNET_YES == plugin->emulate_xhr) 1056 LOG (GNUNET_ERROR_TYPE_DEBUG,
1043 { 1057 "Session %p/request %p: PUT request finished\n",
1044 LOG(GNUNET_ERROR_TYPE_DEBUG, 1058 s,
1045 "Session %p/request %p: PUT request finished\n", 1059 s->put.easyhandle);
1046 s, 1060 s->put.state = H_TMP_DISCONNECTING;
1047 s->put.easyhandle); 1061 return 0;
1048 s->put.state = H_TMP_DISCONNECTING;
1049 return 0;
1050 }
1051
1052 /* We have nothing to send, so pause PUT request */
1053 LOG(GNUNET_ERROR_TYPE_DEBUG,
1054 "Session %p/request %p: nothing to send, suspending\n",
1055 s,
1056 s->put.easyhandle);
1057 s->put_disconnect_task
1058 = GNUNET_SCHEDULER_add_delayed(PUT_DISCONNECT_TIMEOUT,
1059 &client_put_disconnect,
1060 s);
1061 s->put.state = H_PAUSED;
1062 return CURL_READFUNC_PAUSE;
1063 } 1062 }
1063
1064 /* We have nothing to send, so pause PUT request */
1065 LOG (GNUNET_ERROR_TYPE_DEBUG,
1066 "Session %p/request %p: nothing to send, suspending\n",
1067 s,
1068 s->put.easyhandle);
1069 s->put_disconnect_task
1070 = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT,
1071 &client_put_disconnect,
1072 s);
1073 s->put.state = H_PAUSED;
1074 return CURL_READFUNC_PAUSE;
1075 }
1064 /* data to send */ 1076 /* data to send */
1065 GNUNET_assert(msg->pos < msg->size); 1077 GNUNET_assert (msg->pos < msg->size);
1066 /* calculate how much fits in buffer */ 1078 /* calculate how much fits in buffer */
1067 len = GNUNET_MIN(msg->size - msg->pos, 1079 len = GNUNET_MIN (msg->size - msg->pos,
1068 size * nmemb); 1080 size * nmemb);
1069 GNUNET_memcpy(stream, 1081 GNUNET_memcpy (stream,
1070 &msg->buf[msg->pos], 1082 &msg->buf[msg->pos],
1071 len); 1083 len);
1072 msg->pos += len; 1084 msg->pos += len;
1073 if (msg->pos == msg->size) 1085 if (msg->pos == msg->size)
1074 { 1086 {
1075 LOG(GNUNET_ERROR_TYPE_DEBUG, 1087 LOG (GNUNET_ERROR_TYPE_DEBUG,
1076 "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", 1088 "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n",
1077 s, 1089 s,
1078 s->put.easyhandle, 1090 s->put.easyhandle,
1079 msg->size, 1091 msg->size,
1080 msg->pos); 1092 msg->pos);
1081 /* Calling transmit continuation */ 1093 /* Calling transmit continuation */
1082 GNUNET_CONTAINER_DLL_remove(s->msg_head, 1094 GNUNET_CONTAINER_DLL_remove (s->msg_head,
1083 s->msg_tail, 1095 s->msg_tail,
1084 msg); 1096 msg);
1085 GNUNET_assert(0 < s->msgs_in_queue); 1097 GNUNET_assert (0 < s->msgs_in_queue);
1086 s->msgs_in_queue--; 1098 s->msgs_in_queue--;
1087 GNUNET_assert(msg->size <= s->bytes_in_queue); 1099 GNUNET_assert (msg->size <= s->bytes_in_queue);
1088 s->bytes_in_queue -= msg->size; 1100 s->bytes_in_queue -= msg->size;
1089 if (NULL != msg->transmit_cont) 1101 if (NULL != msg->transmit_cont)
1090 msg->transmit_cont(msg->transmit_cont_cls, 1102 msg->transmit_cont (msg->transmit_cont_cls,
1091 &s->address->peer, 1103 &s->address->peer,
1092 GNUNET_OK, 1104 GNUNET_OK,
1093 msg->size, 1105 msg->size,
1094 msg->size + s->overhead); 1106 msg->size + s->overhead);
1095 s->overhead = 0; 1107 s->overhead = 0;
1096 GNUNET_free(msg); 1108 GNUNET_free (msg);
1097 } 1109 }
1098 notify_session_monitor(plugin, 1110 notify_session_monitor (plugin,
1099 s, 1111 s,
1100 GNUNET_TRANSPORT_SS_UPDATE); 1112 GNUNET_TRANSPORT_SS_UPDATE);
1101 GNUNET_asprintf(&stat_txt, 1113 GNUNET_asprintf (&stat_txt,
1102 "# bytes currently in %s_client buffers", 1114 "# bytes currently in %s_client buffers",
1103 plugin->protocol); 1115 plugin->protocol);
1104 GNUNET_STATISTICS_update(plugin->env->stats, 1116 GNUNET_STATISTICS_update (plugin->env->stats,
1105 stat_txt, 1117 stat_txt,
1106 -len, 1118 -len,
1107 GNUNET_NO); 1119 GNUNET_NO);
1108 GNUNET_free(stat_txt); 1120 GNUNET_free (stat_txt);
1109 GNUNET_asprintf(&stat_txt, 1121 GNUNET_asprintf (&stat_txt,
1110 "# bytes transmitted via %s_client", 1122 "# bytes transmitted via %s_client",
1111 plugin->protocol); 1123 plugin->protocol);
1112 GNUNET_STATISTICS_update(plugin->env->stats, 1124 GNUNET_STATISTICS_update (plugin->env->stats,
1113 stat_txt, 1125 stat_txt,
1114 len, 1126 len,
1115 GNUNET_NO); 1127 GNUNET_NO);
1116 GNUNET_free(stat_txt); 1128 GNUNET_free (stat_txt);
1117 return len; 1129 return len;
1118} 1130}
1119 1131
@@ -1124,26 +1136,26 @@ client_send_cb(void *stream,
1124 * @param cls the session 1136 * @param cls the session
1125 */ 1137 */
1126static void 1138static void
1127client_wake_up(void *cls) 1139client_wake_up (void *cls)
1128{ 1140{
1129 struct GNUNET_ATS_Session *s = cls; 1141 struct GNUNET_ATS_Session *s = cls;
1130 1142
1131 s->recv_wakeup_task = NULL; 1143 s->recv_wakeup_task = NULL;
1132 LOG(GNUNET_ERROR_TYPE_DEBUG, 1144 LOG (GNUNET_ERROR_TYPE_DEBUG,
1133 "Session %p/request %p: Waking up GET handle\n", 1145 "Session %p/request %p: Waking up GET handle\n",
1134 s, s->get.easyhandle); 1146 s, s->get.easyhandle);
1135 if (H_PAUSED == s->put.state) 1147 if (H_PAUSED == s->put.state)
1136 { 1148 {
1137 /* PUT request was paused, unpause */ 1149 /* PUT request was paused, unpause */
1138 GNUNET_assert(s->put_disconnect_task != NULL); 1150 GNUNET_assert (s->put_disconnect_task != NULL);
1139 GNUNET_SCHEDULER_cancel(s->put_disconnect_task); 1151 GNUNET_SCHEDULER_cancel (s->put_disconnect_task);
1140 s->put_disconnect_task = NULL; 1152 s->put_disconnect_task = NULL;
1141 s->put.state = H_CONNECTED; 1153 s->put.state = H_CONNECTED;
1142 if (NULL != s->put.easyhandle) 1154 if (NULL != s->put.easyhandle)
1143 curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT); 1155 curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
1144 } 1156 }
1145 if (NULL != s->get.easyhandle) 1157 if (NULL != s->get.easyhandle)
1146 curl_easy_pause(s->get.easyhandle, CURLPAUSE_CONT); 1158 curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT);
1147} 1159}
1148 1160
1149 1161
@@ -1155,8 +1167,8 @@ client_wake_up(void *cls)
1155 * @return always #GNUNET_OK 1167 * @return always #GNUNET_OK
1156 */ 1168 */
1157static int 1169static int
1158client_receive_mst_cb(void *cls, 1170client_receive_mst_cb (void *cls,
1159 const struct GNUNET_MessageHeader *message) 1171 const struct GNUNET_MessageHeader *message)
1160{ 1172{
1161 struct GNUNET_ATS_Session *s = cls; 1173 struct GNUNET_ATS_Session *s = cls;
1162 struct HTTP_Client_Plugin *plugin; 1174 struct HTTP_Client_Plugin *plugin;
@@ -1164,32 +1176,32 @@ client_receive_mst_cb(void *cls,
1164 char *stat_txt; 1176 char *stat_txt;
1165 1177
1166 plugin = s->plugin; 1178 plugin = s->plugin;
1167 delay = s->plugin->env->receive(plugin->env->cls, 1179 delay = s->plugin->env->receive (plugin->env->cls,
1168 s->address, 1180 s->address,
1169 s, 1181 s,
1170 message); 1182 message);
1171 GNUNET_asprintf(&stat_txt, 1183 GNUNET_asprintf (&stat_txt,
1172 "# bytes received via %s_client", 1184 "# bytes received via %s_client",
1173 plugin->protocol); 1185 plugin->protocol);
1174 GNUNET_STATISTICS_update(plugin->env->stats, 1186 GNUNET_STATISTICS_update (plugin->env->stats,
1175 stat_txt, 1187 stat_txt,
1176 ntohs(message->size), 1188 ntohs (message->size),
1177 GNUNET_NO); 1189 GNUNET_NO);
1178 GNUNET_free(stat_txt); 1190 GNUNET_free (stat_txt);
1179 1191
1180 s->next_receive = GNUNET_TIME_relative_to_absolute(delay); 1192 s->next_receive = GNUNET_TIME_relative_to_absolute (delay);
1181 if (GNUNET_TIME_absolute_get().abs_value_us < s->next_receive.abs_value_us) 1193 if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
1182 { 1194 {
1183 LOG(GNUNET_ERROR_TYPE_DEBUG, 1195 LOG (GNUNET_ERROR_TYPE_DEBUG,
1184 "Client: peer `%s' address `%s' next read delayed for %s\n", 1196 "Client: peer `%s' address `%s' next read delayed for %s\n",
1185 GNUNET_i2s(&s->address->peer), 1197 GNUNET_i2s (&s->address->peer),
1186 http_common_plugin_address_to_string(s->plugin->protocol, 1198 http_common_plugin_address_to_string (s->plugin->protocol,
1187 s->address->address, 1199 s->address->address,
1188 s->address->address_length), 1200 s->address->address_length),
1189 GNUNET_STRINGS_relative_time_to_string(delay, 1201 GNUNET_STRINGS_relative_time_to_string (delay,
1190 GNUNET_YES)); 1202 GNUNET_YES));
1191 } 1203 }
1192 client_reschedule_session_timeout(s); 1204 client_reschedule_session_timeout (s);
1193 return GNUNET_OK; 1205 return GNUNET_OK;
1194} 1206}
1195 1207
@@ -1205,10 +1217,10 @@ client_receive_mst_cb(void *cls,
1205 * @return bytes read from stream 1217 * @return bytes read from stream
1206 */ 1218 */
1207static size_t 1219static size_t
1208client_receive_put(void *stream, 1220client_receive_put (void *stream,
1209 size_t size, 1221 size_t size,
1210 size_t nmemb, 1222 size_t nmemb,
1211 void *cls) 1223 void *cls)
1212{ 1224{
1213 return size * nmemb; 1225 return size * nmemb;
1214} 1226}
@@ -1225,53 +1237,53 @@ client_receive_put(void *stream,
1225 * @return bytes read from stream 1237 * @return bytes read from stream
1226 */ 1238 */
1227static size_t 1239static size_t
1228client_receive(void *stream, 1240client_receive (void *stream,
1229 size_t size, 1241 size_t size,
1230 size_t nmemb, 1242 size_t nmemb,
1231 void *cls) 1243 void *cls)
1232{ 1244{
1233 struct GNUNET_ATS_Session *s = cls; 1245 struct GNUNET_ATS_Session *s = cls;
1234 struct GNUNET_TIME_Absolute now; 1246 struct GNUNET_TIME_Absolute now;
1235 size_t len = size * nmemb; 1247 size_t len = size * nmemb;
1236 1248
1237 LOG(GNUNET_ERROR_TYPE_DEBUG, 1249 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Session %p / request %p: Received %u bytes from peer `%s'\n", 1250 "Session %p / request %p: Received %u bytes from peer `%s'\n",
1239 s, 1251 s,
1240 s->get.easyhandle, 1252 s->get.easyhandle,
1241 len, 1253 len,
1242 GNUNET_i2s(&s->address->peer)); 1254 GNUNET_i2s (&s->address->peer));
1243 now = GNUNET_TIME_absolute_get(); 1255 now = GNUNET_TIME_absolute_get ();
1244 if (now.abs_value_us < s->next_receive.abs_value_us) 1256 if (now.abs_value_us < s->next_receive.abs_value_us)
1245 { 1257 {
1246 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 1258 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1247 struct GNUNET_TIME_Relative delta 1259 struct GNUNET_TIME_Relative delta
1248 = GNUNET_TIME_absolute_get_difference(now, s->next_receive); 1260 = GNUNET_TIME_absolute_get_difference (now, s->next_receive);
1249 1261
1250 LOG(GNUNET_ERROR_TYPE_DEBUG, 1262 LOG (GNUNET_ERROR_TYPE_DEBUG,
1251 "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n", 1263 "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1252 s, 1264 s,
1253 s->get.easyhandle, 1265 s->get.easyhandle,
1254 GNUNET_STRINGS_relative_time_to_string(delta, 1266 GNUNET_STRINGS_relative_time_to_string (delta,
1255 GNUNET_YES)); 1267 GNUNET_YES));
1256 if (s->recv_wakeup_task != NULL) 1268 if (s->recv_wakeup_task != NULL)
1257 { 1269 {
1258 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 1270 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
1259 s->recv_wakeup_task = NULL; 1271 s->recv_wakeup_task = NULL;
1260 }
1261 s->recv_wakeup_task
1262 = GNUNET_SCHEDULER_add_delayed(delta,
1263 &client_wake_up,
1264 s);
1265 return CURL_WRITEFUNC_PAUSE;
1266 } 1272 }
1273 s->recv_wakeup_task
1274 = GNUNET_SCHEDULER_add_delayed (delta,
1275 &client_wake_up,
1276 s);
1277 return CURL_WRITEFUNC_PAUSE;
1278 }
1267 if (NULL == s->msg_tk) 1279 if (NULL == s->msg_tk)
1268 s->msg_tk = GNUNET_MST_create(&client_receive_mst_cb, 1280 s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb,
1269 s); 1281 s);
1270 GNUNET_MST_from_buffer(s->msg_tk, 1282 GNUNET_MST_from_buffer (s->msg_tk,
1271 stream, 1283 stream,
1272 len, 1284 len,
1273 GNUNET_NO, 1285 GNUNET_NO,
1274 GNUNET_NO); 1286 GNUNET_NO);
1275 return len; 1287 return len;
1276} 1288}
1277 1289
@@ -1282,7 +1294,7 @@ client_receive(void *stream,
1282 * @param cls plugin as closure 1294 * @param cls plugin as closure
1283 */ 1295 */
1284static void 1296static void
1285client_run(void *cls) 1297client_run (void *cls)
1286{ 1298{
1287 struct HTTP_Client_Plugin *plugin = cls; 1299 struct HTTP_Client_Plugin *plugin = cls;
1288 int running; 1300 int running;
@@ -1295,141 +1307,144 @@ client_run(void *cls)
1295 plugin->client_perform_task = NULL; 1307 plugin->client_perform_task = NULL;
1296 /* While data are available or timeouts occured */ 1308 /* While data are available or timeouts occured */
1297 do 1309 do
1310 {
1311 running = 0;
1312 /* Perform operations for all handles */
1313 mret = curl_multi_perform (plugin->curl_multi_handle, &running);
1314
1315 /* Get additional information for all handles */
1316 while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle,
1317 &msgs_left)))
1298 { 1318 {
1299 running = 0; 1319 CURL *easy_h = msg->easy_handle;
1300 /* Perform operations for all handles */ 1320 struct GNUNET_ATS_Session *s = NULL;
1301 mret = curl_multi_perform(plugin->curl_multi_handle, &running); 1321 char *d = NULL; /* curl requires 'd' to be a 'char *' */
1322
1323 GNUNET_assert (NULL != easy_h);
1324
1325 /* Obtain session from easy handle */
1326 GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE,
1327 &d));
1328 s = (struct GNUNET_ATS_Session *) d;
1329 GNUNET_assert (NULL != s);
1330
1331 if (msg->msg != CURLMSG_DONE)
1332 continue; /* This should not happen */
1333
1334 /* Get HTTP response code */
1335 GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
1336 CURLINFO_RESPONSE_CODE,
1337 &http_statuscode));
1338
1339 if (easy_h == s->put.easyhandle)
1340 put_request = GNUNET_YES;
1341 else
1342 put_request = GNUNET_NO;
1343
1344 /* Log status of terminated request */
1345 if ((0 != msg->data.result) || (http_statuscode != 200))
1346 LOG (GNUNET_ERROR_TYPE_DEBUG,
1347 "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1348 s, msg->easy_handle,
1349 (GNUNET_YES == put_request) ? "PUT" : "GET",
1350 GNUNET_i2s (&s->address->peer),
1351 http_statuscode,
1352 msg->data.result,
1353 curl_easy_strerror (msg->data.result));
1354 else
1355 LOG (GNUNET_ERROR_TYPE_DEBUG,
1356 "Session %p/request %p: %s request to `%s' ended normal\n",
1357 s, msg->easy_handle,
1358 (GNUNET_YES == put_request) ? "PUT" : "GET",
1359 GNUNET_i2s (&s->address->peer));
1360
1361 /* Remove easy handle from multi handle */
1362 curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1363
1364 /* Clean up easy handle */
1365 curl_easy_cleanup (easy_h);
1366
1367 /* Remove information */
1368 GNUNET_assert (plugin->cur_requests > 0);
1369 plugin->cur_requests--;
1370 LOG (GNUNET_ERROR_TYPE_INFO,
1371 "%s request to %s done, number of requests decreased to %u\n",
1372 (GNUNET_YES == put_request) ? "PUT" : "GET",
1373 s->url,
1374 plugin->cur_requests);
1302 1375
1303 /* Get additional information for all handles */ 1376 if (GNUNET_YES == put_request)
1304 while (NULL != (msg = curl_multi_info_read(plugin->curl_multi_handle, &msgs_left))) 1377 {
1378 /* Clean up a PUT request */
1379 s->put.easyhandle = NULL;
1380 s->put.s = NULL;
1381
1382 switch (s->put.state)
1383 {
1384 case H_NOT_CONNECTED:
1385 case H_DISCONNECTED:
1386 case H_TMP_DISCONNECTED:
1387 /* This must not happen */
1388 GNUNET_break (0);
1389 break;
1390
1391 case H_TMP_RECONNECT_REQUIRED:
1392 /* Transport called send while disconnect in progess, reconnect */
1393 if (GNUNET_SYSERR == client_connect_put (s))
1394 {
1395 /* Reconnect failed, disconnect session */
1396 http_client_plugin_session_disconnect (plugin, s);
1397 }
1398 break;
1399
1400 case H_TMP_DISCONNECTING:
1401 /* PUT gets temporarily disconnected */
1402 s->put.state = H_TMP_DISCONNECTED;
1403 break;
1404
1405 case H_PAUSED:
1406 case H_CONNECTED:
1407 /* PUT gets permanently disconnected */
1408 s->put.state = H_DISCONNECTED;
1409 http_client_plugin_session_disconnect (plugin, s);
1410 break;
1411
1412 default:
1413 GNUNET_break (0);
1414 break;
1415 }
1416 }
1417 else if (GNUNET_NO == put_request)
1418 {
1419 /* Clean up a GET request */
1420 s->get.easyhandle = NULL;
1421 s->get.s = NULL;
1422
1423 /* If we are emulating an XHR client we need to make another GET
1424 * request.
1425 */
1426 if (GNUNET_YES == plugin->emulate_xhr)
1427 {
1428 if (GNUNET_SYSERR == client_connect_get (s))
1429 http_client_plugin_session_disconnect (plugin, s);
1430 }
1431 else
1305 { 1432 {
1306 CURL *easy_h = msg->easy_handle; 1433 /* GET request was terminated, so disconnect session */
1307 struct GNUNET_ATS_Session *s = NULL; 1434 http_client_plugin_session_disconnect (plugin, s);
1308 char *d = NULL; /* curl requires 'd' to be a 'char *' */
1309
1310 GNUNET_assert(NULL != easy_h);
1311
1312 /* Obtain session from easy handle */
1313 GNUNET_assert(CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d));
1314 s = (struct GNUNET_ATS_Session *)d;
1315 GNUNET_assert(NULL != s);
1316
1317 if (msg->msg != CURLMSG_DONE)
1318 continue; /* This should not happen */
1319
1320 /* Get HTTP response code */
1321 GNUNET_break(CURLE_OK == curl_easy_getinfo(easy_h,
1322 CURLINFO_RESPONSE_CODE, &http_statuscode));
1323
1324 if (easy_h == s->put.easyhandle)
1325 put_request = GNUNET_YES;
1326 else
1327 put_request = GNUNET_NO;
1328
1329 /* Log status of terminated request */
1330 if ((0 != msg->data.result) || (http_statuscode != 200))
1331 LOG(GNUNET_ERROR_TYPE_DEBUG,
1332 "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1333 s, msg->easy_handle,
1334 (GNUNET_YES == put_request) ? "PUT" : "GET",
1335 GNUNET_i2s(&s->address->peer),
1336 http_statuscode,
1337 msg->data.result,
1338 curl_easy_strerror(msg->data.result));
1339 else
1340 LOG(GNUNET_ERROR_TYPE_DEBUG,
1341 "Session %p/request %p: %s request to `%s' ended normal\n",
1342 s, msg->easy_handle,
1343 (GNUNET_YES == put_request) ? "PUT" : "GET",
1344 GNUNET_i2s(&s->address->peer));
1345
1346 /* Remove easy handle from multi handle */
1347 curl_multi_remove_handle(plugin->curl_multi_handle, easy_h);
1348
1349 /* Clean up easy handle */
1350 curl_easy_cleanup(easy_h);
1351
1352 /* Remove information */
1353 GNUNET_assert(plugin->cur_requests > 0);
1354 plugin->cur_requests--;
1355 LOG(GNUNET_ERROR_TYPE_INFO,
1356 "%s request to %s done, number of requests decreased to %u\n",
1357 (GNUNET_YES == put_request) ? "PUT" : "GET",
1358 s->url,
1359 plugin->cur_requests);
1360
1361 if (GNUNET_YES == put_request)
1362 {
1363 /* Clean up a PUT request */
1364 s->put.easyhandle = NULL;
1365 s->put.s = NULL;
1366
1367 switch (s->put.state)
1368 {
1369 case H_NOT_CONNECTED:
1370 case H_DISCONNECTED:
1371 case H_TMP_DISCONNECTED:
1372 /* This must not happen */
1373 GNUNET_break(0);
1374 break;
1375
1376 case H_TMP_RECONNECT_REQUIRED:
1377 /* Transport called send while disconnect in progess, reconnect */
1378 if (GNUNET_SYSERR == client_connect_put(s))
1379 {
1380 /* Reconnect failed, disconnect session */
1381 http_client_plugin_session_disconnect(plugin, s);
1382 }
1383 break;
1384
1385 case H_TMP_DISCONNECTING:
1386 /* PUT gets temporarily disconnected */
1387 s->put.state = H_TMP_DISCONNECTED;
1388 break;
1389
1390 case H_PAUSED:
1391 case H_CONNECTED:
1392 /* PUT gets permanently disconnected */
1393 s->put.state = H_DISCONNECTED;
1394 http_client_plugin_session_disconnect(plugin, s);
1395 break;
1396
1397 default:
1398 GNUNET_break(0);
1399 break;
1400 }
1401 }
1402 else if (GNUNET_NO == put_request)
1403 {
1404 /* Clean up a GET request */
1405 s->get.easyhandle = NULL;
1406 s->get.s = NULL;
1407
1408 /* If we are emulating an XHR client we need to make another GET
1409 * request.
1410 */
1411 if (GNUNET_YES == plugin->emulate_xhr)
1412 {
1413 if (GNUNET_SYSERR == client_connect_get(s))
1414 http_client_plugin_session_disconnect(plugin, s);
1415 }
1416 else
1417 {
1418 /* GET request was terminated, so disconnect session */
1419 http_client_plugin_session_disconnect(plugin, s);
1420 }
1421 }
1422 else
1423 GNUNET_break(0); /* Must not happen */
1424
1425 GNUNET_STATISTICS_set(plugin->env->stats,
1426 HTTP_STAT_STR_CONNECTIONS,
1427 plugin->cur_requests,
1428 GNUNET_NO);
1429 } 1435 }
1436 }
1437 else
1438 GNUNET_break (0); /* Must not happen */
1439
1440 GNUNET_STATISTICS_set (plugin->env->stats,
1441 HTTP_STAT_STR_CONNECTIONS,
1442 plugin->cur_requests,
1443 GNUNET_NO);
1430 } 1444 }
1445 }
1431 while (mret == CURLM_CALL_MULTI_PERFORM); 1446 while (mret == CURLM_CALL_MULTI_PERFORM);
1432 client_schedule(plugin, GNUNET_NO); 1447 client_schedule (plugin, GNUNET_NO);
1433} 1448}
1434 1449
1435 1450
@@ -1443,51 +1458,51 @@ client_run(void *cls)
1443 * @return opened socket 1458 * @return opened socket
1444 */ 1459 */
1445static curl_socket_t 1460static curl_socket_t
1446open_tcp_stealth_socket_cb(void *clientp, 1461open_tcp_stealth_socket_cb (void *clientp,
1447 curlsocktype purpose, 1462 curlsocktype purpose,
1448 struct curl_sockaddr *address) 1463 struct curl_sockaddr *address)
1449{ 1464{
1450 struct GNUNET_ATS_Session *s = clientp; 1465 struct GNUNET_ATS_Session *s = clientp;
1451 int ret; 1466 int ret;
1452 1467
1453 switch (purpose) 1468 switch (purpose)
1469 {
1470 case CURLSOCKTYPE_IPCXN:
1471 ret = socket (address->family,
1472 address->socktype,
1473 address->protocol);
1474 if (-1 == ret)
1475 return CURL_SOCKET_BAD;
1476 if (((SOCK_STREAM != address->socktype) ||
1477 ((0 != address->protocol) &&
1478 (IPPROTO_TCP != address->protocol))))
1479 return (curl_socket_t) ret;
1480 if ((0 != setsockopt (ret,
1481 IPPROTO_TCP,
1482 TCP_STEALTH,
1483 &s->address->peer,
1484 sizeof(struct GNUNET_PeerIdentity))))
1454 { 1485 {
1455 case CURLSOCKTYPE_IPCXN: 1486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1456 ret = socket(address->family, 1487 _ ("TCP_STEALTH not supported on this platform.\n"));
1457 address->socktype, 1488 (void) close (ret);
1458 address->protocol);
1459 if (-1 == ret)
1460 return CURL_SOCKET_BAD;
1461 if (((SOCK_STREAM != address->socktype) ||
1462 ((0 != address->protocol) &&
1463 (IPPROTO_TCP != address->protocol))))
1464 return (curl_socket_t)ret;
1465 if ((0 != setsockopt(ret,
1466 IPPROTO_TCP,
1467 TCP_STEALTH,
1468 &s->address->peer,
1469 sizeof(struct GNUNET_PeerIdentity))))
1470 {
1471 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1472 _("TCP_STEALTH not supported on this platform.\n"));
1473 (void)close(ret);
1474 return CURL_SOCKET_BAD;
1475 }
1476 return (curl_socket_t)ret;
1477
1478 case CURLSOCKTYPE_ACCEPT:
1479 GNUNET_break(0);
1480 return CURL_SOCKET_BAD; 1489 return CURL_SOCKET_BAD;
1481 break; 1490 }
1491 return (curl_socket_t) ret;
1482 1492
1483 case CURLSOCKTYPE_LAST: 1493 case CURLSOCKTYPE_ACCEPT:
1484 GNUNET_break(0); 1494 GNUNET_break (0);
1485 return CURL_SOCKET_BAD; 1495 return CURL_SOCKET_BAD;
1496 break;
1486 1497
1487 default: 1498 case CURLSOCKTYPE_LAST:
1488 GNUNET_break(0); 1499 GNUNET_break (0);
1489 return CURL_SOCKET_BAD; 1500 return CURL_SOCKET_BAD;
1490 } 1501
1502 default:
1503 GNUNET_break (0);
1504 return CURL_SOCKET_BAD;
1505 }
1491} 1506}
1492#endif 1507#endif
1493 1508
@@ -1499,175 +1514,177 @@ open_tcp_stealth_socket_cb(void *clientp,
1499 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 1514 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1500 */ 1515 */
1501static int 1516static int
1502client_connect_get(struct GNUNET_ATS_Session *s) 1517client_connect_get (struct GNUNET_ATS_Session *s)
1503{ 1518{
1504 CURLMcode mret; 1519 CURLMcode mret;
1505 struct HttpAddress *ha; 1520 struct HttpAddress *ha;
1506 uint32_t options; 1521 uint32_t options;
1507 1522
1508 ha = (struct HttpAddress *)s->address->address; 1523 ha = (struct HttpAddress *) s->address->address;
1509 options = ntohl(ha->options); 1524 options = ntohl (ha->options);
1510 /* create get request */ 1525 /* create get request */
1511 s->get.easyhandle = curl_easy_init(); 1526 s->get.easyhandle = curl_easy_init ();
1512 s->get.s = s; 1527 s->get.s = s;
1513 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) 1528 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1514 { 1529 {
1515#ifdef TCP_STEALTH 1530#ifdef TCP_STEALTH
1516 curl_easy_setopt(s->get.easyhandle, 1531 curl_easy_setopt (s->get.easyhandle,
1517 CURLOPT_OPENSOCKETFUNCTION, 1532 CURLOPT_OPENSOCKETFUNCTION,
1518 &open_tcp_stealth_socket_cb); 1533 &open_tcp_stealth_socket_cb);
1519 curl_easy_setopt(s->get.easyhandle, 1534 curl_easy_setopt (s->get.easyhandle,
1520 CURLOPT_OPENSOCKETDATA, 1535 CURLOPT_OPENSOCKETDATA,
1521 s); 1536 s);
1522#else 1537#else
1523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1524 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); 1539 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1525 curl_easy_cleanup(s->get.easyhandle); 1540 curl_easy_cleanup (s->get.easyhandle);
1526 s->get.easyhandle = NULL; 1541 s->get.easyhandle = NULL;
1527 s->get.s = NULL; 1542 s->get.s = NULL;
1528 return GNUNET_SYSERR; 1543 return GNUNET_SYSERR;
1529#endif 1544#endif
1530 } 1545 }
1531 1546
1532#if VERBOSE_CURL 1547#if VERBOSE_CURL
1533 curl_easy_setopt(s->get.easyhandle, 1548 curl_easy_setopt (s->get.easyhandle,
1534 CURLOPT_VERBOSE, 1549 CURLOPT_VERBOSE,
1535 1L); 1550 1L);
1536 curl_easy_setopt(s->get.easyhandle, 1551 curl_easy_setopt (s->get.easyhandle,
1537 CURLOPT_DEBUGFUNCTION, 1552 CURLOPT_DEBUGFUNCTION,
1538 &client_log); 1553 &client_log);
1539 curl_easy_setopt(s->get.easyhandle, 1554 curl_easy_setopt (s->get.easyhandle,
1540 CURLOPT_DEBUGDATA, 1555 CURLOPT_DEBUGDATA,
1541 &s->get); 1556 &s->get);
1542#endif 1557#endif
1543#if BUILD_HTTPS 1558#if BUILD_HTTPS
1544 curl_easy_setopt(s->get.easyhandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 1559 curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION,
1560 CURL_SSLVERSION_TLSv1);
1545 { 1561 {
1546 if (HTTP_OPTIONS_VERIFY_CERTIFICATE == 1562 if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
1547 (options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 1563 (options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1548 { 1564 {
1549 curl_easy_setopt(s->get.easyhandle, 1565 curl_easy_setopt (s->get.easyhandle,
1550 CURLOPT_SSL_VERIFYPEER, 1L); 1566 CURLOPT_SSL_VERIFYPEER, 1L);
1551 curl_easy_setopt(s->get.easyhandle, 1567 curl_easy_setopt (s->get.easyhandle,
1552 CURLOPT_SSL_VERIFYHOST, 1568 CURLOPT_SSL_VERIFYHOST,
1553 2L); 1569 2L);
1554 } 1570 }
1555 else 1571 else
1556 { 1572 {
1557 curl_easy_setopt(s->get.easyhandle, 1573 curl_easy_setopt (s->get.easyhandle,
1558 CURLOPT_SSL_VERIFYPEER, 1574 CURLOPT_SSL_VERIFYPEER,
1559 0L); 1575 0L);
1560 curl_easy_setopt(s->get.easyhandle, 1576 curl_easy_setopt (s->get.easyhandle,
1561 CURLOPT_SSL_VERIFYHOST, 1577 CURLOPT_SSL_VERIFYHOST,
1562 0L); 1578 0L);
1563 } 1579 }
1564 } 1580 }
1565 curl_easy_setopt(s->get.easyhandle, 1581 curl_easy_setopt (s->get.easyhandle,
1566 CURLOPT_PROTOCOLS, 1582 CURLOPT_PROTOCOLS,
1567 CURLPROTO_HTTPS); 1583 CURLPROTO_HTTPS);
1568 curl_easy_setopt(s->get.easyhandle, 1584 curl_easy_setopt (s->get.easyhandle,
1569 CURLOPT_REDIR_PROTOCOLS, 1585 CURLOPT_REDIR_PROTOCOLS,
1570 CURLPROTO_HTTPS); 1586 CURLPROTO_HTTPS);
1571#else 1587#else
1572 curl_easy_setopt(s->get.easyhandle, 1588 curl_easy_setopt (s->get.easyhandle,
1573 CURLOPT_PROTOCOLS, 1589 CURLOPT_PROTOCOLS,
1574 CURLPROTO_HTTP); 1590 CURLPROTO_HTTP);
1575 curl_easy_setopt(s->get.easyhandle, 1591 curl_easy_setopt (s->get.easyhandle,
1576 CURLOPT_REDIR_PROTOCOLS, 1592 CURLOPT_REDIR_PROTOCOLS,
1577 CURLPROTO_HTTP); 1593 CURLPROTO_HTTP);
1578#endif 1594#endif
1579 1595
1580 if (NULL != s->plugin->proxy_hostname) 1596 if (NULL != s->plugin->proxy_hostname)
1581 { 1597 {
1582 curl_easy_setopt(s->get.easyhandle, 1598 curl_easy_setopt (s->get.easyhandle,
1583 CURLOPT_PROXY, 1599 CURLOPT_PROXY,
1584 s->plugin->proxy_hostname); 1600 s->plugin->proxy_hostname);
1585 curl_easy_setopt(s->get.easyhandle, 1601 curl_easy_setopt (s->get.easyhandle,
1586 CURLOPT_PROXYTYPE, 1602 CURLOPT_PROXYTYPE,
1587 s->plugin->proxytype); 1603 s->plugin->proxytype);
1588 if (NULL != s->plugin->proxy_username) 1604 if (NULL != s->plugin->proxy_username)
1589 curl_easy_setopt(s->get.easyhandle, 1605 curl_easy_setopt (s->get.easyhandle,
1590 CURLOPT_PROXYUSERNAME, 1606 CURLOPT_PROXYUSERNAME,
1591 s->plugin->proxy_username); 1607 s->plugin->proxy_username);
1592 if (NULL != s->plugin->proxy_password) 1608 if (NULL != s->plugin->proxy_password)
1593 curl_easy_setopt(s->get.easyhandle, 1609 curl_easy_setopt (s->get.easyhandle,
1594 CURLOPT_PROXYPASSWORD, 1610 CURLOPT_PROXYPASSWORD,
1595 s->plugin->proxy_password); 1611 s->plugin->proxy_password);
1596 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) 1612 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1597 curl_easy_setopt(s->get.easyhandle, 1613 curl_easy_setopt (s->get.easyhandle,
1598 CURLOPT_HTTPPROXYTUNNEL, 1614 CURLOPT_HTTPPROXYTUNNEL,
1599 s->plugin->proxy_use_httpproxytunnel); 1615 s->plugin->proxy_use_httpproxytunnel);
1600 } 1616 }
1601 1617
1602 if (GNUNET_YES == s->plugin->emulate_xhr) 1618 if (GNUNET_YES == s->plugin->emulate_xhr)
1603 { 1619 {
1604 char *url; 1620 char *url;
1605 1621
1606 GNUNET_asprintf(&url, 1622 GNUNET_asprintf (&url,
1607 "%s,1", 1623 "%s,1",
1608 s->url); 1624 s->url);
1609 curl_easy_setopt(s->get.easyhandle, 1625 curl_easy_setopt (s->get.easyhandle,
1610 CURLOPT_URL, 1626 CURLOPT_URL,
1611 url); 1627 url);
1612 GNUNET_free(url); 1628 GNUNET_free (url);
1613 } 1629 }
1614 else 1630 else
1615 { 1631 {
1616 curl_easy_setopt(s->get.easyhandle, 1632 curl_easy_setopt (s->get.easyhandle,
1617 CURLOPT_URL, 1633 CURLOPT_URL,
1618 s->url); 1634 s->url);
1619 } 1635 }
1620 curl_easy_setopt(s->get.easyhandle, 1636 curl_easy_setopt (s->get.easyhandle,
1621 CURLOPT_READFUNCTION, 1637 CURLOPT_READFUNCTION,
1622 &client_send_cb); 1638 &client_send_cb);
1623 curl_easy_setopt(s->get.easyhandle, 1639 curl_easy_setopt (s->get.easyhandle,
1624 CURLOPT_READDATA, 1640 CURLOPT_READDATA,
1625 s); 1641 s);
1626 curl_easy_setopt(s->get.easyhandle, 1642 curl_easy_setopt (s->get.easyhandle,
1627 CURLOPT_WRITEFUNCTION, 1643 CURLOPT_WRITEFUNCTION,
1628 &client_receive); 1644 &client_receive);
1629 curl_easy_setopt(s->get.easyhandle, 1645 curl_easy_setopt (s->get.easyhandle,
1630 CURLOPT_WRITEDATA, 1646 CURLOPT_WRITEDATA,
1631 s); 1647 s);
1632 /* No timeout by default, timeout done with session timeout */ 1648 /* No timeout by default, timeout done with session timeout */
1633 curl_easy_setopt(s->get.easyhandle, 1649 curl_easy_setopt (s->get.easyhandle,
1634 CURLOPT_TIMEOUT, 1650 CURLOPT_TIMEOUT,
1635 0L); 1651 0L);
1636 curl_easy_setopt(s->get.easyhandle, 1652 curl_easy_setopt (s->get.easyhandle,
1637 CURLOPT_PRIVATE, s); 1653 CURLOPT_PRIVATE, s);
1638 curl_easy_setopt(s->get.easyhandle, 1654 curl_easy_setopt (s->get.easyhandle,
1639 CURLOPT_CONNECTTIMEOUT_MS, 1655 CURLOPT_CONNECTTIMEOUT_MS,
1640 (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); 1656 (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1641 curl_easy_setopt(s->get.easyhandle, CURLOPT_BUFFERSIZE, 1657 / 1000LL));
1642 2 * GNUNET_MAX_MESSAGE_SIZE); 1658 curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
1659 2 * GNUNET_MAX_MESSAGE_SIZE);
1643#if CURL_TCP_NODELAY 1660#if CURL_TCP_NODELAY
1644 curl_easy_setopt(ps->recv_endpoint, 1661 curl_easy_setopt (ps->recv_endpoint,
1645 CURLOPT_TCP_NODELAY, 1662 CURLOPT_TCP_NODELAY,
1646 1L); 1663 1L);
1647#endif 1664#endif
1648 curl_easy_setopt(s->get.easyhandle, 1665 curl_easy_setopt (s->get.easyhandle,
1649 CURLOPT_FOLLOWLOCATION, 1666 CURLOPT_FOLLOWLOCATION,
1650 0L); 1667 0L);
1651 1668
1652 mret = curl_multi_add_handle(s->plugin->curl_multi_handle, 1669 mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1653 s->get.easyhandle); 1670 s->get.easyhandle);
1654 if (CURLM_OK != mret) 1671 if (CURLM_OK != mret)
1655 { 1672 {
1656 LOG(GNUNET_ERROR_TYPE_ERROR, 1673 LOG (GNUNET_ERROR_TYPE_ERROR,
1657 "Session %p : Failed to add GET handle to multihandle: `%s'\n", 1674 "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1658 s, 1675 s,
1659 curl_multi_strerror(mret)); 1676 curl_multi_strerror (mret));
1660 curl_easy_cleanup(s->get.easyhandle); 1677 curl_easy_cleanup (s->get.easyhandle);
1661 s->get.easyhandle = NULL; 1678 s->get.easyhandle = NULL;
1662 s->get.s = NULL; 1679 s->get.s = NULL;
1663 GNUNET_break(0); 1680 GNUNET_break (0);
1664 return GNUNET_SYSERR; 1681 return GNUNET_SYSERR;
1665 } 1682 }
1666 s->plugin->cur_requests++; 1683 s->plugin->cur_requests++;
1667 LOG(GNUNET_ERROR_TYPE_INFO, 1684 LOG (GNUNET_ERROR_TYPE_INFO,
1668 "GET request `%s' established, number of requests increased to %u\n", 1685 "GET request `%s' established, number of requests increased to %u\n",
1669 s->url, 1686 s->url,
1670 s->plugin->cur_requests); 1687 s->plugin->cur_requests);
1671 return GNUNET_OK; 1688 return GNUNET_OK;
1672} 1689}
1673 1690
@@ -1679,166 +1696,167 @@ client_connect_get(struct GNUNET_ATS_Session *s)
1679 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok 1696 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
1680 */ 1697 */
1681static int 1698static int
1682client_connect_put(struct GNUNET_ATS_Session *s) 1699client_connect_put (struct GNUNET_ATS_Session *s)
1683{ 1700{
1684 CURLMcode mret; 1701 CURLMcode mret;
1685 struct HttpAddress *ha; 1702 struct HttpAddress *ha;
1686 uint32_t options; 1703 uint32_t options;
1687 1704
1688 ha = (struct HttpAddress *)s->address->address; 1705 ha = (struct HttpAddress *) s->address->address;
1689 options = ntohl(ha->options); 1706 options = ntohl (ha->options);
1690 /* create put request */ 1707 /* create put request */
1691 LOG(GNUNET_ERROR_TYPE_DEBUG, 1708 LOG (GNUNET_ERROR_TYPE_DEBUG,
1692 "Session %p: Init PUT handle\n", 1709 "Session %p: Init PUT handle\n",
1693 s); 1710 s);
1694 s->put.easyhandle = curl_easy_init(); 1711 s->put.easyhandle = curl_easy_init ();
1695 s->put.s = s; 1712 s->put.s = s;
1696#if VERBOSE_CURL 1713#if VERBOSE_CURL
1697 curl_easy_setopt(s->put.easyhandle, 1714 curl_easy_setopt (s->put.easyhandle,
1698 CURLOPT_VERBOSE, 1715 CURLOPT_VERBOSE,
1699 1L); 1716 1L);
1700 curl_easy_setopt(s->put.easyhandle, 1717 curl_easy_setopt (s->put.easyhandle,
1701 CURLOPT_DEBUGFUNCTION, 1718 CURLOPT_DEBUGFUNCTION,
1702 &client_log); 1719 &client_log);
1703 curl_easy_setopt(s->put.easyhandle, 1720 curl_easy_setopt (s->put.easyhandle,
1704 CURLOPT_DEBUGDATA, 1721 CURLOPT_DEBUGDATA,
1705 &s->put); 1722 &s->put);
1706#endif 1723#endif
1707 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) 1724 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1708 { 1725 {
1709#ifdef TCP_STEALTH 1726#ifdef TCP_STEALTH
1710 curl_easy_setopt(s->put.easyhandle, 1727 curl_easy_setopt (s->put.easyhandle,
1711 CURLOPT_OPENSOCKETFUNCTION, 1728 CURLOPT_OPENSOCKETFUNCTION,
1712 &open_tcp_stealth_socket_cb); 1729 &open_tcp_stealth_socket_cb);
1713 curl_easy_setopt(s->put.easyhandle, 1730 curl_easy_setopt (s->put.easyhandle,
1714 CURLOPT_OPENSOCKETDATA, 1731 CURLOPT_OPENSOCKETDATA,
1715 s); 1732 s);
1716#else 1733#else
1717 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1718 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); 1735 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1719 curl_easy_cleanup(s->put.easyhandle); 1736 curl_easy_cleanup (s->put.easyhandle);
1720 s->put.easyhandle = NULL; 1737 s->put.easyhandle = NULL;
1721 s->put.s = NULL; 1738 s->put.s = NULL;
1722 s->put.state = H_DISCONNECTED; 1739 s->put.state = H_DISCONNECTED;
1723 return GNUNET_SYSERR; 1740 return GNUNET_SYSERR;
1724#endif 1741#endif
1725 } 1742 }
1726#if BUILD_HTTPS 1743#if BUILD_HTTPS
1727 curl_easy_setopt(s->put.easyhandle, 1744 curl_easy_setopt (s->put.easyhandle,
1728 CURLOPT_SSLVERSION, 1745 CURLOPT_SSLVERSION,
1729 CURL_SSLVERSION_TLSv1); 1746 CURL_SSLVERSION_TLSv1);
1730 { 1747 {
1731 struct HttpAddress *ha; 1748 struct HttpAddress *ha;
1732 ha = (struct HttpAddress *)s->address->address; 1749 ha = (struct HttpAddress *) s->address->address;
1733 1750
1734 if (HTTP_OPTIONS_VERIFY_CERTIFICATE == 1751 if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
1735 (ntohl(ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 1752 (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1736 { 1753 {
1737 curl_easy_setopt(s->put.easyhandle, 1754 curl_easy_setopt (s->put.easyhandle,
1738 CURLOPT_SSL_VERIFYPEER, 1755 CURLOPT_SSL_VERIFYPEER,
1739 1L); 1756 1L);
1740 curl_easy_setopt(s->put.easyhandle, 1757 curl_easy_setopt (s->put.easyhandle,
1741 CURLOPT_SSL_VERIFYHOST, 1758 CURLOPT_SSL_VERIFYHOST,
1742 2L); 1759 2L);
1743 } 1760 }
1744 else 1761 else
1745 { 1762 {
1746 curl_easy_setopt(s->put.easyhandle, 1763 curl_easy_setopt (s->put.easyhandle,
1747 CURLOPT_SSL_VERIFYPEER, 1764 CURLOPT_SSL_VERIFYPEER,
1748 0L); 1765 0L);
1749 curl_easy_setopt(s->put.easyhandle, 1766 curl_easy_setopt (s->put.easyhandle,
1750 CURLOPT_SSL_VERIFYHOST, 1767 CURLOPT_SSL_VERIFYHOST,
1751 0L); 1768 0L);
1752 } 1769 }
1753 } 1770 }
1754 curl_easy_setopt(s->put.easyhandle, 1771 curl_easy_setopt (s->put.easyhandle,
1755 CURLOPT_PROTOCOLS, 1772 CURLOPT_PROTOCOLS,
1756 CURLPROTO_HTTPS); 1773 CURLPROTO_HTTPS);
1757 curl_easy_setopt(s->put.easyhandle, 1774 curl_easy_setopt (s->put.easyhandle,
1758 CURLOPT_REDIR_PROTOCOLS, 1775 CURLOPT_REDIR_PROTOCOLS,
1759 CURLPROTO_HTTPS); 1776 CURLPROTO_HTTPS);
1760#else 1777#else
1761 curl_easy_setopt(s->put.easyhandle, 1778 curl_easy_setopt (s->put.easyhandle,
1762 CURLOPT_PROTOCOLS, 1779 CURLOPT_PROTOCOLS,
1763 CURLPROTO_HTTP); 1780 CURLPROTO_HTTP);
1764 curl_easy_setopt(s->put.easyhandle, 1781 curl_easy_setopt (s->put.easyhandle,
1765 CURLOPT_REDIR_PROTOCOLS, 1782 CURLOPT_REDIR_PROTOCOLS,
1766 CURLPROTO_HTTP); 1783 CURLPROTO_HTTP);
1767#endif 1784#endif
1768 if (NULL != s->plugin->proxy_hostname) 1785 if (NULL != s->plugin->proxy_hostname)
1769 { 1786 {
1770 curl_easy_setopt(s->put.easyhandle, 1787 curl_easy_setopt (s->put.easyhandle,
1771 CURLOPT_PROXY, 1788 CURLOPT_PROXY,
1772 s->plugin->proxy_hostname); 1789 s->plugin->proxy_hostname);
1773 curl_easy_setopt(s->put.easyhandle, 1790 curl_easy_setopt (s->put.easyhandle,
1774 CURLOPT_PROXYTYPE, 1791 CURLOPT_PROXYTYPE,
1775 s->plugin->proxytype); 1792 s->plugin->proxytype);
1776 if (NULL != s->plugin->proxy_username) 1793 if (NULL != s->plugin->proxy_username)
1777 curl_easy_setopt(s->put.easyhandle, 1794 curl_easy_setopt (s->put.easyhandle,
1778 CURLOPT_PROXYUSERNAME, 1795 CURLOPT_PROXYUSERNAME,
1779 s->plugin->proxy_username); 1796 s->plugin->proxy_username);
1780 if (NULL != s->plugin->proxy_password) 1797 if (NULL != s->plugin->proxy_password)
1781 curl_easy_setopt(s->put.easyhandle, 1798 curl_easy_setopt (s->put.easyhandle,
1782 CURLOPT_PROXYPASSWORD, 1799 CURLOPT_PROXYPASSWORD,
1783 s->plugin->proxy_password); 1800 s->plugin->proxy_password);
1784 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) 1801 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1785 curl_easy_setopt(s->put.easyhandle, 1802 curl_easy_setopt (s->put.easyhandle,
1786 CURLOPT_HTTPPROXYTUNNEL, 1803 CURLOPT_HTTPPROXYTUNNEL,
1787 s->plugin->proxy_use_httpproxytunnel); 1804 s->plugin->proxy_use_httpproxytunnel);
1788 } 1805 }
1789 1806
1790 curl_easy_setopt(s->put.easyhandle, 1807 curl_easy_setopt (s->put.easyhandle,
1791 CURLOPT_URL, 1808 CURLOPT_URL,
1792 s->url); 1809 s->url);
1793 curl_easy_setopt(s->put.easyhandle, 1810 curl_easy_setopt (s->put.easyhandle,
1794 CURLOPT_UPLOAD, 1811 CURLOPT_UPLOAD,
1795 1L); 1812 1L);
1796 curl_easy_setopt(s->put.easyhandle, 1813 curl_easy_setopt (s->put.easyhandle,
1797 CURLOPT_READFUNCTION, 1814 CURLOPT_READFUNCTION,
1798 &client_send_cb); 1815 &client_send_cb);
1799 curl_easy_setopt(s->put.easyhandle, 1816 curl_easy_setopt (s->put.easyhandle,
1800 CURLOPT_READDATA, 1817 CURLOPT_READDATA,
1801 s); 1818 s);
1802 curl_easy_setopt(s->put.easyhandle, 1819 curl_easy_setopt (s->put.easyhandle,
1803 CURLOPT_WRITEFUNCTION, 1820 CURLOPT_WRITEFUNCTION,
1804 &client_receive_put); 1821 &client_receive_put);
1805 curl_easy_setopt(s->put.easyhandle, 1822 curl_easy_setopt (s->put.easyhandle,
1806 CURLOPT_WRITEDATA, 1823 CURLOPT_WRITEDATA,
1807 s); 1824 s);
1808 /* No timeout by default, timeout done with session timeout */ 1825 /* No timeout by default, timeout done with session timeout */
1809 curl_easy_setopt(s->put.easyhandle, 1826 curl_easy_setopt (s->put.easyhandle,
1810 CURLOPT_TIMEOUT, 1827 CURLOPT_TIMEOUT,
1811 0L); 1828 0L);
1812 curl_easy_setopt(s->put.easyhandle, 1829 curl_easy_setopt (s->put.easyhandle,
1813 CURLOPT_PRIVATE, 1830 CURLOPT_PRIVATE,
1814 s); 1831 s);
1815 curl_easy_setopt(s->put.easyhandle, 1832 curl_easy_setopt (s->put.easyhandle,
1816 CURLOPT_CONNECTTIMEOUT_MS, 1833 CURLOPT_CONNECTTIMEOUT_MS,
1817 (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); 1834 (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1818 curl_easy_setopt(s->put.easyhandle, CURLOPT_BUFFERSIZE, 1835 / 1000LL));
1819 2 * GNUNET_MAX_MESSAGE_SIZE); 1836 curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE,
1837 2 * GNUNET_MAX_MESSAGE_SIZE);
1820#if CURL_TCP_NODELAY 1838#if CURL_TCP_NODELAY
1821 curl_easy_setopt(s->put.easyhandle, CURLOPT_TCP_NODELAY, 1); 1839 curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
1822#endif 1840#endif
1823 mret = curl_multi_add_handle(s->plugin->curl_multi_handle, 1841 mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1824 s->put.easyhandle); 1842 s->put.easyhandle);
1825 if (CURLM_OK != mret) 1843 if (CURLM_OK != mret)
1826 { 1844 {
1827 LOG(GNUNET_ERROR_TYPE_ERROR, 1845 LOG (GNUNET_ERROR_TYPE_ERROR,
1828 "Session %p : Failed to add PUT handle to multihandle: `%s'\n", 1846 "Session %p : Failed to add PUT handle to multihandle: `%s'\n",
1829 s, curl_multi_strerror(mret)); 1847 s, curl_multi_strerror (mret));
1830 curl_easy_cleanup(s->put.easyhandle); 1848 curl_easy_cleanup (s->put.easyhandle);
1831 s->put.easyhandle = NULL; 1849 s->put.easyhandle = NULL;
1832 s->put.s = NULL; 1850 s->put.s = NULL;
1833 s->put.state = H_DISCONNECTED; 1851 s->put.state = H_DISCONNECTED;
1834 return GNUNET_SYSERR; 1852 return GNUNET_SYSERR;
1835 } 1853 }
1836 s->put.state = H_CONNECTED; 1854 s->put.state = H_CONNECTED;
1837 s->plugin->cur_requests++; 1855 s->plugin->cur_requests++;
1838 1856
1839 LOG(GNUNET_ERROR_TYPE_INFO, 1857 LOG (GNUNET_ERROR_TYPE_INFO,
1840 "PUT request `%s' established, number of requests increased to %u\n", 1858 "PUT request `%s' established, number of requests increased to %u\n",
1841 s->url, s->plugin->cur_requests); 1859 s->url, s->plugin->cur_requests);
1842 1860
1843 return GNUNET_OK; 1861 return GNUNET_OK;
1844} 1862}
@@ -1851,67 +1869,67 @@ client_connect_put(struct GNUNET_ATS_Session *s)
1851 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 1869 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1852 */ 1870 */
1853static int 1871static int
1854client_connect(struct GNUNET_ATS_Session *s) 1872client_connect (struct GNUNET_ATS_Session *s)
1855{ 1873{
1856 struct HTTP_Client_Plugin *plugin = s->plugin; 1874 struct HTTP_Client_Plugin *plugin = s->plugin;
1857 int res = GNUNET_OK; 1875 int res = GNUNET_OK;
1858 1876
1859 /* create url */ 1877 /* create url */
1860 if (NULL == 1878 if (NULL ==
1861 http_common_plugin_address_to_string(plugin->protocol, 1879 http_common_plugin_address_to_string (plugin->protocol,
1862 s->address->address, 1880 s->address->address,
1863 s->address->address_length)) 1881 s->address->address_length))
1864 { 1882 {
1865 LOG(GNUNET_ERROR_TYPE_DEBUG, 1883 LOG (GNUNET_ERROR_TYPE_DEBUG,
1866 "Invalid address peer `%s'\n", 1884 "Invalid address peer `%s'\n",
1867 GNUNET_i2s(&s->address->peer)); 1885 GNUNET_i2s (&s->address->peer));
1868 return GNUNET_SYSERR; 1886 return GNUNET_SYSERR;
1869 } 1887 }
1870 1888
1871 GNUNET_asprintf(&s->url, 1889 GNUNET_asprintf (&s->url,
1872 "%s/%s;%u", 1890 "%s/%s;%u",
1873 http_common_plugin_address_to_url(NULL, 1891 http_common_plugin_address_to_url (NULL,
1874 s->address->address, 1892 s->address->address,
1875 s->address->address_length), 1893 s->address->address_length),
1876 GNUNET_i2s_full(plugin->env->my_identity), 1894 GNUNET_i2s_full (plugin->env->my_identity),
1877 plugin->last_tag); 1895 plugin->last_tag);
1878 1896
1879 plugin->last_tag++; 1897 plugin->last_tag++;
1880 LOG(GNUNET_ERROR_TYPE_DEBUG, 1898 LOG (GNUNET_ERROR_TYPE_DEBUG,
1881 "Initiating outbound session peer `%s' using address `%s'\n", 1899 "Initiating outbound session peer `%s' using address `%s'\n",
1882 GNUNET_i2s(&s->address->peer), s->url); 1900 GNUNET_i2s (&s->address->peer), s->url);
1883 1901
1884 if (GNUNET_SYSERR == client_connect_get(s)) 1902 if (GNUNET_SYSERR == client_connect_get (s))
1885 return GNUNET_SYSERR; 1903 return GNUNET_SYSERR;
1886 /* If we are emulating an XHR client then delay sending a PUT request until 1904 /* If we are emulating an XHR client then delay sending a PUT request until
1887 * there is something to send. 1905 * there is something to send.
1888 */ 1906 */
1889 if (GNUNET_YES == plugin->emulate_xhr) 1907 if (GNUNET_YES == plugin->emulate_xhr)
1890 { 1908 {
1891 s->put.state = H_TMP_DISCONNECTED; 1909 s->put.state = H_TMP_DISCONNECTED;
1892 } 1910 }
1893 else if (GNUNET_SYSERR == client_connect_put(s)) 1911 else if (GNUNET_SYSERR == client_connect_put (s))
1894 return GNUNET_SYSERR; 1912 return GNUNET_SYSERR;
1895 1913
1896 LOG(GNUNET_ERROR_TYPE_DEBUG, 1914 LOG (GNUNET_ERROR_TYPE_DEBUG,
1897 "Session %p: connected with GET %p and PUT %p\n", 1915 "Session %p: connected with GET %p and PUT %p\n",
1898 s, s->get.easyhandle, 1916 s, s->get.easyhandle,
1899 s->put.easyhandle); 1917 s->put.easyhandle);
1900 /* Perform connect */ 1918 /* Perform connect */
1901 GNUNET_STATISTICS_set(plugin->env->stats, 1919 GNUNET_STATISTICS_set (plugin->env->stats,
1902 HTTP_STAT_STR_CONNECTIONS, 1920 HTTP_STAT_STR_CONNECTIONS,
1903 plugin->cur_requests, 1921 plugin->cur_requests,
1904 GNUNET_NO); 1922 GNUNET_NO);
1905 /* Re-schedule since handles have changed */ 1923 /* Re-schedule since handles have changed */
1906 if (NULL != plugin->client_perform_task) 1924 if (NULL != plugin->client_perform_task)
1907 { 1925 {
1908 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 1926 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
1909 plugin->client_perform_task = NULL; 1927 plugin->client_perform_task = NULL;
1910 } 1928 }
1911 1929
1912 /* Schedule task to run immediately */ 1930 /* Schedule task to run immediately */
1913 plugin->client_perform_task = GNUNET_SCHEDULER_add_now(client_run, 1931 plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run,
1914 plugin); 1932 plugin);
1915 return res; 1933 return res;
1916} 1934}
1917 1935
@@ -1924,8 +1942,8 @@ client_connect(struct GNUNET_ATS_Session *s)
1924 * @return the network type 1942 * @return the network type
1925 */ 1943 */
1926static enum GNUNET_NetworkType 1944static enum GNUNET_NetworkType
1927http_client_plugin_get_network(void *cls, 1945http_client_plugin_get_network (void *cls,
1928 struct GNUNET_ATS_Session *session) 1946 struct GNUNET_ATS_Session *session)
1929{ 1947{
1930 return session->scope; 1948 return session->scope;
1931} 1949}
@@ -1939,13 +1957,14 @@ http_client_plugin_get_network(void *cls,
1939 * @return the network type 1957 * @return the network type
1940 */ 1958 */
1941static enum GNUNET_NetworkType 1959static enum GNUNET_NetworkType
1942http_client_plugin_get_network_for_address(void *cls, 1960http_client_plugin_get_network_for_address (void *cls,
1943 const struct GNUNET_HELLO_Address *address) 1961 const struct
1962 GNUNET_HELLO_Address *address)
1944{ 1963{
1945 struct HTTP_Client_Plugin *plugin = cls; 1964 struct HTTP_Client_Plugin *plugin = cls;
1946 1965
1947 return http_common_get_network_for_address(plugin->env, 1966 return http_common_get_network_for_address (plugin->env,
1948 address); 1967 address);
1949} 1968}
1950 1969
1951 1970
@@ -1955,33 +1974,33 @@ http_client_plugin_get_network_for_address(void *cls,
1955 * @param cls the `struct GNUNET_ATS_Session` of the idle session 1974 * @param cls the `struct GNUNET_ATS_Session` of the idle session
1956 */ 1975 */
1957static void 1976static void
1958client_session_timeout(void *cls) 1977client_session_timeout (void *cls)
1959{ 1978{
1960 struct GNUNET_ATS_Session *s = cls; 1979 struct GNUNET_ATS_Session *s = cls;
1961 struct GNUNET_TIME_Relative left; 1980 struct GNUNET_TIME_Relative left;
1962 1981
1963 s->timeout_task = NULL; 1982 s->timeout_task = NULL;
1964 left = GNUNET_TIME_absolute_get_remaining(s->timeout); 1983 left = GNUNET_TIME_absolute_get_remaining (s->timeout);
1965 if (0 != left.rel_value_us) 1984 if (0 != left.rel_value_us)
1966 { 1985 {
1967 /* not actually our turn yet, but let's at least update 1986 /* not actually our turn yet, but let's at least update
1968 the monitor, it may think we're about to die ... */ 1987 the monitor, it may think we're about to die ... */
1969 notify_session_monitor(s->plugin, 1988 notify_session_monitor (s->plugin,
1970 s, 1989 s,
1971 GNUNET_TRANSPORT_SS_UPDATE); 1990 GNUNET_TRANSPORT_SS_UPDATE);
1972 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, 1991 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left,
1973 &client_session_timeout, 1992 &client_session_timeout,
1974 s); 1993 s);
1975 return; 1994 return;
1976 } 1995 }
1977 LOG(TIMEOUT_LOG, 1996 LOG (TIMEOUT_LOG,
1978 "Session %p was idle for %s, disconnecting\n", 1997 "Session %p was idle for %s, disconnecting\n",
1979 s, 1998 s,
1980 GNUNET_STRINGS_relative_time_to_string(HTTP_CLIENT_SESSION_TIMEOUT, 1999 GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT,
1981 GNUNET_YES)); 2000 GNUNET_YES));
1982 GNUNET_assert(GNUNET_OK == 2001 GNUNET_assert (GNUNET_OK ==
1983 http_client_plugin_session_disconnect(s->plugin, 2002 http_client_plugin_session_disconnect (s->plugin,
1984 s)); 2003 s));
1985} 2004}
1986 2005
1987 2006
@@ -1994,8 +2013,8 @@ client_session_timeout(void *cls)
1994 * @return the session or NULL of max connections exceeded 2013 * @return the session or NULL of max connections exceeded
1995 */ 2014 */
1996static struct GNUNET_ATS_Session * 2015static struct GNUNET_ATS_Session *
1997http_client_plugin_get_session(void *cls, 2016http_client_plugin_get_session (void *cls,
1998 const struct GNUNET_HELLO_Address *address) 2017 const struct GNUNET_HELLO_Address *address)
1999{ 2018{
2000 struct HTTP_Client_Plugin *plugin = cls; 2019 struct HTTP_Client_Plugin *plugin = cls;
2001 struct GNUNET_ATS_Session *s; 2020 struct GNUNET_ATS_Session *s;
@@ -2004,96 +2023,97 @@ http_client_plugin_get_session(void *cls,
2004 size_t salen = 0; 2023 size_t salen = 0;
2005 int res; 2024 int res;
2006 2025
2007 GNUNET_assert(NULL != address->address); 2026 GNUNET_assert (NULL != address->address);
2008 2027
2009 /* find existing session */ 2028 /* find existing session */
2010 s = client_lookup_session(plugin, address); 2029 s = client_lookup_session (plugin, address);
2011 if (NULL != s) 2030 if (NULL != s)
2012 return s; 2031 return s;
2013 2032
2014 /* create a new session */ 2033 /* create a new session */
2015 if (plugin->max_requests <= plugin->cur_requests) 2034 if (plugin->max_requests <= plugin->cur_requests)
2016 { 2035 {
2017 LOG(GNUNET_ERROR_TYPE_WARNING, 2036 LOG (GNUNET_ERROR_TYPE_WARNING,
2018 "Maximum number of requests (%u) reached: " 2037 "Maximum number of requests (%u) reached: "
2019 "cannot connect to peer `%s'\n", 2038 "cannot connect to peer `%s'\n",
2020 plugin->max_requests, 2039 plugin->max_requests,
2021 GNUNET_i2s(&address->peer)); 2040 GNUNET_i2s (&address->peer));
2022 return NULL; 2041 return NULL;
2023 } 2042 }
2024 2043
2025 /* Determine network location */ 2044 /* Determine network location */
2026 net_type = GNUNET_NT_UNSPECIFIED; 2045 net_type = GNUNET_NT_UNSPECIFIED;
2027 sa = http_common_socket_from_address(address->address, 2046 sa = http_common_socket_from_address (address->address,
2028 address->address_length, 2047 address->address_length,
2029 &res); 2048 &res);
2030 if (GNUNET_SYSERR == res) 2049 if (GNUNET_SYSERR == res)
2031 return NULL; 2050 return NULL;
2032 if (GNUNET_YES == res) 2051 if (GNUNET_YES == res)
2052 {
2053 GNUNET_assert (NULL != sa);
2054 if (AF_INET == sa->sa_family)
2033 { 2055 {
2034 GNUNET_assert(NULL != sa); 2056 salen = sizeof(struct sockaddr_in);
2035 if (AF_INET == sa->sa_family)
2036 {
2037 salen = sizeof(struct sockaddr_in);
2038 }
2039 else if (AF_INET6 == sa->sa_family)
2040 {
2041 salen = sizeof(struct sockaddr_in6);
2042 }
2043 net_type = plugin->env->get_address_type(plugin->env->cls, sa, salen);
2044 GNUNET_free(sa);
2045 } 2057 }
2046 else if (GNUNET_NO == res) 2058 else if (AF_INET6 == sa->sa_family)
2047 { 2059 {
2048 /* Cannot convert to sockaddr -> is external hostname */ 2060 salen = sizeof(struct sockaddr_in6);
2049 net_type = GNUNET_NT_WAN;
2050 } 2061 }
2062 net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2063 GNUNET_free (sa);
2064 }
2065 else if (GNUNET_NO == res)
2066 {
2067 /* Cannot convert to sockaddr -> is external hostname */
2068 net_type = GNUNET_NT_WAN;
2069 }
2051 if (GNUNET_NT_UNSPECIFIED == net_type) 2070 if (GNUNET_NT_UNSPECIFIED == net_type)
2052 { 2071 {
2053 GNUNET_break(0); 2072 GNUNET_break (0);
2054 return NULL; 2073 return NULL;
2055 } 2074 }
2056 2075
2057 s = GNUNET_new(struct GNUNET_ATS_Session); 2076 s = GNUNET_new (struct GNUNET_ATS_Session);
2058 s->plugin = plugin; 2077 s->plugin = plugin;
2059 s->address = GNUNET_HELLO_address_copy(address); 2078 s->address = GNUNET_HELLO_address_copy (address);
2060 s->scope = net_type; 2079 s->scope = net_type;
2061 2080
2062 s->put.state = H_NOT_CONNECTED; 2081 s->put.state = H_NOT_CONNECTED;
2063 s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_CLIENT_SESSION_TIMEOUT); 2082 s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT);
2064 s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_CLIENT_SESSION_TIMEOUT, 2083 s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT,
2065 &client_session_timeout, 2084 &client_session_timeout,
2066 s); 2085 s);
2067 LOG(GNUNET_ERROR_TYPE_DEBUG, 2086 LOG (GNUNET_ERROR_TYPE_DEBUG,
2068 "Created new session %p for `%s' address `%s''\n", 2087 "Created new session %p for `%s' address `%s''\n",
2069 s, 2088 s,
2070 http_common_plugin_address_to_string(plugin->protocol, 2089 http_common_plugin_address_to_string (plugin->protocol,
2071 s->address->address, 2090 s->address->address,
2072 s->address->address_length), 2091 s->address->address_length),
2073 GNUNET_i2s(&s->address->peer)); 2092 GNUNET_i2s (&s->address->peer));
2074 2093
2075 /* add new session */ 2094 /* add new session */
2076 (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions, 2095 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
2077 &s->address->peer, 2096 &s->address->peer,
2078 s, 2097 s,
2079 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2098 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2080 /* initiate new connection */ 2099 /* initiate new connection */
2081 if (GNUNET_SYSERR == client_connect(s)) 2100 if (GNUNET_SYSERR == client_connect (s))
2082 { 2101 {
2083 LOG(GNUNET_ERROR_TYPE_ERROR, 2102 LOG (GNUNET_ERROR_TYPE_ERROR,
2084 "Cannot connect to peer `%s' address `%s''\n", 2103 "Cannot connect to peer `%s' address `%s''\n",
2085 http_common_plugin_address_to_string(plugin->protocol, 2104 http_common_plugin_address_to_string (plugin->protocol,
2086 s->address->address, s->address->address_length), 2105 s->address->address,
2087 GNUNET_i2s(&s->address->peer)); 2106 s->address->address_length),
2088 client_delete_session(s); 2107 GNUNET_i2s (&s->address->peer));
2089 return NULL; 2108 client_delete_session (s);
2090 } 2109 return NULL;
2091 notify_session_monitor(plugin, 2110 }
2092 s, 2111 notify_session_monitor (plugin,
2093 GNUNET_TRANSPORT_SS_INIT); 2112 s,
2094 notify_session_monitor(plugin, 2113 GNUNET_TRANSPORT_SS_INIT);
2095 s, 2114 notify_session_monitor (plugin,
2096 GNUNET_TRANSPORT_SS_UP); /* or handshake? */ 2115 s,
2116 GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2097 return s; 2117 return s;
2098} 2118}
2099 2119
@@ -2105,18 +2125,19 @@ http_client_plugin_get_session(void *cls,
2105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 2125 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2106 */ 2126 */
2107static int 2127static int
2108client_start(struct HTTP_Client_Plugin *plugin) 2128client_start (struct HTTP_Client_Plugin *plugin)
2109{ 2129{
2110 curl_global_init(CURL_GLOBAL_ALL); 2130 curl_global_init (CURL_GLOBAL_ALL);
2111 plugin->curl_multi_handle = curl_multi_init(); 2131 plugin->curl_multi_handle = curl_multi_init ();
2112 2132
2113 if (NULL == plugin->curl_multi_handle) 2133 if (NULL == plugin->curl_multi_handle)
2114 { 2134 {
2115 LOG(GNUNET_ERROR_TYPE_ERROR, 2135 LOG (GNUNET_ERROR_TYPE_ERROR,
2116 _("Could not initialize curl multi handle, failed to start %s plugin!\n"), 2136 _ (
2117 plugin->name); 2137 "Could not initialize curl multi handle, failed to start %s plugin!\n"),
2118 return GNUNET_SYSERR; 2138 plugin->name);
2119 } 2139 return GNUNET_SYSERR;
2140 }
2120 return GNUNET_OK; 2141 return GNUNET_OK;
2121} 2142}
2122 2143
@@ -2134,9 +2155,9 @@ client_start(struct HTTP_Client_Plugin *plugin)
2134 * and transport; always returns #GNUNET_NO (this is the client!) 2155 * and transport; always returns #GNUNET_NO (this is the client!)
2135 */ 2156 */
2136static int 2157static int
2137http_client_plugin_address_suggested(void *cls, 2158http_client_plugin_address_suggested (void *cls,
2138 const void *addr, 2159 const void *addr,
2139 size_t addrlen) 2160 size_t addrlen)
2140{ 2161{
2141 /* A HTTP/S client does not have any valid address so:*/ 2162 /* A HTTP/S client does not have any valid address so:*/
2142 return GNUNET_NO; 2163 return GNUNET_NO;
@@ -2150,43 +2171,43 @@ http_client_plugin_address_suggested(void *cls,
2150 * @return NULL 2171 * @return NULL
2151 */ 2172 */
2152void * 2173void *
2153LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) 2174LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2154{ 2175{
2155 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2176 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2156 struct HTTP_Client_Plugin *plugin = api->cls; 2177 struct HTTP_Client_Plugin *plugin = api->cls;
2157 2178
2158 if (NULL == api->cls) 2179 if (NULL == api->cls)
2159 { 2180 {
2160 /* Stub shutdown */ 2181 /* Stub shutdown */
2161 GNUNET_free(api); 2182 GNUNET_free (api);
2162 return NULL; 2183 return NULL;
2163 } 2184 }
2164 LOG(GNUNET_ERROR_TYPE_DEBUG, 2185 LOG (GNUNET_ERROR_TYPE_DEBUG,
2165 _("Shutting down plugin `%s'\n"), 2186 _ ("Shutting down plugin `%s'\n"),
2166 plugin->name); 2187 plugin->name);
2167 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 2188 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
2168 &destroy_session_cb, 2189 &destroy_session_cb,
2169 plugin); 2190 plugin);
2170 if (NULL != plugin->client_perform_task) 2191 if (NULL != plugin->client_perform_task)
2171 { 2192 {
2172 GNUNET_SCHEDULER_cancel(plugin->client_perform_task); 2193 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
2173 plugin->client_perform_task = NULL; 2194 plugin->client_perform_task = NULL;
2174 } 2195 }
2175 if (NULL != plugin->curl_multi_handle) 2196 if (NULL != plugin->curl_multi_handle)
2176 { 2197 {
2177 curl_multi_cleanup(plugin->curl_multi_handle); 2198 curl_multi_cleanup (plugin->curl_multi_handle);
2178 plugin->curl_multi_handle = NULL; 2199 plugin->curl_multi_handle = NULL;
2179 } 2200 }
2180 curl_global_cleanup(); 2201 curl_global_cleanup ();
2181 LOG(GNUNET_ERROR_TYPE_DEBUG, 2202 LOG (GNUNET_ERROR_TYPE_DEBUG,
2182 _("Shutdown for plugin `%s' complete\n"), 2203 _ ("Shutdown for plugin `%s' complete\n"),
2183 plugin->name); 2204 plugin->name);
2184 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); 2205 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions);
2185 GNUNET_free_non_null(plugin->proxy_hostname); 2206 GNUNET_free_non_null (plugin->proxy_hostname);
2186 GNUNET_free_non_null(plugin->proxy_username); 2207 GNUNET_free_non_null (plugin->proxy_username);
2187 GNUNET_free_non_null(plugin->proxy_password); 2208 GNUNET_free_non_null (plugin->proxy_password);
2188 GNUNET_free(plugin); 2209 GNUNET_free (plugin);
2189 GNUNET_free(api); 2210 GNUNET_free (api);
2190 return NULL; 2211 return NULL;
2191} 2212}
2192 2213
@@ -2198,115 +2219,116 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
2198 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2219 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2199 */ 2220 */
2200static int 2221static int
2201client_configure_plugin(struct HTTP_Client_Plugin *plugin) 2222client_configure_plugin (struct HTTP_Client_Plugin *plugin)
2202{ 2223{
2203 unsigned long long max_requests; 2224 unsigned long long max_requests;
2204 char *proxy_type; 2225 char *proxy_type;
2205 2226
2206 /* Optional parameters */ 2227 /* Optional parameters */
2207 if (GNUNET_OK != 2228 if (GNUNET_OK !=
2208 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, 2229 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
2209 plugin->name, 2230 plugin->name,
2210 "MAX_CONNECTIONS", 2231 "MAX_CONNECTIONS",
2211 &max_requests)) 2232 &max_requests))
2212 max_requests = 128; 2233 max_requests = 128;
2213 plugin->max_requests = max_requests; 2234 plugin->max_requests = max_requests;
2214 2235
2215 LOG(GNUNET_ERROR_TYPE_DEBUG, 2236 LOG (GNUNET_ERROR_TYPE_DEBUG,
2216 _("Maximum number of requests is %u\n"), 2237 _ ("Maximum number of requests is %u\n"),
2217 plugin->max_requests); 2238 plugin->max_requests);
2218 2239
2219 /* Read proxy configuration */ 2240 /* Read proxy configuration */
2220 if (GNUNET_OK == 2241 if (GNUNET_OK ==
2221 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 2242 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2222 plugin->name, 2243 plugin->name,
2223 "PROXY", 2244 "PROXY",
2224 &plugin->proxy_hostname)) 2245 &plugin->proxy_hostname))
2246 {
2247 LOG (GNUNET_ERROR_TYPE_DEBUG,
2248 "Found proxy host: `%s'\n",
2249 plugin->proxy_hostname);
2250 /* proxy username */
2251 if (GNUNET_OK ==
2252 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2253 plugin->name,
2254 "PROXY_USERNAME",
2255 &plugin->proxy_username))
2225 { 2256 {
2226 LOG(GNUNET_ERROR_TYPE_DEBUG, 2257 LOG (GNUNET_ERROR_TYPE_DEBUG,
2227 "Found proxy host: `%s'\n", 2258 "Found proxy username name: `%s'\n",
2228 plugin->proxy_hostname); 2259 plugin->proxy_username);
2229 /* proxy username */ 2260 }
2230 if (GNUNET_OK ==
2231 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2232 plugin->name,
2233 "PROXY_USERNAME",
2234 &plugin->proxy_username))
2235 {
2236 LOG(GNUNET_ERROR_TYPE_DEBUG,
2237 "Found proxy username name: `%s'\n",
2238 plugin->proxy_username);
2239 }
2240
2241 /* proxy password */
2242 if (GNUNET_OK ==
2243 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2244 plugin->name,
2245 "PROXY_PASSWORD",
2246 &plugin->proxy_password))
2247 {
2248 LOG(GNUNET_ERROR_TYPE_DEBUG,
2249 "Found proxy password name: `%s'\n",
2250 plugin->proxy_password);
2251 }
2252 2261
2253 /* proxy type */ 2262 /* proxy password */
2254 if (GNUNET_OK == 2263 if (GNUNET_OK ==
2255 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, 2264 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2256 plugin->name, 2265 plugin->name,
2257 "PROXY_TYPE", 2266 "PROXY_PASSWORD",
2258 &proxy_type)) 2267 &plugin->proxy_password))
2259 { 2268 {
2260 GNUNET_STRINGS_utf8_toupper(proxy_type, proxy_type); 2269 LOG (GNUNET_ERROR_TYPE_DEBUG,
2261 2270 "Found proxy password name: `%s'\n",
2262 if (0 == strcmp(proxy_type, "HTTP")) 2271 plugin->proxy_password);
2263 plugin->proxytype = CURLPROXY_HTTP; 2272 }
2264 else if (0 == strcmp(proxy_type, "SOCKS4"))
2265 plugin->proxytype = CURLPROXY_SOCKS4;
2266 else if (0 == strcmp(proxy_type, "SOCKS5"))
2267 plugin->proxytype = CURLPROXY_SOCKS5;
2268 else if (0 == strcmp(proxy_type, "SOCKS4A"))
2269 plugin->proxytype = CURLPROXY_SOCKS4A;
2270 else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME "))
2271 plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2272 else
2273 {
2274 LOG(GNUNET_ERROR_TYPE_ERROR,
2275 _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2276 proxy_type);
2277
2278 GNUNET_free(proxy_type);
2279 GNUNET_free(plugin->proxy_hostname);
2280 plugin->proxy_hostname = NULL;
2281 GNUNET_free_non_null(plugin->proxy_username);
2282 plugin->proxy_username = NULL;
2283 GNUNET_free_non_null(plugin->proxy_password);
2284 plugin->proxy_password = NULL;
2285
2286 return GNUNET_SYSERR;
2287 }
2288
2289 LOG(GNUNET_ERROR_TYPE_DEBUG,
2290 "Found proxy type: `%s'\n",
2291 proxy_type);
2292 }
2293 2273
2294 /* proxy http tunneling */ 2274 /* proxy type */
2295 plugin->proxy_use_httpproxytunnel 2275 if (GNUNET_OK ==
2296 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 2276 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2297 plugin->name, 2277 plugin->name,
2298 "PROXY_HTTP_TUNNELING"); 2278 "PROXY_TYPE",
2299 if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel) 2279 &proxy_type))
2300 plugin->proxy_use_httpproxytunnel = GNUNET_NO; 2280 {
2281 GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type);
2282
2283 if (0 == strcmp (proxy_type, "HTTP"))
2284 plugin->proxytype = CURLPROXY_HTTP;
2285 else if (0 == strcmp (proxy_type, "SOCKS4"))
2286 plugin->proxytype = CURLPROXY_SOCKS4;
2287 else if (0 == strcmp (proxy_type, "SOCKS5"))
2288 plugin->proxytype = CURLPROXY_SOCKS5;
2289 else if (0 == strcmp (proxy_type, "SOCKS4A"))
2290 plugin->proxytype = CURLPROXY_SOCKS4A;
2291 else if (0 == strcmp (proxy_type, "SOCKS5_HOSTNAME "))
2292 plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2293 else
2294 {
2295 LOG (GNUNET_ERROR_TYPE_ERROR,
2296 _ (
2297 "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2298 proxy_type);
2299
2300 GNUNET_free (proxy_type);
2301 GNUNET_free (plugin->proxy_hostname);
2302 plugin->proxy_hostname = NULL;
2303 GNUNET_free_non_null (plugin->proxy_username);
2304 plugin->proxy_username = NULL;
2305 GNUNET_free_non_null (plugin->proxy_password);
2306 plugin->proxy_password = NULL;
2307
2308 return GNUNET_SYSERR;
2309 }
2301 2310
2302 GNUNET_free_non_null(proxy_type); 2311 LOG (GNUNET_ERROR_TYPE_DEBUG,
2312 "Found proxy type: `%s'\n",
2313 proxy_type);
2303 } 2314 }
2304 2315
2316 /* proxy http tunneling */
2317 plugin->proxy_use_httpproxytunnel
2318 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
2319 plugin->name,
2320 "PROXY_HTTP_TUNNELING");
2321 if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel)
2322 plugin->proxy_use_httpproxytunnel = GNUNET_NO;
2323
2324 GNUNET_free_non_null (proxy_type);
2325 }
2326
2305 /* Should we emulate an XHR client for testing? */ 2327 /* Should we emulate an XHR client for testing? */
2306 plugin->emulate_xhr 2328 plugin->emulate_xhr
2307 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, 2329 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
2308 plugin->name, 2330 plugin->name,
2309 "EMULATE_XHR"); 2331 "EMULATE_XHR");
2310 return GNUNET_OK; 2332 return GNUNET_OK;
2311} 2333}
2312 2334
@@ -2320,13 +2342,13 @@ client_configure_plugin(struct HTTP_Client_Plugin *plugin)
2320 * @return res string if conversion was successful, NULL otherwise 2342 * @return res string if conversion was successful, NULL otherwise
2321 */ 2343 */
2322static const char * 2344static const char *
2323http_client_plugin_address_to_string(void *cls, 2345http_client_plugin_address_to_string (void *cls,
2324 const void *addr, 2346 const void *addr,
2325 size_t addrlen) 2347 size_t addrlen)
2326{ 2348{
2327 return http_common_plugin_address_to_string(PLUGIN_NAME, 2349 return http_common_plugin_address_to_string (PLUGIN_NAME,
2328 addr, 2350 addr,
2329 addrlen); 2351 addrlen);
2330} 2352}
2331 2353
2332 2354
@@ -2340,11 +2362,12 @@ http_client_plugin_address_to_string(void *cls,
2340 * @param session which session is being updated 2362 * @param session which session is being updated
2341 */ 2363 */
2342static void 2364static void
2343http_client_plugin_update_session_timeout(void *cls, 2365http_client_plugin_update_session_timeout (void *cls,
2344 const struct GNUNET_PeerIdentity *peer, 2366 const struct
2345 struct GNUNET_ATS_Session *session) 2367 GNUNET_PeerIdentity *peer,
2368 struct GNUNET_ATS_Session *session)
2346{ 2369{
2347 client_reschedule_session_timeout(session); 2370 client_reschedule_session_timeout (session);
2348} 2371}
2349 2372
2350 2373
@@ -2359,24 +2382,24 @@ http_client_plugin_update_session_timeout(void *cls,
2359 * @param delay new delay to use for receiving 2382 * @param delay new delay to use for receiving
2360 */ 2383 */
2361static void 2384static void
2362http_client_plugin_update_inbound_delay(void *cls, 2385http_client_plugin_update_inbound_delay (void *cls,
2363 const struct GNUNET_PeerIdentity *peer, 2386 const struct GNUNET_PeerIdentity *peer,
2364 struct GNUNET_ATS_Session *s, 2387 struct GNUNET_ATS_Session *s,
2365 struct GNUNET_TIME_Relative delay) 2388 struct GNUNET_TIME_Relative delay)
2366{ 2389{
2367 s->next_receive = GNUNET_TIME_relative_to_absolute(delay); 2390 s->next_receive = GNUNET_TIME_relative_to_absolute (delay);
2368 LOG(GNUNET_ERROR_TYPE_DEBUG, 2391 LOG (GNUNET_ERROR_TYPE_DEBUG,
2369 "New inbound delay %s\n", 2392 "New inbound delay %s\n",
2370 GNUNET_STRINGS_relative_time_to_string(delay, 2393 GNUNET_STRINGS_relative_time_to_string (delay,
2371 GNUNET_NO)); 2394 GNUNET_NO));
2372 if (s->recv_wakeup_task != NULL) 2395 if (s->recv_wakeup_task != NULL)
2373 { 2396 {
2374 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); 2397 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
2375 s->recv_wakeup_task 2398 s->recv_wakeup_task
2376 = GNUNET_SCHEDULER_add_delayed(delay, 2399 = GNUNET_SCHEDULER_add_delayed (delay,
2377 &client_wake_up, 2400 &client_wake_up,
2378 s); 2401 s);
2379 } 2402 }
2380} 2403}
2381 2404
2382 2405
@@ -2390,19 +2413,19 @@ http_client_plugin_update_inbound_delay(void *cls,
2390 * @return #GNUNET_OK (continue to iterate) 2413 * @return #GNUNET_OK (continue to iterate)
2391 */ 2414 */
2392static int 2415static int
2393send_session_info_iter(void *cls, 2416send_session_info_iter (void *cls,
2394 const struct GNUNET_PeerIdentity *peer, 2417 const struct GNUNET_PeerIdentity *peer,
2395 void *value) 2418 void *value)
2396{ 2419{
2397 struct HTTP_Client_Plugin *plugin = cls; 2420 struct HTTP_Client_Plugin *plugin = cls;
2398 struct GNUNET_ATS_Session *session = value; 2421 struct GNUNET_ATS_Session *session = value;
2399 2422
2400 notify_session_monitor(plugin, 2423 notify_session_monitor (plugin,
2401 session, 2424 session,
2402 GNUNET_TRANSPORT_SS_INIT); 2425 GNUNET_TRANSPORT_SS_INIT);
2403 notify_session_monitor(plugin, 2426 notify_session_monitor (plugin,
2404 session, 2427 session,
2405 GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */ 2428 GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2406 return GNUNET_OK; 2429 return GNUNET_OK;
2407} 2430}
2408 2431
@@ -2420,22 +2443,22 @@ send_session_info_iter(void *cls,
2420 * @param sic_cls closure for @a sic 2443 * @param sic_cls closure for @a sic
2421 */ 2444 */
2422static void 2445static void
2423http_client_plugin_setup_monitor(void *cls, 2446http_client_plugin_setup_monitor (void *cls,
2424 GNUNET_TRANSPORT_SessionInfoCallback sic, 2447 GNUNET_TRANSPORT_SessionInfoCallback sic,
2425 void *sic_cls) 2448 void *sic_cls)
2426{ 2449{
2427 struct HTTP_Client_Plugin *plugin = cls; 2450 struct HTTP_Client_Plugin *plugin = cls;
2428 2451
2429 plugin->sic = sic; 2452 plugin->sic = sic;
2430 plugin->sic_cls = sic_cls; 2453 plugin->sic_cls = sic_cls;
2431 if (NULL != sic) 2454 if (NULL != sic)
2432 { 2455 {
2433 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, 2456 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
2434 &send_session_info_iter, 2457 &send_session_info_iter,
2435 plugin); 2458 plugin);
2436 /* signal end of first iteration */ 2459 /* signal end of first iteration */
2437 sic(sic_cls, NULL, NULL); 2460 sic (sic_cls, NULL, NULL);
2438 } 2461 }
2439} 2462}
2440 2463
2441 2464
@@ -2443,29 +2466,29 @@ http_client_plugin_setup_monitor(void *cls,
2443 * Entry point for the plugin. 2466 * Entry point for the plugin.
2444 */ 2467 */
2445void * 2468void *
2446LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) 2469LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2447{ 2470{
2448 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2471 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2449 struct GNUNET_TRANSPORT_PluginFunctions *api; 2472 struct GNUNET_TRANSPORT_PluginFunctions *api;
2450 struct HTTP_Client_Plugin *plugin; 2473 struct HTTP_Client_Plugin *plugin;
2451 2474
2452 if (NULL == env->receive) 2475 if (NULL == env->receive)
2453 { 2476 {
2454 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 2477 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2455 initialze the plugin or the API */ 2478 initialze the plugin or the API */
2456 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 2479 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2457 api->cls = NULL; 2480 api->cls = NULL;
2458 api->address_to_string = &http_client_plugin_address_to_string; 2481 api->address_to_string = &http_client_plugin_address_to_string;
2459 api->string_to_address = &http_common_plugin_string_to_address; 2482 api->string_to_address = &http_common_plugin_string_to_address;
2460 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 2483 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
2461 return api; 2484 return api;
2462 } 2485 }
2463 2486
2464 plugin = GNUNET_new(struct HTTP_Client_Plugin); 2487 plugin = GNUNET_new (struct HTTP_Client_Plugin);
2465 plugin->env = env; 2488 plugin->env = env;
2466 plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128, 2489 plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128,
2467 GNUNET_YES); 2490 GNUNET_YES);
2468 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); 2491 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2469 api->cls = plugin; 2492 api->cls = plugin;
2470 api->send = &http_client_plugin_send; 2493 api->send = &http_client_plugin_send;
2471 api->disconnect_session = &http_client_plugin_session_disconnect; 2494 api->disconnect_session = &http_client_plugin_session_disconnect;
@@ -2490,18 +2513,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
2490#endif 2513#endif
2491 plugin->last_tag = 1; 2514 plugin->last_tag = 1;
2492 2515
2493 if (GNUNET_SYSERR == client_configure_plugin(plugin)) 2516 if (GNUNET_SYSERR == client_configure_plugin (plugin))
2494 { 2517 {
2495 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 2518 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
2496 return NULL; 2519 return NULL;
2497 } 2520 }
2498 2521
2499 /* Start client */ 2522 /* Start client */
2500 if (GNUNET_SYSERR == client_start(plugin)) 2523 if (GNUNET_SYSERR == client_start (plugin))
2501 { 2524 {
2502 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); 2525 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
2503 return NULL; 2526 return NULL;
2504 } 2527 }
2505 return api; 2528 return api;
2506} 2529}
2507 2530