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_server.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 3571 |
1 files changed, 1782 insertions, 1789 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 495105fe3..1b454c09f 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.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_server.c | 22 | * @file transport/plugin_transport_http_server.c |
@@ -51,14 +51,13 @@ | |||
51 | #define _SEND 1 | 51 | #define _SEND 1 |
52 | 52 | ||
53 | 53 | ||
54 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-" PLUGIN_NAME,__VA_ARGS__) | 54 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-" PLUGIN_NAME, __VA_ARGS__) |
55 | 55 | ||
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Information we keep with MHD for an HTTP request. | 58 | * Information we keep with MHD for an HTTP request. |
59 | */ | 59 | */ |
60 | struct ServerRequest | 60 | struct ServerRequest { |
61 | { | ||
62 | /** | 61 | /** |
63 | * The session this server request belongs to | 62 | * The session this server request belongs to |
64 | * Can be NULL, when session was disconnected and freed | 63 | * Can be NULL, when session was disconnected and freed |
@@ -96,15 +95,13 @@ struct ServerRequest | |||
96 | * Currently suspended | 95 | * Currently suspended |
97 | */ | 96 | */ |
98 | bool suspended; | 97 | bool suspended; |
99 | |||
100 | }; | 98 | }; |
101 | 99 | ||
102 | 100 | ||
103 | /** | 101 | /** |
104 | * Wrapper to manage addresses | 102 | * Wrapper to manage addresses |
105 | */ | 103 | */ |
106 | struct HttpAddressWrapper | 104 | struct HttpAddressWrapper { |
107 | { | ||
108 | /** | 105 | /** |
109 | * Linked list next | 106 | * Linked list next |
110 | */ | 107 | */ |
@@ -130,8 +127,7 @@ struct HttpAddressWrapper | |||
130 | /** | 127 | /** |
131 | * Message to send using http | 128 | * Message to send using http |
132 | */ | 129 | */ |
133 | struct HTTP_Message | 130 | struct HTTP_Message { |
134 | { | ||
135 | /** | 131 | /** |
136 | * next pointer for double linked list | 132 | * next pointer for double linked list |
137 | */ | 133 | */ |
@@ -179,9 +175,7 @@ struct HTTP_Message | |||
179 | /** | 175 | /** |
180 | * Session handle for connections. | 176 | * Session handle for connections. |
181 | */ | 177 | */ |
182 | struct GNUNET_ATS_Session | 178 | struct GNUNET_ATS_Session { |
183 | { | ||
184 | |||
185 | /** | 179 | /** |
186 | * To whom are we talking to (set to our identity | 180 | * To whom are we talking to (set to our identity |
187 | * if we are still waiting for the welcome message) | 181 | * if we are still waiting for the welcome message) |
@@ -268,15 +262,13 @@ struct GNUNET_ATS_Session | |||
268 | * #GNUNET_YES if this session is known to the service. | 262 | * #GNUNET_YES if this session is known to the service. |
269 | */ | 263 | */ |
270 | int known_to_service; | 264 | int known_to_service; |
271 | |||
272 | }; | 265 | }; |
273 | 266 | ||
274 | 267 | ||
275 | /** | 268 | /** |
276 | * Encapsulation of all of the state of the plugin. | 269 | * Encapsulation of all of the state of the plugin. |
277 | */ | 270 | */ |
278 | struct HTTP_Server_Plugin | 271 | struct HTTP_Server_Plugin { |
279 | { | ||
280 | /** | 272 | /** |
281 | * Our environment. | 273 | * Our environment. |
282 | */ | 274 | */ |
@@ -457,7 +449,6 @@ struct HTTP_Server_Plugin | |||
457 | * Regex for parsing URLs. FIXME: this seems overkill. | 449 | * Regex for parsing URLs. FIXME: this seems overkill. |
458 | */ | 450 | */ |
459 | regex_t url_regex; | 451 | regex_t url_regex; |
460 | |||
461 | }; | 452 | }; |
462 | 453 | ||
463 | 454 | ||
@@ -470,15 +461,15 @@ struct HTTP_Server_Plugin | |||
470 | * @param state new state of the session | 461 | * @param state new state of the session |
471 | */ | 462 | */ |
472 | static void | 463 | static void |
473 | notify_session_monitor (struct HTTP_Server_Plugin *plugin, | 464 | notify_session_monitor(struct HTTP_Server_Plugin *plugin, |
474 | struct GNUNET_ATS_Session *session, | 465 | struct GNUNET_ATS_Session *session, |
475 | enum GNUNET_TRANSPORT_SessionState state) | 466 | enum GNUNET_TRANSPORT_SessionState state) |
476 | { | 467 | { |
477 | struct GNUNET_TRANSPORT_SessionInfo info; | 468 | struct GNUNET_TRANSPORT_SessionInfo info; |
478 | 469 | ||
479 | if (NULL == plugin->sic) | 470 | if (NULL == plugin->sic) |
480 | return; | 471 | return; |
481 | memset (&info, 0, sizeof (info)); | 472 | memset(&info, 0, sizeof(info)); |
482 | info.state = state; | 473 | info.state = state; |
483 | info.is_inbound = GNUNET_YES; | 474 | info.is_inbound = GNUNET_YES; |
484 | info.num_msg_pending = session->msgs_in_queue; | 475 | info.num_msg_pending = session->msgs_in_queue; |
@@ -486,9 +477,9 @@ notify_session_monitor (struct HTTP_Server_Plugin *plugin, | |||
486 | info.receive_delay = session->next_receive; | 477 | info.receive_delay = session->next_receive; |
487 | info.session_timeout = session->timeout; | 478 | info.session_timeout = session->timeout; |
488 | info.address = session->address; | 479 | info.address = session->address; |
489 | plugin->sic (plugin->sic_cls, | 480 | plugin->sic(plugin->sic_cls, |
490 | session, | 481 | session, |
491 | &info); | 482 | &info); |
492 | } | 483 | } |
493 | 484 | ||
494 | 485 | ||
@@ -498,16 +489,16 @@ notify_session_monitor (struct HTTP_Server_Plugin *plugin, | |||
498 | * @param cls the session | 489 | * @param cls the session |
499 | */ | 490 | */ |
500 | static void | 491 | static void |
501 | server_wake_up (void *cls) | 492 | server_wake_up(void *cls) |
502 | { | 493 | { |
503 | struct GNUNET_ATS_Session *s = cls; | 494 | struct GNUNET_ATS_Session *s = cls; |
504 | 495 | ||
505 | s->recv_wakeup_task = NULL; | 496 | s->recv_wakeup_task = NULL; |
506 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 497 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
507 | "Session %p: Waking up PUT handle\n", | 498 | "Session %p: Waking up PUT handle\n", |
508 | s); | 499 | s); |
509 | GNUNET_assert (s->server_recv->suspended); | 500 | GNUNET_assert(s->server_recv->suspended); |
510 | MHD_resume_connection (s->server_recv->mhd_conn); | 501 | MHD_resume_connection(s->server_recv->mhd_conn); |
511 | s->server_recv->suspended = false; | 502 | s->server_recv->suspended = false; |
512 | } | 503 | } |
513 | 504 | ||
@@ -521,9 +512,9 @@ server_wake_up (void *cls) | |||
521 | * until timeout | 512 | * until timeout |
522 | */ | 513 | */ |
523 | static void | 514 | static void |
524 | server_reschedule (struct HTTP_Server_Plugin *plugin, | 515 | server_reschedule(struct HTTP_Server_Plugin *plugin, |
525 | struct MHD_Daemon *server, | 516 | struct MHD_Daemon *server, |
526 | int now); | 517 | int now); |
527 | 518 | ||
528 | 519 | ||
529 | /** | 520 | /** |
@@ -532,106 +523,106 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, | |||
532 | * @param s the session to delete | 523 | * @param s the session to delete |
533 | */ | 524 | */ |
534 | static void | 525 | static void |
535 | server_delete_session (struct GNUNET_ATS_Session *s) | 526 | server_delete_session(struct GNUNET_ATS_Session *s) |
536 | { | 527 | { |
537 | struct HTTP_Server_Plugin *plugin = s->plugin; | 528 | struct HTTP_Server_Plugin *plugin = s->plugin; |
538 | struct HTTP_Message *msg; | 529 | struct HTTP_Message *msg; |
539 | 530 | ||
540 | if (NULL != s->timeout_task) | 531 | if (NULL != s->timeout_task) |
541 | { | 532 | { |
542 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 533 | GNUNET_SCHEDULER_cancel(s->timeout_task); |
543 | s->timeout_task = NULL; | 534 | s->timeout_task = NULL; |
544 | s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 535 | s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
545 | } | 536 | } |
546 | if (NULL != s->recv_wakeup_task) | 537 | if (NULL != s->recv_wakeup_task) |
547 | { | 538 | { |
548 | GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); | 539 | GNUNET_SCHEDULER_cancel(s->recv_wakeup_task); |
549 | s->recv_wakeup_task = NULL; | 540 | s->recv_wakeup_task = NULL; |
550 | if (NULL != s->server_recv) | 541 | if (NULL != s->server_recv) |
551 | { | 542 | { |
552 | GNUNET_assert (s->server_recv->suspended); | 543 | GNUNET_assert(s->server_recv->suspended); |
553 | s->server_recv->suspended = false; | 544 | s->server_recv->suspended = false; |
554 | MHD_resume_connection (s->server_recv->mhd_conn); | 545 | MHD_resume_connection(s->server_recv->mhd_conn); |
555 | } | 546 | } |
556 | } | 547 | } |
557 | GNUNET_assert (GNUNET_OK == | 548 | GNUNET_assert(GNUNET_OK == |
558 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, | 549 | GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, |
559 | &s->target, | 550 | &s->target, |
560 | s)); | 551 | s)); |
561 | while (NULL != (msg = s->msg_head)) | 552 | while (NULL != (msg = s->msg_head)) |
562 | { | 553 | { |
563 | GNUNET_CONTAINER_DLL_remove (s->msg_head, | 554 | GNUNET_CONTAINER_DLL_remove(s->msg_head, |
564 | s->msg_tail, | 555 | s->msg_tail, |
565 | msg); | 556 | msg); |
566 | if (NULL != msg->transmit_cont) | 557 | if (NULL != msg->transmit_cont) |
567 | msg->transmit_cont (msg->transmit_cont_cls, | 558 | msg->transmit_cont(msg->transmit_cont_cls, |
568 | &s->target, | 559 | &s->target, |
569 | GNUNET_SYSERR, | 560 | GNUNET_SYSERR, |
570 | msg->size, | 561 | msg->size, |
571 | msg->pos + msg->overhead); | 562 | msg->pos + msg->overhead); |
572 | GNUNET_assert (s->msgs_in_queue > 0); | 563 | GNUNET_assert(s->msgs_in_queue > 0); |
573 | s->msgs_in_queue--; | 564 | s->msgs_in_queue--; |
574 | GNUNET_assert (s->bytes_in_queue >= msg->size); | 565 | GNUNET_assert(s->bytes_in_queue >= msg->size); |
575 | s->bytes_in_queue -= msg->size; | 566 | s->bytes_in_queue -= msg->size; |
576 | GNUNET_free (msg); | 567 | GNUNET_free(msg); |
577 | } | 568 | } |
578 | 569 | ||
579 | GNUNET_assert (0 == s->msgs_in_queue); | 570 | GNUNET_assert(0 == s->msgs_in_queue); |
580 | GNUNET_assert (0 == s->bytes_in_queue); | 571 | GNUNET_assert(0 == s->bytes_in_queue); |
581 | 572 | ||
582 | if (NULL != s->server_send) | 573 | if (NULL != s->server_send) |
583 | { | 574 | { |
584 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 575 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
585 | "Server: %p / %p Terminating inbound PUT session to peer `%s'\n", | 576 | "Server: %p / %p Terminating inbound PUT session to peer `%s'\n", |
586 | s, s->server_send, | 577 | s, s->server_send, |
587 | GNUNET_i2s (&s->target)); | 578 | GNUNET_i2s(&s->target)); |
588 | s->server_send->session = NULL; | 579 | s->server_send->session = NULL; |
589 | MHD_set_connection_option (s->server_send->mhd_conn, | 580 | MHD_set_connection_option(s->server_send->mhd_conn, |
590 | MHD_CONNECTION_OPTION_TIMEOUT, | 581 | MHD_CONNECTION_OPTION_TIMEOUT, |
591 | 1 /* 0 = no timeout, so this is MIN */); | 582 | 1 /* 0 = no timeout, so this is MIN */); |
592 | if (s->server_send->suspended) | 583 | if (s->server_send->suspended) |
593 | { | 584 | { |
594 | s->server_send->suspended = false; | 585 | s->server_send->suspended = false; |
595 | MHD_resume_connection (s->server_send->mhd_conn); | 586 | MHD_resume_connection(s->server_send->mhd_conn); |
596 | } | 587 | } |
597 | server_reschedule (plugin, | 588 | server_reschedule(plugin, |
598 | s->server_send->mhd_daemon, | 589 | s->server_send->mhd_daemon, |
599 | GNUNET_YES); | 590 | GNUNET_YES); |
600 | } | 591 | } |
601 | 592 | ||
602 | if (NULL != s->server_recv) | 593 | if (NULL != s->server_recv) |
603 | { | 594 | { |
604 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 595 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
605 | "Server: %p / %p Terminating inbound GET session to peer `%s'\n", | 596 | "Server: %p / %p Terminating inbound GET session to peer `%s'\n", |
606 | s, s->server_recv, GNUNET_i2s (&s->target)); | 597 | s, s->server_recv, GNUNET_i2s(&s->target)); |
607 | s->server_recv->session = NULL; | 598 | s->server_recv->session = NULL; |
608 | MHD_set_connection_option (s->server_recv->mhd_conn, | 599 | MHD_set_connection_option(s->server_recv->mhd_conn, |
609 | MHD_CONNECTION_OPTION_TIMEOUT, | 600 | MHD_CONNECTION_OPTION_TIMEOUT, |
610 | 1 /* 0 = no timeout, so this is MIN */); | 601 | 1 /* 0 = no timeout, so this is MIN */); |
611 | server_reschedule (plugin, | 602 | server_reschedule(plugin, |
612 | s->server_recv->mhd_daemon, | 603 | s->server_recv->mhd_daemon, |
613 | GNUNET_YES); | 604 | GNUNET_YES); |
614 | } | 605 | } |
615 | notify_session_monitor (plugin, | 606 | notify_session_monitor(plugin, |
616 | s, | 607 | s, |
617 | GNUNET_TRANSPORT_SS_DONE); | 608 | GNUNET_TRANSPORT_SS_DONE); |
618 | if (GNUNET_YES == s->known_to_service) | 609 | if (GNUNET_YES == s->known_to_service) |
619 | { | 610 | { |
620 | plugin->env->session_end (plugin->env->cls, | 611 | plugin->env->session_end(plugin->env->cls, |
621 | s->address, | 612 | s->address, |
622 | s); | 613 | s); |
623 | s->known_to_service = GNUNET_NO; | 614 | s->known_to_service = GNUNET_NO; |
624 | } | 615 | } |
625 | if (NULL != s->msg_tk) | 616 | if (NULL != s->msg_tk) |
626 | { | 617 | { |
627 | GNUNET_MST_destroy (s->msg_tk); | 618 | GNUNET_MST_destroy(s->msg_tk); |
628 | s->msg_tk = NULL; | 619 | s->msg_tk = NULL; |
629 | } | 620 | } |
630 | GNUNET_HELLO_address_free (s->address); | 621 | GNUNET_HELLO_address_free(s->address); |
631 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 622 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
632 | "Session %p destroyed\n", | 623 | "Session %p destroyed\n", |
633 | s); | 624 | s); |
634 | GNUNET_free (s); | 625 | GNUNET_free(s); |
635 | } | 626 | } |
636 | 627 | ||
637 | 628 | ||
@@ -644,10 +635,10 @@ server_delete_session (struct GNUNET_ATS_Session *s) | |||
644 | * @return #GNUNET_OK on success | 635 | * @return #GNUNET_OK on success |
645 | */ | 636 | */ |
646 | static int | 637 | static int |
647 | http_server_plugin_disconnect_session (void *cls, | 638 | http_server_plugin_disconnect_session(void *cls, |
648 | struct GNUNET_ATS_Session *s) | 639 | struct GNUNET_ATS_Session *s) |
649 | { | 640 | { |
650 | server_delete_session (s); | 641 | server_delete_session(s); |
651 | return GNUNET_OK; | 642 | return GNUNET_OK; |
652 | } | 643 | } |
653 | 644 | ||
@@ -658,31 +649,31 @@ http_server_plugin_disconnect_session (void *cls, | |||
658 | * @param cls the session | 649 | * @param cls the session |
659 | */ | 650 | */ |
660 | static void | 651 | static void |
661 | server_session_timeout (void *cls) | 652 | server_session_timeout(void *cls) |
662 | { | 653 | { |
663 | struct GNUNET_ATS_Session *s = cls; | 654 | struct GNUNET_ATS_Session *s = cls; |
664 | struct GNUNET_TIME_Relative left; | 655 | struct GNUNET_TIME_Relative left; |
665 | 656 | ||
666 | s->timeout_task = NULL; | 657 | s->timeout_task = NULL; |
667 | left = GNUNET_TIME_absolute_get_remaining (s->timeout); | 658 | left = GNUNET_TIME_absolute_get_remaining(s->timeout); |
668 | if (0 != left.rel_value_us) | 659 | if (0 != left.rel_value_us) |
669 | { | 660 | { |
670 | /* not actually our turn yet, but let's at least update | 661 | /* not actually our turn yet, but let's at least update |
671 | the monitor, it may think we're about to die ... */ | 662 | the monitor, it may think we're about to die ... */ |
672 | notify_session_monitor (s->plugin, | 663 | notify_session_monitor(s->plugin, |
673 | s, | 664 | s, |
674 | GNUNET_TRANSPORT_SS_UP); | 665 | GNUNET_TRANSPORT_SS_UP); |
675 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, | 666 | s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, |
676 | &server_session_timeout, | 667 | &server_session_timeout, |
677 | s); | 668 | s); |
678 | return; | 669 | return; |
679 | } | 670 | } |
680 | GNUNET_log (TIMEOUT_LOG, | 671 | GNUNET_log(TIMEOUT_LOG, |
681 | "Session %p was idle for %s, disconnecting\n", | 672 | "Session %p was idle for %s, disconnecting\n", |
682 | s, | 673 | s, |
683 | GNUNET_STRINGS_relative_time_to_string (HTTP_SERVER_SESSION_TIMEOUT, | 674 | GNUNET_STRINGS_relative_time_to_string(HTTP_SERVER_SESSION_TIMEOUT, |
684 | GNUNET_YES)); | 675 | GNUNET_YES)); |
685 | server_delete_session (s); | 676 | server_delete_session(s); |
686 | } | 677 | } |
687 | 678 | ||
688 | 679 | ||
@@ -692,10 +683,10 @@ server_session_timeout (void *cls) | |||
692 | * @param s the session | 683 | * @param s the session |
693 | */ | 684 | */ |
694 | static void | 685 | static void |
695 | server_reschedule_session_timeout (struct GNUNET_ATS_Session *s) | 686 | server_reschedule_session_timeout(struct GNUNET_ATS_Session *s) |
696 | { | 687 | { |
697 | GNUNET_assert (NULL != s->timeout_task); | 688 | GNUNET_assert(NULL != s->timeout_task); |
698 | s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 689 | s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
699 | } | 690 | } |
700 | 691 | ||
701 | 692 | ||
@@ -727,65 +718,65 @@ server_reschedule_session_timeout (struct GNUNET_ATS_Session *s) | |||
727 | * and does NOT mean that the message was not transmitted (DV) | 718 | * and does NOT mean that the message was not transmitted (DV) |
728 | */ | 719 | */ |
729 | static ssize_t | 720 | static ssize_t |
730 | http_server_plugin_send (void *cls, | 721 | http_server_plugin_send(void *cls, |
731 | struct GNUNET_ATS_Session *session, | 722 | struct GNUNET_ATS_Session *session, |
732 | const char *msgbuf, | 723 | const char *msgbuf, |
733 | size_t msgbuf_size, | 724 | size_t msgbuf_size, |
734 | unsigned int priority, | 725 | unsigned int priority, |
735 | struct GNUNET_TIME_Relative to, | 726 | struct GNUNET_TIME_Relative to, |
736 | GNUNET_TRANSPORT_TransmitContinuation cont, | 727 | GNUNET_TRANSPORT_TransmitContinuation cont, |
737 | void *cont_cls) | 728 | void *cont_cls) |
738 | { | 729 | { |
739 | struct HTTP_Server_Plugin *plugin = cls; | 730 | struct HTTP_Server_Plugin *plugin = cls; |
740 | struct HTTP_Message *msg; | 731 | struct HTTP_Message *msg; |
741 | ssize_t bytes_sent = 0; | 732 | ssize_t bytes_sent = 0; |
742 | char *stat_txt; | 733 | char *stat_txt; |
743 | 734 | ||
744 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 735 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
745 | "Session %p/request %p: Sending message with %u to peer `%s'\n", | 736 | "Session %p/request %p: Sending message with %u to peer `%s'\n", |
746 | session, | 737 | session, |
747 | session->server_send, | 738 | session->server_send, |
748 | msgbuf_size, | 739 | msgbuf_size, |
749 | GNUNET_i2s (&session->target)); | 740 | GNUNET_i2s(&session->target)); |
750 | 741 | ||
751 | /* create new message and schedule */ | 742 | /* create new message and schedule */ |
752 | bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size; | 743 | bytes_sent = sizeof(struct HTTP_Message) + msgbuf_size; |
753 | msg = GNUNET_malloc (bytes_sent); | 744 | msg = GNUNET_malloc(bytes_sent); |
754 | msg->next = NULL; | 745 | msg->next = NULL; |
755 | msg->size = msgbuf_size; | 746 | msg->size = msgbuf_size; |
756 | msg->pos = 0; | 747 | msg->pos = 0; |
757 | msg->buf = (char *) &msg[1]; | 748 | msg->buf = (char *)&msg[1]; |
758 | msg->transmit_cont = cont; | 749 | msg->transmit_cont = cont; |
759 | msg->transmit_cont_cls = cont_cls; | 750 | msg->transmit_cont_cls = cont_cls; |
760 | GNUNET_memcpy (msg->buf, | 751 | GNUNET_memcpy(msg->buf, |
761 | msgbuf, | 752 | msgbuf, |
762 | msgbuf_size); | 753 | msgbuf_size); |
763 | GNUNET_CONTAINER_DLL_insert_tail (session->msg_head, | 754 | GNUNET_CONTAINER_DLL_insert_tail(session->msg_head, |
764 | session->msg_tail, | 755 | session->msg_tail, |
765 | msg); | 756 | msg); |
766 | session->msgs_in_queue++; | 757 | session->msgs_in_queue++; |
767 | session->bytes_in_queue += msg->size; | 758 | session->bytes_in_queue += msg->size; |
768 | notify_session_monitor (plugin, | 759 | notify_session_monitor(plugin, |
769 | session, | 760 | session, |
770 | GNUNET_TRANSPORT_SS_UP); | 761 | GNUNET_TRANSPORT_SS_UP); |
771 | GNUNET_asprintf (&stat_txt, | 762 | GNUNET_asprintf(&stat_txt, |
772 | "# bytes currently in %s_server buffers", | 763 | "# bytes currently in %s_server buffers", |
773 | plugin->protocol); | 764 | plugin->protocol); |
774 | GNUNET_STATISTICS_update (plugin->env->stats, | 765 | GNUNET_STATISTICS_update(plugin->env->stats, |
775 | stat_txt, msgbuf_size, GNUNET_NO); | 766 | stat_txt, msgbuf_size, GNUNET_NO); |
776 | GNUNET_free (stat_txt); | 767 | GNUNET_free(stat_txt); |
777 | 768 | ||
778 | if (NULL != session->server_send) | 769 | if (NULL != session->server_send) |
779 | { | ||
780 | if (session->server_send->suspended) | ||
781 | { | 770 | { |
782 | MHD_resume_connection (session->server_send->mhd_conn); | 771 | if (session->server_send->suspended) |
783 | session->server_send->suspended = false; | 772 | { |
773 | MHD_resume_connection(session->server_send->mhd_conn); | ||
774 | session->server_send->suspended = false; | ||
775 | } | ||
776 | server_reschedule(session->plugin, | ||
777 | session->server_send->mhd_daemon, | ||
778 | GNUNET_YES); | ||
784 | } | 779 | } |
785 | server_reschedule (session->plugin, | ||
786 | session->server_send->mhd_daemon, | ||
787 | GNUNET_YES); | ||
788 | } | ||
789 | return bytes_sent; | 780 | return bytes_sent; |
790 | } | 781 | } |
791 | 782 | ||
@@ -799,9 +790,9 @@ http_server_plugin_send (void *cls, | |||
799 | * @return #GNUNET_OK (continue to iterate) | 790 | * @return #GNUNET_OK (continue to iterate) |
800 | */ | 791 | */ |
801 | static int | 792 | static int |
802 | destroy_session_shutdown_cb (void *cls, | 793 | destroy_session_shutdown_cb(void *cls, |
803 | const struct GNUNET_PeerIdentity *peer, | 794 | const struct GNUNET_PeerIdentity *peer, |
804 | void *value) | 795 | void *value) |
805 | { | 796 | { |
806 | struct GNUNET_ATS_Session *s = value; | 797 | struct GNUNET_ATS_Session *s = value; |
807 | struct ServerRequest *sc_send; | 798 | struct ServerRequest *sc_send; |
@@ -809,7 +800,7 @@ destroy_session_shutdown_cb (void *cls, | |||
809 | 800 | ||
810 | sc_send = s->server_send; | 801 | sc_send = s->server_send; |
811 | sc_recv = s->server_recv; | 802 | sc_recv = s->server_recv; |
812 | server_delete_session (s); | 803 | server_delete_session(s); |
813 | if (NULL != sc_send) | 804 | if (NULL != sc_send) |
814 | sc_send->session = NULL; | 805 | sc_send->session = NULL; |
815 | if (NULL != sc_recv) | 806 | if (NULL != sc_recv) |
@@ -828,13 +819,13 @@ destroy_session_shutdown_cb (void *cls, | |||
828 | * @return #GNUNET_OK (continue to iterate) | 819 | * @return #GNUNET_OK (continue to iterate) |
829 | */ | 820 | */ |
830 | static int | 821 | static int |
831 | destroy_session_cb (void *cls, | 822 | destroy_session_cb(void *cls, |
832 | const struct GNUNET_PeerIdentity *peer, | 823 | const struct GNUNET_PeerIdentity *peer, |
833 | void *value) | 824 | void *value) |
834 | { | 825 | { |
835 | struct GNUNET_ATS_Session *s = value; | 826 | struct GNUNET_ATS_Session *s = value; |
836 | 827 | ||
837 | server_delete_session (s); | 828 | server_delete_session(s); |
838 | return GNUNET_OK; | 829 | return GNUNET_OK; |
839 | } | 830 | } |
840 | 831 | ||
@@ -848,18 +839,18 @@ destroy_session_cb (void *cls, | |||
848 | * @param target peer from which to disconnect | 839 | * @param target peer from which to disconnect |
849 | */ | 840 | */ |
850 | static void | 841 | static void |
851 | http_server_plugin_disconnect_peer (void *cls, | 842 | http_server_plugin_disconnect_peer(void *cls, |
852 | const struct GNUNET_PeerIdentity *target) | 843 | const struct GNUNET_PeerIdentity *target) |
853 | { | 844 | { |
854 | struct HTTP_Server_Plugin *plugin = cls; | 845 | struct HTTP_Server_Plugin *plugin = cls; |
855 | 846 | ||
856 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 847 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
857 | "Transport tells me to disconnect `%s'\n", | 848 | "Transport tells me to disconnect `%s'\n", |
858 | GNUNET_i2s (target)); | 849 | GNUNET_i2s(target)); |
859 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, | 850 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, |
860 | target, | 851 | target, |
861 | &destroy_session_cb, | 852 | &destroy_session_cb, |
862 | plugin); | 853 | plugin); |
863 | } | 854 | } |
864 | 855 | ||
865 | 856 | ||
@@ -876,9 +867,9 @@ http_server_plugin_disconnect_peer (void *cls, | |||
876 | * and transport | 867 | * and transport |
877 | */ | 868 | */ |
878 | static int | 869 | static int |
879 | http_server_plugin_address_suggested (void *cls, | 870 | http_server_plugin_address_suggested(void *cls, |
880 | const void *addr, | 871 | const void *addr, |
881 | size_t addrlen) | 872 | size_t addrlen) |
882 | { | 873 | { |
883 | struct HTTP_Server_Plugin *plugin = cls; | 874 | struct HTTP_Server_Plugin *plugin = cls; |
884 | struct HttpAddressWrapper *next; | 875 | struct HttpAddressWrapper *next; |
@@ -886,26 +877,26 @@ http_server_plugin_address_suggested (void *cls, | |||
886 | const struct HttpAddress *haddr = addr; | 877 | const struct HttpAddress *haddr = addr; |
887 | 878 | ||
888 | if ((NULL != plugin->ext_addr) && | 879 | if ((NULL != plugin->ext_addr) && |
889 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, | 880 | GNUNET_YES == (http_common_cmp_addresses(addr, addrlen, |
890 | plugin->ext_addr->address, | 881 | plugin->ext_addr->address, |
891 | plugin->ext_addr->address_length))) | 882 | plugin->ext_addr->address_length))) |
892 | { | 883 | { |
893 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ | 884 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ |
894 | if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != | 885 | if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != |
895 | (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | 886 | (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
896 | return GNUNET_NO; /* VERIFY option not set as required! */ | 887 | return GNUNET_NO; /* VERIFY option not set as required! */ |
897 | return GNUNET_OK; | ||
898 | } | ||
899 | next = plugin->addr_head; | ||
900 | while (NULL != (pos = next)) | ||
901 | { | ||
902 | next = pos->next; | ||
903 | if (GNUNET_YES == (http_common_cmp_addresses(addr, | ||
904 | addrlen, | ||
905 | pos->address, | ||
906 | pos->addrlen))) | ||
907 | return GNUNET_OK; | 888 | return GNUNET_OK; |
908 | } | 889 | } |
890 | next = plugin->addr_head; | ||
891 | while (NULL != (pos = next)) | ||
892 | { | ||
893 | next = pos->next; | ||
894 | if (GNUNET_YES == (http_common_cmp_addresses(addr, | ||
895 | addrlen, | ||
896 | pos->address, | ||
897 | pos->addrlen))) | ||
898 | return GNUNET_OK; | ||
899 | } | ||
909 | return GNUNET_NO; | 900 | return GNUNET_NO; |
910 | } | 901 | } |
911 | 902 | ||
@@ -921,8 +912,8 @@ http_server_plugin_address_suggested (void *cls, | |||
921 | * @return always NULL | 912 | * @return always NULL |
922 | */ | 913 | */ |
923 | static struct GNUNET_ATS_Session * | 914 | static struct GNUNET_ATS_Session * |
924 | http_server_plugin_get_session (void *cls, | 915 | http_server_plugin_get_session(void *cls, |
925 | const struct GNUNET_HELLO_Address *address) | 916 | const struct GNUNET_HELLO_Address *address) |
926 | { | 917 | { |
927 | return NULL; | 918 | return NULL; |
928 | } | 919 | } |
@@ -935,14 +926,14 @@ http_server_plugin_get_session (void *cls, | |||
935 | * @param cls plugin as closure | 926 | * @param cls plugin as closure |
936 | */ | 927 | */ |
937 | static void | 928 | static void |
938 | server_v4_run (void *cls) | 929 | server_v4_run(void *cls) |
939 | { | 930 | { |
940 | struct HTTP_Server_Plugin *plugin = cls; | 931 | struct HTTP_Server_Plugin *plugin = cls; |
941 | 932 | ||
942 | plugin->server_v4_task = NULL; | 933 | plugin->server_v4_task = NULL; |
943 | plugin->server_v4_immediately = GNUNET_NO; | 934 | plugin->server_v4_immediately = GNUNET_NO; |
944 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); | 935 | GNUNET_assert(MHD_YES == MHD_run(plugin->server_v4)); |
945 | server_reschedule (plugin, plugin->server_v4, GNUNET_NO); | 936 | server_reschedule(plugin, plugin->server_v4, GNUNET_NO); |
946 | } | 937 | } |
947 | 938 | ||
948 | 939 | ||
@@ -953,14 +944,14 @@ server_v4_run (void *cls) | |||
953 | * @param cls plugin as closure | 944 | * @param cls plugin as closure |
954 | */ | 945 | */ |
955 | static void | 946 | static void |
956 | server_v6_run (void *cls) | 947 | server_v6_run(void *cls) |
957 | { | 948 | { |
958 | struct HTTP_Server_Plugin *plugin = cls; | 949 | struct HTTP_Server_Plugin *plugin = cls; |
959 | 950 | ||
960 | plugin->server_v6_task = NULL; | 951 | plugin->server_v6_task = NULL; |
961 | plugin->server_v6_immediately = GNUNET_NO; | 952 | plugin->server_v6_immediately = GNUNET_NO; |
962 | GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); | 953 | GNUNET_assert(MHD_YES == MHD_run(plugin->server_v6)); |
963 | server_reschedule (plugin, plugin->server_v6, GNUNET_NO); | 954 | server_reschedule(plugin, plugin->server_v6, GNUNET_NO); |
964 | } | 955 | } |
965 | 956 | ||
966 | 957 | ||
@@ -974,9 +965,9 @@ server_v6_run (void *cls) | |||
974 | * @return gnunet task identifier | 965 | * @return gnunet task identifier |
975 | */ | 966 | */ |
976 | static struct GNUNET_SCHEDULER_Task * | 967 | static struct GNUNET_SCHEDULER_Task * |
977 | server_schedule (struct HTTP_Server_Plugin *plugin, | 968 | server_schedule(struct HTTP_Server_Plugin *plugin, |
978 | struct MHD_Daemon *daemon_handle, | 969 | struct MHD_Daemon *daemon_handle, |
979 | int now) | 970 | int now) |
980 | { | 971 | { |
981 | struct GNUNET_SCHEDULER_Task * ret; | 972 | struct GNUNET_SCHEDULER_Task * ret; |
982 | fd_set rs; | 973 | fd_set rs; |
@@ -994,76 +985,76 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
994 | return NULL; | 985 | return NULL; |
995 | 986 | ||
996 | ret = NULL; | 987 | ret = NULL; |
997 | FD_ZERO (&rs); | 988 | FD_ZERO(&rs); |
998 | FD_ZERO (&ws); | 989 | FD_ZERO(&ws); |
999 | FD_ZERO (&es); | 990 | FD_ZERO(&es); |
1000 | wrs = GNUNET_NETWORK_fdset_create (); | 991 | wrs = GNUNET_NETWORK_fdset_create(); |
1001 | wws = GNUNET_NETWORK_fdset_create (); | 992 | wws = GNUNET_NETWORK_fdset_create(); |
1002 | max = -1; | 993 | max = -1; |
1003 | GNUNET_assert (MHD_YES == | 994 | GNUNET_assert(MHD_YES == |
1004 | MHD_get_fdset (daemon_handle, | 995 | MHD_get_fdset(daemon_handle, |
1005 | &rs, | 996 | &rs, |
1006 | &ws, | 997 | &ws, |
1007 | &es, | 998 | &es, |
1008 | &max)); | 999 | &max)); |
1009 | haveto = MHD_get_timeout (daemon_handle, &timeout); | 1000 | haveto = MHD_get_timeout(daemon_handle, &timeout); |
1010 | if (haveto == MHD_YES) | 1001 | if (haveto == MHD_YES) |
1011 | { | 1002 | { |
1012 | if (timeout != last_timeout) | 1003 | if (timeout != last_timeout) |
1013 | { | 1004 | { |
1014 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1005 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1015 | "SELECT Timeout changed from %llu to %llu (ms)\n", | 1006 | "SELECT Timeout changed from %llu to %llu (ms)\n", |
1016 | last_timeout, timeout); | 1007 | last_timeout, timeout); |
1017 | last_timeout = timeout; | 1008 | last_timeout = timeout; |
1018 | } | 1009 | } |
1019 | if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL) | 1010 | if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL) |
1020 | tv.rel_value_us = (uint64_t) timeout * 1000LL; | 1011 | tv.rel_value_us = (uint64_t)timeout * 1000LL; |
1021 | else | 1012 | else |
1022 | tv = GNUNET_TIME_UNIT_SECONDS; | 1013 | tv = GNUNET_TIME_UNIT_SECONDS; |
1023 | } | 1014 | } |
1024 | else | 1015 | else |
1025 | tv = GNUNET_TIME_UNIT_SECONDS; | 1016 | tv = GNUNET_TIME_UNIT_SECONDS; |
1026 | /* Force immediate run, since we have outbound data to send */ | 1017 | /* Force immediate run, since we have outbound data to send */ |
1027 | if (now == GNUNET_YES) | 1018 | if (now == GNUNET_YES) |
1028 | tv = GNUNET_TIME_UNIT_MILLISECONDS; | 1019 | tv = GNUNET_TIME_UNIT_MILLISECONDS; |
1029 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | 1020 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); |
1030 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 1021 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); |
1031 | 1022 | ||
1032 | if (daemon_handle == plugin->server_v4) | 1023 | if (daemon_handle == plugin->server_v4) |
1033 | { | ||
1034 | if (plugin->server_v4_task != NULL) | ||
1035 | { | 1024 | { |
1036 | GNUNET_SCHEDULER_cancel (plugin->server_v4_task); | 1025 | if (plugin->server_v4_task != NULL) |
1037 | plugin->server_v4_task = NULL; | 1026 | { |
1038 | } | 1027 | GNUNET_SCHEDULER_cancel(plugin->server_v4_task); |
1028 | plugin->server_v4_task = NULL; | ||
1029 | } | ||
1039 | #if 0 | 1030 | #if 0 |
1040 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1031 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1041 | "Scheduling IPv4 server task in %llu ms\n", | 1032 | "Scheduling IPv4 server task in %llu ms\n", |
1042 | tv); | 1033 | tv); |
1043 | #endif | 1034 | #endif |
1044 | ret = | 1035 | ret = |
1045 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1036 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1046 | tv, wrs, wws, | 1037 | tv, wrs, wws, |
1047 | &server_v4_run, plugin); | 1038 | &server_v4_run, plugin); |
1048 | } | 1039 | } |
1049 | if (daemon_handle == plugin->server_v6) | 1040 | if (daemon_handle == plugin->server_v6) |
1050 | { | ||
1051 | if (plugin->server_v6_task != NULL) | ||
1052 | { | 1041 | { |
1053 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | 1042 | if (plugin->server_v6_task != NULL) |
1054 | plugin->server_v6_task = NULL; | 1043 | { |
1055 | } | 1044 | GNUNET_SCHEDULER_cancel(plugin->server_v6_task); |
1045 | plugin->server_v6_task = NULL; | ||
1046 | } | ||
1056 | #if 0 | 1047 | #if 0 |
1057 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1048 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1058 | "Scheduling IPv6 server task in %llu ms\n", tv); | 1049 | "Scheduling IPv6 server task in %llu ms\n", tv); |
1059 | #endif | 1050 | #endif |
1060 | ret = | 1051 | ret = |
1061 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1052 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1062 | tv, wrs, wws, | 1053 | tv, wrs, wws, |
1063 | &server_v6_run, plugin); | 1054 | &server_v6_run, plugin); |
1064 | } | 1055 | } |
1065 | GNUNET_NETWORK_fdset_destroy (wrs); | 1056 | GNUNET_NETWORK_fdset_destroy(wrs); |
1066 | GNUNET_NETWORK_fdset_destroy (wws); | 1057 | GNUNET_NETWORK_fdset_destroy(wws); |
1067 | return ret; | 1058 | return ret; |
1068 | } | 1059 | } |
1069 | 1060 | ||
@@ -1077,41 +1068,41 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
1077 | * until timeout | 1068 | * until timeout |
1078 | */ | 1069 | */ |
1079 | static void | 1070 | static void |
1080 | server_reschedule (struct HTTP_Server_Plugin *plugin, | 1071 | server_reschedule(struct HTTP_Server_Plugin *plugin, |
1081 | struct MHD_Daemon *server, | 1072 | struct MHD_Daemon *server, |
1082 | int now) | 1073 | int now) |
1083 | { | 1074 | { |
1084 | if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) | 1075 | if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) |
1085 | { | 1076 | { |
1086 | if (GNUNET_YES == plugin->server_v4_immediately) | 1077 | if (GNUNET_YES == plugin->server_v4_immediately) |
1087 | return; /* No rescheduling, server will run asap */ | 1078 | return; /* No rescheduling, server will run asap */ |
1088 | 1079 | ||
1089 | if (GNUNET_YES == now) | 1080 | if (GNUNET_YES == now) |
1090 | plugin->server_v4_immediately = GNUNET_YES; | 1081 | plugin->server_v4_immediately = GNUNET_YES; |
1091 | 1082 | ||
1092 | if (plugin->server_v4_task != NULL) | 1083 | if (plugin->server_v4_task != NULL) |
1093 | { | 1084 | { |
1094 | GNUNET_SCHEDULER_cancel (plugin->server_v4_task); | 1085 | GNUNET_SCHEDULER_cancel(plugin->server_v4_task); |
1095 | plugin->server_v4_task = NULL; | 1086 | plugin->server_v4_task = NULL; |
1087 | } | ||
1088 | plugin->server_v4_task = server_schedule(plugin, plugin->server_v4, now); | ||
1096 | } | 1089 | } |
1097 | plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now); | ||
1098 | } | ||
1099 | 1090 | ||
1100 | if ((server == plugin->server_v6) && (plugin->server_v6 != NULL)) | 1091 | if ((server == plugin->server_v6) && (plugin->server_v6 != NULL)) |
1101 | { | 1092 | { |
1102 | if (GNUNET_YES == plugin->server_v6_immediately) | 1093 | if (GNUNET_YES == plugin->server_v6_immediately) |
1103 | return; /* No rescheduling, server will run asap */ | 1094 | return; /* No rescheduling, server will run asap */ |
1104 | 1095 | ||
1105 | if (GNUNET_YES == now) | 1096 | if (GNUNET_YES == now) |
1106 | plugin->server_v6_immediately = GNUNET_YES; | 1097 | plugin->server_v6_immediately = GNUNET_YES; |
1107 | 1098 | ||
1108 | if (plugin->server_v6_task != NULL) | 1099 | if (plugin->server_v6_task != NULL) |
1109 | { | 1100 | { |
1110 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | 1101 | GNUNET_SCHEDULER_cancel(plugin->server_v6_task); |
1111 | plugin->server_v6_task = NULL; | 1102 | plugin->server_v6_task = NULL; |
1103 | } | ||
1104 | plugin->server_v6_task = server_schedule(plugin, plugin->server_v6, now); | ||
1112 | } | 1105 | } |
1113 | plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now); | ||
1114 | } | ||
1115 | } | 1106 | } |
1116 | 1107 | ||
1117 | 1108 | ||
@@ -1124,7 +1115,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, | |||
1124 | * @return keepalive factor | 1115 | * @return keepalive factor |
1125 | */ | 1116 | */ |
1126 | static unsigned int | 1117 | static unsigned int |
1127 | http_server_query_keepalive_factor (void *cls) | 1118 | http_server_query_keepalive_factor(void *cls) |
1128 | { | 1119 | { |
1129 | return 3; | 1120 | return 3; |
1130 | } | 1121 | } |
@@ -1140,11 +1131,11 @@ http_server_query_keepalive_factor (void *cls) | |||
1140 | * @param session which session is being updated | 1131 | * @param session which session is being updated |
1141 | */ | 1132 | */ |
1142 | static void | 1133 | static void |
1143 | http_server_plugin_update_session_timeout (void *cls, | 1134 | http_server_plugin_update_session_timeout(void *cls, |
1144 | const struct GNUNET_PeerIdentity *peer, | 1135 | const struct GNUNET_PeerIdentity *peer, |
1145 | struct GNUNET_ATS_Session *session) | 1136 | struct GNUNET_ATS_Session *session) |
1146 | { | 1137 | { |
1147 | server_reschedule_session_timeout (session); | 1138 | server_reschedule_session_timeout(session); |
1148 | } | 1139 | } |
1149 | 1140 | ||
1150 | 1141 | ||
@@ -1156,31 +1147,31 @@ http_server_plugin_update_session_timeout (void *cls, | |||
1156 | * @param to timeout in seconds | 1147 | * @param to timeout in seconds |
1157 | */ | 1148 | */ |
1158 | static void | 1149 | static void |
1159 | server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | 1150 | server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin, |
1160 | struct GNUNET_ATS_Session *s, | 1151 | struct GNUNET_ATS_Session *s, |
1161 | unsigned int to) | 1152 | unsigned int to) |
1162 | { | 1153 | { |
1163 | /* Setting timeouts for other connections */ | 1154 | /* Setting timeouts for other connections */ |
1164 | if (NULL != s->server_recv) | 1155 | if (NULL != s->server_recv) |
1165 | { | 1156 | { |
1166 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1157 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1167 | "Setting timeout for %p to %u sec.\n", | 1158 | "Setting timeout for %p to %u sec.\n", |
1168 | s->server_recv, to); | 1159 | s->server_recv, to); |
1169 | MHD_set_connection_option (s->server_recv->mhd_conn, | 1160 | MHD_set_connection_option(s->server_recv->mhd_conn, |
1170 | MHD_CONNECTION_OPTION_TIMEOUT, | 1161 | MHD_CONNECTION_OPTION_TIMEOUT, |
1171 | to); | 1162 | to); |
1172 | server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO); | 1163 | server_reschedule(plugin, s->server_recv->mhd_daemon, GNUNET_NO); |
1173 | } | 1164 | } |
1174 | if (NULL != s->server_send) | 1165 | if (NULL != s->server_send) |
1175 | { | 1166 | { |
1176 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1167 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1177 | "Setting timeout for %p to %u sec.\n", | 1168 | "Setting timeout for %p to %u sec.\n", |
1178 | s->server_send, to); | 1169 | s->server_send, to); |
1179 | MHD_set_connection_option (s->server_send->mhd_conn, | 1170 | MHD_set_connection_option(s->server_send->mhd_conn, |
1180 | MHD_CONNECTION_OPTION_TIMEOUT, | 1171 | MHD_CONNECTION_OPTION_TIMEOUT, |
1181 | to); | 1172 | to); |
1182 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); | 1173 | server_reschedule(plugin, s->server_send->mhd_daemon, GNUNET_NO); |
1183 | } | 1174 | } |
1184 | } | 1175 | } |
1185 | 1176 | ||
1186 | 1177 | ||
@@ -1195,11 +1186,11 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
1195 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1186 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1196 | */ | 1187 | */ |
1197 | static int | 1188 | static int |
1198 | server_parse_url (struct HTTP_Server_Plugin *plugin, | 1189 | server_parse_url(struct HTTP_Server_Plugin *plugin, |
1199 | const char *url, | 1190 | const char *url, |
1200 | struct GNUNET_PeerIdentity *target, | 1191 | struct GNUNET_PeerIdentity *target, |
1201 | uint32_t *tag, | 1192 | uint32_t *tag, |
1202 | uint32_t *options) | 1193 | uint32_t *options) |
1203 | { | 1194 | { |
1204 | regmatch_t matches[4]; | 1195 | regmatch_t matches[4]; |
1205 | const char *tag_start; | 1196 | const char *tag_start; |
@@ -1214,105 +1205,105 @@ server_parse_url (struct HTTP_Server_Plugin *plugin, | |||
1214 | ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$") | 1205 | ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$") |
1215 | 1206 | ||
1216 | if (NULL == url) | 1207 | if (NULL == url) |
1217 | { | 1208 | { |
1218 | GNUNET_break (0); | 1209 | GNUNET_break(0); |
1219 | return GNUNET_SYSERR; | 1210 | return GNUNET_SYSERR; |
1220 | } | 1211 | } |
1221 | 1212 | ||
1222 | if (regexec(&plugin->url_regex, url, 4, matches, 0)) | 1213 | if (regexec(&plugin->url_regex, url, 4, matches, 0)) |
1223 | { | 1214 | { |
1224 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1215 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1225 | "URL `%s' did not match regex\n", url); | 1216 | "URL `%s' did not match regex\n", url); |
1226 | return GNUNET_SYSERR; | 1217 | return GNUNET_SYSERR; |
1227 | } | 1218 | } |
1228 | 1219 | ||
1229 | target_start = &url[matches[1].rm_so]; | 1220 | target_start = &url[matches[1].rm_so]; |
1230 | tag_start = &url[matches[2].rm_so]; | 1221 | tag_start = &url[matches[2].rm_so]; |
1231 | 1222 | ||
1232 | /* convert tag */ | 1223 | /* convert tag */ |
1233 | rc = strtoul (tag_start, &tag_end, 10); | 1224 | rc = strtoul(tag_start, &tag_end, 10); |
1234 | if (&url[matches[2].rm_eo] != tag_end) | 1225 | if (&url[matches[2].rm_eo] != tag_end) |
1235 | { | 1226 | { |
1236 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1227 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1237 | "URL tag did not line up with submatch\n"); | 1228 | "URL tag did not line up with submatch\n"); |
1238 | return GNUNET_SYSERR; | 1229 | return GNUNET_SYSERR; |
1239 | } | 1230 | } |
1240 | if (rc == 0) | 1231 | if (rc == 0) |
1241 | { | 1232 | { |
1242 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1233 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1243 | "URL tag is zero\n"); | 1234 | "URL tag is zero\n"); |
1244 | return GNUNET_SYSERR; | 1235 | return GNUNET_SYSERR; |
1245 | } | 1236 | } |
1246 | if ((rc == ULONG_MAX) && (ERANGE == errno)) | 1237 | if ((rc == ULONG_MAX) && (ERANGE == errno)) |
1247 | { | 1238 | { |
1248 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1239 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1249 | "URL tag > ULONG_MAX\n"); | 1240 | "URL tag > ULONG_MAX\n"); |
1250 | return GNUNET_SYSERR; | 1241 | return GNUNET_SYSERR; |
1251 | } | 1242 | } |
1252 | if (rc > UINT32_MAX) | 1243 | if (rc > UINT32_MAX) |
1253 | { | 1244 | { |
1254 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1245 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1255 | "URL tag > UINT32_MAX\n"); | 1246 | "URL tag > UINT32_MAX\n"); |
1256 | return GNUNET_SYSERR; | 1247 | return GNUNET_SYSERR; |
1257 | } | 1248 | } |
1258 | (*tag) = (uint32_t)rc; | 1249 | (*tag) = (uint32_t)rc; |
1259 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1250 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1260 | "Found tag `%u' in url\n", | 1251 | "Found tag `%u' in url\n", |
1261 | *tag); | 1252 | *tag); |
1262 | 1253 | ||
1263 | /* convert peer id */ | 1254 | /* convert peer id */ |
1264 | hash_length = matches[1].rm_eo - matches[1].rm_so; | 1255 | hash_length = matches[1].rm_eo - matches[1].rm_so; |
1265 | if (hash_length != plugin->peer_id_length) | 1256 | if (hash_length != plugin->peer_id_length) |
1266 | { | ||
1267 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1268 | "URL target is %u bytes, expecting %u\n", | ||
1269 | hash_length, plugin->peer_id_length); | ||
1270 | return GNUNET_SYSERR; | ||
1271 | } | ||
1272 | if (GNUNET_OK != | ||
1273 | GNUNET_CRYPTO_eddsa_public_key_from_string (target_start, | ||
1274 | hash_length, | ||
1275 | &target->public_key)) | ||
1276 | { | ||
1277 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1278 | "URL target conversion failed\n"); | ||
1279 | return GNUNET_SYSERR; | ||
1280 | } | ||
1281 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1282 | "Found target `%s' in URL\n", | ||
1283 | GNUNET_i2s_full (target)); | ||
1284 | |||
1285 | /* convert options */ | ||
1286 | if (-1 == matches[3].rm_so) | ||
1287 | { | ||
1288 | *options = 0; | ||
1289 | } | ||
1290 | else | ||
1291 | { | ||
1292 | rc = strtoul (&url[matches[3].rm_so + 1], &options_end, 10); | ||
1293 | if (&url[matches[3].rm_eo] != options_end) | ||
1294 | { | 1257 | { |
1295 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1258 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1296 | "URL options did not line up with submatch\n"); | 1259 | "URL target is %u bytes, expecting %u\n", |
1260 | hash_length, plugin->peer_id_length); | ||
1297 | return GNUNET_SYSERR; | 1261 | return GNUNET_SYSERR; |
1298 | } | 1262 | } |
1299 | if ((rc == ULONG_MAX) && (ERANGE == errno)) | 1263 | if (GNUNET_OK != |
1264 | GNUNET_CRYPTO_eddsa_public_key_from_string(target_start, | ||
1265 | hash_length, | ||
1266 | &target->public_key)) | ||
1300 | { | 1267 | { |
1301 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1268 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1302 | "URL options > ULONG_MAX\n"); | 1269 | "URL target conversion failed\n"); |
1303 | return GNUNET_SYSERR; | 1270 | return GNUNET_SYSERR; |
1304 | } | 1271 | } |
1305 | if (rc > UINT32_MAX) | 1272 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1273 | "Found target `%s' in URL\n", | ||
1274 | GNUNET_i2s_full(target)); | ||
1275 | |||
1276 | /* convert options */ | ||
1277 | if (-1 == matches[3].rm_so) | ||
1306 | { | 1278 | { |
1307 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1279 | *options = 0; |
1308 | "URL options > UINT32_MAX\n"); | 1280 | } |
1309 | return GNUNET_SYSERR; | 1281 | else |
1282 | { | ||
1283 | rc = strtoul(&url[matches[3].rm_so + 1], &options_end, 10); | ||
1284 | if (&url[matches[3].rm_eo] != options_end) | ||
1285 | { | ||
1286 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1287 | "URL options did not line up with submatch\n"); | ||
1288 | return GNUNET_SYSERR; | ||
1289 | } | ||
1290 | if ((rc == ULONG_MAX) && (ERANGE == errno)) | ||
1291 | { | ||
1292 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1293 | "URL options > ULONG_MAX\n"); | ||
1294 | return GNUNET_SYSERR; | ||
1295 | } | ||
1296 | if (rc > UINT32_MAX) | ||
1297 | { | ||
1298 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1299 | "URL options > UINT32_MAX\n"); | ||
1300 | return GNUNET_SYSERR; | ||
1301 | } | ||
1302 | (*options) = (uint32_t)rc; | ||
1303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1304 | "Found options `%u' in url\n", | ||
1305 | *options); | ||
1310 | } | 1306 | } |
1311 | (*options) = (uint32_t) rc; | ||
1312 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1313 | "Found options `%u' in url\n", | ||
1314 | *options); | ||
1315 | } | ||
1316 | return GNUNET_OK; | 1307 | return GNUNET_OK; |
1317 | } | 1308 | } |
1318 | 1309 | ||
@@ -1320,8 +1311,7 @@ server_parse_url (struct HTTP_Server_Plugin *plugin, | |||
1320 | /** | 1311 | /** |
1321 | * Closure for #session_tag_it(). | 1312 | * Closure for #session_tag_it(). |
1322 | */ | 1313 | */ |
1323 | struct GNUNET_ATS_SessionTagContext | 1314 | struct GNUNET_ATS_SessionTagContext { |
1324 | { | ||
1325 | /** | 1315 | /** |
1326 | * Set to session matching the tag. | 1316 | * Set to session matching the tag. |
1327 | */ | 1317 | */ |
@@ -1343,18 +1333,18 @@ struct GNUNET_ATS_SessionTagContext | |||
1343 | * @return #GNUNET_NO if we found the session, #GNUNET_OK if not | 1333 | * @return #GNUNET_NO if we found the session, #GNUNET_OK if not |
1344 | */ | 1334 | */ |
1345 | static int | 1335 | static int |
1346 | session_tag_it (void *cls, | 1336 | session_tag_it(void *cls, |
1347 | const struct GNUNET_PeerIdentity *key, | 1337 | const struct GNUNET_PeerIdentity *key, |
1348 | void *value) | 1338 | void *value) |
1349 | { | 1339 | { |
1350 | struct GNUNET_ATS_SessionTagContext *stc = cls; | 1340 | struct GNUNET_ATS_SessionTagContext *stc = cls; |
1351 | struct GNUNET_ATS_Session *s = value; | 1341 | struct GNUNET_ATS_Session *s = value; |
1352 | 1342 | ||
1353 | if (s->tag == stc->tag) | 1343 | if (s->tag == stc->tag) |
1354 | { | 1344 | { |
1355 | stc->res = s; | 1345 | stc->res = s; |
1356 | return GNUNET_NO; | 1346 | return GNUNET_NO; |
1357 | } | 1347 | } |
1358 | return GNUNET_YES; | 1348 | return GNUNET_YES; |
1359 | } | 1349 | } |
1360 | 1350 | ||
@@ -1369,10 +1359,10 @@ session_tag_it (void *cls, | |||
1369 | * @return the server connecetion | 1359 | * @return the server connecetion |
1370 | */ | 1360 | */ |
1371 | static struct ServerRequest * | 1361 | static struct ServerRequest * |
1372 | server_lookup_connection (struct HTTP_Server_Plugin *plugin, | 1362 | server_lookup_connection(struct HTTP_Server_Plugin *plugin, |
1373 | struct MHD_Connection *mhd_connection, | 1363 | struct MHD_Connection *mhd_connection, |
1374 | const char *url, | 1364 | const char *url, |
1375 | const char *method) | 1365 | const char *method) |
1376 | { | 1366 | { |
1377 | struct GNUNET_ATS_Session *s = NULL; | 1367 | struct GNUNET_ATS_Session *s = NULL; |
1378 | struct ServerRequest *sc = NULL; | 1368 | struct ServerRequest *sc = NULL; |
@@ -1386,129 +1376,131 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1386 | unsigned int to; | 1376 | unsigned int to; |
1387 | enum GNUNET_NetworkType scope; | 1377 | enum GNUNET_NetworkType scope; |
1388 | 1378 | ||
1389 | conn_info = MHD_get_connection_info (mhd_connection, | 1379 | conn_info = MHD_get_connection_info(mhd_connection, |
1390 | MHD_CONNECTION_INFO_CLIENT_ADDRESS); | 1380 | MHD_CONNECTION_INFO_CLIENT_ADDRESS); |
1391 | if ((conn_info->client_addr->sa_family != AF_INET) && | 1381 | if ((conn_info->client_addr->sa_family != AF_INET) && |
1392 | (conn_info->client_addr->sa_family != AF_INET6)) | 1382 | (conn_info->client_addr->sa_family != AF_INET6)) |
1393 | return NULL; | 1383 | return NULL; |
1394 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1384 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1395 | "New %s request from %s\n", | 1385 | "New %s request from %s\n", |
1396 | method, | 1386 | method, |
1397 | url); | 1387 | url); |
1398 | stc.tag = 0; | 1388 | stc.tag = 0; |
1399 | options = 0; /* make gcc happy */ | 1389 | options = 0; /* make gcc happy */ |
1400 | if (GNUNET_SYSERR == | 1390 | if (GNUNET_SYSERR == |
1401 | server_parse_url (plugin, url, &target, &stc.tag, &options)) | 1391 | server_parse_url(plugin, url, &target, &stc.tag, &options)) |
1402 | { | 1392 | { |
1403 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1393 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1404 | "Invalid url %s\n", url); | 1394 | "Invalid url %s\n", url); |
1405 | return NULL; | 1395 | return NULL; |
1406 | } | 1396 | } |
1407 | if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) | 1397 | if (0 == strcmp(MHD_HTTP_METHOD_PUT, method)) |
1408 | direction = _RECEIVE; | 1398 | direction = _RECEIVE; |
1409 | else if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) | 1399 | else if (0 == strcmp(MHD_HTTP_METHOD_GET, method)) |
1410 | direction = _SEND; | 1400 | direction = _SEND; |
1411 | else | 1401 | else |
1412 | { | 1402 | { |
1413 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1403 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1414 | "Invalid method %s for request from %s\n", | 1404 | "Invalid method %s for request from %s\n", |
1415 | method, url); | 1405 | method, url); |
1416 | return NULL; | 1406 | return NULL; |
1417 | } | 1407 | } |
1418 | 1408 | ||
1419 | plugin->cur_request++; | 1409 | plugin->cur_request++; |
1420 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1410 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1421 | "New %s request from %s with tag %u (%u of %u)\n", | 1411 | "New %s request from %s with tag %u (%u of %u)\n", |
1422 | method, | 1412 | method, |
1423 | GNUNET_i2s (&target), | 1413 | GNUNET_i2s(&target), |
1424 | stc.tag, | 1414 | stc.tag, |
1425 | plugin->cur_request, plugin->max_request); | 1415 | plugin->cur_request, plugin->max_request); |
1426 | /* find existing session */ | 1416 | /* find existing session */ |
1427 | stc.res = NULL; | 1417 | stc.res = NULL; |
1428 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, | 1418 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, |
1429 | &target, | 1419 | &target, |
1430 | &session_tag_it, | 1420 | &session_tag_it, |
1431 | &stc); | 1421 | &stc); |
1432 | if (NULL == (s = stc.res)) | 1422 | if (NULL == (s = stc.res)) |
1433 | { | 1423 | { |
1434 | /* create new session */ | 1424 | /* create new session */ |
1435 | addr = NULL; | 1425 | addr = NULL; |
1436 | switch (conn_info->client_addr->sa_family) | 1426 | switch (conn_info->client_addr->sa_family) |
1437 | { | 1427 | { |
1438 | case (AF_INET): | 1428 | case (AF_INET): |
1439 | addr = http_common_address_from_socket (plugin->protocol, | 1429 | addr = http_common_address_from_socket(plugin->protocol, |
1440 | conn_info->client_addr, | 1430 | conn_info->client_addr, |
1441 | sizeof (struct sockaddr_in)); | 1431 | sizeof(struct sockaddr_in)); |
1442 | addr_len = http_common_address_get_size (addr); | 1432 | addr_len = http_common_address_get_size(addr); |
1443 | scope = plugin->env->get_address_type (plugin->env->cls, | 1433 | scope = plugin->env->get_address_type(plugin->env->cls, |
1444 | conn_info->client_addr, | 1434 | conn_info->client_addr, |
1445 | sizeof (struct sockaddr_in)); | 1435 | sizeof(struct sockaddr_in)); |
1446 | break; | 1436 | break; |
1447 | case (AF_INET6): | 1437 | |
1448 | addr = http_common_address_from_socket (plugin->protocol, | 1438 | case (AF_INET6): |
1449 | conn_info->client_addr, | 1439 | addr = http_common_address_from_socket(plugin->protocol, |
1450 | sizeof (struct sockaddr_in6)); | 1440 | conn_info->client_addr, |
1451 | addr_len = http_common_address_get_size (addr); | 1441 | sizeof(struct sockaddr_in6)); |
1452 | scope = plugin->env->get_address_type (plugin->env->cls, | 1442 | addr_len = http_common_address_get_size(addr); |
1453 | conn_info->client_addr, | 1443 | scope = plugin->env->get_address_type(plugin->env->cls, |
1454 | sizeof (struct sockaddr_in6)); | 1444 | conn_info->client_addr, |
1455 | break; | 1445 | sizeof(struct sockaddr_in6)); |
1456 | default: | 1446 | break; |
1457 | /* external host name */ | 1447 | |
1458 | return NULL; | 1448 | default: |
1459 | } | 1449 | /* external host name */ |
1460 | s = GNUNET_new (struct GNUNET_ATS_Session); | 1450 | return NULL; |
1461 | s->target = target; | 1451 | } |
1462 | s->plugin = plugin; | 1452 | s = GNUNET_new(struct GNUNET_ATS_Session); |
1463 | s->scope = scope; | 1453 | s->target = target; |
1464 | s->address = GNUNET_HELLO_address_allocate (&s->target, | 1454 | s->plugin = plugin; |
1465 | PLUGIN_NAME, | 1455 | s->scope = scope; |
1466 | addr, | 1456 | s->address = GNUNET_HELLO_address_allocate(&s->target, |
1467 | addr_len, | 1457 | PLUGIN_NAME, |
1468 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 1458 | addr, |
1469 | s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; | 1459 | addr_len, |
1470 | s->tag = stc.tag; | 1460 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
1471 | s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_SERVER_SESSION_TIMEOUT); | 1461 | s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; |
1472 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_SERVER_SESSION_TIMEOUT, | 1462 | s->tag = stc.tag; |
1473 | &server_session_timeout, | 1463 | s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_SERVER_SESSION_TIMEOUT); |
1474 | s); | 1464 | s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_SERVER_SESSION_TIMEOUT, |
1475 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions, | 1465 | &server_session_timeout, |
1466 | s); | ||
1467 | (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions, | ||
1476 | &s->target, | 1468 | &s->target, |
1477 | s, | 1469 | s, |
1478 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1470 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1479 | notify_session_monitor (plugin, | 1471 | notify_session_monitor(plugin, |
1480 | s, | 1472 | s, |
1481 | GNUNET_TRANSPORT_SS_INIT); | 1473 | GNUNET_TRANSPORT_SS_INIT); |
1482 | notify_session_monitor (plugin, | 1474 | notify_session_monitor(plugin, |
1483 | s, | 1475 | s, |
1484 | GNUNET_TRANSPORT_SS_HANDSHAKE); | 1476 | GNUNET_TRANSPORT_SS_HANDSHAKE); |
1485 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1477 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1486 | "Creating new session %p for peer `%s' connecting from `%s'\n", | 1478 | "Creating new session %p for peer `%s' connecting from `%s'\n", |
1487 | s, GNUNET_i2s (&target), | 1479 | s, GNUNET_i2s(&target), |
1488 | http_common_plugin_address_to_string (plugin->protocol, | 1480 | http_common_plugin_address_to_string(plugin->protocol, |
1489 | addr, | 1481 | addr, |
1490 | addr_len)); | 1482 | addr_len)); |
1491 | GNUNET_free_non_null (addr); | 1483 | GNUNET_free_non_null(addr); |
1492 | } | 1484 | } |
1493 | 1485 | ||
1494 | if ( (_RECEIVE == direction) && | 1486 | if ((_RECEIVE == direction) && |
1495 | (NULL != s->server_recv) ) | 1487 | (NULL != s->server_recv)) |
1496 | { | 1488 | { |
1497 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1489 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1498 | "Duplicate PUT request from `%s' tag %u, dismissing new request\n", | 1490 | "Duplicate PUT request from `%s' tag %u, dismissing new request\n", |
1499 | GNUNET_i2s (&target), | 1491 | GNUNET_i2s(&target), |
1500 | stc.tag); | 1492 | stc.tag); |
1501 | return NULL; | 1493 | return NULL; |
1502 | } | 1494 | } |
1503 | if ((_SEND == direction) && (NULL != s->server_send)) | 1495 | if ((_SEND == direction) && (NULL != s->server_send)) |
1504 | { | 1496 | { |
1505 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1497 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1506 | "Duplicate GET request from `%s' tag %u, dismissing new request\n", | 1498 | "Duplicate GET request from `%s' tag %u, dismissing new request\n", |
1507 | GNUNET_i2s (&target), | 1499 | GNUNET_i2s(&target), |
1508 | stc.tag); | 1500 | stc.tag); |
1509 | return NULL; | 1501 | return NULL; |
1510 | } | 1502 | } |
1511 | sc = GNUNET_new (struct ServerRequest); | 1503 | sc = GNUNET_new(struct ServerRequest); |
1512 | if (conn_info->client_addr->sa_family == AF_INET) | 1504 | if (conn_info->client_addr->sa_family == AF_INET) |
1513 | sc->mhd_daemon = plugin->server_v4; | 1505 | sc->mhd_daemon = plugin->server_v4; |
1514 | if (conn_info->client_addr->sa_family == AF_INET6) | 1506 | if (conn_info->client_addr->sa_family == AF_INET6) |
@@ -1519,30 +1511,30 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1519 | sc->session = s; | 1511 | sc->session = s; |
1520 | sc->options = options; | 1512 | sc->options = options; |
1521 | if (direction == _SEND) | 1513 | if (direction == _SEND) |
1522 | { | 1514 | { |
1523 | s->server_send = sc; | 1515 | s->server_send = sc; |
1524 | } | 1516 | } |
1525 | if (direction == _RECEIVE) | 1517 | if (direction == _RECEIVE) |
1526 | { | 1518 | { |
1527 | s->server_recv = sc; | 1519 | s->server_recv = sc; |
1528 | } | 1520 | } |
1529 | 1521 | ||
1530 | if ((GNUNET_NO == s->known_to_service) && | 1522 | if ((GNUNET_NO == s->known_to_service) && |
1531 | (NULL != s->server_send) && | 1523 | (NULL != s->server_send) && |
1532 | (NULL != s->server_recv) ) | 1524 | (NULL != s->server_recv)) |
1533 | { | 1525 | { |
1534 | s->known_to_service = GNUNET_YES; | 1526 | s->known_to_service = GNUNET_YES; |
1535 | notify_session_monitor (plugin, | 1527 | notify_session_monitor(plugin, |
1536 | s, | 1528 | s, |
1537 | GNUNET_TRANSPORT_SS_UP); | 1529 | GNUNET_TRANSPORT_SS_UP); |
1538 | plugin->env->session_start (plugin->env->cls, | 1530 | plugin->env->session_start(plugin->env->cls, |
1539 | s->address, | 1531 | s->address, |
1540 | s, | 1532 | s, |
1541 | s->scope); | 1533 | s->scope); |
1542 | } | 1534 | } |
1543 | 1535 | ||
1544 | to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL); | 1536 | to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL); |
1545 | server_mhd_connection_timeout (plugin, s, to); | 1537 | server_mhd_connection_timeout(plugin, s, to); |
1546 | return sc; | 1538 | return sc; |
1547 | } | 1539 | } |
1548 | 1540 | ||
@@ -1557,10 +1549,10 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1557 | * @return bytes written to @a buf | 1549 | * @return bytes written to @a buf |
1558 | */ | 1550 | */ |
1559 | static ssize_t | 1551 | static ssize_t |
1560 | server_send_callback (void *cls, | 1552 | server_send_callback(void *cls, |
1561 | uint64_t pos, | 1553 | uint64_t pos, |
1562 | char *buf, | 1554 | char *buf, |
1563 | size_t max) | 1555 | size_t max) |
1564 | { | 1556 | { |
1565 | struct ServerRequest *sc = cls; | 1557 | struct ServerRequest *sc = cls; |
1566 | struct GNUNET_ATS_Session *s = sc->session; | 1558 | struct GNUNET_ATS_Session *s = sc->session; |
@@ -1569,79 +1561,79 @@ server_send_callback (void *cls, | |||
1569 | char *stat_txt; | 1561 | char *stat_txt; |
1570 | 1562 | ||
1571 | if (NULL == s) | 1563 | if (NULL == s) |
1572 | { | 1564 | { |
1573 | /* session is disconnecting */ | 1565 | /* session is disconnecting */ |
1574 | return 0; | 1566 | return 0; |
1575 | } | 1567 | } |
1576 | 1568 | ||
1577 | sc = s->server_send; | 1569 | sc = s->server_send; |
1578 | if (NULL == sc) | 1570 | if (NULL == sc) |
1579 | return 0; | 1571 | return 0; |
1580 | msg = s->msg_head; | 1572 | msg = s->msg_head; |
1581 | if (NULL != msg) | 1573 | if (NULL != msg) |
1582 | { | 1574 | { |
1583 | /* sending */ | 1575 | /* sending */ |
1584 | bytes_read = GNUNET_MIN (msg->size - msg->pos, | 1576 | bytes_read = GNUNET_MIN(msg->size - msg->pos, |
1585 | max); | 1577 | max); |
1586 | GNUNET_memcpy (buf, &msg->buf[msg->pos], bytes_read); | 1578 | GNUNET_memcpy(buf, &msg->buf[msg->pos], bytes_read); |
1587 | msg->pos += bytes_read; | 1579 | msg->pos += bytes_read; |
1588 | 1580 | ||
1589 | /* removing message */ | 1581 | /* removing message */ |
1590 | if (msg->pos == msg->size) | 1582 | if (msg->pos == msg->size) |
1591 | { | 1583 | { |
1592 | GNUNET_CONTAINER_DLL_remove (s->msg_head, | 1584 | GNUNET_CONTAINER_DLL_remove(s->msg_head, |
1593 | s->msg_tail, | 1585 | s->msg_tail, |
1594 | msg); | 1586 | msg); |
1595 | if (NULL != msg->transmit_cont) | 1587 | if (NULL != msg->transmit_cont) |
1596 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK, | 1588 | msg->transmit_cont(msg->transmit_cont_cls, &s->target, GNUNET_OK, |
1597 | msg->size, msg->size + msg->overhead); | 1589 | msg->size, msg->size + msg->overhead); |
1598 | GNUNET_assert (s->msgs_in_queue > 0); | 1590 | GNUNET_assert(s->msgs_in_queue > 0); |
1599 | s->msgs_in_queue--; | 1591 | s->msgs_in_queue--; |
1600 | GNUNET_assert (s->bytes_in_queue >= msg->size); | 1592 | GNUNET_assert(s->bytes_in_queue >= msg->size); |
1601 | s->bytes_in_queue -= msg->size; | 1593 | s->bytes_in_queue -= msg->size; |
1602 | GNUNET_free (msg); | 1594 | GNUNET_free(msg); |
1603 | notify_session_monitor (s->plugin, | 1595 | notify_session_monitor(s->plugin, |
1604 | s, | 1596 | s, |
1605 | GNUNET_TRANSPORT_SS_UPDATE); | 1597 | GNUNET_TRANSPORT_SS_UPDATE); |
1598 | } | ||
1606 | } | 1599 | } |
1607 | } | ||
1608 | if (0 < bytes_read) | 1600 | if (0 < bytes_read) |
1609 | { | 1601 | { |
1610 | sc->connected = GNUNET_YES; | 1602 | sc->connected = GNUNET_YES; |
1611 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1603 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1612 | "Sent %u bytes to peer `%s' with session %p \n", | 1604 | "Sent %u bytes to peer `%s' with session %p \n", |
1613 | bytes_read, | 1605 | bytes_read, |
1614 | GNUNET_i2s (&s->target), | 1606 | GNUNET_i2s(&s->target), |
1615 | s); | 1607 | s); |
1616 | GNUNET_asprintf (&stat_txt, | 1608 | GNUNET_asprintf(&stat_txt, |
1617 | "# bytes currently in %s_server buffers", | 1609 | "# bytes currently in %s_server buffers", |
1618 | s->plugin->protocol); | 1610 | s->plugin->protocol); |
1619 | GNUNET_STATISTICS_update (s->plugin->env->stats, | 1611 | GNUNET_STATISTICS_update(s->plugin->env->stats, |
1620 | stat_txt, | 1612 | stat_txt, |
1621 | - bytes_read, | 1613 | -bytes_read, |
1622 | GNUNET_NO); | 1614 | GNUNET_NO); |
1623 | GNUNET_free (stat_txt); | 1615 | GNUNET_free(stat_txt); |
1624 | GNUNET_asprintf (&stat_txt, | 1616 | GNUNET_asprintf(&stat_txt, |
1625 | "# bytes transmitted via %s_server", | 1617 | "# bytes transmitted via %s_server", |
1626 | s->plugin->protocol); | 1618 | s->plugin->protocol); |
1627 | GNUNET_STATISTICS_update (s->plugin->env->stats, | 1619 | GNUNET_STATISTICS_update(s->plugin->env->stats, |
1628 | stat_txt, bytes_read, GNUNET_NO); | 1620 | stat_txt, bytes_read, GNUNET_NO); |
1629 | GNUNET_free (stat_txt); | 1621 | GNUNET_free(stat_txt); |
1630 | } | 1622 | } |
1631 | else if ((sc->options & OPTION_LONG_POLL) && sc->connected) | 1623 | else if ((sc->options & OPTION_LONG_POLL) && sc->connected) |
1632 | { | 1624 | { |
1633 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1625 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1634 | "Completing GET response to peer `%s' with session %p\n", | 1626 | "Completing GET response to peer `%s' with session %p\n", |
1635 | GNUNET_i2s (&s->target), | 1627 | GNUNET_i2s(&s->target), |
1636 | s); | 1628 | s); |
1637 | return MHD_CONTENT_READER_END_OF_STREAM; | 1629 | return MHD_CONTENT_READER_END_OF_STREAM; |
1638 | } | 1630 | } |
1639 | else | 1631 | else |
1640 | { | 1632 | { |
1641 | MHD_suspend_connection (s->server_send->mhd_conn); | 1633 | MHD_suspend_connection(s->server_send->mhd_conn); |
1642 | s->server_send->suspended = true; | 1634 | s->server_send->suspended = true; |
1643 | return 0; | 1635 | return 0; |
1644 | } | 1636 | } |
1645 | return bytes_read; | 1637 | return bytes_read; |
1646 | } | 1638 | } |
1647 | 1639 | ||
@@ -1654,8 +1646,8 @@ server_send_callback (void *cls, | |||
1654 | * @return #GNUNET_OK (all OK) | 1646 | * @return #GNUNET_OK (all OK) |
1655 | */ | 1647 | */ |
1656 | static int | 1648 | static int |
1657 | server_receive_mst_cb (void *cls, | 1649 | server_receive_mst_cb(void *cls, |
1658 | const struct GNUNET_MessageHeader *message) | 1650 | const struct GNUNET_MessageHeader *message) |
1659 | { | 1651 | { |
1660 | struct GNUNET_ATS_Session *s = cls; | 1652 | struct GNUNET_ATS_Session *s = cls; |
1661 | struct HTTP_Server_Plugin *plugin = s->plugin; | 1653 | struct HTTP_Server_Plugin *plugin = s->plugin; |
@@ -1663,41 +1655,41 @@ server_receive_mst_cb (void *cls, | |||
1663 | char *stat_txt; | 1655 | char *stat_txt; |
1664 | 1656 | ||
1665 | if (GNUNET_NO == s->known_to_service) | 1657 | if (GNUNET_NO == s->known_to_service) |
1666 | { | 1658 | { |
1667 | s->known_to_service = GNUNET_YES; | 1659 | s->known_to_service = GNUNET_YES; |
1668 | plugin->env->session_start (plugin->env->cls, | 1660 | plugin->env->session_start(plugin->env->cls, |
1669 | s->address, | 1661 | s->address, |
1670 | s, | 1662 | s, |
1671 | s->scope); | 1663 | s->scope); |
1672 | notify_session_monitor (plugin, | 1664 | notify_session_monitor(plugin, |
1673 | s, | 1665 | s, |
1674 | GNUNET_TRANSPORT_SS_UP); | 1666 | GNUNET_TRANSPORT_SS_UP); |
1675 | } | 1667 | } |
1676 | delay = plugin->env->receive (plugin->env->cls, | 1668 | delay = plugin->env->receive(plugin->env->cls, |
1677 | s->address, | 1669 | s->address, |
1678 | s, | 1670 | s, |
1679 | message); | 1671 | message); |
1680 | GNUNET_asprintf (&stat_txt, | 1672 | GNUNET_asprintf(&stat_txt, |
1681 | "# bytes received via %s_server", | 1673 | "# bytes received via %s_server", |
1682 | plugin->protocol); | 1674 | plugin->protocol); |
1683 | GNUNET_STATISTICS_update (plugin->env->stats, | 1675 | GNUNET_STATISTICS_update(plugin->env->stats, |
1684 | stat_txt, | 1676 | stat_txt, |
1685 | ntohs (message->size), | 1677 | ntohs(message->size), |
1686 | GNUNET_NO); | 1678 | GNUNET_NO); |
1687 | GNUNET_free (stat_txt); | 1679 | GNUNET_free(stat_txt); |
1688 | s->next_receive = GNUNET_TIME_relative_to_absolute (delay); | 1680 | s->next_receive = GNUNET_TIME_relative_to_absolute(delay); |
1689 | if (delay.rel_value_us > 0) | 1681 | if (delay.rel_value_us > 0) |
1690 | { | 1682 | { |
1691 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1683 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1692 | "Peer `%s' address `%s' next read delayed for %s\n", | 1684 | "Peer `%s' address `%s' next read delayed for %s\n", |
1693 | GNUNET_i2s (&s->target), | 1685 | GNUNET_i2s(&s->target), |
1694 | http_common_plugin_address_to_string (plugin->protocol, | 1686 | http_common_plugin_address_to_string(plugin->protocol, |
1695 | s->address->address, | 1687 | s->address->address, |
1696 | s->address->address_length), | 1688 | s->address->address_length), |
1697 | GNUNET_STRINGS_relative_time_to_string (delay, | 1689 | GNUNET_STRINGS_relative_time_to_string(delay, |
1698 | GNUNET_YES)); | 1690 | GNUNET_YES)); |
1699 | } | 1691 | } |
1700 | server_reschedule_session_timeout (s); | 1692 | server_reschedule_session_timeout(s); |
1701 | return GNUNET_OK; | 1693 | return GNUNET_OK; |
1702 | } | 1694 | } |
1703 | 1695 | ||
@@ -1711,15 +1703,15 @@ server_receive_mst_cb (void *cls, | |||
1711 | static void | 1703 | static void |
1712 | add_cors_headers(struct MHD_Response *response) | 1704 | add_cors_headers(struct MHD_Response *response) |
1713 | { | 1705 | { |
1714 | MHD_add_response_header (response, | 1706 | MHD_add_response_header(response, |
1715 | "Access-Control-Allow-Origin", | 1707 | "Access-Control-Allow-Origin", |
1716 | "*"); | 1708 | "*"); |
1717 | MHD_add_response_header (response, | 1709 | MHD_add_response_header(response, |
1718 | "Access-Control-Allow-Methods", | 1710 | "Access-Control-Allow-Methods", |
1719 | "GET, PUT, OPTIONS"); | 1711 | "GET, PUT, OPTIONS"); |
1720 | MHD_add_response_header (response, | 1712 | MHD_add_response_header(response, |
1721 | "Access-Control-Max-Age", | 1713 | "Access-Control-Max-Age", |
1722 | "86400"); | 1714 | "86400"); |
1723 | } | 1715 | } |
1724 | 1716 | ||
1725 | 1717 | ||
@@ -1737,14 +1729,14 @@ add_cors_headers(struct MHD_Response *response) | |||
1737 | * @return MHD_YES if connection is accepted, MHD_NO on reject | 1729 | * @return MHD_YES if connection is accepted, MHD_NO on reject |
1738 | */ | 1730 | */ |
1739 | static int | 1731 | static int |
1740 | server_access_cb (void *cls, | 1732 | server_access_cb(void *cls, |
1741 | struct MHD_Connection *mhd_connection, | 1733 | struct MHD_Connection *mhd_connection, |
1742 | const char *url, | 1734 | const char *url, |
1743 | const char *method, | 1735 | const char *method, |
1744 | const char *version, | 1736 | const char *version, |
1745 | const char *upload_data, | 1737 | const char *upload_data, |
1746 | size_t *upload_data_size, | 1738 | size_t *upload_data_size, |
1747 | void **httpSessionCache) | 1739 | void **httpSessionCache) |
1748 | { | 1740 | { |
1749 | struct HTTP_Server_Plugin *plugin = cls; | 1741 | struct HTTP_Server_Plugin *plugin = cls; |
1750 | struct ServerRequest *sc = *httpSessionCache; | 1742 | struct ServerRequest *sc = *httpSessionCache; |
@@ -1752,166 +1744,166 @@ server_access_cb (void *cls, | |||
1752 | struct MHD_Response *response; | 1744 | struct MHD_Response *response; |
1753 | int res = MHD_YES; | 1745 | int res = MHD_YES; |
1754 | 1746 | ||
1755 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1747 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1756 | _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), | 1748 | _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), |
1757 | sc, | 1749 | sc, |
1758 | plugin->cur_request, | 1750 | plugin->cur_request, |
1759 | plugin->max_request, | 1751 | plugin->max_request, |
1760 | method, | 1752 | method, |
1761 | version, | 1753 | version, |
1762 | url, | 1754 | url, |
1763 | (*upload_data_size)); | 1755 | (*upload_data_size)); |
1764 | if (NULL == sc) | 1756 | if (NULL == sc) |
1765 | { | ||
1766 | /* CORS pre-flight request */ | ||
1767 | if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method)) | ||
1768 | { | 1757 | { |
1769 | response = MHD_create_response_from_buffer (0, NULL, | 1758 | /* CORS pre-flight request */ |
1770 | MHD_RESPMEM_PERSISTENT); | 1759 | if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method)) |
1771 | add_cors_headers(response); | 1760 | { |
1772 | res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 1761 | response = MHD_create_response_from_buffer(0, NULL, |
1773 | MHD_destroy_response (response); | 1762 | MHD_RESPMEM_PERSISTENT); |
1774 | return res; | 1763 | add_cors_headers(response); |
1775 | } | 1764 | res = MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); |
1776 | /* new connection */ | 1765 | MHD_destroy_response(response); |
1777 | sc = server_lookup_connection (plugin, mhd_connection, url, method); | 1766 | return res; |
1778 | if (NULL != sc) | 1767 | } |
1779 | { | 1768 | /* new connection */ |
1780 | /* attach to new / existing session */ | 1769 | sc = server_lookup_connection(plugin, mhd_connection, url, method); |
1781 | (*httpSessionCache) = sc; | 1770 | if (NULL != sc) |
1782 | } | 1771 | { |
1783 | else | 1772 | /* attach to new / existing session */ |
1784 | { | 1773 | (*httpSessionCache) = sc; |
1785 | /* existing session already has matching connection, refuse */ | 1774 | } |
1786 | response = MHD_create_response_from_buffer (strlen (HTTP_ERROR_RESPONSE), | 1775 | else |
1787 | HTTP_ERROR_RESPONSE, | 1776 | { |
1788 | MHD_RESPMEM_PERSISTENT); | 1777 | /* existing session already has matching connection, refuse */ |
1789 | MHD_add_response_header (response, | 1778 | response = MHD_create_response_from_buffer(strlen(HTTP_ERROR_RESPONSE), |
1790 | MHD_HTTP_HEADER_CONTENT_TYPE, | 1779 | HTTP_ERROR_RESPONSE, |
1791 | "text/html"); | 1780 | MHD_RESPMEM_PERSISTENT); |
1792 | add_cors_headers(response); | 1781 | MHD_add_response_header(response, |
1793 | res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); | 1782 | MHD_HTTP_HEADER_CONTENT_TYPE, |
1794 | MHD_destroy_response (response); | 1783 | "text/html"); |
1795 | return res; | 1784 | add_cors_headers(response); |
1785 | res = MHD_queue_response(mhd_connection, MHD_HTTP_NOT_FOUND, response); | ||
1786 | MHD_destroy_response(response); | ||
1787 | return res; | ||
1788 | } | ||
1796 | } | 1789 | } |
1797 | } | ||
1798 | /* 'old' connection */ | 1790 | /* 'old' connection */ |
1799 | if (NULL == (s = sc->session)) | 1791 | if (NULL == (s = sc->session)) |
1800 | { | 1792 | { |
1801 | /* Session was already disconnected; | 1793 | /* Session was already disconnected; |
1802 | sent HTTP/1.1: 200 OK as response */ | 1794 | sent HTTP/1.1: 200 OK as response */ |
1803 | response = MHD_create_response_from_buffer (strlen ("Thank you!"), | 1795 | response = MHD_create_response_from_buffer(strlen("Thank you!"), |
1804 | "Thank you!", | 1796 | "Thank you!", |
1805 | MHD_RESPMEM_PERSISTENT); | 1797 | MHD_RESPMEM_PERSISTENT); |
1806 | add_cors_headers(response); | 1798 | add_cors_headers(response); |
1807 | MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 1799 | MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); |
1808 | MHD_destroy_response (response); | 1800 | MHD_destroy_response(response); |
1809 | return MHD_YES; | ||
1810 | } | ||
1811 | |||
1812 | if (sc->direction == _SEND) | ||
1813 | { | ||
1814 | response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 32 * 1024, | ||
1815 | &server_send_callback, sc, NULL); | ||
1816 | add_cors_headers(response); | ||
1817 | MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | ||
1818 | MHD_destroy_response (response); | ||
1819 | return MHD_YES; | ||
1820 | } | ||
1821 | if (sc->direction == _RECEIVE) | ||
1822 | { | ||
1823 | if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO)) | ||
1824 | { | ||
1825 | /* (*upload_data_size == 0) first callback when header are passed */ | ||
1826 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1827 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n", | ||
1828 | s, sc, | ||
1829 | GNUNET_i2s (&s->target), | ||
1830 | http_common_plugin_address_to_string (plugin->protocol, | ||
1831 | s->address->address, | ||
1832 | s->address->address_length)); | ||
1833 | sc->connected = GNUNET_YES; | ||
1834 | return MHD_YES; | 1801 | return MHD_YES; |
1835 | } | 1802 | } |
1836 | else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) | 1803 | |
1837 | { | 1804 | if (sc->direction == _SEND) |
1838 | /* (*upload_data_size == 0) when upload is complete */ | 1805 | { |
1839 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1806 | response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 32 * 1024, |
1840 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", | 1807 | &server_send_callback, sc, NULL); |
1841 | s, sc, | ||
1842 | GNUNET_i2s (&s->target), | ||
1843 | http_common_plugin_address_to_string (plugin->protocol, | ||
1844 | s->address->address, | ||
1845 | s->address->address_length)); | ||
1846 | sc->connected = GNUNET_NO; | ||
1847 | /* Sent HTTP/1.1: 200 OK as PUT Response\ */ | ||
1848 | response = MHD_create_response_from_buffer (strlen ("Thank you!"), | ||
1849 | "Thank you!", | ||
1850 | MHD_RESPMEM_PERSISTENT); | ||
1851 | add_cors_headers(response); | 1808 | add_cors_headers(response); |
1852 | MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); | 1809 | MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); |
1853 | MHD_destroy_response (response); | 1810 | MHD_destroy_response(response); |
1854 | return MHD_YES; | 1811 | return MHD_YES; |
1855 | } | 1812 | } |
1856 | else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) | 1813 | if (sc->direction == _RECEIVE) |
1857 | { | 1814 | { |
1858 | struct GNUNET_TIME_Relative delay; | 1815 | if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO)) |
1859 | 1816 | { | |
1860 | /* (*upload_data_size > 0) for every segment received */ | 1817 | /* (*upload_data_size == 0) first callback when header are passed */ |
1861 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1818 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1862 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", | 1819 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n", |
1863 | s, sc, | 1820 | s, sc, |
1864 | GNUNET_i2s (&s->target), | 1821 | GNUNET_i2s(&s->target), |
1865 | http_common_plugin_address_to_string (plugin->protocol, | 1822 | http_common_plugin_address_to_string(plugin->protocol, |
1866 | s->address->address, | 1823 | s->address->address, |
1867 | s->address->address_length), | 1824 | s->address->address_length)); |
1868 | *upload_data_size); | 1825 | sc->connected = GNUNET_YES; |
1869 | delay = GNUNET_TIME_absolute_get_remaining (s->next_receive); | 1826 | return MHD_YES; |
1870 | if (0 == delay.rel_value_us) | 1827 | } |
1871 | { | 1828 | else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) |
1872 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1873 | "PUT with %u bytes forwarded to MST\n", | ||
1874 | *upload_data_size); | ||
1875 | if (s->msg_tk == NULL) | ||
1876 | { | 1829 | { |
1877 | s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb, | 1830 | /* (*upload_data_size == 0) when upload is complete */ |
1878 | s); | 1831 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1832 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", | ||
1833 | s, sc, | ||
1834 | GNUNET_i2s(&s->target), | ||
1835 | http_common_plugin_address_to_string(plugin->protocol, | ||
1836 | s->address->address, | ||
1837 | s->address->address_length)); | ||
1838 | sc->connected = GNUNET_NO; | ||
1839 | /* Sent HTTP/1.1: 200 OK as PUT Response\ */ | ||
1840 | response = MHD_create_response_from_buffer(strlen("Thank you!"), | ||
1841 | "Thank you!", | ||
1842 | MHD_RESPMEM_PERSISTENT); | ||
1843 | add_cors_headers(response); | ||
1844 | MHD_queue_response(mhd_connection, MHD_HTTP_OK, response); | ||
1845 | MHD_destroy_response(response); | ||
1846 | return MHD_YES; | ||
1847 | } | ||
1848 | else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) | ||
1849 | { | ||
1850 | struct GNUNET_TIME_Relative delay; | ||
1851 | |||
1852 | /* (*upload_data_size > 0) for every segment received */ | ||
1853 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1854 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", | ||
1855 | s, sc, | ||
1856 | GNUNET_i2s(&s->target), | ||
1857 | http_common_plugin_address_to_string(plugin->protocol, | ||
1858 | s->address->address, | ||
1859 | s->address->address_length), | ||
1860 | *upload_data_size); | ||
1861 | delay = GNUNET_TIME_absolute_get_remaining(s->next_receive); | ||
1862 | if (0 == delay.rel_value_us) | ||
1863 | { | ||
1864 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1865 | "PUT with %u bytes forwarded to MST\n", | ||
1866 | *upload_data_size); | ||
1867 | if (s->msg_tk == NULL) | ||
1868 | { | ||
1869 | s->msg_tk = GNUNET_MST_create(&server_receive_mst_cb, | ||
1870 | s); | ||
1871 | } | ||
1872 | GNUNET_MST_from_buffer(s->msg_tk, | ||
1873 | upload_data, | ||
1874 | *upload_data_size, | ||
1875 | GNUNET_NO, GNUNET_NO); | ||
1876 | server_mhd_connection_timeout(plugin, s, | ||
1877 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL | ||
1878 | / 1000LL); | ||
1879 | (*upload_data_size) = 0; | ||
1880 | } | ||
1881 | else | ||
1882 | { | ||
1883 | /* delay processing */ | ||
1884 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1885 | "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n", | ||
1886 | s, | ||
1887 | sc, | ||
1888 | GNUNET_STRINGS_relative_time_to_string(delay, | ||
1889 | GNUNET_YES)); | ||
1890 | GNUNET_assert(s->server_recv->mhd_conn == mhd_connection); | ||
1891 | MHD_suspend_connection(s->server_recv->mhd_conn); | ||
1892 | s->server_recv->suspended = true; | ||
1893 | if (NULL == s->recv_wakeup_task) | ||
1894 | s->recv_wakeup_task | ||
1895 | = GNUNET_SCHEDULER_add_delayed(delay, | ||
1896 | &server_wake_up, | ||
1897 | s); | ||
1898 | } | ||
1899 | return MHD_YES; | ||
1879 | } | 1900 | } |
1880 | GNUNET_MST_from_buffer (s->msg_tk, | ||
1881 | upload_data, | ||
1882 | *upload_data_size, | ||
1883 | GNUNET_NO, GNUNET_NO); | ||
1884 | server_mhd_connection_timeout (plugin, s, | ||
1885 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL | ||
1886 | / 1000LL); | ||
1887 | (*upload_data_size) = 0; | ||
1888 | } | ||
1889 | else | 1901 | else |
1890 | { | 1902 | { |
1891 | /* delay processing */ | 1903 | GNUNET_break(0); |
1892 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1904 | return MHD_NO; |
1893 | "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n", | 1905 | } |
1894 | s, | ||
1895 | sc, | ||
1896 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
1897 | GNUNET_YES)); | ||
1898 | GNUNET_assert(s->server_recv->mhd_conn == mhd_connection); | ||
1899 | MHD_suspend_connection (s->server_recv->mhd_conn); | ||
1900 | s->server_recv->suspended = true; | ||
1901 | if (NULL == s->recv_wakeup_task) | ||
1902 | s->recv_wakeup_task | ||
1903 | = GNUNET_SCHEDULER_add_delayed (delay, | ||
1904 | &server_wake_up, | ||
1905 | s); | ||
1906 | } | ||
1907 | return MHD_YES; | ||
1908 | } | ||
1909 | else | ||
1910 | { | ||
1911 | GNUNET_break (0); | ||
1912 | return MHD_NO; | ||
1913 | } | 1906 | } |
1914 | } | ||
1915 | return res; | 1907 | return res; |
1916 | } | 1908 | } |
1917 | 1909 | ||
@@ -1924,54 +1916,54 @@ server_access_cb (void *cls, | |||
1924 | * @param httpSessionCache the pointer to distinguish | 1916 | * @param httpSessionCache the pointer to distinguish |
1925 | */ | 1917 | */ |
1926 | static void | 1918 | static void |
1927 | server_disconnect_cb (void *cls, | 1919 | server_disconnect_cb(void *cls, |
1928 | struct MHD_Connection *connection, | 1920 | struct MHD_Connection *connection, |
1929 | void **httpSessionCache) | 1921 | void **httpSessionCache) |
1930 | { | 1922 | { |
1931 | struct HTTP_Server_Plugin *plugin = cls; | 1923 | struct HTTP_Server_Plugin *plugin = cls; |
1932 | struct ServerRequest *sc = *httpSessionCache; | 1924 | struct ServerRequest *sc = *httpSessionCache; |
1933 | 1925 | ||
1934 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1926 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1935 | "Disconnect for connection %p\n", | 1927 | "Disconnect for connection %p\n", |
1936 | sc); | 1928 | sc); |
1937 | if (NULL == sc) | 1929 | if (NULL == sc) |
1938 | { | 1930 | { |
1939 | /* CORS pre-flight request finished */ | 1931 | /* CORS pre-flight request finished */ |
1940 | return; | 1932 | return; |
1941 | } | 1933 | } |
1942 | 1934 | ||
1943 | if (NULL != sc->session) | 1935 | if (NULL != sc->session) |
1944 | { | 1936 | { |
1945 | if (sc->direction == _SEND) | 1937 | if (sc->direction == _SEND) |
1946 | { | 1938 | { |
1947 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1939 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1948 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", | 1940 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", |
1949 | GNUNET_i2s (&sc->session->target), | 1941 | GNUNET_i2s(&sc->session->target), |
1950 | sc->session->server_send, | 1942 | sc->session->server_send, |
1951 | http_common_plugin_address_to_string (plugin->protocol, | 1943 | http_common_plugin_address_to_string(plugin->protocol, |
1952 | sc->session->address->address, | 1944 | sc->session->address->address, |
1953 | sc->session->address->address_length)); | 1945 | sc->session->address->address_length)); |
1954 | 1946 | ||
1955 | sc->session->server_send = NULL; | 1947 | sc->session->server_send = NULL; |
1956 | } | 1948 | } |
1957 | else if (sc->direction == _RECEIVE) | 1949 | else if (sc->direction == _RECEIVE) |
1958 | { | 1950 | { |
1959 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1951 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1960 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", | 1952 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", |
1961 | GNUNET_i2s (&sc->session->target), | 1953 | GNUNET_i2s(&sc->session->target), |
1962 | sc->session->server_recv, | 1954 | sc->session->server_recv, |
1963 | http_common_plugin_address_to_string (plugin->protocol, | 1955 | http_common_plugin_address_to_string(plugin->protocol, |
1964 | sc->session->address->address, | 1956 | sc->session->address->address, |
1965 | sc->session->address->address_length)); | 1957 | sc->session->address->address_length)); |
1966 | sc->session->server_recv = NULL; | 1958 | sc->session->server_recv = NULL; |
1967 | if (NULL != sc->session->msg_tk) | 1959 | if (NULL != sc->session->msg_tk) |
1968 | { | 1960 | { |
1969 | GNUNET_MST_destroy (sc->session->msg_tk); | 1961 | GNUNET_MST_destroy(sc->session->msg_tk); |
1970 | sc->session->msg_tk = NULL; | 1962 | sc->session->msg_tk = NULL; |
1971 | } | 1963 | } |
1972 | } | 1964 | } |
1973 | } | 1965 | } |
1974 | GNUNET_free (sc); | 1966 | GNUNET_free(sc); |
1975 | plugin->cur_request--; | 1967 | plugin->cur_request--; |
1976 | } | 1968 | } |
1977 | 1969 | ||
@@ -1986,10 +1978,10 @@ server_disconnect_cb (void *cls, | |||
1986 | * @see #MHD_OPTION_NOTIFY_CONNECTION | 1978 | * @see #MHD_OPTION_NOTIFY_CONNECTION |
1987 | */ | 1979 | */ |
1988 | static void | 1980 | static void |
1989 | server_connection_cb (void *cls, | 1981 | server_connection_cb(void *cls, |
1990 | struct MHD_Connection *connection, | 1982 | struct MHD_Connection *connection, |
1991 | void **socket_context, | 1983 | void **socket_context, |
1992 | enum MHD_ConnectionNotificationCode toe) | 1984 | enum MHD_ConnectionNotificationCode toe) |
1993 | { | 1985 | { |
1994 | struct HTTP_Server_Plugin *plugin = cls; | 1986 | struct HTTP_Server_Plugin *plugin = cls; |
1995 | const union MHD_ConnectionInfo *info; | 1987 | const union MHD_ConnectionInfo *info; |
@@ -1998,12 +1990,12 @@ server_connection_cb (void *cls, | |||
1998 | return; | 1990 | return; |
1999 | 1991 | ||
2000 | /* Reschedule to remove closed socket from our select set */ | 1992 | /* Reschedule to remove closed socket from our select set */ |
2001 | info = MHD_get_connection_info (connection, | 1993 | info = MHD_get_connection_info(connection, |
2002 | MHD_CONNECTION_INFO_DAEMON); | 1994 | MHD_CONNECTION_INFO_DAEMON); |
2003 | GNUNET_assert (NULL != info); | 1995 | GNUNET_assert(NULL != info); |
2004 | server_reschedule (plugin, | 1996 | server_reschedule(plugin, |
2005 | info->daemon, | 1997 | info->daemon, |
2006 | GNUNET_YES); | 1998 | GNUNET_YES); |
2007 | } | 1999 | } |
2008 | 2000 | ||
2009 | 2001 | ||
@@ -2016,27 +2008,27 @@ server_connection_cb (void *cls, | |||
2016 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected | 2008 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected |
2017 | */ | 2009 | */ |
2018 | static int | 2010 | static int |
2019 | server_accept_cb (void *cls, | 2011 | server_accept_cb(void *cls, |
2020 | const struct sockaddr *addr, | 2012 | const struct sockaddr *addr, |
2021 | socklen_t addr_len) | 2013 | socklen_t addr_len) |
2022 | { | 2014 | { |
2023 | struct HTTP_Server_Plugin *plugin = cls; | 2015 | struct HTTP_Server_Plugin *plugin = cls; |
2024 | 2016 | ||
2025 | if (plugin->cur_request <= plugin->max_request) | 2017 | if (plugin->cur_request <= plugin->max_request) |
2026 | { | 2018 | { |
2027 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2019 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2028 | _("Accepting connection (%u of %u) from `%s'\n"), | 2020 | _("Accepting connection (%u of %u) from `%s'\n"), |
2029 | plugin->cur_request, plugin->max_request, | 2021 | plugin->cur_request, plugin->max_request, |
2030 | GNUNET_a2s (addr, addr_len)); | 2022 | GNUNET_a2s(addr, addr_len)); |
2031 | return MHD_YES; | 2023 | return MHD_YES; |
2032 | } | 2024 | } |
2033 | else | 2025 | else |
2034 | { | 2026 | { |
2035 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2027 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2036 | _("Server reached maximum number connections (%u), rejecting new connection\n"), | 2028 | _("Server reached maximum number connections (%u), rejecting new connection\n"), |
2037 | plugin->max_request); | 2029 | plugin->max_request); |
2038 | return MHD_NO; | 2030 | return MHD_NO; |
2039 | } | 2031 | } |
2040 | } | 2032 | } |
2041 | 2033 | ||
2042 | 2034 | ||
@@ -2049,19 +2041,19 @@ server_accept_cb (void *cls, | |||
2049 | * will be called by MHD) | 2041 | * will be called by MHD) |
2050 | */ | 2042 | */ |
2051 | static void | 2043 | static void |
2052 | server_log (void *arg, | 2044 | server_log(void *arg, |
2053 | const char *fmt, | 2045 | const char *fmt, |
2054 | va_list ap) | 2046 | va_list ap) |
2055 | { | 2047 | { |
2056 | char text[1024]; | 2048 | char text[1024]; |
2057 | 2049 | ||
2058 | vsnprintf (text, | 2050 | vsnprintf(text, |
2059 | sizeof (text), | 2051 | sizeof(text), |
2060 | fmt, | 2052 | fmt, |
2061 | ap); | 2053 | ap); |
2062 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2054 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2063 | "Server: %s\n", | 2055 | "Server: %s\n", |
2064 | text); | 2056 | text); |
2065 | } | 2057 | } |
2066 | 2058 | ||
2067 | 2059 | ||
@@ -2073,32 +2065,32 @@ server_log (void *arg, | |||
2073 | * @return content of the file | 2065 | * @return content of the file |
2074 | */ | 2066 | */ |
2075 | static char * | 2067 | static char * |
2076 | server_load_file (const char *file) | 2068 | server_load_file(const char *file) |
2077 | { | 2069 | { |
2078 | struct GNUNET_DISK_FileHandle *gn_file; | 2070 | struct GNUNET_DISK_FileHandle *gn_file; |
2079 | uint64_t fsize; | 2071 | uint64_t fsize; |
2080 | char *text = NULL; | 2072 | char *text = NULL; |
2081 | 2073 | ||
2082 | if (GNUNET_OK != GNUNET_DISK_file_size (file, | 2074 | if (GNUNET_OK != GNUNET_DISK_file_size(file, |
2083 | &fsize, GNUNET_NO, GNUNET_YES)) | 2075 | &fsize, GNUNET_NO, GNUNET_YES)) |
2084 | return NULL; | 2076 | return NULL; |
2085 | text = GNUNET_malloc (fsize + 1); | 2077 | text = GNUNET_malloc(fsize + 1); |
2086 | gn_file = | 2078 | gn_file = |
2087 | GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ, | 2079 | GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ, |
2088 | GNUNET_DISK_PERM_USER_READ); | 2080 | GNUNET_DISK_PERM_USER_READ); |
2089 | if (NULL == gn_file) | 2081 | if (NULL == gn_file) |
2090 | { | 2082 | { |
2091 | GNUNET_free (text); | 2083 | GNUNET_free(text); |
2092 | return NULL; | 2084 | return NULL; |
2093 | } | 2085 | } |
2094 | if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize)) | 2086 | if (GNUNET_SYSERR == GNUNET_DISK_file_read(gn_file, text, fsize)) |
2095 | { | 2087 | { |
2096 | GNUNET_free (text); | 2088 | GNUNET_free(text); |
2097 | GNUNET_DISK_file_close (gn_file); | 2089 | GNUNET_DISK_file_close(gn_file); |
2098 | return NULL; | 2090 | return NULL; |
2099 | } | 2091 | } |
2100 | text[fsize] = '\0'; | 2092 | text[fsize] = '\0'; |
2101 | GNUNET_DISK_file_close (gn_file); | 2093 | GNUNET_DISK_file_close(gn_file); |
2102 | return text; | 2094 | return text; |
2103 | } | 2095 | } |
2104 | #endif | 2096 | #endif |
@@ -2112,7 +2104,7 @@ server_load_file (const char *file) | |||
2112 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 2104 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
2113 | */ | 2105 | */ |
2114 | static int | 2106 | static int |
2115 | server_load_certificate (struct HTTP_Server_Plugin *plugin) | 2107 | server_load_certificate(struct HTTP_Server_Plugin *plugin) |
2116 | { | 2108 | { |
2117 | int res = GNUNET_OK; | 2109 | int res = GNUNET_OK; |
2118 | char *key_file; | 2110 | char *key_file; |
@@ -2120,110 +2112,110 @@ server_load_certificate (struct HTTP_Server_Plugin *plugin) | |||
2120 | 2112 | ||
2121 | 2113 | ||
2122 | if (GNUNET_OK != | 2114 | if (GNUNET_OK != |
2123 | GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, | 2115 | GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg, |
2124 | plugin->name, | 2116 | plugin->name, |
2125 | "KEY_FILE", &key_file)) | 2117 | "KEY_FILE", &key_file)) |
2126 | { | 2118 | { |
2127 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 2119 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
2128 | plugin->name, "CERT_FILE"); | 2120 | plugin->name, "CERT_FILE"); |
2129 | return GNUNET_SYSERR; | 2121 | return GNUNET_SYSERR; |
2130 | } | 2122 | } |
2131 | if (GNUNET_OK != | 2123 | if (GNUNET_OK != |
2132 | GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, | 2124 | GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg, |
2133 | plugin->name, | 2125 | plugin->name, |
2134 | "CERT_FILE", &cert_file)) | 2126 | "CERT_FILE", &cert_file)) |
2135 | { | 2127 | { |
2136 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 2128 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
2137 | plugin->name, "CERT_FILE"); | 2129 | plugin->name, "CERT_FILE"); |
2138 | GNUNET_free (key_file); | 2130 | GNUNET_free(key_file); |
2139 | return GNUNET_SYSERR; | 2131 | return GNUNET_SYSERR; |
2140 | } | 2132 | } |
2141 | /* Get crypto init string from config. If not present, use | 2133 | /* Get crypto init string from config. If not present, use |
2142 | * default values */ | 2134 | * default values */ |
2143 | if (GNUNET_OK == | 2135 | if (GNUNET_OK == |
2144 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 2136 | GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, |
2145 | plugin->name, | 2137 | plugin->name, |
2146 | "CRYPTO_INIT", | 2138 | "CRYPTO_INIT", |
2147 | &plugin->crypto_init)) | 2139 | &plugin->crypto_init)) |
2148 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2140 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2149 | "Using crypto init string `%s'\n", | 2141 | "Using crypto init string `%s'\n", |
2150 | plugin->crypto_init); | 2142 | plugin->crypto_init); |
2151 | else | 2143 | else |
2152 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2144 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2153 | "Using default crypto init string \n"); | 2145 | "Using default crypto init string \n"); |
2154 | 2146 | ||
2155 | /* read key & certificates from file */ | 2147 | /* read key & certificates from file */ |
2156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2148 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2157 | "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n", | 2149 | "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n", |
2158 | key_file, cert_file); | 2150 | key_file, cert_file); |
2151 | |||
2152 | plugin->key = server_load_file(key_file); | ||
2153 | plugin->cert = server_load_file(cert_file); | ||
2154 | |||
2155 | if ((plugin->key == NULL) || (plugin->cert == NULL)) | ||
2156 | { | ||
2157 | struct GNUNET_OS_Process *cert_creation; | ||
2158 | |||
2159 | GNUNET_free_non_null(plugin->key); | ||
2160 | plugin->key = NULL; | ||
2161 | GNUNET_free_non_null(plugin->cert); | ||
2162 | plugin->cert = NULL; | ||
2163 | |||
2164 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2165 | "No usable TLS certificate found, creating certificate\n"); | ||
2166 | errno = 0; | ||
2167 | cert_creation = | ||
2168 | GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
2169 | NULL, NULL, NULL, | ||
2170 | "gnunet-transport-certificate-creation", | ||
2171 | "gnunet-transport-certificate-creation", | ||
2172 | key_file, | ||
2173 | cert_file, | ||
2174 | NULL); | ||
2175 | if (NULL == cert_creation) | ||
2176 | { | ||
2177 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
2178 | _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n")); | ||
2179 | GNUNET_free(key_file); | ||
2180 | GNUNET_free(cert_file); | ||
2181 | |||
2182 | GNUNET_free_non_null(plugin->key); | ||
2183 | plugin->key = NULL; | ||
2184 | GNUNET_free_non_null(plugin->cert); | ||
2185 | plugin->cert = NULL; | ||
2186 | GNUNET_free_non_null(plugin->crypto_init); | ||
2187 | plugin->crypto_init = NULL; | ||
2188 | |||
2189 | return GNUNET_SYSERR; | ||
2190 | } | ||
2191 | GNUNET_assert(GNUNET_OK == GNUNET_OS_process_wait(cert_creation)); | ||
2192 | GNUNET_OS_process_destroy(cert_creation); | ||
2159 | 2193 | ||
2160 | plugin->key = server_load_file (key_file); | 2194 | plugin->key = server_load_file(key_file); |
2161 | plugin->cert = server_load_file (cert_file); | 2195 | plugin->cert = server_load_file(cert_file); |
2196 | } | ||
2162 | 2197 | ||
2163 | if ((plugin->key == NULL) || (plugin->cert == NULL)) | 2198 | if ((plugin->key == NULL) || (plugin->cert == NULL)) |
2164 | { | 2199 | { |
2165 | struct GNUNET_OS_Process *cert_creation; | 2200 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2166 | 2201 | _("No usable TLS certificate found and creating one at `%s/%s' failed!\n"), | |
2167 | GNUNET_free_non_null (plugin->key); | 2202 | key_file, cert_file); |
2168 | plugin->key = NULL; | 2203 | GNUNET_free(key_file); |
2169 | GNUNET_free_non_null (plugin->cert); | 2204 | GNUNET_free(cert_file); |
2170 | plugin->cert = NULL; | 2205 | |
2171 | 2206 | GNUNET_free_non_null(plugin->key); | |
2172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2173 | "No usable TLS certificate found, creating certificate\n"); | ||
2174 | errno = 0; | ||
2175 | cert_creation = | ||
2176 | GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
2177 | NULL, NULL, NULL, | ||
2178 | "gnunet-transport-certificate-creation", | ||
2179 | "gnunet-transport-certificate-creation", | ||
2180 | key_file, | ||
2181 | cert_file, | ||
2182 | NULL); | ||
2183 | if (NULL == cert_creation) | ||
2184 | { | ||
2185 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2186 | _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n")); | ||
2187 | GNUNET_free (key_file); | ||
2188 | GNUNET_free (cert_file); | ||
2189 | |||
2190 | GNUNET_free_non_null (plugin->key); | ||
2191 | plugin->key = NULL; | 2207 | plugin->key = NULL; |
2192 | GNUNET_free_non_null (plugin->cert); | 2208 | GNUNET_free_non_null(plugin->cert); |
2193 | plugin->cert = NULL; | 2209 | plugin->cert = NULL; |
2194 | GNUNET_free_non_null (plugin->crypto_init); | 2210 | GNUNET_free_non_null(plugin->crypto_init); |
2195 | plugin->crypto_init = NULL; | 2211 | plugin->crypto_init = NULL; |
2196 | 2212 | ||
2197 | return GNUNET_SYSERR; | 2213 | return GNUNET_SYSERR; |
2198 | } | 2214 | } |
2199 | GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation)); | 2215 | GNUNET_free(key_file); |
2200 | GNUNET_OS_process_destroy (cert_creation); | 2216 | GNUNET_free(cert_file); |
2201 | 2217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | |
2202 | plugin->key = server_load_file (key_file); | 2218 | "TLS certificate loaded\n"); |
2203 | plugin->cert = server_load_file (cert_file); | ||
2204 | } | ||
2205 | |||
2206 | if ((plugin->key == NULL) || (plugin->cert == NULL)) | ||
2207 | { | ||
2208 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2209 | _("No usable TLS certificate found and creating one at `%s/%s' failed!\n"), | ||
2210 | key_file, cert_file); | ||
2211 | GNUNET_free (key_file); | ||
2212 | GNUNET_free (cert_file); | ||
2213 | |||
2214 | GNUNET_free_non_null (plugin->key); | ||
2215 | plugin->key = NULL; | ||
2216 | GNUNET_free_non_null (plugin->cert); | ||
2217 | plugin->cert = NULL; | ||
2218 | GNUNET_free_non_null (plugin->crypto_init); | ||
2219 | plugin->crypto_init = NULL; | ||
2220 | |||
2221 | return GNUNET_SYSERR; | ||
2222 | } | ||
2223 | GNUNET_free (key_file); | ||
2224 | GNUNET_free (cert_file); | ||
2225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2226 | "TLS certificate loaded\n"); | ||
2227 | return res; | 2219 | return res; |
2228 | } | 2220 | } |
2229 | #endif | 2221 | #endif |
@@ -2239,81 +2231,81 @@ server_load_certificate (struct HTTP_Server_Plugin *plugin) | |||
2239 | * @return NULL on error | 2231 | * @return NULL on error |
2240 | */ | 2232 | */ |
2241 | static struct MHD_Daemon * | 2233 | static struct MHD_Daemon * |
2242 | run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin, | 2234 | run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, |
2243 | const struct sockaddr_in *addr, | 2235 | const struct sockaddr_in *addr, |
2244 | int v6) | 2236 | int v6) |
2245 | { | 2237 | { |
2246 | struct MHD_Daemon *server; | 2238 | struct MHD_Daemon *server; |
2247 | unsigned int timeout; | 2239 | unsigned int timeout; |
2248 | 2240 | ||
2249 | #if MHD_VERSION >= 0x00090E00 | 2241 | #if MHD_VERSION >= 0x00090E00 |
2250 | timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL; | 2242 | timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL; |
2251 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2243 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2252 | "MHD can set timeout per connection! Default time out %u sec.\n", | 2244 | "MHD can set timeout per connection! Default time out %u sec.\n", |
2253 | timeout); | 2245 | timeout); |
2254 | #else | 2246 | #else |
2255 | timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL; | 2247 | timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL; |
2256 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2248 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2257 | "MHD cannot set timeout per connection! Default time out %u sec.\n", | 2249 | "MHD cannot set timeout per connection! Default time out %u sec.\n", |
2258 | timeout); | 2250 | timeout); |
2259 | #endif | 2251 | #endif |
2260 | server = MHD_start_daemon ( | 2252 | server = MHD_start_daemon( |
2261 | #if VERBOSE_SERVER | 2253 | #if VERBOSE_SERVER |
2262 | MHD_USE_DEBUG | | 2254 | MHD_USE_DEBUG | |
2263 | #endif | 2255 | #endif |
2264 | #if BUILD_HTTPS | 2256 | #if BUILD_HTTPS |
2265 | MHD_USE_SSL | | 2257 | MHD_USE_SSL | |
2266 | #endif | 2258 | #endif |
2267 | MHD_USE_SUSPEND_RESUME | | 2259 | MHD_USE_SUSPEND_RESUME | |
2268 | v6, | 2260 | v6, |
2269 | plugin->port, | 2261 | plugin->port, |
2270 | &server_accept_cb, plugin, | 2262 | &server_accept_cb, plugin, |
2271 | &server_access_cb, plugin, | 2263 | &server_access_cb, plugin, |
2272 | MHD_OPTION_SOCK_ADDR, | 2264 | MHD_OPTION_SOCK_ADDR, |
2273 | addr, | 2265 | addr, |
2274 | MHD_OPTION_CONNECTION_LIMIT, | 2266 | MHD_OPTION_CONNECTION_LIMIT, |
2275 | (unsigned int) plugin->max_request, | 2267 | (unsigned int)plugin->max_request, |
2276 | #if BUILD_HTTPS | 2268 | #if BUILD_HTTPS |
2277 | MHD_OPTION_HTTPS_PRIORITIES, | 2269 | MHD_OPTION_HTTPS_PRIORITIES, |
2278 | plugin->crypto_init, | 2270 | plugin->crypto_init, |
2279 | MHD_OPTION_HTTPS_MEM_KEY, | 2271 | MHD_OPTION_HTTPS_MEM_KEY, |
2280 | plugin->key, | 2272 | plugin->key, |
2281 | MHD_OPTION_HTTPS_MEM_CERT, | 2273 | MHD_OPTION_HTTPS_MEM_CERT, |
2282 | plugin->cert, | 2274 | plugin->cert, |
2283 | #endif | 2275 | #endif |
2284 | MHD_OPTION_CONNECTION_TIMEOUT, | 2276 | MHD_OPTION_CONNECTION_TIMEOUT, |
2285 | timeout, | 2277 | timeout, |
2286 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 2278 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
2287 | (size_t) (2 * | 2279 | (size_t)(2 * |
2288 | GNUNET_MAX_MESSAGE_SIZE), | 2280 | GNUNET_MAX_MESSAGE_SIZE), |
2289 | MHD_OPTION_NOTIFY_COMPLETED, | 2281 | MHD_OPTION_NOTIFY_COMPLETED, |
2290 | &server_disconnect_cb, plugin, | 2282 | &server_disconnect_cb, plugin, |
2291 | MHD_OPTION_NOTIFY_CONNECTION, | 2283 | MHD_OPTION_NOTIFY_CONNECTION, |
2292 | &server_connection_cb, plugin, | 2284 | &server_connection_cb, plugin, |
2293 | MHD_OPTION_EXTERNAL_LOGGER, | 2285 | MHD_OPTION_EXTERNAL_LOGGER, |
2294 | &server_log, NULL, | 2286 | &server_log, NULL, |
2295 | MHD_OPTION_END); | 2287 | MHD_OPTION_END); |
2296 | #ifdef TCP_STEALTH | 2288 | #ifdef TCP_STEALTH |
2297 | if ( (NULL != server) && | 2289 | if ((NULL != server) && |
2298 | (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH)) ) | 2290 | (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH))) |
2299 | { | 2291 | { |
2300 | const union MHD_DaemonInfo *di; | 2292 | const union MHD_DaemonInfo *di; |
2301 | 2293 | ||
2302 | di = MHD_get_daemon_info (server, | 2294 | di = MHD_get_daemon_info(server, |
2303 | MHD_DAEMON_INFO_LISTEN_FD, | 2295 | MHD_DAEMON_INFO_LISTEN_FD, |
2304 | NULL); | 2296 | NULL); |
2305 | if ( (0 != setsockopt ((int) di->listen_fd, | 2297 | if ((0 != setsockopt((int)di->listen_fd, |
2306 | IPPROTO_TCP, | 2298 | IPPROTO_TCP, |
2307 | TCP_STEALTH, | 2299 | TCP_STEALTH, |
2308 | plugin->env->my_identity, | 2300 | plugin->env->my_identity, |
2309 | sizeof (struct GNUNET_PeerIdentity))) ) | 2301 | sizeof(struct GNUNET_PeerIdentity)))) |
2310 | { | 2302 | { |
2311 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2312 | _("TCP_STEALTH not supported on this platform.\n")); | 2304 | _("TCP_STEALTH not supported on this platform.\n")); |
2313 | MHD_stop_daemon (server); | 2305 | MHD_stop_daemon(server); |
2314 | server = NULL; | 2306 | server = NULL; |
2307 | } | ||
2315 | } | 2308 | } |
2316 | } | ||
2317 | #endif | 2309 | #endif |
2318 | return server; | 2310 | return server; |
2319 | } | 2311 | } |
@@ -2326,76 +2318,76 @@ run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin, | |||
2326 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 2318 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
2327 | */ | 2319 | */ |
2328 | static int | 2320 | static int |
2329 | server_start (struct HTTP_Server_Plugin *plugin) | 2321 | server_start(struct HTTP_Server_Plugin *plugin) |
2330 | { | 2322 | { |
2331 | const char *msg; | 2323 | const char *msg; |
2332 | 2324 | ||
2333 | GNUNET_assert (NULL != plugin); | 2325 | GNUNET_assert(NULL != plugin); |
2334 | #if BUILD_HTTPS | 2326 | #if BUILD_HTTPS |
2335 | if (GNUNET_SYSERR == server_load_certificate (plugin)) | 2327 | if (GNUNET_SYSERR == server_load_certificate(plugin)) |
2336 | { | 2328 | { |
2337 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2329 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2338 | _("Could not load or create server certificate! Loading plugin failed!\n")); | 2330 | _("Could not load or create server certificate! Loading plugin failed!\n")); |
2339 | return GNUNET_SYSERR; | 2331 | return GNUNET_SYSERR; |
2340 | } | 2332 | } |
2341 | #endif | 2333 | #endif |
2342 | 2334 | ||
2343 | 2335 | ||
2344 | 2336 | ||
2345 | plugin->server_v4 = NULL; | 2337 | plugin->server_v4 = NULL; |
2346 | if (GNUNET_YES == plugin->use_ipv4) | 2338 | if (GNUNET_YES == plugin->use_ipv4) |
2347 | { | ||
2348 | plugin->server_v4 | ||
2349 | = run_mhd_start_daemon (plugin, | ||
2350 | (const struct sockaddr_in *) plugin->server_addr_v4, | ||
2351 | MHD_NO_FLAG); | ||
2352 | |||
2353 | if (NULL == plugin->server_v4) | ||
2354 | { | 2339 | { |
2355 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2340 | plugin->server_v4 |
2356 | "Failed to start %s IPv4 server component on port %u\n", | 2341 | = run_mhd_start_daemon(plugin, |
2357 | plugin->name, | 2342 | (const struct sockaddr_in *)plugin->server_addr_v4, |
2358 | plugin->port); | 2343 | MHD_NO_FLAG); |
2344 | |||
2345 | if (NULL == plugin->server_v4) | ||
2346 | { | ||
2347 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
2348 | "Failed to start %s IPv4 server component on port %u\n", | ||
2349 | plugin->name, | ||
2350 | plugin->port); | ||
2351 | } | ||
2352 | else | ||
2353 | server_reschedule(plugin, | ||
2354 | plugin->server_v4, | ||
2355 | GNUNET_NO); | ||
2359 | } | 2356 | } |
2360 | else | ||
2361 | server_reschedule (plugin, | ||
2362 | plugin->server_v4, | ||
2363 | GNUNET_NO); | ||
2364 | } | ||
2365 | 2357 | ||
2366 | 2358 | ||
2367 | plugin->server_v6 = NULL; | 2359 | plugin->server_v6 = NULL; |
2368 | if (GNUNET_YES == plugin->use_ipv6) | 2360 | if (GNUNET_YES == plugin->use_ipv6) |
2369 | { | ||
2370 | plugin->server_v6 | ||
2371 | = run_mhd_start_daemon (plugin, | ||
2372 | (const struct sockaddr_in *) plugin->server_addr_v6, | ||
2373 | MHD_USE_IPv6); | ||
2374 | if (NULL == plugin->server_v6) | ||
2375 | { | 2361 | { |
2376 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2362 | plugin->server_v6 |
2377 | "Failed to start %s IPv6 server component on port %u\n", | 2363 | = run_mhd_start_daemon(plugin, |
2378 | plugin->name, | 2364 | (const struct sockaddr_in *)plugin->server_addr_v6, |
2379 | plugin->port); | 2365 | MHD_USE_IPv6); |
2366 | if (NULL == plugin->server_v6) | ||
2367 | { | ||
2368 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
2369 | "Failed to start %s IPv6 server component on port %u\n", | ||
2370 | plugin->name, | ||
2371 | plugin->port); | ||
2372 | } | ||
2373 | else | ||
2374 | { | ||
2375 | server_reschedule(plugin, | ||
2376 | plugin->server_v6, | ||
2377 | GNUNET_NO); | ||
2378 | } | ||
2380 | } | 2379 | } |
2381 | else | 2380 | msg = "No"; |
2381 | if ((NULL == plugin->server_v6) && | ||
2382 | (NULL == plugin->server_v4)) | ||
2382 | { | 2383 | { |
2383 | server_reschedule (plugin, | 2384 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2384 | plugin->server_v6, | 2385 | "%s %s server component started on port %u\n", |
2385 | GNUNET_NO); | 2386 | msg, |
2387 | plugin->name, | ||
2388 | plugin->port); | ||
2389 | return GNUNET_SYSERR; | ||
2386 | } | 2390 | } |
2387 | } | ||
2388 | msg = "No"; | ||
2389 | if ( (NULL == plugin->server_v6) && | ||
2390 | (NULL == plugin->server_v4) ) | ||
2391 | { | ||
2392 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2393 | "%s %s server component started on port %u\n", | ||
2394 | msg, | ||
2395 | plugin->name, | ||
2396 | plugin->port); | ||
2397 | return GNUNET_SYSERR; | ||
2398 | } | ||
2399 | if ((NULL != plugin->server_v6) && | 2391 | if ((NULL != plugin->server_v6) && |
2400 | (NULL != plugin->server_v4)) | 2392 | (NULL != plugin->server_v4)) |
2401 | msg = "IPv4 and IPv6"; | 2393 | msg = "IPv4 and IPv6"; |
@@ -2403,11 +2395,11 @@ server_start (struct HTTP_Server_Plugin *plugin) | |||
2403 | msg = "IPv6"; | 2395 | msg = "IPv6"; |
2404 | else if (NULL != plugin->server_v4) | 2396 | else if (NULL != plugin->server_v4) |
2405 | msg = "IPv4"; | 2397 | msg = "IPv4"; |
2406 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2398 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2407 | "%s %s server component started on port %u\n", | 2399 | "%s %s server component started on port %u\n", |
2408 | msg, | 2400 | msg, |
2409 | plugin->name, | 2401 | plugin->name, |
2410 | plugin->port); | 2402 | plugin->port); |
2411 | return GNUNET_OK; | 2403 | return GNUNET_OK; |
2412 | } | 2404 | } |
2413 | 2405 | ||
@@ -2421,47 +2413,47 @@ server_start (struct HTTP_Server_Plugin *plugin) | |||
2421 | * @param addrlen address length | 2413 | * @param addrlen address length |
2422 | */ | 2414 | */ |
2423 | static void | 2415 | static void |
2424 | server_add_address (void *cls, | 2416 | server_add_address(void *cls, |
2425 | int add_remove, | 2417 | int add_remove, |
2426 | const struct sockaddr *addr, | 2418 | const struct sockaddr *addr, |
2427 | socklen_t addrlen) | 2419 | socklen_t addrlen) |
2428 | { | 2420 | { |
2429 | struct HTTP_Server_Plugin *plugin = cls; | 2421 | struct HTTP_Server_Plugin *plugin = cls; |
2430 | struct GNUNET_HELLO_Address *address; | 2422 | struct GNUNET_HELLO_Address *address; |
2431 | struct HttpAddressWrapper *w = NULL; | 2423 | struct HttpAddressWrapper *w = NULL; |
2432 | 2424 | ||
2433 | w = GNUNET_new (struct HttpAddressWrapper); | 2425 | w = GNUNET_new(struct HttpAddressWrapper); |
2434 | w->address = http_common_address_from_socket (plugin->protocol, | 2426 | w->address = http_common_address_from_socket(plugin->protocol, |
2435 | addr, | 2427 | addr, |
2436 | addrlen); | 2428 | addrlen); |
2437 | if (NULL == w->address) | 2429 | if (NULL == w->address) |
2438 | { | 2430 | { |
2439 | GNUNET_free (w); | 2431 | GNUNET_free(w); |
2440 | return; | 2432 | return; |
2441 | } | 2433 | } |
2442 | w->addrlen = http_common_address_get_size (w->address); | 2434 | w->addrlen = http_common_address_get_size(w->address); |
2443 | 2435 | ||
2444 | GNUNET_CONTAINER_DLL_insert (plugin->addr_head, | 2436 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, |
2445 | plugin->addr_tail, | 2437 | plugin->addr_tail, |
2446 | w); | 2438 | w); |
2447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2439 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2448 | "Notifying transport to add address `%s'\n", | 2440 | "Notifying transport to add address `%s'\n", |
2449 | http_common_plugin_address_to_string (plugin->protocol, | 2441 | http_common_plugin_address_to_string(plugin->protocol, |
2450 | w->address, | 2442 | w->address, |
2451 | w->addrlen)); | 2443 | w->addrlen)); |
2452 | /* modify our published address list */ | 2444 | /* modify our published address list */ |
2453 | #if BUILD_HTTPS | 2445 | #if BUILD_HTTPS |
2454 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 2446 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
2455 | "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | 2447 | "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); |
2456 | #else | 2448 | #else |
2457 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 2449 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
2458 | "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | 2450 | "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); |
2459 | #endif | 2451 | #endif |
2460 | 2452 | ||
2461 | plugin->env->notify_address (plugin->env->cls, | 2453 | plugin->env->notify_address(plugin->env->cls, |
2462 | add_remove, | 2454 | add_remove, |
2463 | address); | 2455 | address); |
2464 | GNUNET_HELLO_address_free (address); | 2456 | GNUNET_HELLO_address_free(address); |
2465 | } | 2457 | } |
2466 | 2458 | ||
2467 | 2459 | ||
@@ -2474,10 +2466,10 @@ server_add_address (void *cls, | |||
2474 | * @param addrlen address length | 2466 | * @param addrlen address length |
2475 | */ | 2467 | */ |
2476 | static void | 2468 | static void |
2477 | server_remove_address (void *cls, | 2469 | server_remove_address(void *cls, |
2478 | int add_remove, | 2470 | int add_remove, |
2479 | const struct sockaddr *addr, | 2471 | const struct sockaddr *addr, |
2480 | socklen_t addrlen) | 2472 | socklen_t addrlen) |
2481 | { | 2473 | { |
2482 | struct HTTP_Server_Plugin *plugin = cls; | 2474 | struct HTTP_Server_Plugin *plugin = cls; |
2483 | struct GNUNET_HELLO_Address *address; | 2475 | struct GNUNET_HELLO_Address *address; |
@@ -2485,48 +2477,48 @@ server_remove_address (void *cls, | |||
2485 | size_t saddr_len; | 2477 | size_t saddr_len; |
2486 | void * saddr; | 2478 | void * saddr; |
2487 | 2479 | ||
2488 | saddr = http_common_address_from_socket (plugin->protocol, | 2480 | saddr = http_common_address_from_socket(plugin->protocol, |
2489 | addr, | 2481 | addr, |
2490 | addrlen); | 2482 | addrlen); |
2491 | if (NULL == saddr) | 2483 | if (NULL == saddr) |
2492 | return; | 2484 | return; |
2493 | saddr_len = http_common_address_get_size (saddr); | 2485 | saddr_len = http_common_address_get_size(saddr); |
2494 | 2486 | ||
2495 | while (NULL != w) | 2487 | while (NULL != w) |
2496 | { | 2488 | { |
2497 | if (GNUNET_YES == | 2489 | if (GNUNET_YES == |
2498 | http_common_cmp_addresses (w->address, | 2490 | http_common_cmp_addresses(w->address, |
2499 | w->addrlen, | 2491 | w->addrlen, |
2500 | saddr, | 2492 | saddr, |
2501 | saddr_len)) | 2493 | saddr_len)) |
2502 | break; | 2494 | break; |
2503 | w = w->next; | 2495 | w = w->next; |
2504 | } | 2496 | } |
2505 | GNUNET_free (saddr); | 2497 | GNUNET_free(saddr); |
2506 | 2498 | ||
2507 | if (NULL == w) | 2499 | if (NULL == w) |
2508 | return; | 2500 | return; |
2509 | 2501 | ||
2510 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2502 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2511 | "Notifying transport to remove address `%s'\n", | 2503 | "Notifying transport to remove address `%s'\n", |
2512 | http_common_plugin_address_to_string (plugin->protocol, | 2504 | http_common_plugin_address_to_string(plugin->protocol, |
2513 | w->address, | 2505 | w->address, |
2514 | w->addrlen)); | 2506 | w->addrlen)); |
2515 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, | 2507 | GNUNET_CONTAINER_DLL_remove(plugin->addr_head, |
2516 | plugin->addr_tail, | 2508 | plugin->addr_tail, |
2517 | w); | 2509 | w); |
2518 | /* modify our published address list */ | 2510 | /* modify our published address list */ |
2519 | #if BUILD_HTTPS | 2511 | #if BUILD_HTTPS |
2520 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 2512 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
2521 | "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | 2513 | "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); |
2522 | #else | 2514 | #else |
2523 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 2515 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
2524 | "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | 2516 | "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); |
2525 | #endif | 2517 | #endif |
2526 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | 2518 | plugin->env->notify_address(plugin->env->cls, add_remove, address); |
2527 | GNUNET_HELLO_address_free (address); | 2519 | GNUNET_HELLO_address_free(address); |
2528 | GNUNET_free (w->address); | 2520 | GNUNET_free(w->address); |
2529 | GNUNET_free (w); | 2521 | GNUNET_free(w); |
2530 | } | 2522 | } |
2531 | 2523 | ||
2532 | 2524 | ||
@@ -2544,66 +2536,67 @@ server_remove_address (void *cls, | |||
2544 | * @param addrlen actual lenght of the address | 2536 | * @param addrlen actual lenght of the address |
2545 | */ | 2537 | */ |
2546 | static void | 2538 | static void |
2547 | server_nat_port_map_callback (void *cls, | 2539 | server_nat_port_map_callback(void *cls, |
2548 | void **app_ctx, | 2540 | void **app_ctx, |
2549 | int add_remove, | 2541 | int add_remove, |
2550 | enum GNUNET_NAT_AddressClass ac, | 2542 | enum GNUNET_NAT_AddressClass ac, |
2551 | const struct sockaddr *addr, | 2543 | const struct sockaddr *addr, |
2552 | socklen_t addrlen) | 2544 | socklen_t addrlen) |
2553 | { | 2545 | { |
2554 | struct HTTP_Server_Plugin *plugin = cls; | 2546 | struct HTTP_Server_Plugin *plugin = cls; |
2555 | 2547 | ||
2556 | (void) app_ctx; | 2548 | (void)app_ctx; |
2557 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2549 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2558 | "NAT called to %s address `%s'\n", | 2550 | "NAT called to %s address `%s'\n", |
2559 | (add_remove == GNUNET_NO) ? "remove" : "add", | 2551 | (add_remove == GNUNET_NO) ? "remove" : "add", |
2560 | GNUNET_a2s (addr, addrlen)); | 2552 | GNUNET_a2s(addr, addrlen)); |
2561 | 2553 | ||
2562 | if (AF_INET == addr->sa_family) | 2554 | if (AF_INET == addr->sa_family) |
2563 | { | 2555 | { |
2564 | struct sockaddr_in *s4 = (struct sockaddr_in *) addr; | 2556 | struct sockaddr_in *s4 = (struct sockaddr_in *)addr; |
2565 | 2557 | ||
2566 | if (GNUNET_NO == plugin->use_ipv4) | 2558 | if (GNUNET_NO == plugin->use_ipv4) |
2567 | return; | 2559 | return; |
2568 | 2560 | ||
2569 | if ((NULL != plugin->server_addr_v4) && | 2561 | if ((NULL != plugin->server_addr_v4) && |
2570 | (0 != memcmp (&plugin->server_addr_v4->sin_addr, | 2562 | (0 != memcmp(&plugin->server_addr_v4->sin_addr, |
2571 | &s4->sin_addr, | 2563 | &s4->sin_addr, |
2572 | sizeof (struct in_addr)))) | 2564 | sizeof(struct in_addr)))) |
2573 | { | 2565 | { |
2574 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2566 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2575 | "Skipping address `%s' (not bindto address)\n", | 2567 | "Skipping address `%s' (not bindto address)\n", |
2576 | GNUNET_a2s (addr, addrlen)); | 2568 | GNUNET_a2s(addr, addrlen)); |
2577 | return; | 2569 | return; |
2570 | } | ||
2578 | } | 2571 | } |
2579 | } | ||
2580 | 2572 | ||
2581 | if (AF_INET6 == addr->sa_family) | 2573 | if (AF_INET6 == addr->sa_family) |
2582 | { | ||
2583 | struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) addr; | ||
2584 | if (GNUNET_NO == plugin->use_ipv6) | ||
2585 | return; | ||
2586 | |||
2587 | if ((NULL != plugin->server_addr_v6) && | ||
2588 | (0 != memcmp (&plugin->server_addr_v6->sin6_addr, | ||
2589 | &s6->sin6_addr, sizeof (struct in6_addr)))) | ||
2590 | { | 2574 | { |
2591 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2575 | struct sockaddr_in6 *s6 = (struct sockaddr_in6 *)addr; |
2592 | "Skipping address `%s' (not bindto address)\n", | 2576 | if (GNUNET_NO == plugin->use_ipv6) |
2593 | GNUNET_a2s (addr, addrlen)); | 2577 | return; |
2594 | return; | 2578 | |
2579 | if ((NULL != plugin->server_addr_v6) && | ||
2580 | (0 != memcmp(&plugin->server_addr_v6->sin6_addr, | ||
2581 | &s6->sin6_addr, sizeof(struct in6_addr)))) | ||
2582 | { | ||
2583 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
2584 | "Skipping address `%s' (not bindto address)\n", | ||
2585 | GNUNET_a2s(addr, addrlen)); | ||
2586 | return; | ||
2587 | } | ||
2595 | } | 2588 | } |
2596 | } | ||
2597 | 2589 | ||
2598 | switch (add_remove) | 2590 | switch (add_remove) |
2599 | { | 2591 | { |
2600 | case GNUNET_YES: | 2592 | case GNUNET_YES: |
2601 | server_add_address (cls, add_remove, addr, addrlen); | 2593 | server_add_address(cls, add_remove, addr, addrlen); |
2602 | break; | 2594 | break; |
2603 | case GNUNET_NO: | 2595 | |
2604 | server_remove_address (cls, add_remove, addr, addrlen); | 2596 | case GNUNET_NO: |
2605 | break; | 2597 | server_remove_address(cls, add_remove, addr, addrlen); |
2606 | } | 2598 | break; |
2599 | } | ||
2607 | } | 2600 | } |
2608 | 2601 | ||
2609 | 2602 | ||
@@ -2618,11 +2611,11 @@ server_nat_port_map_callback (void *cls, | |||
2618 | * @return number of addresses | 2611 | * @return number of addresses |
2619 | */ | 2612 | */ |
2620 | static int | 2613 | static int |
2621 | server_get_addresses (struct HTTP_Server_Plugin *plugin, | 2614 | server_get_addresses(struct HTTP_Server_Plugin *plugin, |
2622 | const char *service_name, | 2615 | const char *service_name, |
2623 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 2616 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
2624 | struct sockaddr ***addrs, | 2617 | struct sockaddr ***addrs, |
2625 | socklen_t ** addr_lens) | 2618 | socklen_t ** addr_lens) |
2626 | { | 2619 | { |
2627 | int disablev6; | 2620 | int disablev6; |
2628 | unsigned long long port; | 2621 | unsigned long long port; |
@@ -2643,156 +2636,156 @@ server_get_addresses (struct HTTP_Server_Plugin *plugin, | |||
2643 | disablev6 = !plugin->use_ipv6; | 2636 | disablev6 = !plugin->use_ipv6; |
2644 | 2637 | ||
2645 | port = 0; | 2638 | port = 0; |
2646 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) | 2639 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) |
2647 | { | ||
2648 | GNUNET_break (GNUNET_OK == | ||
2649 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, | ||
2650 | "PORT", &port)); | ||
2651 | if (port > 65535) | ||
2652 | { | 2640 | { |
2653 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2641 | GNUNET_break(GNUNET_OK == |
2654 | _("Require valid port number for service in configuration!\n")); | 2642 | GNUNET_CONFIGURATION_get_value_number(cfg, service_name, |
2655 | return GNUNET_SYSERR; | 2643 | "PORT", &port)); |
2644 | if (port > 65535) | ||
2645 | { | ||
2646 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
2647 | _("Require valid port number for service in configuration!\n")); | ||
2648 | return GNUNET_SYSERR; | ||
2649 | } | ||
2656 | } | 2650 | } |
2657 | } | ||
2658 | if (0 == port) | 2651 | if (0 == port) |
2659 | { | 2652 | { |
2660 | LOG (GNUNET_ERROR_TYPE_INFO, | 2653 | LOG(GNUNET_ERROR_TYPE_INFO, |
2661 | "Starting in listen only mode\n"); | 2654 | "Starting in listen only mode\n"); |
2662 | return -1; /* listen only */ | 2655 | return -1; /* listen only */ |
2663 | } | 2656 | } |
2664 | 2657 | ||
2665 | 2658 | ||
2666 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, | 2659 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, |
2667 | "BINDTO")) | 2660 | "BINDTO")) |
2668 | { | 2661 | { |
2669 | GNUNET_break (GNUNET_OK == | 2662 | GNUNET_break(GNUNET_OK == |
2670 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, | 2663 | GNUNET_CONFIGURATION_get_value_string(cfg, service_name, |
2671 | "BINDTO", &hostname)); | 2664 | "BINDTO", &hostname)); |
2672 | } | 2665 | } |
2673 | else | 2666 | else |
2674 | hostname = NULL; | 2667 | hostname = NULL; |
2675 | 2668 | ||
2676 | if (NULL != hostname) | 2669 | if (NULL != hostname) |
2677 | { | ||
2678 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2679 | "Resolving `%s' since that is where `%s' will bind to.\n", | ||
2680 | hostname, service_name); | ||
2681 | memset (&hints, 0, sizeof (struct addrinfo)); | ||
2682 | if (disablev6) | ||
2683 | hints.ai_family = AF_INET; | ||
2684 | if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || | ||
2685 | (NULL == res)) | ||
2686 | { | ||
2687 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2688 | _("Failed to resolve `%s': %s\n"), | ||
2689 | hostname, | ||
2690 | gai_strerror (ret)); | ||
2691 | GNUNET_free (hostname); | ||
2692 | return GNUNET_SYSERR; | ||
2693 | } | ||
2694 | next = res; | ||
2695 | i = 0; | ||
2696 | while (NULL != (pos = next)) | ||
2697 | { | 2670 | { |
2698 | next = pos->ai_next; | 2671 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2699 | if ((disablev6) && (pos->ai_family == AF_INET6)) | 2672 | "Resolving `%s' since that is where `%s' will bind to.\n", |
2700 | continue; | 2673 | hostname, service_name); |
2701 | i++; | 2674 | memset(&hints, 0, sizeof(struct addrinfo)); |
2702 | } | 2675 | if (disablev6) |
2703 | if (0 == i) | 2676 | hints.ai_family = AF_INET; |
2704 | { | 2677 | if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || |
2705 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2678 | (NULL == res)) |
2706 | _("Failed to find %saddress for `%s'.\n"), | 2679 | { |
2707 | disablev6 ? "IPv4 " : "", hostname); | 2680 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2708 | freeaddrinfo (res); | 2681 | _("Failed to resolve `%s': %s\n"), |
2709 | GNUNET_free (hostname); | 2682 | hostname, |
2710 | return GNUNET_SYSERR; | 2683 | gai_strerror(ret)); |
2684 | GNUNET_free(hostname); | ||
2685 | return GNUNET_SYSERR; | ||
2686 | } | ||
2687 | next = res; | ||
2688 | i = 0; | ||
2689 | while (NULL != (pos = next)) | ||
2690 | { | ||
2691 | next = pos->ai_next; | ||
2692 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
2693 | continue; | ||
2694 | i++; | ||
2695 | } | ||
2696 | if (0 == i) | ||
2697 | { | ||
2698 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
2699 | _("Failed to find %saddress for `%s'.\n"), | ||
2700 | disablev6 ? "IPv4 " : "", hostname); | ||
2701 | freeaddrinfo(res); | ||
2702 | GNUNET_free(hostname); | ||
2703 | return GNUNET_SYSERR; | ||
2704 | } | ||
2705 | resi = i; | ||
2706 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); | ||
2707 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); | ||
2708 | i = 0; | ||
2709 | next = res; | ||
2710 | while (NULL != (pos = next)) | ||
2711 | { | ||
2712 | next = pos->ai_next; | ||
2713 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
2714 | continue; | ||
2715 | if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol)) | ||
2716 | continue; /* not TCP */ | ||
2717 | if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype)) | ||
2718 | continue; /* huh? */ | ||
2719 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
2720 | "Service will bind to `%s'\n", | ||
2721 | GNUNET_a2s(pos->ai_addr, | ||
2722 | pos->ai_addrlen)); | ||
2723 | if (pos->ai_family == AF_INET) | ||
2724 | { | ||
2725 | GNUNET_assert(pos->ai_addrlen == sizeof(struct sockaddr_in)); | ||
2726 | saddrlens[i] = pos->ai_addrlen; | ||
2727 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
2728 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
2729 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | ||
2730 | } | ||
2731 | else | ||
2732 | { | ||
2733 | GNUNET_assert(pos->ai_family == AF_INET6); | ||
2734 | GNUNET_assert(pos->ai_addrlen == sizeof(struct sockaddr_in6)); | ||
2735 | saddrlens[i] = pos->ai_addrlen; | ||
2736 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
2737 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
2738 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); | ||
2739 | } | ||
2740 | i++; | ||
2741 | } | ||
2742 | GNUNET_free(hostname); | ||
2743 | freeaddrinfo(res); | ||
2744 | resi = i; | ||
2711 | } | 2745 | } |
2712 | resi = i; | ||
2713 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | ||
2714 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | ||
2715 | i = 0; | ||
2716 | next = res; | ||
2717 | while (NULL != (pos = next)) | ||
2718 | { | ||
2719 | next = pos->ai_next; | ||
2720 | if ((disablev6) && (pos->ai_family == AF_INET6)) | ||
2721 | continue; | ||
2722 | if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol)) | ||
2723 | continue; /* not TCP */ | ||
2724 | if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype)) | ||
2725 | continue; /* huh? */ | ||
2726 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2727 | "Service will bind to `%s'\n", | ||
2728 | GNUNET_a2s (pos->ai_addr, | ||
2729 | pos->ai_addrlen)); | ||
2730 | if (pos->ai_family == AF_INET) | ||
2731 | { | ||
2732 | GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); | ||
2733 | saddrlens[i] = pos->ai_addrlen; | ||
2734 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
2735 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
2736 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | ||
2737 | } | ||
2738 | else | ||
2739 | { | ||
2740 | GNUNET_assert (pos->ai_family == AF_INET6); | ||
2741 | GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); | ||
2742 | saddrlens[i] = pos->ai_addrlen; | ||
2743 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
2744 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
2745 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | ||
2746 | } | ||
2747 | i++; | ||
2748 | } | ||
2749 | GNUNET_free (hostname); | ||
2750 | freeaddrinfo (res); | ||
2751 | resi = i; | ||
2752 | } | ||
2753 | else | 2746 | else |
2754 | { | ||
2755 | /* will bind against everything, just set port */ | ||
2756 | if (disablev6) | ||
2757 | { | 2747 | { |
2758 | /* V4-only */ | 2748 | /* will bind against everything, just set port */ |
2759 | resi = 1; | 2749 | if (disablev6) |
2760 | i = 0; | 2750 | { |
2761 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | 2751 | /* V4-only */ |
2762 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | 2752 | resi = 1; |
2763 | 2753 | i = 0; | |
2764 | saddrlens[i] = sizeof (struct sockaddr_in); | 2754 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); |
2765 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 2755 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); |
2756 | |||
2757 | saddrlens[i] = sizeof(struct sockaddr_in); | ||
2758 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
2766 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2759 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2767 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; | 2760 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; |
2768 | #endif | 2761 | #endif |
2769 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 2762 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; |
2770 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 2763 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); |
2771 | } | 2764 | } |
2772 | else | 2765 | else |
2773 | { | 2766 | { |
2774 | /* dual stack */ | 2767 | /* dual stack */ |
2775 | resi = 2; | 2768 | resi = 2; |
2776 | saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); | 2769 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); |
2777 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); | 2770 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); |
2778 | i = 0; | 2771 | i = 0; |
2779 | saddrlens[i] = sizeof (struct sockaddr_in6); | 2772 | saddrlens[i] = sizeof(struct sockaddr_in6); |
2780 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 2773 | saddrs[i] = GNUNET_malloc(saddrlens[i]); |
2781 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2774 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2782 | ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; | 2775 | ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; |
2783 | #endif | 2776 | #endif |
2784 | ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; | 2777 | ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; |
2785 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | 2778 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); |
2786 | i++; | 2779 | i++; |
2787 | saddrlens[i] = sizeof (struct sockaddr_in); | 2780 | saddrlens[i] = sizeof(struct sockaddr_in); |
2788 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | 2781 | saddrs[i] = GNUNET_malloc(saddrlens[i]); |
2789 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2782 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2790 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; | 2783 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; |
2791 | #endif | 2784 | #endif |
2792 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; | 2785 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; |
2793 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | 2786 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); |
2787 | } | ||
2794 | } | 2788 | } |
2795 | } | ||
2796 | *addrs = saddrs; | 2789 | *addrs = saddrs; |
2797 | *addr_lens = saddrlens; | 2790 | *addr_lens = saddrlens; |
2798 | return resi; | 2791 | return resi; |
@@ -2805,44 +2798,44 @@ server_get_addresses (struct HTTP_Server_Plugin *plugin, | |||
2805 | * @param plugin the plugin handle | 2798 | * @param plugin the plugin handle |
2806 | */ | 2799 | */ |
2807 | static void | 2800 | static void |
2808 | server_start_report_addresses (struct HTTP_Server_Plugin *plugin) | 2801 | server_start_report_addresses(struct HTTP_Server_Plugin *plugin) |
2809 | { | 2802 | { |
2810 | int res = GNUNET_OK; | 2803 | int res = GNUNET_OK; |
2811 | struct sockaddr **addrs; | 2804 | struct sockaddr **addrs; |
2812 | socklen_t *addrlens; | 2805 | socklen_t *addrlens; |
2813 | 2806 | ||
2814 | res = server_get_addresses (plugin, | 2807 | res = server_get_addresses(plugin, |
2815 | plugin->name, | 2808 | plugin->name, |
2816 | plugin->env->cfg, | 2809 | plugin->env->cfg, |
2817 | &addrs, &addrlens); | 2810 | &addrs, &addrlens); |
2818 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2811 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2819 | _("Found %u addresses to report to NAT service\n"), | 2812 | _("Found %u addresses to report to NAT service\n"), |
2820 | res); | 2813 | res); |
2821 | 2814 | ||
2822 | if (GNUNET_SYSERR == res) | 2815 | if (GNUNET_SYSERR == res) |
2823 | { | 2816 | { |
2824 | plugin->nat = NULL; | 2817 | plugin->nat = NULL; |
2825 | return; | 2818 | return; |
2826 | } | 2819 | } |
2827 | 2820 | ||
2828 | plugin->nat | 2821 | plugin->nat |
2829 | = GNUNET_NAT_register (plugin->env->cfg, | 2822 | = GNUNET_NAT_register(plugin->env->cfg, |
2830 | "transport-http_server", | 2823 | "transport-http_server", |
2831 | IPPROTO_TCP, | 2824 | IPPROTO_TCP, |
2832 | (unsigned int) res, | 2825 | (unsigned int)res, |
2833 | (const struct sockaddr **) addrs, | 2826 | (const struct sockaddr **)addrs, |
2834 | addrlens, | 2827 | addrlens, |
2835 | &server_nat_port_map_callback, | 2828 | &server_nat_port_map_callback, |
2836 | NULL, | 2829 | NULL, |
2837 | plugin); | 2830 | plugin); |
2838 | while (res > 0) | 2831 | while (res > 0) |
2839 | { | 2832 | { |
2840 | res--; | 2833 | res--; |
2841 | GNUNET_assert (NULL != addrs[res]); | 2834 | GNUNET_assert(NULL != addrs[res]); |
2842 | GNUNET_free (addrs[res]); | 2835 | GNUNET_free(addrs[res]); |
2843 | } | 2836 | } |
2844 | GNUNET_free_non_null (addrs); | 2837 | GNUNET_free_non_null(addrs); |
2845 | GNUNET_free_non_null (addrlens); | 2838 | GNUNET_free_non_null(addrlens); |
2846 | } | 2839 | } |
2847 | 2840 | ||
2848 | 2841 | ||
@@ -2852,26 +2845,26 @@ server_start_report_addresses (struct HTTP_Server_Plugin *plugin) | |||
2852 | * @param plugin the plugin handle | 2845 | * @param plugin the plugin handle |
2853 | */ | 2846 | */ |
2854 | static void | 2847 | static void |
2855 | server_stop_report_addresses (struct HTTP_Server_Plugin *plugin) | 2848 | server_stop_report_addresses(struct HTTP_Server_Plugin *plugin) |
2856 | { | 2849 | { |
2857 | struct HttpAddressWrapper *w; | 2850 | struct HttpAddressWrapper *w; |
2858 | 2851 | ||
2859 | /* Stop NAT handle */ | 2852 | /* Stop NAT handle */ |
2860 | if (NULL != plugin->nat) | 2853 | if (NULL != plugin->nat) |
2861 | { | 2854 | { |
2862 | GNUNET_NAT_unregister (plugin->nat); | 2855 | GNUNET_NAT_unregister(plugin->nat); |
2863 | plugin->nat = NULL; | 2856 | plugin->nat = NULL; |
2864 | } | 2857 | } |
2865 | /* Clean up addresses */ | 2858 | /* Clean up addresses */ |
2866 | while (NULL != plugin->addr_head) | 2859 | while (NULL != plugin->addr_head) |
2867 | { | 2860 | { |
2868 | w = plugin->addr_head; | 2861 | w = plugin->addr_head; |
2869 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, | 2862 | GNUNET_CONTAINER_DLL_remove(plugin->addr_head, |
2870 | plugin->addr_tail, | 2863 | plugin->addr_tail, |
2871 | w); | 2864 | w); |
2872 | GNUNET_free (w->address); | 2865 | GNUNET_free(w->address); |
2873 | GNUNET_free (w); | 2866 | GNUNET_free(w); |
2874 | } | 2867 | } |
2875 | } | 2868 | } |
2876 | 2869 | ||
2877 | 2870 | ||
@@ -2882,39 +2875,39 @@ server_stop_report_addresses (struct HTTP_Server_Plugin *plugin) | |||
2882 | * @return #GNUNET_YES on success, else #GNUNET_NO | 2875 | * @return #GNUNET_YES on success, else #GNUNET_NO |
2883 | */ | 2876 | */ |
2884 | static int | 2877 | static int |
2885 | server_check_ipv6_support (struct HTTP_Server_Plugin *plugin) | 2878 | server_check_ipv6_support(struct HTTP_Server_Plugin *plugin) |
2886 | { | 2879 | { |
2887 | struct GNUNET_NETWORK_Handle *desc = NULL; | 2880 | struct GNUNET_NETWORK_Handle *desc = NULL; |
2888 | int res = GNUNET_NO; | 2881 | int res = GNUNET_NO; |
2889 | 2882 | ||
2890 | /* Probe IPv6 support */ | 2883 | /* Probe IPv6 support */ |
2891 | desc = GNUNET_NETWORK_socket_create (PF_INET6, | 2884 | desc = GNUNET_NETWORK_socket_create(PF_INET6, |
2892 | SOCK_STREAM, | 2885 | SOCK_STREAM, |
2893 | 0); | 2886 | 0); |
2894 | if (NULL == desc) | 2887 | if (NULL == desc) |
2895 | { | 2888 | { |
2896 | if ( (errno == ENOBUFS) || | 2889 | if ((errno == ENOBUFS) || |
2897 | (errno == ENOMEM) || | 2890 | (errno == ENOMEM) || |
2898 | (errno == ENFILE) || | 2891 | (errno == ENFILE) || |
2899 | (errno == EACCES) ) | 2892 | (errno == EACCES)) |
2900 | { | 2893 | { |
2901 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 2894 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
2902 | "socket"); | 2895 | "socket"); |
2903 | } | 2896 | } |
2904 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2897 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2905 | _("Disabling IPv6 since it is not supported on this system!\n")); | 2898 | _("Disabling IPv6 since it is not supported on this system!\n")); |
2906 | res = GNUNET_NO; | 2899 | res = GNUNET_NO; |
2907 | } | 2900 | } |
2908 | else | 2901 | else |
2909 | { | 2902 | { |
2910 | GNUNET_break (GNUNET_OK == | 2903 | GNUNET_break(GNUNET_OK == |
2911 | GNUNET_NETWORK_socket_close (desc)); | 2904 | GNUNET_NETWORK_socket_close(desc)); |
2912 | desc = NULL; | 2905 | desc = NULL; |
2913 | res = GNUNET_YES; | 2906 | res = GNUNET_YES; |
2914 | } | 2907 | } |
2915 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2908 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2916 | "Testing IPv6 on this system: %s\n", | 2909 | "Testing IPv6 on this system: %s\n", |
2917 | (res == GNUNET_YES) ? "successful" : "failed"); | 2910 | (res == GNUNET_YES) ? "successful" : "failed"); |
2918 | return res; | 2911 | return res; |
2919 | } | 2912 | } |
2920 | 2913 | ||
@@ -2925,7 +2918,7 @@ server_check_ipv6_support (struct HTTP_Server_Plugin *plugin) | |||
2925 | * @param cls plugin | 2918 | * @param cls plugin |
2926 | */ | 2919 | */ |
2927 | static void | 2920 | static void |
2928 | server_notify_external_hostname (void *cls) | 2921 | server_notify_external_hostname(void *cls) |
2929 | { | 2922 | { |
2930 | struct HTTP_Server_Plugin *plugin = cls; | 2923 | struct HTTP_Server_Plugin *plugin = cls; |
2931 | struct HttpAddress *ext_addr; | 2924 | struct HttpAddress *ext_addr; |
@@ -2934,48 +2927,48 @@ server_notify_external_hostname (void *cls) | |||
2934 | char *url; | 2927 | char *url; |
2935 | 2928 | ||
2936 | plugin->notify_ext_task = NULL; | 2929 | plugin->notify_ext_task = NULL; |
2937 | GNUNET_asprintf (&url, | 2930 | GNUNET_asprintf(&url, |
2938 | "%s://%s", | 2931 | "%s://%s", |
2939 | plugin->protocol, | 2932 | plugin->protocol, |
2940 | plugin->external_hostname); | 2933 | plugin->external_hostname); |
2941 | urlen = strlen (url) + 1; | 2934 | urlen = strlen(url) + 1; |
2942 | ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); | 2935 | ext_addr = GNUNET_malloc(sizeof(struct HttpAddress) + urlen); |
2943 | ext_addr->options = htonl (plugin->options); | 2936 | ext_addr->options = htonl(plugin->options); |
2944 | ext_addr->urlen = htonl (urlen); | 2937 | ext_addr->urlen = htonl(urlen); |
2945 | ext_addr_len = sizeof (struct HttpAddress) + urlen; | 2938 | ext_addr_len = sizeof(struct HttpAddress) + urlen; |
2946 | GNUNET_memcpy (&ext_addr[1], url, urlen); | 2939 | GNUNET_memcpy(&ext_addr[1], url, urlen); |
2947 | GNUNET_free (url); | 2940 | GNUNET_free(url); |
2948 | 2941 | ||
2949 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2942 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2950 | "Notifying transport about external hostname address `%s'\n", | 2943 | "Notifying transport about external hostname address `%s'\n", |
2951 | plugin->external_hostname); | 2944 | plugin->external_hostname); |
2952 | 2945 | ||
2953 | #if BUILD_HTTPS | 2946 | #if BUILD_HTTPS |
2954 | if (GNUNET_YES == plugin->verify_external_hostname) | 2947 | if (GNUNET_YES == plugin->verify_external_hostname) |
2955 | LOG (GNUNET_ERROR_TYPE_INFO, | 2948 | LOG(GNUNET_ERROR_TYPE_INFO, |
2956 | "Enabling SSL verification for external hostname address `%s'\n", | 2949 | "Enabling SSL verification for external hostname address `%s'\n", |
2957 | plugin->external_hostname); | 2950 | plugin->external_hostname); |
2958 | plugin->ext_addr | 2951 | plugin->ext_addr |
2959 | = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 2952 | = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
2960 | "https_client", | 2953 | "https_client", |
2961 | ext_addr, | 2954 | ext_addr, |
2962 | ext_addr_len, | 2955 | ext_addr_len, |
2963 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 2956 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
2964 | plugin->env->notify_address (plugin->env->cls, | 2957 | plugin->env->notify_address(plugin->env->cls, |
2965 | GNUNET_YES, | 2958 | GNUNET_YES, |
2966 | plugin->ext_addr); | 2959 | plugin->ext_addr); |
2967 | GNUNET_free (ext_addr); | 2960 | GNUNET_free(ext_addr); |
2968 | #else | 2961 | #else |
2969 | plugin->ext_addr | 2962 | plugin->ext_addr |
2970 | = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 2963 | = GNUNET_HELLO_address_allocate(plugin->env->my_identity, |
2971 | "http_client", | 2964 | "http_client", |
2972 | ext_addr, | 2965 | ext_addr, |
2973 | ext_addr_len, | 2966 | ext_addr_len, |
2974 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 2967 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
2975 | plugin->env->notify_address (plugin->env->cls, | 2968 | plugin->env->notify_address(plugin->env->cls, |
2976 | GNUNET_YES, | 2969 | GNUNET_YES, |
2977 | plugin->ext_addr); | 2970 | plugin->ext_addr); |
2978 | GNUNET_free (ext_addr); | 2971 | GNUNET_free(ext_addr); |
2979 | #endif | 2972 | #endif |
2980 | } | 2973 | } |
2981 | 2974 | ||
@@ -2987,7 +2980,7 @@ server_notify_external_hostname (void *cls) | |||
2987 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 2980 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
2988 | */ | 2981 | */ |
2989 | static int | 2982 | static int |
2990 | server_configure_plugin (struct HTTP_Server_Plugin *plugin) | 2983 | server_configure_plugin(struct HTTP_Server_Plugin *plugin) |
2991 | { | 2984 | { |
2992 | unsigned long long port; | 2985 | unsigned long long port; |
2993 | unsigned long long max_connections; | 2986 | unsigned long long max_connections; |
@@ -2998,225 +2991,225 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin) | |||
2998 | 2991 | ||
2999 | /* Use IPv4? */ | 2992 | /* Use IPv4? */ |
3000 | if (GNUNET_CONFIGURATION_have_value | 2993 | if (GNUNET_CONFIGURATION_have_value |
3001 | (plugin->env->cfg, plugin->name, "USE_IPv4")) | 2994 | (plugin->env->cfg, plugin->name, "USE_IPv4")) |
3002 | { | 2995 | { |
3003 | plugin->use_ipv4 = | 2996 | plugin->use_ipv4 = |
3004 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 2997 | GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, |
3005 | plugin->name, | 2998 | plugin->name, |
3006 | "USE_IPv4"); | 2999 | "USE_IPv4"); |
3007 | } | 3000 | } |
3008 | else | 3001 | else |
3009 | plugin->use_ipv4 = GNUNET_YES; | 3002 | plugin->use_ipv4 = GNUNET_YES; |
3010 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3003 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3011 | _("IPv4 support is %s\n"), | 3004 | _("IPv4 support is %s\n"), |
3012 | (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled"); | 3005 | (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled"); |
3013 | 3006 | ||
3014 | /* Use IPv6? */ | 3007 | /* Use IPv6? */ |
3015 | if (GNUNET_CONFIGURATION_have_value | 3008 | if (GNUNET_CONFIGURATION_have_value |
3016 | (plugin->env->cfg, plugin->name, "USE_IPv6")) | 3009 | (plugin->env->cfg, plugin->name, "USE_IPv6")) |
3017 | { | 3010 | { |
3018 | plugin->use_ipv6 = | 3011 | plugin->use_ipv6 = |
3019 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 3012 | GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, |
3020 | plugin->name, | 3013 | plugin->name, |
3021 | "USE_IPv6"); | 3014 | "USE_IPv6"); |
3022 | } | 3015 | } |
3023 | else | 3016 | else |
3024 | plugin->use_ipv6 = GNUNET_YES; | 3017 | plugin->use_ipv6 = GNUNET_YES; |
3025 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3018 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3026 | _("IPv6 support is %s\n"), | 3019 | _("IPv6 support is %s\n"), |
3027 | (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled"); | 3020 | (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled"); |
3028 | 3021 | ||
3029 | if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO)) | 3022 | if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO)) |
3030 | { | 3023 | { |
3031 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3024 | LOG(GNUNET_ERROR_TYPE_ERROR, |
3032 | _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n")); | 3025 | _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n")); |
3033 | return GNUNET_SYSERR; | 3026 | return GNUNET_SYSERR; |
3034 | } | 3027 | } |
3035 | 3028 | ||
3036 | /* Reading port number from config file */ | 3029 | /* Reading port number from config file */ |
3037 | if ((GNUNET_OK != | 3030 | if ((GNUNET_OK != |
3038 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 3031 | GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, |
3039 | plugin->name, | 3032 | plugin->name, |
3040 | "PORT", &port)) || (port > 65535)) | 3033 | "PORT", &port)) || (port > 65535)) |
3041 | { | 3034 | { |
3042 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3035 | LOG(GNUNET_ERROR_TYPE_ERROR, |
3043 | _("Port is required! Fix in configuration\n")); | 3036 | _("Port is required! Fix in configuration\n")); |
3044 | return GNUNET_SYSERR; | ||
3045 | } | ||
3046 | plugin->port = port; | ||
3047 | |||
3048 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
3049 | _("Using port %u\n"), plugin->port); | ||
3050 | |||
3051 | if ( (plugin->use_ipv4 == GNUNET_YES) && | ||
3052 | (GNUNET_YES == | ||
3053 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | ||
3054 | plugin->name, | ||
3055 | "BINDTO", | ||
3056 | &bind4_address))) | ||
3057 | { | ||
3058 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
3059 | "Binding %s plugin to specific IPv4 address: `%s'\n", | ||
3060 | plugin->protocol, | ||
3061 | bind4_address); | ||
3062 | plugin->server_addr_v4 = GNUNET_new (struct sockaddr_in); | ||
3063 | if (1 != inet_pton (AF_INET, | ||
3064 | bind4_address, | ||
3065 | &plugin->server_addr_v4->sin_addr)) | ||
3066 | { | ||
3067 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
3068 | _("Specific IPv4 address `%s' in configuration file is invalid!\n"), | ||
3069 | bind4_address); | ||
3070 | GNUNET_free (bind4_address); | ||
3071 | GNUNET_free (plugin->server_addr_v4); | ||
3072 | plugin->server_addr_v4 = NULL; | ||
3073 | return GNUNET_SYSERR; | 3037 | return GNUNET_SYSERR; |
3074 | } | 3038 | } |
3075 | else | 3039 | plugin->port = port; |
3040 | |||
3041 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
3042 | _("Using port %u\n"), plugin->port); | ||
3043 | |||
3044 | if ((plugin->use_ipv4 == GNUNET_YES) && | ||
3045 | (GNUNET_YES == | ||
3046 | GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, | ||
3047 | plugin->name, | ||
3048 | "BINDTO", | ||
3049 | &bind4_address))) | ||
3076 | { | 3050 | { |
3077 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3051 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3078 | "Binding to IPv4 address %s\n", | 3052 | "Binding %s plugin to specific IPv4 address: `%s'\n", |
3079 | bind4_address); | 3053 | plugin->protocol, |
3080 | plugin->server_addr_v4->sin_family = AF_INET; | 3054 | bind4_address); |
3081 | plugin->server_addr_v4->sin_port = htons (plugin->port); | 3055 | plugin->server_addr_v4 = GNUNET_new(struct sockaddr_in); |
3056 | if (1 != inet_pton(AF_INET, | ||
3057 | bind4_address, | ||
3058 | &plugin->server_addr_v4->sin_addr)) | ||
3059 | { | ||
3060 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
3061 | _("Specific IPv4 address `%s' in configuration file is invalid!\n"), | ||
3062 | bind4_address); | ||
3063 | GNUNET_free(bind4_address); | ||
3064 | GNUNET_free(plugin->server_addr_v4); | ||
3065 | plugin->server_addr_v4 = NULL; | ||
3066 | return GNUNET_SYSERR; | ||
3067 | } | ||
3068 | else | ||
3069 | { | ||
3070 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
3071 | "Binding to IPv4 address %s\n", | ||
3072 | bind4_address); | ||
3073 | plugin->server_addr_v4->sin_family = AF_INET; | ||
3074 | plugin->server_addr_v4->sin_port = htons(plugin->port); | ||
3075 | } | ||
3076 | GNUNET_free(bind4_address); | ||
3082 | } | 3077 | } |
3083 | GNUNET_free (bind4_address); | ||
3084 | } | ||
3085 | 3078 | ||
3086 | if ((plugin->use_ipv6 == GNUNET_YES) && | 3079 | if ((plugin->use_ipv6 == GNUNET_YES) && |
3087 | (GNUNET_YES == | 3080 | (GNUNET_YES == |
3088 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 3081 | GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, |
3089 | plugin->name, | 3082 | plugin->name, |
3090 | "BINDTO6", | 3083 | "BINDTO6", |
3091 | &bind6_address))) | 3084 | &bind6_address))) |
3092 | { | ||
3093 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
3094 | "Binding %s plugin to specific IPv6 address: `%s'\n", | ||
3095 | plugin->protocol, bind6_address); | ||
3096 | plugin->server_addr_v6 = GNUNET_new (struct sockaddr_in6); | ||
3097 | if (1 != | ||
3098 | inet_pton (AF_INET6, | ||
3099 | bind6_address, | ||
3100 | &plugin->server_addr_v6->sin6_addr)) | ||
3101 | { | ||
3102 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
3103 | _("Specific IPv6 address `%s' in configuration file is invalid!\n"), | ||
3104 | bind6_address); | ||
3105 | GNUNET_free (bind6_address); | ||
3106 | GNUNET_free (plugin->server_addr_v6); | ||
3107 | plugin->server_addr_v6 = NULL; | ||
3108 | return GNUNET_SYSERR; | ||
3109 | } | ||
3110 | else | ||
3111 | { | 3085 | { |
3112 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3086 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3113 | "Binding to IPv6 address %s\n", | 3087 | "Binding %s plugin to specific IPv6 address: `%s'\n", |
3114 | bind6_address); | 3088 | plugin->protocol, bind6_address); |
3115 | plugin->server_addr_v6->sin6_family = AF_INET6; | 3089 | plugin->server_addr_v6 = GNUNET_new(struct sockaddr_in6); |
3116 | plugin->server_addr_v6->sin6_port = htons (plugin->port); | 3090 | if (1 != |
3091 | inet_pton(AF_INET6, | ||
3092 | bind6_address, | ||
3093 | &plugin->server_addr_v6->sin6_addr)) | ||
3094 | { | ||
3095 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
3096 | _("Specific IPv6 address `%s' in configuration file is invalid!\n"), | ||
3097 | bind6_address); | ||
3098 | GNUNET_free(bind6_address); | ||
3099 | GNUNET_free(plugin->server_addr_v6); | ||
3100 | plugin->server_addr_v6 = NULL; | ||
3101 | return GNUNET_SYSERR; | ||
3102 | } | ||
3103 | else | ||
3104 | { | ||
3105 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
3106 | "Binding to IPv6 address %s\n", | ||
3107 | bind6_address); | ||
3108 | plugin->server_addr_v6->sin6_family = AF_INET6; | ||
3109 | plugin->server_addr_v6->sin6_port = htons(plugin->port); | ||
3110 | } | ||
3111 | GNUNET_free(bind6_address); | ||
3117 | } | 3112 | } |
3118 | GNUNET_free (bind6_address); | ||
3119 | } | ||
3120 | 3113 | ||
3121 | plugin->verify_external_hostname = GNUNET_NO; | 3114 | plugin->verify_external_hostname = GNUNET_NO; |
3122 | #if BUILD_HTTPS | 3115 | #if BUILD_HTTPS |
3123 | plugin->verify_external_hostname | 3116 | plugin->verify_external_hostname |
3124 | = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 3117 | = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, |
3125 | plugin->name, | 3118 | plugin->name, |
3126 | "VERIFY_EXTERNAL_HOSTNAME"); | 3119 | "VERIFY_EXTERNAL_HOSTNAME"); |
3127 | if (GNUNET_SYSERR == plugin->verify_external_hostname) | 3120 | if (GNUNET_SYSERR == plugin->verify_external_hostname) |
3128 | plugin->verify_external_hostname = GNUNET_NO; | 3121 | plugin->verify_external_hostname = GNUNET_NO; |
3129 | if (GNUNET_YES == plugin->verify_external_hostname) | 3122 | if (GNUNET_YES == plugin->verify_external_hostname) |
3130 | plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE; | 3123 | plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE; |
3131 | #endif | 3124 | #endif |
3132 | external_hostname_use_port | 3125 | external_hostname_use_port |
3133 | = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 3126 | = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, |
3134 | plugin->name, | 3127 | plugin->name, |
3135 | "EXTERNAL_HOSTNAME_USE_PORT"); | 3128 | "EXTERNAL_HOSTNAME_USE_PORT"); |
3136 | if (GNUNET_SYSERR == external_hostname_use_port) | 3129 | if (GNUNET_SYSERR == external_hostname_use_port) |
3137 | external_hostname_use_port = GNUNET_NO; | 3130 | external_hostname_use_port = GNUNET_NO; |
3138 | 3131 | ||
3139 | 3132 | ||
3140 | if (GNUNET_YES == | 3133 | if (GNUNET_YES == |
3141 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 3134 | GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg, |
3142 | plugin->name, | 3135 | plugin->name, |
3143 | "EXTERNAL_HOSTNAME", | 3136 | "EXTERNAL_HOSTNAME", |
3144 | &eh_tmp)) | 3137 | &eh_tmp)) |
3145 | { | 3138 | { |
3146 | char *tmp; | 3139 | char *tmp; |
3147 | char *pos = NULL; | 3140 | char *pos = NULL; |
3148 | char *pos_url = NULL; | 3141 | char *pos_url = NULL; |
3149 | 3142 | ||
3150 | if (NULL != strstr(eh_tmp, "://")) | 3143 | if (NULL != strstr(eh_tmp, "://")) |
3151 | tmp = &strstr(eh_tmp, "://")[3]; | 3144 | tmp = &strstr(eh_tmp, "://")[3]; |
3152 | else | ||
3153 | tmp = eh_tmp; | ||
3154 | |||
3155 | if (GNUNET_YES == external_hostname_use_port) | ||
3156 | { | ||
3157 | if ( (strlen (tmp) > 1) && (NULL != (pos = strchr(tmp, '/'))) ) | ||
3158 | { | ||
3159 | pos_url = pos + 1; | ||
3160 | pos[0] = '\0'; | ||
3161 | GNUNET_asprintf (&plugin->external_hostname, | ||
3162 | "%s:%u/%s", | ||
3163 | tmp, | ||
3164 | (uint16_t) port, | ||
3165 | pos_url); | ||
3166 | } | ||
3167 | else | 3145 | else |
3168 | GNUNET_asprintf (&plugin->external_hostname, | 3146 | tmp = eh_tmp; |
3169 | "%s:%u", | 3147 | |
3170 | tmp, | 3148 | if (GNUNET_YES == external_hostname_use_port) |
3171 | (uint16_t) port); | 3149 | { |
3172 | } | 3150 | if ((strlen(tmp) > 1) && (NULL != (pos = strchr(tmp, '/')))) |
3173 | else | 3151 | { |
3174 | plugin->external_hostname = GNUNET_strdup (tmp); | 3152 | pos_url = pos + 1; |
3175 | GNUNET_free (eh_tmp); | 3153 | pos[0] = '\0'; |
3176 | 3154 | GNUNET_asprintf(&plugin->external_hostname, | |
3177 | LOG (GNUNET_ERROR_TYPE_INFO, | 3155 | "%s:%u/%s", |
3178 | _("Using external hostname `%s'\n"), | 3156 | tmp, |
3179 | plugin->external_hostname); | 3157 | (uint16_t)port, |
3180 | plugin->notify_ext_task = GNUNET_SCHEDULER_add_now (&server_notify_external_hostname, | 3158 | pos_url); |
3181 | plugin); | 3159 | } |
3182 | 3160 | else | |
3183 | /* Use only configured external hostname */ | 3161 | GNUNET_asprintf(&plugin->external_hostname, |
3184 | if (GNUNET_CONFIGURATION_have_value | 3162 | "%s:%u", |
3185 | (plugin->env->cfg, | 3163 | tmp, |
3186 | plugin->name, | 3164 | (uint16_t)port); |
3187 | "EXTERNAL_HOSTNAME_ONLY")) | 3165 | } |
3188 | { | 3166 | else |
3189 | plugin->external_only = | 3167 | plugin->external_hostname = GNUNET_strdup(tmp); |
3190 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 3168 | GNUNET_free(eh_tmp); |
3191 | plugin->name, | 3169 | |
3192 | "EXTERNAL_HOSTNAME_ONLY"); | 3170 | LOG(GNUNET_ERROR_TYPE_INFO, |
3193 | } | 3171 | _("Using external hostname `%s'\n"), |
3194 | else | 3172 | plugin->external_hostname); |
3195 | plugin->external_only = GNUNET_NO; | 3173 | plugin->notify_ext_task = GNUNET_SCHEDULER_add_now(&server_notify_external_hostname, |
3174 | plugin); | ||
3175 | |||
3176 | /* Use only configured external hostname */ | ||
3177 | if (GNUNET_CONFIGURATION_have_value | ||
3178 | (plugin->env->cfg, | ||
3179 | plugin->name, | ||
3180 | "EXTERNAL_HOSTNAME_ONLY")) | ||
3181 | { | ||
3182 | plugin->external_only = | ||
3183 | GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg, | ||
3184 | plugin->name, | ||
3185 | "EXTERNAL_HOSTNAME_ONLY"); | ||
3186 | } | ||
3187 | else | ||
3188 | plugin->external_only = GNUNET_NO; | ||
3196 | 3189 | ||
3197 | if (GNUNET_YES == plugin->external_only) | 3190 | if (GNUNET_YES == plugin->external_only) |
3198 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3191 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3199 | _("Notifying transport only about hostname `%s'\n"), | 3192 | _("Notifying transport only about hostname `%s'\n"), |
3200 | plugin->external_hostname); | 3193 | plugin->external_hostname); |
3201 | } | 3194 | } |
3202 | else | 3195 | else |
3203 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3196 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3204 | "No external hostname configured\n"); | 3197 | "No external hostname configured\n"); |
3205 | 3198 | ||
3206 | /* Optional parameters */ | 3199 | /* Optional parameters */ |
3207 | if (GNUNET_OK != | 3200 | if (GNUNET_OK != |
3208 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 3201 | GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg, |
3209 | plugin->name, | 3202 | plugin->name, |
3210 | "MAX_CONNECTIONS", | 3203 | "MAX_CONNECTIONS", |
3211 | &max_connections)) | 3204 | &max_connections)) |
3212 | max_connections = 128; | 3205 | max_connections = 128; |
3213 | plugin->max_request = max_connections; | 3206 | plugin->max_request = max_connections; |
3214 | 3207 | ||
3215 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3208 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3216 | _("Maximum number of connections is %u\n"), | 3209 | _("Maximum number of connections is %u\n"), |
3217 | plugin->max_request); | 3210 | plugin->max_request); |
3218 | 3211 | ||
3219 | plugin->peer_id_length = strlen (GNUNET_i2s_full (plugin->env->my_identity)); | 3212 | plugin->peer_id_length = strlen(GNUNET_i2s_full(plugin->env->my_identity)); |
3220 | 3213 | ||
3221 | return GNUNET_OK; | 3214 | return GNUNET_OK; |
3222 | } | 3215 | } |
@@ -3229,94 +3222,94 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin) | |||
3229 | * @return NULL | 3222 | * @return NULL |
3230 | */ | 3223 | */ |
3231 | void * | 3224 | void * |
3232 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | 3225 | LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls) |
3233 | { | 3226 | { |
3234 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 3227 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
3235 | struct HTTP_Server_Plugin *plugin = api->cls; | 3228 | struct HTTP_Server_Plugin *plugin = api->cls; |
3236 | 3229 | ||
3237 | if (NULL == api->cls) | 3230 | if (NULL == api->cls) |
3238 | { | 3231 | { |
3239 | /* Free for stub mode */ | 3232 | /* Free for stub mode */ |
3240 | GNUNET_free (api); | 3233 | GNUNET_free(api); |
3241 | return NULL; | 3234 | return NULL; |
3242 | } | 3235 | } |
3243 | plugin->in_shutdown = GNUNET_YES; | 3236 | plugin->in_shutdown = GNUNET_YES; |
3244 | LOG (GNUNET_ERROR_TYPE_INFO, | 3237 | LOG(GNUNET_ERROR_TYPE_INFO, |
3245 | _("Shutting down plugin `%s'\n"), | 3238 | _("Shutting down plugin `%s'\n"), |
3246 | plugin->name); | 3239 | plugin->name); |
3247 | 3240 | ||
3248 | if (NULL != plugin->notify_ext_task) | 3241 | if (NULL != plugin->notify_ext_task) |
3249 | { | 3242 | { |
3250 | GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); | 3243 | GNUNET_SCHEDULER_cancel(plugin->notify_ext_task); |
3251 | plugin->notify_ext_task = NULL; | 3244 | plugin->notify_ext_task = NULL; |
3252 | } | 3245 | } |
3253 | 3246 | ||
3254 | if (NULL != plugin->ext_addr) | 3247 | if (NULL != plugin->ext_addr) |
3255 | { | 3248 | { |
3256 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3249 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3257 | "Notifying transport to remove address `%s'\n", | 3250 | "Notifying transport to remove address `%s'\n", |
3258 | http_common_plugin_address_to_string (plugin->protocol, | 3251 | http_common_plugin_address_to_string(plugin->protocol, |
3259 | plugin->ext_addr->address, | 3252 | plugin->ext_addr->address, |
3260 | plugin->ext_addr->address_length)); | 3253 | plugin->ext_addr->address_length)); |
3261 | #if BUILD_HTTPS | 3254 | #if BUILD_HTTPS |
3262 | plugin->env->notify_address (plugin->env->cls, | 3255 | plugin->env->notify_address(plugin->env->cls, |
3263 | GNUNET_NO, | 3256 | GNUNET_NO, |
3264 | plugin->ext_addr); | 3257 | plugin->ext_addr); |
3265 | #else | 3258 | #else |
3266 | plugin->env->notify_address (plugin->env->cls, | 3259 | plugin->env->notify_address(plugin->env->cls, |
3267 | GNUNET_NO, | 3260 | GNUNET_NO, |
3268 | plugin->ext_addr); | 3261 | plugin->ext_addr); |
3269 | #endif | 3262 | #endif |
3270 | GNUNET_HELLO_address_free (plugin->ext_addr); | 3263 | GNUNET_HELLO_address_free(plugin->ext_addr); |
3271 | plugin->ext_addr = NULL; | 3264 | plugin->ext_addr = NULL; |
3272 | } | 3265 | } |
3273 | 3266 | ||
3274 | /* Stop to report addresses to transport service */ | 3267 | /* Stop to report addresses to transport service */ |
3275 | server_stop_report_addresses (plugin); | 3268 | server_stop_report_addresses(plugin); |
3276 | if (NULL != plugin->server_v4_task) | 3269 | if (NULL != plugin->server_v4_task) |
3277 | { | 3270 | { |
3278 | GNUNET_SCHEDULER_cancel (plugin->server_v4_task); | 3271 | GNUNET_SCHEDULER_cancel(plugin->server_v4_task); |
3279 | plugin->server_v4_task = NULL; | 3272 | plugin->server_v4_task = NULL; |
3280 | } | 3273 | } |
3281 | 3274 | ||
3282 | if (NULL != plugin->server_v6_task) | 3275 | if (NULL != plugin->server_v6_task) |
3283 | { | 3276 | { |
3284 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | 3277 | GNUNET_SCHEDULER_cancel(plugin->server_v6_task); |
3285 | plugin->server_v6_task = NULL; | 3278 | plugin->server_v6_task = NULL; |
3286 | } | 3279 | } |
3287 | #if BUILD_HTTPS | 3280 | #if BUILD_HTTPS |
3288 | GNUNET_free_non_null (plugin->crypto_init); | 3281 | GNUNET_free_non_null(plugin->crypto_init); |
3289 | GNUNET_free_non_null (plugin->cert); | 3282 | GNUNET_free_non_null(plugin->cert); |
3290 | GNUNET_free_non_null (plugin->key); | 3283 | GNUNET_free_non_null(plugin->key); |
3291 | #endif | 3284 | #endif |
3292 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, | 3285 | GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, |
3293 | &destroy_session_shutdown_cb, | 3286 | &destroy_session_shutdown_cb, |
3294 | plugin); | 3287 | plugin); |
3295 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); | 3288 | GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions); |
3296 | plugin->sessions = NULL; | 3289 | plugin->sessions = NULL; |
3297 | if (NULL != plugin->server_v4) | 3290 | if (NULL != plugin->server_v4) |
3298 | { | 3291 | { |
3299 | MHD_stop_daemon (plugin->server_v4); | 3292 | MHD_stop_daemon(plugin->server_v4); |
3300 | plugin->server_v4 = NULL; | 3293 | plugin->server_v4 = NULL; |
3301 | } | 3294 | } |
3302 | if (NULL != plugin->server_v6) | 3295 | if (NULL != plugin->server_v6) |
3303 | { | 3296 | { |
3304 | MHD_stop_daemon (plugin->server_v6); | 3297 | MHD_stop_daemon(plugin->server_v6); |
3305 | plugin->server_v6 = NULL; | 3298 | plugin->server_v6 = NULL; |
3306 | } | 3299 | } |
3307 | /* Clean up */ | 3300 | /* Clean up */ |
3308 | GNUNET_free_non_null (plugin->external_hostname); | 3301 | GNUNET_free_non_null(plugin->external_hostname); |
3309 | GNUNET_free_non_null (plugin->ext_addr); | 3302 | GNUNET_free_non_null(plugin->ext_addr); |
3310 | GNUNET_free_non_null (plugin->server_addr_v4); | 3303 | GNUNET_free_non_null(plugin->server_addr_v4); |
3311 | GNUNET_free_non_null (plugin->server_addr_v6); | 3304 | GNUNET_free_non_null(plugin->server_addr_v6); |
3312 | regfree (&plugin->url_regex); | 3305 | regfree(&plugin->url_regex); |
3313 | 3306 | ||
3314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3307 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3315 | _("Shutdown for plugin `%s' complete\n"), | 3308 | _("Shutdown for plugin `%s' complete\n"), |
3316 | plugin->name); | 3309 | plugin->name); |
3317 | 3310 | ||
3318 | GNUNET_free (plugin); | 3311 | GNUNET_free(plugin); |
3319 | GNUNET_free (api); | 3312 | GNUNET_free(api); |
3320 | return NULL; | 3313 | return NULL; |
3321 | } | 3314 | } |
3322 | 3315 | ||
@@ -3333,13 +3326,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3333 | * @return string representing the same address | 3326 | * @return string representing the same address |
3334 | */ | 3327 | */ |
3335 | static const char * | 3328 | static const char * |
3336 | http_server_plugin_address_to_string (void *cls, | 3329 | http_server_plugin_address_to_string(void *cls, |
3337 | const void *addr, | 3330 | const void *addr, |
3338 | size_t addrlen) | 3331 | size_t addrlen) |
3339 | { | 3332 | { |
3340 | return http_common_plugin_address_to_string (PLUGIN_NAME, | 3333 | return http_common_plugin_address_to_string(PLUGIN_NAME, |
3341 | addr, | 3334 | addr, |
3342 | addrlen); | 3335 | addrlen); |
3343 | } | 3336 | } |
3344 | 3337 | ||
3345 | 3338 | ||
@@ -3351,8 +3344,8 @@ http_server_plugin_address_to_string (void *cls, | |||
3351 | * @return the network type in HBO or #GNUNET_SYSERR | 3344 | * @return the network type in HBO or #GNUNET_SYSERR |
3352 | */ | 3345 | */ |
3353 | static enum GNUNET_NetworkType | 3346 | static enum GNUNET_NetworkType |
3354 | http_server_plugin_get_network (void *cls, | 3347 | http_server_plugin_get_network(void *cls, |
3355 | struct GNUNET_ATS_Session *session) | 3348 | struct GNUNET_ATS_Session *session) |
3356 | { | 3349 | { |
3357 | return session->scope; | 3350 | return session->scope; |
3358 | } | 3351 | } |
@@ -3366,13 +3359,13 @@ http_server_plugin_get_network (void *cls, | |||
3366 | * @return the network type | 3359 | * @return the network type |
3367 | */ | 3360 | */ |
3368 | static enum GNUNET_NetworkType | 3361 | static enum GNUNET_NetworkType |
3369 | http_server_plugin_get_network_for_address (void *cls, | 3362 | http_server_plugin_get_network_for_address(void *cls, |
3370 | const struct GNUNET_HELLO_Address *address) | 3363 | const struct GNUNET_HELLO_Address *address) |
3371 | { | 3364 | { |
3372 | struct HTTP_Server_Plugin *plugin = cls; | 3365 | struct HTTP_Server_Plugin *plugin = cls; |
3373 | 3366 | ||
3374 | return http_common_get_network_for_address (plugin->env, | 3367 | return http_common_get_network_for_address(plugin->env, |
3375 | address); | 3368 | address); |
3376 | } | 3369 | } |
3377 | 3370 | ||
3378 | 3371 | ||
@@ -3387,24 +3380,24 @@ http_server_plugin_get_network_for_address (void *cls, | |||
3387 | * @param delay new delay to use for receiving | 3380 | * @param delay new delay to use for receiving |
3388 | */ | 3381 | */ |
3389 | static void | 3382 | static void |
3390 | http_server_plugin_update_inbound_delay (void *cls, | 3383 | http_server_plugin_update_inbound_delay(void *cls, |
3391 | const struct GNUNET_PeerIdentity *peer, | 3384 | const struct GNUNET_PeerIdentity *peer, |
3392 | struct GNUNET_ATS_Session *session, | 3385 | struct GNUNET_ATS_Session *session, |
3393 | struct GNUNET_TIME_Relative delay) | 3386 | struct GNUNET_TIME_Relative delay) |
3394 | { | 3387 | { |
3395 | session->next_receive = GNUNET_TIME_relative_to_absolute (delay); | 3388 | session->next_receive = GNUNET_TIME_relative_to_absolute(delay); |
3396 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3389 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3397 | "New inbound delay %s\n", | 3390 | "New inbound delay %s\n", |
3398 | GNUNET_STRINGS_relative_time_to_string (delay, | 3391 | GNUNET_STRINGS_relative_time_to_string(delay, |
3399 | GNUNET_NO)); | 3392 | GNUNET_NO)); |
3400 | if (NULL != session->recv_wakeup_task) | 3393 | if (NULL != session->recv_wakeup_task) |
3401 | { | 3394 | { |
3402 | GNUNET_SCHEDULER_cancel (session->recv_wakeup_task); | 3395 | GNUNET_SCHEDULER_cancel(session->recv_wakeup_task); |
3403 | session->recv_wakeup_task | 3396 | session->recv_wakeup_task |
3404 | = GNUNET_SCHEDULER_add_delayed (delay, | 3397 | = GNUNET_SCHEDULER_add_delayed(delay, |
3405 | &server_wake_up, | 3398 | &server_wake_up, |
3406 | session); | 3399 | session); |
3407 | } | 3400 | } |
3408 | } | 3401 | } |
3409 | 3402 | ||
3410 | 3403 | ||
@@ -3418,16 +3411,16 @@ http_server_plugin_update_inbound_delay (void *cls, | |||
3418 | * @return #GNUNET_OK (continue to iterate) | 3411 | * @return #GNUNET_OK (continue to iterate) |
3419 | */ | 3412 | */ |
3420 | static int | 3413 | static int |
3421 | send_session_info_iter (void *cls, | 3414 | send_session_info_iter(void *cls, |
3422 | const struct GNUNET_PeerIdentity *peer, | 3415 | const struct GNUNET_PeerIdentity *peer, |
3423 | void *value) | 3416 | void *value) |
3424 | { | 3417 | { |
3425 | struct HTTP_Server_Plugin *plugin = cls; | 3418 | struct HTTP_Server_Plugin *plugin = cls; |
3426 | struct GNUNET_ATS_Session *session = value; | 3419 | struct GNUNET_ATS_Session *session = value; |
3427 | 3420 | ||
3428 | notify_session_monitor (plugin, | 3421 | notify_session_monitor(plugin, |
3429 | session, | 3422 | session, |
3430 | GNUNET_TRANSPORT_SS_INIT); | 3423 | GNUNET_TRANSPORT_SS_INIT); |
3431 | return GNUNET_OK; | 3424 | return GNUNET_OK; |
3432 | } | 3425 | } |
3433 | 3426 | ||
@@ -3445,22 +3438,22 @@ send_session_info_iter (void *cls, | |||
3445 | * @param sic_cls closure for @a sic | 3438 | * @param sic_cls closure for @a sic |
3446 | */ | 3439 | */ |
3447 | static void | 3440 | static void |
3448 | http_server_plugin_setup_monitor (void *cls, | 3441 | http_server_plugin_setup_monitor(void *cls, |
3449 | GNUNET_TRANSPORT_SessionInfoCallback sic, | 3442 | GNUNET_TRANSPORT_SessionInfoCallback sic, |
3450 | void *sic_cls) | 3443 | void *sic_cls) |
3451 | { | 3444 | { |
3452 | struct HTTP_Server_Plugin *plugin = cls; | 3445 | struct HTTP_Server_Plugin *plugin = cls; |
3453 | 3446 | ||
3454 | plugin->sic = sic; | 3447 | plugin->sic = sic; |
3455 | plugin->sic_cls = sic_cls; | 3448 | plugin->sic_cls = sic_cls; |
3456 | if (NULL != sic) | 3449 | if (NULL != sic) |
3457 | { | 3450 | { |
3458 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, | 3451 | GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions, |
3459 | &send_session_info_iter, | 3452 | &send_session_info_iter, |
3460 | plugin); | 3453 | plugin); |
3461 | /* signal end of first iteration */ | 3454 | /* signal end of first iteration */ |
3462 | sic (sic_cls, NULL, NULL); | 3455 | sic(sic_cls, NULL, NULL); |
3463 | } | 3456 | } |
3464 | } | 3457 | } |
3465 | 3458 | ||
3466 | 3459 | ||
@@ -3471,29 +3464,29 @@ http_server_plugin_setup_monitor (void *cls, | |||
3471 | * @return api | 3464 | * @return api |
3472 | */ | 3465 | */ |
3473 | void * | 3466 | void * |
3474 | LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | 3467 | LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls) |
3475 | { | 3468 | { |
3476 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 3469 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
3477 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 3470 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
3478 | struct HTTP_Server_Plugin *plugin; | 3471 | struct HTTP_Server_Plugin *plugin; |
3479 | 3472 | ||
3480 | if (NULL == env->receive) | 3473 | if (NULL == env->receive) |
3481 | { | 3474 | { |
3482 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 3475 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
3483 | initialze the plugin or the API */ | 3476 | initialze the plugin or the API */ |
3484 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 3477 | api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); |
3485 | api->cls = NULL; | 3478 | api->cls = NULL; |
3486 | api->address_to_string = &http_server_plugin_address_to_string; | 3479 | api->address_to_string = &http_server_plugin_address_to_string; |
3487 | api->string_to_address = &http_common_plugin_string_to_address; | 3480 | api->string_to_address = &http_common_plugin_string_to_address; |
3488 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 3481 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
3489 | return api; | 3482 | return api; |
3490 | } | 3483 | } |
3491 | plugin = GNUNET_new (struct HTTP_Server_Plugin); | 3484 | plugin = GNUNET_new(struct HTTP_Server_Plugin); |
3492 | plugin->env = env; | 3485 | plugin->env = env; |
3493 | plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128, | 3486 | plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128, |
3494 | GNUNET_YES); | 3487 | GNUNET_YES); |
3495 | 3488 | ||
3496 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 3489 | api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); |
3497 | api->cls = plugin; | 3490 | api->cls = plugin; |
3498 | api->send = &http_server_plugin_send; | 3491 | api->send = &http_server_plugin_send; |
3499 | api->disconnect_peer = &http_server_plugin_disconnect_peer; | 3492 | api->disconnect_peer = &http_server_plugin_disconnect_peer; |
@@ -3519,51 +3512,51 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3519 | #endif | 3512 | #endif |
3520 | 3513 | ||
3521 | if (GNUNET_YES == | 3514 | if (GNUNET_YES == |
3522 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 3515 | GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
3523 | plugin->name, | 3516 | plugin->name, |
3524 | "TCP_STEALTH")) | 3517 | "TCP_STEALTH")) |
3525 | { | 3518 | { |
3526 | #ifdef TCP_STEALTH | 3519 | #ifdef TCP_STEALTH |
3527 | plugin->options |= HTTP_OPTIONS_TCP_STEALTH; | 3520 | plugin->options |= HTTP_OPTIONS_TCP_STEALTH; |
3528 | #else | 3521 | #else |
3529 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3522 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
3530 | _("TCP_STEALTH not supported on this platform.\n")); | 3523 | _("TCP_STEALTH not supported on this platform.\n")); |
3531 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); | 3524 | LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); |
3532 | return NULL; | 3525 | return NULL; |
3533 | #endif | 3526 | #endif |
3534 | } | 3527 | } |
3535 | 3528 | ||
3536 | /* Compile URL regex */ | 3529 | /* Compile URL regex */ |
3537 | if (regcomp (&plugin->url_regex, | 3530 | if (regcomp(&plugin->url_regex, |
3538 | URL_REGEX, | 3531 | URL_REGEX, |
3539 | REG_EXTENDED)) | 3532 | REG_EXTENDED)) |
3540 | { | 3533 | { |
3541 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3534 | LOG(GNUNET_ERROR_TYPE_ERROR, |
3542 | _("Unable to compile URL regex\n")); | 3535 | _("Unable to compile URL regex\n")); |
3543 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); | 3536 | LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); |
3544 | return NULL; | 3537 | return NULL; |
3545 | } | 3538 | } |
3546 | 3539 | ||
3547 | /* Configure plugin */ | 3540 | /* Configure plugin */ |
3548 | if (GNUNET_SYSERR == server_configure_plugin (plugin)) | 3541 | if (GNUNET_SYSERR == server_configure_plugin(plugin)) |
3549 | { | 3542 | { |
3550 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); | 3543 | LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); |
3551 | return NULL; | 3544 | return NULL; |
3552 | } | 3545 | } |
3553 | 3546 | ||
3554 | /* Check IPv6 support */ | 3547 | /* Check IPv6 support */ |
3555 | if (GNUNET_YES == plugin->use_ipv6) | 3548 | if (GNUNET_YES == plugin->use_ipv6) |
3556 | plugin->use_ipv6 = server_check_ipv6_support (plugin); | 3549 | plugin->use_ipv6 = server_check_ipv6_support(plugin); |
3557 | 3550 | ||
3558 | /* Report addresses to transport service */ | 3551 | /* Report addresses to transport service */ |
3559 | if (GNUNET_NO == plugin->external_only) | 3552 | if (GNUNET_NO == plugin->external_only) |
3560 | server_start_report_addresses (plugin); | 3553 | server_start_report_addresses(plugin); |
3561 | 3554 | ||
3562 | if (GNUNET_SYSERR == server_start (plugin)) | 3555 | if (GNUNET_SYSERR == server_start(plugin)) |
3563 | { | 3556 | { |
3564 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); | 3557 | LIBGNUNET_PLUGIN_TRANSPORT_DONE(api); |
3565 | return NULL; | 3558 | return NULL; |
3566 | } | 3559 | } |
3567 | return api; | 3560 | return api; |
3568 | } | 3561 | } |
3569 | 3562 | ||