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