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