diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-12 11:51:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-12 11:51:03 +0000 |
commit | 95659c78f10bb8a925bd2ba2e5287fa36562633b (patch) | |
tree | 954c4044c3d154ec82b0f0ec9b58d08ab43da67d /src/transport/plugin_transport_http_server.c | |
parent | cee16bdcf34ba0ea19b190464e41c62f1c467832 (diff) | |
download | gnunet-95659c78f10bb8a925bd2ba2e5287fa36562633b.tar.gz gnunet-95659c78f10bb8a925bd2ba2e5287fa36562633b.zip |
-extend transport plugin API with capability to just disconnect a single session (not yet used)
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 386 |
1 files changed, 197 insertions, 189 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 6d706efba..72562607d 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -23,7 +23,6 @@ | |||
23 | * @brief HTTP/S server transport plugin | 23 | * @brief HTTP/S server transport plugin |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_statistics_service.h" | 28 | #include "gnunet_statistics_service.h" |
@@ -49,7 +48,9 @@ | |||
49 | #define _SEND 1 | 48 | #define _SEND 1 |
50 | 49 | ||
51 | 50 | ||
52 | /* Enable output for debbuging URL's of incoming requests */ | 51 | /** |
52 | * Enable output for debbuging URL's of incoming requests | ||
53 | */ | ||
53 | #define DEBUG_URL_PARSE GNUNET_NO | 54 | #define DEBUG_URL_PARSE GNUNET_NO |
54 | 55 | ||
55 | 56 | ||
@@ -159,22 +160,34 @@ struct Session | |||
159 | 160 | ||
160 | struct ServerConnection | 161 | struct ServerConnection |
161 | { | 162 | { |
162 | /* _RECV or _SEND */ | 163 | /** |
164 | * _RECV or _SEND | ||
165 | */ | ||
163 | int direction; | 166 | int direction; |
164 | 167 | ||
165 | /* Should this connection get disconnected? GNUNET_YES/NO */ | 168 | /** |
169 | * Should this connection get disconnected? GNUNET_YES/NO | ||
170 | */ | ||
166 | int disconnect; | 171 | int disconnect; |
167 | 172 | ||
168 | /* For PUT connections: Is this the first or last callback with size 0 */ | 173 | /** |
174 | * For PUT connections: Is this the first or last callback with size 0 | ||
175 | */ | ||
169 | int connected; | 176 | int connected; |
170 | 177 | ||
171 | /* The session this server connection belongs to */ | 178 | /** |
179 | * The session this server connection belongs to | ||
180 | */ | ||
172 | struct Session *session; | 181 | struct Session *session; |
173 | 182 | ||
174 | /* The MHD connection */ | 183 | /** |
184 | * The MHD connection | ||
185 | */ | ||
175 | struct MHD_Connection *mhd_conn; | 186 | struct MHD_Connection *mhd_conn; |
176 | 187 | ||
177 | /* The MHD daemon */ | 188 | /** |
189 | * The MHD daemon | ||
190 | */ | ||
178 | struct MHD_Daemon *mhd_daemon; | 191 | struct MHD_Daemon *mhd_daemon; |
179 | }; | 192 | }; |
180 | 193 | ||
@@ -192,7 +205,6 @@ struct HTTP_Server_Plugin | |||
192 | /** | 205 | /** |
193 | * Linked list head of open sessions. | 206 | * Linked list head of open sessions. |
194 | */ | 207 | */ |
195 | |||
196 | struct Session *head; | 208 | struct Session *head; |
197 | 209 | ||
198 | /** | 210 | /** |
@@ -225,7 +237,6 @@ struct HTTP_Server_Plugin | |||
225 | */ | 237 | */ |
226 | int verify_external_hostname; | 238 | int verify_external_hostname; |
227 | 239 | ||
228 | |||
229 | /** | 240 | /** |
230 | * Maximum number of sockets the plugin can use | 241 | * Maximum number of sockets the plugin can use |
231 | * Each http inbound /outbound connections are two connections | 242 | * Each http inbound /outbound connections are two connections |
@@ -440,12 +451,6 @@ struct HTTP_Message | |||
440 | 451 | ||
441 | 452 | ||
442 | /** | 453 | /** |
443 | * The http_server plugin handle | ||
444 | */ | ||
445 | static struct HTTP_Server_Plugin * p; | ||
446 | |||
447 | |||
448 | /** | ||
449 | * Start session timeout for session s | 454 | * Start session timeout for session s |
450 | * @param s the session | 455 | * @param s the session |
451 | */ | 456 | */ |
@@ -470,11 +475,15 @@ server_stop_session_timeout (struct Session *s); | |||
470 | 475 | ||
471 | 476 | ||
472 | /** | 477 | /** |
473 | * Disconnect a session s | 478 | * Disconnect session @a s |
479 | * | ||
480 | * @param cls closure with the `struct HTTP_Server_Plugin` | ||
474 | * @param s the session | 481 | * @param s the session |
482 | * @return #GNUNET_OK on success | ||
475 | */ | 483 | */ |
476 | static int | 484 | static int |
477 | server_disconnect (struct Session *s); | 485 | http_server_plugin_disconnect_session (void *cls, |
486 | struct Session *s); | ||
478 | 487 | ||
479 | 488 | ||
480 | /** | 489 | /** |
@@ -482,7 +491,7 @@ server_disconnect (struct Session *s); | |||
482 | * | 491 | * |
483 | * @param plugin the plugin handle | 492 | * @param plugin the plugin handle |
484 | * @param s the session | 493 | * @param s the session |
485 | * @return GNUNET_YES on success, GNUNET_NO on error | 494 | * @return #GNUNET_YES on success, #GNUNET_NO on error |
486 | */ | 495 | */ |
487 | static int | 496 | static int |
488 | server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); | 497 | server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); |
@@ -492,12 +501,13 @@ server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); | |||
492 | * Reschedule the execution of both IPv4 and IPv6 server | 501 | * Reschedule the execution of both IPv4 and IPv6 server |
493 | * @param plugin the plugin | 502 | * @param plugin the plugin |
494 | * @param server which server to schedule v4 or v6? | 503 | * @param server which server to schedule v4 or v6? |
495 | * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait | 504 | * @param now #GNUNET_YES to schedule execution immediately, #GNUNET_NO to wait |
496 | * until timeout | 505 | * until timeout |
497 | */ | 506 | */ |
498 | static void | 507 | static void |
499 | server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | 508 | server_reschedule (struct HTTP_Server_Plugin *plugin, |
500 | int now); | 509 | struct MHD_Daemon *server, |
510 | int now); | ||
501 | 511 | ||
502 | 512 | ||
503 | /** | 513 | /** |
@@ -511,7 +521,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | |||
511 | * @param cls closure | 521 | * @param cls closure |
512 | * @param session which session must be used | 522 | * @param session which session must be used |
513 | * @param msgbuf the message to transmit | 523 | * @param msgbuf the message to transmit |
514 | * @param msgbuf_size number of bytes in 'msgbuf' | 524 | * @param msgbuf_size number of bytes in @a msgbuf |
515 | * @param priority how important is the message (most plugins will | 525 | * @param priority how important is the message (most plugins will |
516 | * ignore message priority and just FIFO) | 526 | * ignore message priority and just FIFO) |
517 | * @param to how long to wait at most for the transmission (does not | 527 | * @param to how long to wait at most for the transmission (does not |
@@ -522,7 +532,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | |||
522 | * been transmitted (or if the transport is ready | 532 | * been transmitted (or if the transport is ready |
523 | * for the next transmission call; or if the | 533 | * for the next transmission call; or if the |
524 | * peer disconnected...); can be NULL | 534 | * peer disconnected...); can be NULL |
525 | * @param cont_cls closure for cont | 535 | * @param cont_cls closure for @a cont |
526 | * @return number of bytes used (on the physical network, with overheads); | 536 | * @return number of bytes used (on the physical network, with overheads); |
527 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 537 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
528 | * and does NOT mean that the message was not transmitted (DV) | 538 | * and does NOT mean that the message was not transmitted (DV) |
@@ -562,8 +572,8 @@ http_server_plugin_send (void *cls, | |||
562 | } | 572 | } |
563 | else | 573 | else |
564 | { | 574 | { |
565 | if (GNUNET_YES == session->server_send->disconnect) | 575 | if (GNUNET_YES == session->server_send->disconnect) |
566 | return GNUNET_SYSERR; | 576 | return GNUNET_SYSERR; |
567 | } | 577 | } |
568 | 578 | ||
569 | 579 | ||
@@ -592,16 +602,15 @@ http_server_plugin_send (void *cls, | |||
592 | 602 | ||
593 | if (NULL != session->server_send) | 603 | if (NULL != session->server_send) |
594 | { | 604 | { |
595 | server_reschedule (session->plugin, | 605 | server_reschedule (session->plugin, |
596 | session->server_send->mhd_daemon, | 606 | session->server_send->mhd_daemon, |
597 | GNUNET_YES); | 607 | GNUNET_YES); |
598 | server_reschedule_session_timeout (session); | 608 | server_reschedule_session_timeout (session); |
599 | } | 609 | } |
600 | return bytes_sent; | 610 | return bytes_sent; |
601 | } | 611 | } |
602 | 612 | ||
603 | 613 | ||
604 | |||
605 | /** | 614 | /** |
606 | * Function that can be used to force the plugin to disconnect | 615 | * Function that can be used to force the plugin to disconnect |
607 | * from the given peer and cancel all previous transmissions | 616 | * from the given peer and cancel all previous transmissions |
@@ -611,16 +620,16 @@ http_server_plugin_send (void *cls, | |||
611 | * @param target peer from which to disconnect | 620 | * @param target peer from which to disconnect |
612 | */ | 621 | */ |
613 | static void | 622 | static void |
614 | http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 623 | http_server_plugin_disconnect_peer (void *cls, |
624 | const struct GNUNET_PeerIdentity *target) | ||
615 | { | 625 | { |
616 | struct HTTP_Server_Plugin *plugin = cls; | 626 | struct HTTP_Server_Plugin *plugin = cls; |
617 | struct Session *next = NULL; | 627 | struct Session *next; |
618 | struct Session *pos = NULL; | 628 | struct Session *pos; |
619 | 629 | ||
620 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 630 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
621 | "Transport tells me to disconnect `%s'\n", | 631 | "Transport tells me to disconnect `%s'\n", |
622 | GNUNET_i2s (target)); | 632 | GNUNET_i2s (target)); |
623 | |||
624 | next = plugin->head; | 633 | next = plugin->head; |
625 | while (NULL != (pos = next)) | 634 | while (NULL != (pos = next)) |
626 | { | 635 | { |
@@ -630,10 +639,9 @@ http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
630 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 639 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
631 | "Disconnecting session %p to `%s'\n", | 640 | "Disconnecting session %p to `%s'\n", |
632 | pos, GNUNET_i2s (target)); | 641 | pos, GNUNET_i2s (target)); |
633 | server_disconnect (pos); | 642 | http_server_plugin_disconnect_session (plugin, pos); |
634 | } | 643 | } |
635 | } | 644 | } |
636 | |||
637 | } | 645 | } |
638 | 646 | ||
639 | 647 | ||
@@ -645,41 +653,42 @@ http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
645 | * | 653 | * |
646 | * @param cls closure | 654 | * @param cls closure |
647 | * @param addr pointer to the address | 655 | * @param addr pointer to the address |
648 | * @param addrlen length of addr | 656 | * @param addrlen length of @a addr |
649 | * @return GNUNET_OK if this is a plausible address for this peer | 657 | * @return #GNUNET_OK if this is a plausible address for this peer |
650 | * and transport | 658 | * and transport |
651 | */ | 659 | */ |
652 | static int | 660 | static int |
653 | http_server_plugin_address_suggested (void *cls, const void *addr, | 661 | http_server_plugin_address_suggested (void *cls, |
654 | size_t addrlen) | 662 | const void *addr, |
663 | size_t addrlen) | ||
655 | { | 664 | { |
656 | struct HttpAddressWrapper *next; | 665 | struct HTTP_Server_Plugin *plugin = cls; |
657 | struct HttpAddressWrapper *pos; | 666 | struct HttpAddressWrapper *next; |
658 | const struct HttpAddress *haddr = addr; | 667 | struct HttpAddressWrapper *pos; |
659 | 668 | const struct HttpAddress *haddr = addr; | |
660 | if ((NULL != p->ext_addr) && | 669 | |
661 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, | 670 | if ((NULL != plugin->ext_addr) && |
662 | p->ext_addr, p->ext_addr_len))) | 671 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, |
663 | { | 672 | plugin->ext_addr, |
664 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ | 673 | plugin->ext_addr_len))) |
665 | if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != | 674 | { |
666 | (p->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | 675 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ |
667 | return GNUNET_NO; /* VERIFY option not set as required! */ | 676 | if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != |
668 | return GNUNET_OK; | 677 | (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
669 | } | 678 | return GNUNET_NO; /* VERIFY option not set as required! */ |
670 | 679 | return GNUNET_OK; | |
671 | next = p->addr_head; | 680 | } |
672 | while (NULL != (pos = next)) | 681 | next = plugin->addr_head; |
673 | { | 682 | while (NULL != (pos = next)) |
674 | next = pos->next; | 683 | { |
675 | if (GNUNET_YES == (http_common_cmp_addresses(addr, | 684 | next = pos->next; |
676 | addrlen, | 685 | if (GNUNET_YES == (http_common_cmp_addresses(addr, |
677 | pos->address, | 686 | addrlen, |
678 | pos->addrlen))) | 687 | pos->address, |
679 | return GNUNET_OK; | 688 | pos->addrlen))) |
680 | 689 | return GNUNET_OK; | |
681 | } | 690 | } |
682 | return GNUNET_NO; | 691 | return GNUNET_NO; |
683 | } | 692 | } |
684 | 693 | ||
685 | 694 | ||
@@ -705,33 +714,32 @@ http_server_plugin_get_session (void *cls, | |||
705 | * Deleting the session | 714 | * Deleting the session |
706 | * Must not be used afterwards | 715 | * Must not be used afterwards |
707 | * | 716 | * |
717 | * @param cls closure with the `struct HTTP_ServerPlugin` | ||
708 | * @param s the session to delete | 718 | * @param s the session to delete |
719 | * @return #GNUNET_OK on success | ||
709 | */ | 720 | */ |
710 | static void | 721 | static int |
711 | server_delete_session (struct Session *s) | 722 | server_delete_session (void *cls, |
723 | struct Session *s) | ||
712 | { | 724 | { |
713 | struct HTTP_Server_Plugin *plugin = s->plugin; | 725 | struct HTTP_Server_Plugin *plugin = cls; |
714 | server_stop_session_timeout(s); | 726 | struct HTTP_Message *msg; |
727 | struct HTTP_Message *tmp; | ||
715 | 728 | ||
729 | server_stop_session_timeout(s); | ||
716 | GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); | 730 | GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); |
717 | struct HTTP_Message *msg = s->msg_head; | 731 | msg = s->msg_head; |
718 | struct HTTP_Message *tmp = NULL; | 732 | while (NULL != msg) |
719 | |||
720 | while (msg != NULL) | ||
721 | { | 733 | { |
722 | tmp = msg->next; | 734 | tmp = msg->next; |
723 | |||
724 | GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); | 735 | GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); |
725 | if (msg->transmit_cont != NULL) | 736 | if (NULL != msg->transmit_cont) |
726 | { | ||
727 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, | 737 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, |
728 | msg->size, msg->pos + msg->overhead); | 738 | msg->size, msg->pos + msg->overhead); |
729 | } | ||
730 | GNUNET_free (msg); | 739 | GNUNET_free (msg); |
731 | msg = tmp; | 740 | msg = tmp; |
732 | } | 741 | } |
733 | 742 | if (NULL != s->msg_tk) | |
734 | if (s->msg_tk != NULL) | ||
735 | { | 743 | { |
736 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 744 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
737 | s->msg_tk = NULL; | 745 | s->msg_tk = NULL; |
@@ -739,9 +747,11 @@ server_delete_session (struct Session *s) | |||
739 | GNUNET_free (s->addr); | 747 | GNUNET_free (s->addr); |
740 | GNUNET_free_non_null (s->server_recv); | 748 | GNUNET_free_non_null (s->server_recv); |
741 | GNUNET_free_non_null (s->server_send); | 749 | GNUNET_free_non_null (s->server_send); |
742 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 750 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
751 | plugin->name, | ||
743 | "Session %p destroyed\n", s); | 752 | "Session %p destroyed\n", s); |
744 | GNUNET_free (s); | 753 | GNUNET_free (s); |
754 | return GNUNET_OK; | ||
745 | } | 755 | } |
746 | 756 | ||
747 | 757 | ||
@@ -770,11 +780,11 @@ server_stop_session_timeout (struct Session *s) | |||
770 | * @param plugin plugin | 780 | * @param plugin plugin |
771 | * @param daemon_handle the MHD daemon handle | 781 | * @param daemon_handle the MHD daemon handle |
772 | * @param now schedule immediately | 782 | * @param now schedule immediately |
773 | * @return gnunet task identifier | 783 | * @return task identifier |
774 | */ | 784 | */ |
775 | static GNUNET_SCHEDULER_TaskIdentifier | 785 | static GNUNET_SCHEDULER_TaskIdentifier |
776 | server_schedule (struct HTTP_Server_Plugin *plugin, | 786 | server_schedule (struct HTTP_Server_Plugin *plugin, |
777 | struct MHD_Daemon *daemon_handle, | 787 | struct MHD_Daemon *daemon_handle, |
778 | int now); | 788 | int now); |
779 | 789 | ||
780 | 790 | ||
@@ -782,12 +792,13 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
782 | * Reschedule the execution of both IPv4 and IPv6 server | 792 | * Reschedule the execution of both IPv4 and IPv6 server |
783 | * @param plugin the plugin | 793 | * @param plugin the plugin |
784 | * @param server which server to schedule v4 or v6? | 794 | * @param server which server to schedule v4 or v6? |
785 | * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait | 795 | * @param now #GNUNET_YES to schedule execution immediately, #GNUNET_NO to wait |
786 | * until timeout | 796 | * until timeout |
787 | */ | 797 | */ |
788 | static void | 798 | static void |
789 | server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | 799 | server_reschedule (struct HTTP_Server_Plugin *plugin, |
790 | int now) | 800 | struct MHD_Daemon *server, |
801 | int now) | ||
791 | { | 802 | { |
792 | if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) | 803 | if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) |
793 | { | 804 | { |
@@ -824,21 +835,24 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | |||
824 | 835 | ||
825 | 836 | ||
826 | /** | 837 | /** |
827 | * Disconnect session s | 838 | * Disconnect session @a s |
828 | * | 839 | * |
840 | * @param cls closure with the `struct HTTP_Server_Plugin` | ||
829 | * @param s the session | 841 | * @param s the session |
830 | * @return GNUNET_OK on success | 842 | * @return #GNUNET_OK on success |
831 | */ | 843 | */ |
832 | static int | 844 | static int |
833 | server_disconnect (struct Session *s) | 845 | http_server_plugin_disconnect_session (void *cls, |
846 | struct Session *s) | ||
834 | { | 847 | { |
835 | struct ServerConnection * send = NULL; | 848 | struct HTTP_Server_Plugin *plugin = cls; |
836 | struct ServerConnection * recv = NULL; | 849 | struct ServerConnection * send; |
850 | struct ServerConnection * recv; | ||
837 | 851 | ||
838 | if (GNUNET_NO == server_exist_session (p, s)) | 852 | if (GNUNET_NO == server_exist_session (plugin, s)) |
839 | { | 853 | { |
840 | GNUNET_break (0); | 854 | GNUNET_break (0); |
841 | return GNUNET_SYSERR; | 855 | return GNUNET_SYSERR; |
842 | } | 856 | } |
843 | 857 | ||
844 | send = (struct ServerConnection *) s->server_send; | 858 | send = (struct ServerConnection *) s->server_send; |
@@ -849,10 +863,9 @@ server_disconnect (struct Session *s) | |||
849 | s, s->server_send, GNUNET_i2s (&s->target)); | 863 | s, s->server_send, GNUNET_i2s (&s->target)); |
850 | 864 | ||
851 | send->disconnect = GNUNET_YES; | 865 | send->disconnect = GNUNET_YES; |
852 | #if MHD_VERSION >= 0x00090E00 | 866 | MHD_set_connection_option (send->mhd_conn, |
853 | MHD_set_connection_option (send->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, | 867 | MHD_CONNECTION_OPTION_TIMEOUT, |
854 | 1); | 868 | 1); |
855 | #endif | ||
856 | server_reschedule (s->plugin, send->mhd_daemon, GNUNET_YES); | 869 | server_reschedule (s->plugin, send->mhd_daemon, GNUNET_YES); |
857 | } | 870 | } |
858 | 871 | ||
@@ -864,17 +877,15 @@ server_disconnect (struct Session *s) | |||
864 | s, s->server_recv, GNUNET_i2s (&s->target)); | 877 | s, s->server_recv, GNUNET_i2s (&s->target)); |
865 | 878 | ||
866 | recv->disconnect = GNUNET_YES; | 879 | recv->disconnect = GNUNET_YES; |
867 | #if MHD_VERSION >= 0x00090E00 | 880 | MHD_set_connection_option (recv->mhd_conn, |
868 | MHD_set_connection_option (recv->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, | 881 | MHD_CONNECTION_OPTION_TIMEOUT, |
869 | 1); | 882 | 1); |
870 | #endif | ||
871 | server_reschedule (s->plugin, recv->mhd_daemon, GNUNET_YES); | 883 | server_reschedule (s->plugin, recv->mhd_daemon, GNUNET_YES); |
872 | } | 884 | } |
873 | return GNUNET_OK; | 885 | return GNUNET_OK; |
874 | } | 886 | } |
875 | 887 | ||
876 | 888 | ||
877 | |||
878 | /** | 889 | /** |
879 | * Tell MHD that the connection should timeout after @a to seconds. | 890 | * Tell MHD that the connection should timeout after @a to seconds. |
880 | * | 891 | * |
@@ -887,7 +898,6 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
887 | struct Session *s, | 898 | struct Session *s, |
888 | unsigned int to) | 899 | unsigned int to) |
889 | { | 900 | { |
890 | #if MHD_VERSION >= 0x00090E00 | ||
891 | /* Setting timeouts for other connections */ | 901 | /* Setting timeouts for other connections */ |
892 | if (NULL != s->server_recv) | 902 | if (NULL != s->server_recv) |
893 | { | 903 | { |
@@ -909,9 +919,9 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
909 | to); | 919 | to); |
910 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); | 920 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); |
911 | } | 921 | } |
912 | #endif | ||
913 | } | 922 | } |
914 | 923 | ||
924 | |||
915 | /** | 925 | /** |
916 | * Parse incoming URL for tag and target | 926 | * Parse incoming URL for tag and target |
917 | * | 927 | * |
@@ -919,9 +929,8 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
919 | * @param url incoming url | 929 | * @param url incoming url |
920 | * @param target where to store the target | 930 | * @param target where to store the target |
921 | * @param tag where to store the tag | 931 | * @param tag where to store the tag |
922 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 932 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
923 | */ | 933 | */ |
924 | |||
925 | static int | 934 | static int |
926 | server_parse_url (struct HTTP_Server_Plugin *plugin, | 935 | server_parse_url (struct HTTP_Server_Plugin *plugin, |
927 | const char *url, | 936 | const char *url, |
@@ -1136,7 +1145,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1136 | return NULL; | 1145 | return NULL; |
1137 | } | 1146 | } |
1138 | 1147 | ||
1139 | s = GNUNET_malloc (sizeof (struct Session)); | 1148 | s = GNUNET_new (struct Session); |
1140 | memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); | 1149 | memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); |
1141 | s->plugin = plugin; | 1150 | s->plugin = plugin; |
1142 | s->addr = addr; | 1151 | s->addr = addr; |
@@ -1155,9 +1164,11 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1155 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1164 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1156 | "Creating new session %p for peer `%s' connecting from `%s'\n", | 1165 | "Creating new session %p for peer `%s' connecting from `%s'\n", |
1157 | s, GNUNET_i2s (&target), | 1166 | s, GNUNET_i2s (&target), |
1158 | http_common_plugin_address_to_string (NULL, p->protocol, addr, addr_len)); | 1167 | http_common_plugin_address_to_string (NULL, |
1168 | plugin->protocol, | ||
1169 | addr, addr_len)); | ||
1159 | } | 1170 | } |
1160 | sc = GNUNET_malloc (sizeof (struct ServerConnection)); | 1171 | sc = GNUNET_new (struct ServerConnection); |
1161 | if (conn_info->client_addr->sa_family == AF_INET) | 1172 | if (conn_info->client_addr->sa_family == AF_INET) |
1162 | sc->mhd_daemon = plugin->server_v4; | 1173 | sc->mhd_daemon = plugin->server_v4; |
1163 | if (conn_info->client_addr->sa_family == AF_INET6) | 1174 | if (conn_info->client_addr->sa_family == AF_INET6) |
@@ -1218,19 +1229,16 @@ server_lookup_session (struct HTTP_Server_Plugin *plugin, | |||
1218 | return NULL; | 1229 | return NULL; |
1219 | } | 1230 | } |
1220 | 1231 | ||
1221 | int | 1232 | |
1222 | server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s) | 1233 | static int |
1234 | server_exist_session (struct HTTP_Server_Plugin *plugin, | ||
1235 | struct Session *s) | ||
1223 | { | 1236 | { |
1224 | struct Session * head; | 1237 | struct Session * head; |
1225 | 1238 | ||
1226 | GNUNET_assert (NULL != plugin); | ||
1227 | GNUNET_assert (NULL != s); | ||
1228 | |||
1229 | for (head = plugin->head; head != NULL; head = head->next) | 1239 | for (head = plugin->head; head != NULL; head = head->next) |
1230 | { | ||
1231 | if (head == s) | 1240 | if (head == s) |
1232 | return GNUNET_YES; | 1241 | return GNUNET_YES; |
1233 | } | ||
1234 | return GNUNET_NO; | 1242 | return GNUNET_NO; |
1235 | } | 1243 | } |
1236 | 1244 | ||
@@ -1252,8 +1260,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1252 | struct HTTP_Message *msg; | 1260 | struct HTTP_Message *msg; |
1253 | char *stat_txt; | 1261 | char *stat_txt; |
1254 | 1262 | ||
1255 | GNUNET_assert (NULL != p); | 1263 | if (GNUNET_NO == server_exist_session (s->plugin, s)) |
1256 | if (GNUNET_NO == server_exist_session (p, s)) | ||
1257 | return 0; | 1264 | return 0; |
1258 | msg = s->msg_head; | 1265 | msg = s->msg_head; |
1259 | if (NULL != msg) | 1266 | if (NULL != msg) |
@@ -1278,12 +1285,14 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1278 | { | 1285 | { |
1279 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 1286 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
1280 | "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); | 1287 | "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); |
1281 | GNUNET_asprintf (&stat_txt, "# bytes currently in %s_server buffers", p->protocol); | 1288 | GNUNET_asprintf (&stat_txt, "# bytes currently in %s_server buffers", |
1282 | GNUNET_STATISTICS_update (p->env->stats, | 1289 | s->plugin->protocol); |
1290 | GNUNET_STATISTICS_update (s->plugin->env->stats, | ||
1283 | stat_txt, -bytes_read, GNUNET_NO); | 1291 | stat_txt, -bytes_read, GNUNET_NO); |
1284 | GNUNET_free (stat_txt); | 1292 | GNUNET_free (stat_txt); |
1285 | GNUNET_asprintf (&stat_txt, "# bytes transmitted via %s_server", p->protocol); | 1293 | GNUNET_asprintf (&stat_txt, "# bytes transmitted via %s_server", |
1286 | GNUNET_STATISTICS_update (p->env->stats, | 1294 | s->plugin->protocol); |
1295 | GNUNET_STATISTICS_update (s->plugin->env->stats, | ||
1287 | stat_txt, bytes_read, GNUNET_NO); | 1296 | stat_txt, bytes_read, GNUNET_NO); |
1288 | GNUNET_free (stat_txt); | 1297 | GNUNET_free (stat_txt); |
1289 | } | 1298 | } |
@@ -1297,7 +1306,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1297 | * @param cls current session as closure | 1306 | * @param cls current session as closure |
1298 | * @param client client | 1307 | * @param client client |
1299 | * @param message the message to be forwarded to transport service | 1308 | * @param message the message to be forwarded to transport service |
1300 | * @return GNUNET_OK | 1309 | * @return #GNUNET_OK |
1301 | */ | 1310 | */ |
1302 | static int | 1311 | static int |
1303 | server_receive_mst_cb (void *cls, void *client, | 1312 | server_receive_mst_cb (void *cls, void *client, |
@@ -1309,8 +1318,7 @@ server_receive_mst_cb (void *cls, void *client, | |||
1309 | struct GNUNET_TIME_Relative delay; | 1318 | struct GNUNET_TIME_Relative delay; |
1310 | char *stat_txt; | 1319 | char *stat_txt; |
1311 | 1320 | ||
1312 | GNUNET_assert (NULL != p); | 1321 | if (GNUNET_NO == server_exist_session (s->plugin, s)) |
1313 | if (GNUNET_NO == server_exist_session(p, s)) | ||
1314 | return GNUNET_OK; | 1322 | return GNUNET_OK; |
1315 | 1323 | ||
1316 | 1324 | ||
@@ -1340,7 +1348,9 @@ server_receive_mst_cb (void *cls, void *client, | |||
1340 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1348 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1341 | "Peer `%s' address `%s' next read delayed for %s\n", | 1349 | "Peer `%s' address `%s' next read delayed for %s\n", |
1342 | GNUNET_i2s (&s->target), | 1350 | GNUNET_i2s (&s->target), |
1343 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen), | 1351 | http_common_plugin_address_to_string (NULL, |
1352 | plugin->protocol, | ||
1353 | s->addr, s->addrlen), | ||
1344 | GNUNET_STRINGS_relative_time_to_string (delay, | 1354 | GNUNET_STRINGS_relative_time_to_string (delay, |
1345 | GNUNET_YES)); | 1355 | GNUNET_YES)); |
1346 | } | 1356 | } |
@@ -1448,7 +1458,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1448 | s, sc, | 1458 | s, sc, |
1449 | GNUNET_i2s (&s->target), | 1459 | GNUNET_i2s (&s->target), |
1450 | http_common_plugin_address_to_string (NULL, | 1460 | http_common_plugin_address_to_string (NULL, |
1451 | p->protocol, | 1461 | plugin->protocol, |
1452 | s->addr, | 1462 | s->addr, |
1453 | s->addrlen)); | 1463 | s->addrlen)); |
1454 | sc->connected = GNUNET_YES; | 1464 | sc->connected = GNUNET_YES; |
@@ -1462,7 +1472,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1462 | s, sc, | 1472 | s, sc, |
1463 | GNUNET_i2s (&s->target), | 1473 | GNUNET_i2s (&s->target), |
1464 | http_common_plugin_address_to_string (NULL, | 1474 | http_common_plugin_address_to_string (NULL, |
1465 | p->protocol, | 1475 | plugin->protocol, |
1466 | s->addr, | 1476 | s->addr, |
1467 | s->addrlen)); | 1477 | s->addrlen)); |
1468 | sc->connected = GNUNET_NO; | 1478 | sc->connected = GNUNET_NO; |
@@ -1482,7 +1492,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1482 | s, sc, | 1492 | s, sc, |
1483 | GNUNET_i2s (&s->target), | 1493 | GNUNET_i2s (&s->target), |
1484 | http_common_plugin_address_to_string (NULL, | 1494 | http_common_plugin_address_to_string (NULL, |
1485 | p->protocol, | 1495 | plugin->protocol, |
1486 | s->addr, | 1496 | s->addr, |
1487 | s->addrlen), | 1497 | s->addrlen), |
1488 | *upload_data_size); | 1498 | *upload_data_size); |
@@ -1526,7 +1536,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1526 | /** | 1536 | /** |
1527 | * Callback from MHD when a connection disconnects | 1537 | * Callback from MHD when a connection disconnects |
1528 | * | 1538 | * |
1529 | * @param cls closure | 1539 | * @param cls closure with the `struct HTTP_Server_Plugin *` |
1530 | * @param connection the disconnected MHD connection | 1540 | * @param connection the disconnected MHD connection |
1531 | * @param httpSessionCache the pointer to distinguish | 1541 | * @param httpSessionCache the pointer to distinguish |
1532 | */ | 1542 | */ |
@@ -1534,37 +1544,34 @@ static void | |||
1534 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, | 1544 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, |
1535 | void **httpSessionCache) | 1545 | void **httpSessionCache) |
1536 | { | 1546 | { |
1547 | struct HTTP_Server_Plugin *plugin = cls; | ||
1537 | struct ServerConnection *sc = *httpSessionCache; | 1548 | struct ServerConnection *sc = *httpSessionCache; |
1538 | struct Session *s = NULL; | 1549 | struct Session *s = NULL; |
1539 | struct Session *t = NULL; | 1550 | struct Session *t = NULL; |
1540 | struct HTTP_Server_Plugin *plugin = NULL; | ||
1541 | 1551 | ||
1542 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, p->name, | 1552 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1553 | plugin->name, | ||
1543 | "Disconnect for connection %p \n", sc); | 1554 | "Disconnect for connection %p \n", sc); |
1544 | 1555 | ||
1545 | if (sc == NULL) | 1556 | if (sc == NULL) |
1546 | return; | 1557 | return; |
1547 | 1558 | ||
1548 | if (NULL == (s = server_lookup_session (p, sc))) | 1559 | if (NULL == (s = server_lookup_session (plugin, sc))) |
1549 | return; | 1560 | return; |
1550 | 1561 | for (t = plugin->head; t != NULL; t = t->next) | |
1551 | GNUNET_assert (NULL != p); | ||
1552 | for (t = p->head; t != NULL; t = t->next) | ||
1553 | { | ||
1554 | if (t == s) | 1562 | if (t == s) |
1555 | break; | 1563 | break; |
1556 | } | ||
1557 | if (NULL == t) | 1564 | if (NULL == t) |
1558 | return; | 1565 | return; |
1559 | 1566 | ||
1560 | plugin = s->plugin; | ||
1561 | if (sc->direction == _SEND) | 1567 | if (sc->direction == _SEND) |
1562 | { | 1568 | { |
1563 | |||
1564 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1569 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1565 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", | 1570 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", |
1566 | GNUNET_i2s (&s->target), s->server_send, | 1571 | GNUNET_i2s (&s->target), s->server_send, |
1567 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); | 1572 | http_common_plugin_address_to_string (NULL, |
1573 | plugin->protocol, | ||
1574 | s->addr, s->addrlen)); | ||
1568 | s->server_send = NULL; | 1575 | s->server_send = NULL; |
1569 | if (NULL != (s->server_recv)) | 1576 | if (NULL != (s->server_recv)) |
1570 | { | 1577 | { |
@@ -1582,7 +1589,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1582 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1589 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1583 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", | 1590 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", |
1584 | GNUNET_i2s (&s->target), s->server_recv, | 1591 | GNUNET_i2s (&s->target), s->server_recv, |
1585 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); | 1592 | http_common_plugin_address_to_string (NULL, |
1593 | plugin->protocol, | ||
1594 | s->addr, s->addrlen)); | ||
1586 | s->server_recv = NULL; | 1595 | s->server_recv = NULL; |
1587 | /* Do not terminate session when PUT disconnects | 1596 | /* Do not terminate session when PUT disconnects |
1588 | if (NULL != (s->server_send)) | 1597 | if (NULL != (s->server_send)) |
@@ -1610,7 +1619,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1610 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1619 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1611 | "Peer `%s' on address `%s' disconnected\n", | 1620 | "Peer `%s' on address `%s' disconnected\n", |
1612 | GNUNET_i2s (&s->target), | 1621 | GNUNET_i2s (&s->target), |
1613 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); | 1622 | http_common_plugin_address_to_string (NULL, |
1623 | plugin->protocol, | ||
1624 | s->addr, s->addrlen)); | ||
1614 | 1625 | ||
1615 | if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) | 1626 | if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) |
1616 | { | 1627 | { |
@@ -1618,20 +1629,18 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1618 | s->session_ended = GNUNET_YES; | 1629 | s->session_ended = GNUNET_YES; |
1619 | plugin->env->session_end (plugin->env->cls, &s->target, s); | 1630 | plugin->env->session_end (plugin->env->cls, &s->target, s); |
1620 | } | 1631 | } |
1621 | server_delete_session (s); | 1632 | server_delete_session (plugin, s); |
1622 | } | 1633 | } |
1623 | |||
1624 | } | 1634 | } |
1625 | 1635 | ||
1626 | 1636 | ||
1627 | /** | 1637 | /** |
1628 | * Check if incoming connection is accepted. | 1638 | * Check if incoming connection is accepted. |
1629 | 1639 | * | |
1630 | * @param cls plugin as closure | 1640 | * @param cls plugin as closure |
1631 | * @param addr address of incoming connection | 1641 | * @param addr address of incoming connection |
1632 | * @param addr_len address length of incoming connection | 1642 | * @param addr_len address length of incoming connection |
1633 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected | 1643 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected |
1634 | * | ||
1635 | */ | 1644 | */ |
1636 | static int | 1645 | static int |
1637 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | 1646 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) |
@@ -1655,6 +1664,7 @@ server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | |||
1655 | } | 1664 | } |
1656 | } | 1665 | } |
1657 | 1666 | ||
1667 | |||
1658 | static void | 1668 | static void |
1659 | server_log (void *arg, const char *fmt, va_list ap) | 1669 | server_log (void *arg, const char *fmt, va_list ap) |
1660 | { | 1670 | { |
@@ -1717,8 +1727,6 @@ server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1717 | } | 1727 | } |
1718 | 1728 | ||
1719 | 1729 | ||
1720 | #define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG | ||
1721 | |||
1722 | /** | 1730 | /** |
1723 | * Function that queries MHD's select sets and | 1731 | * Function that queries MHD's select sets and |
1724 | * starts the task waiting for them. | 1732 | * starts the task waiting for them. |
@@ -1740,7 +1748,7 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
1740 | struct GNUNET_NETWORK_FDSet *wws; | 1748 | struct GNUNET_NETWORK_FDSet *wws; |
1741 | struct GNUNET_NETWORK_FDSet *wes; | 1749 | struct GNUNET_NETWORK_FDSet *wes; |
1742 | int max; | 1750 | int max; |
1743 | UNSIGNED_MHD_LONG_LONG timeout; | 1751 | MHD_UNSIGNED_LONG_LONG timeout; |
1744 | static unsigned long long last_timeout = 0; | 1752 | static unsigned long long last_timeout = 0; |
1745 | int haveto; | 1753 | int haveto; |
1746 | 1754 | ||
@@ -2158,8 +2166,6 @@ server_stop (struct HTTP_Server_Plugin *plugin) | |||
2158 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | 2166 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); |
2159 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | 2167 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; |
2160 | } | 2168 | } |
2161 | p = NULL; | ||
2162 | |||
2163 | #if BUILD_HTTPS | 2169 | #if BUILD_HTTPS |
2164 | GNUNET_free_non_null (plugin->crypto_init); | 2170 | GNUNET_free_non_null (plugin->crypto_init); |
2165 | GNUNET_free_non_null (plugin->cert); | 2171 | GNUNET_free_non_null (plugin->cert); |
@@ -2198,7 +2204,9 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2198 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); | 2204 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); |
2199 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2205 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2200 | "Notifying transport to add address `%s'\n", | 2206 | "Notifying transport to add address `%s'\n", |
2201 | http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen)); | 2207 | http_common_plugin_address_to_string (NULL, |
2208 | plugin->protocol, | ||
2209 | w->address, w->addrlen)); | ||
2202 | #if BUILD_HTTPS | 2210 | #if BUILD_HTTPS |
2203 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); | 2211 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); |
2204 | #else | 2212 | #else |
@@ -2240,7 +2248,9 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2240 | 2248 | ||
2241 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2249 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2242 | "Notifying transport to remove address `%s'\n", | 2250 | "Notifying transport to remove address `%s'\n", |
2243 | http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen)); | 2251 | http_common_plugin_address_to_string (NULL, |
2252 | plugin->protocol, | ||
2253 | w->address, w->addrlen)); | ||
2244 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); | 2254 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); |
2245 | #if BUILD_HTTPS | 2255 | #if BUILD_HTTPS |
2246 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); | 2256 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); |
@@ -2880,7 +2890,6 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin) | |||
2880 | static void | 2890 | static void |
2881 | server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2891 | server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2882 | { | 2892 | { |
2883 | GNUNET_assert (NULL != cls); | ||
2884 | struct Session *s = cls; | 2893 | struct Session *s = cls; |
2885 | 2894 | ||
2886 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 2895 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -2891,7 +2900,8 @@ server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
2891 | GNUNET_YES)); | 2900 | GNUNET_YES)); |
2892 | 2901 | ||
2893 | /* call session destroy function */ | 2902 | /* call session destroy function */ |
2894 | GNUNET_assert (GNUNET_OK == server_disconnect (s)); | 2903 | GNUNET_assert (GNUNET_OK == |
2904 | http_server_plugin_disconnect_session (s->plugin, s)); | ||
2895 | } | 2905 | } |
2896 | 2906 | ||
2897 | 2907 | ||
@@ -2966,24 +2976,24 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
2966 | 2976 | ||
2967 | if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task) | 2977 | if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task) |
2968 | { | 2978 | { |
2969 | GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); | 2979 | GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); |
2970 | plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; | 2980 | plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; |
2971 | } | 2981 | } |
2972 | 2982 | ||
2973 | if (NULL != plugin->ext_addr) | 2983 | if (NULL != plugin->ext_addr) |
2974 | { | 2984 | { |
2975 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2985 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2976 | "Notifying transport to remove address `%s'\n", | 2986 | "Notifying transport to remove address `%s'\n", |
2977 | http_common_plugin_address_to_string (NULL, | 2987 | http_common_plugin_address_to_string (NULL, |
2978 | p->protocol, | 2988 | plugin->protocol, |
2979 | plugin->ext_addr, | 2989 | plugin->ext_addr, |
2980 | plugin->ext_addr_len)); | 2990 | plugin->ext_addr_len)); |
2981 | #if BUILD_HTTPS | 2991 | #if BUILD_HTTPS |
2982 | plugin->env->notify_address (plugin->env->cls, | 2992 | plugin->env->notify_address (plugin->env->cls, |
2983 | GNUNET_NO, | 2993 | GNUNET_NO, |
2984 | plugin->ext_addr, | 2994 | plugin->ext_addr, |
2985 | plugin->ext_addr_len, | 2995 | plugin->ext_addr_len, |
2986 | "https_client"); | 2996 | "https_client"); |
2987 | #else | 2997 | #else |
2988 | plugin->env->notify_address (plugin->env->cls, | 2998 | plugin->env->notify_address (plugin->env->cls, |
2989 | GNUNET_NO, | 2999 | GNUNET_NO, |
@@ -2991,7 +3001,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
2991 | plugin->ext_addr_len, | 3001 | plugin->ext_addr_len, |
2992 | "http_client"); | 3002 | "http_client"); |
2993 | #endif | 3003 | #endif |
2994 | |||
2995 | } | 3004 | } |
2996 | 3005 | ||
2997 | /* Stop to report addresses to transport service */ | 3006 | /* Stop to report addresses to transport service */ |
@@ -3000,18 +3009,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3000 | next = plugin->head; | 3009 | next = plugin->head; |
3001 | while (NULL != (pos = next)) | 3010 | while (NULL != (pos = next)) |
3002 | { | 3011 | { |
3003 | next = pos->next; | 3012 | next = pos->next; |
3004 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 3013 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
3005 | "Removing left over session %p\n", pos); | 3014 | "Removing left over session %p\n", pos); |
3006 | |||
3007 | if ((GNUNET_YES == pos->session_passed) && (GNUNET_NO == pos->session_ended)) | ||
3008 | { | ||
3009 | /* Notify transport immediately that this session is invalid */ | ||
3010 | pos->session_ended = GNUNET_YES; | ||
3011 | plugin->env->session_end (plugin->env->cls, &pos->target, pos); | ||
3012 | } | ||
3013 | 3015 | ||
3014 | server_delete_session (pos); | 3016 | if ((GNUNET_YES == pos->session_passed) && (GNUNET_NO == pos->session_ended)) |
3017 | { | ||
3018 | /* Notify transport immediately that this session is invalid */ | ||
3019 | pos->session_ended = GNUNET_YES; | ||
3020 | plugin->env->session_end (plugin->env->cls, &pos->target, pos); | ||
3021 | } | ||
3022 | server_delete_session (plugin, pos); | ||
3015 | } | 3023 | } |
3016 | 3024 | ||
3017 | /* Clean up */ | 3025 | /* Clean up */ |
@@ -3071,15 +3079,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3071 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 3079 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
3072 | struct HTTP_Server_Plugin *plugin; | 3080 | struct HTTP_Server_Plugin *plugin; |
3073 | 3081 | ||
3074 | plugin = GNUNET_malloc (sizeof (struct HTTP_Server_Plugin)); | 3082 | plugin = GNUNET_new (struct HTTP_Server_Plugin); |
3075 | plugin->env = env; | 3083 | plugin->env = env; |
3076 | p = plugin; | ||
3077 | 3084 | ||
3078 | if (NULL == env->receive) | 3085 | if (NULL == env->receive) |
3079 | { | 3086 | { |
3080 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 3087 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
3081 | initialze the plugin or the API */ | 3088 | initialze the plugin or the API */ |
3082 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3089 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3083 | api->cls = NULL; | 3090 | api->cls = NULL; |
3084 | api->address_to_string = &http_plugin_address_to_string; | 3091 | api->address_to_string = &http_plugin_address_to_string; |
3085 | api->string_to_address = &http_common_plugin_string_to_address; | 3092 | api->string_to_address = &http_common_plugin_string_to_address; |
@@ -3087,10 +3094,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3087 | return api; | 3094 | return api; |
3088 | } | 3095 | } |
3089 | 3096 | ||
3090 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3097 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3091 | api->cls = plugin; | 3098 | api->cls = plugin; |
3092 | api->send = &http_server_plugin_send; | 3099 | api->send = &http_server_plugin_send; |
3093 | api->disconnect = &http_server_plugin_disconnect; | 3100 | api->disconnect_peer = &http_server_plugin_disconnect_peer; |
3101 | api->disconnect_session = &http_server_plugin_disconnect_session; | ||
3094 | api->check_address = &http_server_plugin_address_suggested; | 3102 | api->check_address = &http_server_plugin_address_suggested; |
3095 | api->get_session = &http_server_plugin_get_session; | 3103 | api->get_session = &http_server_plugin_get_session; |
3096 | 3104 | ||