2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/plugin_transport_http_server.c
23 * @brief HTTP/S server transport plugin
24 * @author Matthias Wachs
28 #include "gnunet_protocols.h"
29 #include "gnunet_connection_lib.h"
30 #include "gnunet_server_lib.h"
31 #include "gnunet_service_lib.h"
32 #include "gnunet_statistics_service.h"
33 #include "gnunet_transport_service.h"
34 #include "gnunet_transport_plugin.h"
36 #include "gnunet_container_lib.h"
37 #include "gnunet_nat_lib.h"
38 #include "plugin_transport_http_common.h"
39 #include "microhttpd.h"
42 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_server_init
43 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_server_done
45 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_server_init
46 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_server_done
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>"
54 * Encapsulation of all of the state of the plugin.
59 * Session handle for connections.
64 * Stored in a linked list.
69 * Stored in a linked list.
74 * To whom are we talking to (set to our identity
75 * if we are still waiting for the welcome message)
77 struct GNUNET_PeerIdentity target;
80 * Pointer to the global plugin struct.
82 struct HTTP_Server_Plugin *plugin;
85 * next pointer for double linked list
87 struct HTTP_Message *msg_head;
90 * previous pointer for double linked list
92 struct HTTP_Message *msg_tail;
95 * Message stream tokenizer for incoming data
97 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
102 struct ServerConnection *server_recv;
107 struct ServerConnection *server_send;
120 * Unique HTTP/S connection tag for this connection
125 * ATS network type in NBO
127 uint32_t ats_address_network_type;
130 * Was session given to transport service?
135 * Absolute time when to receive data again
136 * Used for receive throttling
138 struct GNUNET_TIME_Absolute next_receive;
141 * Session timeout task
143 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
146 struct ServerConnection
151 /* Should this connection get disconnected? GNUNET_YES/NO */
154 /* The session this server connection belongs to */
155 struct Session *session;
157 /* The MHD connection */
158 struct MHD_Connection *mhd_conn;
161 struct MHD_Daemon *mhd_daemon;
165 * Encapsulation of all of the state of the plugin.
167 struct HTTP_Server_Plugin
172 struct GNUNET_TRANSPORT_PluginEnvironment *env;
175 * Linked list head of open sessions.
178 struct Session *head;
181 * Linked list tail of open sessions.
183 struct Session *tail;
198 char *external_hostname;
201 * Maximum number of sockets the plugin can use
202 * Each http inbound /outbound connections are two connections
204 unsigned int max_connections;
207 * Current number of sockets the plugin can use
208 * Each http inbound /outbound connections are two connections
210 unsigned int cur_connections;
213 * External hostname the plugin can be connected to, can be different to
214 * the host's FQDN, used e.g. for reverse proxying
219 * External address length
239 * Task calling transport service about external address
241 GNUNET_SCHEDULER_TaskIdentifier notify_ext_task;
244 * NAT handle & address management
246 struct GNUNET_NAT_Handle *nat;
249 * List of own addresses
253 * IPv4 addresses DLL head
255 struct HttpAddressWrapper *addr_head;
258 * IPv4 addresses DLL tail
260 struct HttpAddressWrapper *addr_tail;
263 * IPv4 server socket to bind to
265 struct sockaddr_in *server_addr_v4;
268 * IPv6 server socket to bind to
270 struct sockaddr_in6 *server_addr_v6;
275 GNUNET_SCHEDULER_TaskIdentifier server_v4_task;
280 GNUNET_SCHEDULER_TaskIdentifier server_v6_task;
283 * The IPv4 server is scheduled to run asap
285 int server_v4_immediately;
288 * The IPv6 server is scheduled to run asap
290 int server_v6_immediately;
295 struct MHD_Daemon *server_v4;
300 struct MHD_Daemon *server_v6;
308 * Use RC4-128 instead of AES:
309 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
328 * Wrapper to manage addresses
330 struct HttpAddressWrapper
335 struct HttpAddressWrapper *next;
338 * Linked list previous
340 struct HttpAddressWrapper *prev;
348 * Message to send using http
353 * next pointer for double linked list
355 struct HTTP_Message *next;
358 * previous pointer for double linked list
360 struct HTTP_Message *prev;
363 * buffer containing data to send
368 * amount of data already sent
378 * Continuation function to call once the transmission buffer
379 * has again space available. NULL if there is no
380 * continuation to call.
382 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
385 * Closure for transmit_cont.
387 void *transmit_cont_cls;
391 static struct HTTP_Server_Plugin * p;
394 * Start session timeout
397 server_start_session_timeout (struct Session *s);
400 * Increment session timeout due to activity
403 server_reschedule_session_timeout (struct Session *s);
409 server_stop_session_timeout (struct Session *s);
412 * Disconnect a session
415 server_disconnect (struct Session *s);
418 server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s);
421 * Reschedule the execution of both IPv4 and IPv6 server
422 * @param plugin the plugin
423 * @param server which server to schedule v4 or v6?
424 * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait
428 server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now);
431 * Function that can be used by the transport service to transmit
432 * a message using the plugin. Note that in the case of a
433 * peer disconnecting, the continuation MUST be called
434 * prior to the disconnect notification itself. This function
435 * will be called with this peer's HELLO message to initiate
436 * a fresh connection to another peer.
439 * @param session which session must be used
440 * @param msgbuf the message to transmit
441 * @param msgbuf_size number of bytes in 'msgbuf'
442 * @param priority how important is the message (most plugins will
443 * ignore message priority and just FIFO)
444 * @param to how long to wait at most for the transmission (does not
445 * require plugins to discard the message after the timeout,
446 * just advisory for the desired delay; most plugins will ignore
448 * @param cont continuation to call once the message has
449 * been transmitted (or if the transport is ready
450 * for the next transmission call; or if the
451 * peer disconnected...); can be NULL
452 * @param cont_cls closure for cont
453 * @return number of bytes used (on the physical network, with overheads);
454 * -1 on hard errors (i.e. address invalid); 0 is a legal value
455 * and does NOT mean that the message was not transmitted (DV)
458 http_server_plugin_send (void *cls,
459 struct Session *session,
460 const char *msgbuf, size_t msgbuf_size,
461 unsigned int priority,
462 struct GNUNET_TIME_Relative to,
463 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
465 struct HTTP_Server_Plugin *plugin = cls;
466 struct HTTP_Message *msg;
469 GNUNET_assert (plugin != NULL);
470 GNUNET_assert (session != NULL);
472 if (GNUNET_NO == server_exist_session (plugin, session))
475 return GNUNET_SYSERR;
477 GNUNET_assert (NULL != session->server_send);
479 if (GNUNET_YES == session->server_send->disconnect)
480 return GNUNET_SYSERR;
482 /* create new message and schedule */
483 bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size;
484 msg = GNUNET_malloc (bytes_sent);
486 msg->size = msgbuf_size;
488 msg->buf = (char *) &msg[1];
489 msg->transmit_cont = cont;
490 msg->transmit_cont_cls = cont_cls;
491 memcpy (msg->buf, msgbuf, msgbuf_size);
493 GNUNET_CONTAINER_DLL_insert_tail (session->msg_head, session->msg_tail, msg);
495 server_reschedule (session->plugin, session->server_send->mhd_daemon, GNUNET_YES);
496 server_reschedule_session_timeout (session);
498 /* struct Plugin *plugin = cls; */
505 * Function that can be used to force the plugin to disconnect
506 * from the given peer and cancel all previous transmissions
507 * (and their continuationc).
510 * @param target peer from which to disconnect
513 http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
515 struct HTTP_Server_Plugin *plugin = cls;
516 struct Session *next = NULL;
517 struct Session *pos = NULL;
519 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
520 "Transport tells me to disconnect `%s'\n",
521 GNUNET_i2s (target));
524 while (NULL != (pos = next))
527 if (0 == memcmp (target, &pos->target, sizeof (struct GNUNET_PeerIdentity)))
529 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
530 "Disconnecting session %p to `%s'\n",
531 pos, GNUNET_i2s (target));
532 GNUNET_assert (GNUNET_OK == server_disconnect (pos));
540 * Another peer has suggested an address for this
541 * peer and transport plugin. Check that this could be a valid
542 * address. If so, consider adding it to the list
546 * @param addr pointer to the address
547 * @param addrlen length of addr
548 * @return GNUNET_OK if this is a plausible address for this peer
552 http_server_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
554 struct HTTP_Server_Plugin *plugin = cls;
555 struct HttpAddressWrapper *next;
556 struct HttpAddressWrapper *pos;
559 if ((NULL != plugin->ext_addr) && GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, plugin->ext_addr, plugin->ext_addr_len)))
562 next = plugin->addr_head;
563 while (NULL != (pos = next))
566 if (GNUNET_YES == (http_common_cmp_addresses(addr,
578 * Creates a new outbound session the transport
579 * service will use to send data to the peer
581 * Since HTTP/S server cannot create sessions, always return NULL
583 * @param cls the plugin
584 * @param address the address
585 * @return always NULL
587 static struct Session *
588 http_server_plugin_get_session (void *cls,
589 const struct GNUNET_HELLO_Address *address)
596 * Deleting the session
597 * Must not be used afterwards
601 server_delete_session (struct Session *s)
603 struct HTTP_Server_Plugin *plugin = s->plugin;
604 server_stop_session_timeout(s);
606 if (GNUNET_YES == s->session_passed)
607 plugin->env->session_end (plugin->env->cls, &s->target, s);
609 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
610 struct HTTP_Message *msg = s->msg_head;
611 struct HTTP_Message *tmp = NULL;
617 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
618 if (msg->transmit_cont != NULL)
620 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
626 if (s->msg_tk != NULL)
628 GNUNET_SERVER_mst_destroy (s->msg_tk);
631 GNUNET_free (s->addr);
632 GNUNET_free_non_null (s->server_recv);
633 GNUNET_free_non_null (s->server_send);
636 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
637 "Session %p destroyed\n", s);
645 server_stop_session_timeout (struct Session *s)
647 GNUNET_assert (NULL != s);
649 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
651 GNUNET_SCHEDULER_cancel (s->timeout_task);
652 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
653 GNUNET_log (TIMEOUT_LOG, "Timeout stopped for session %p\n", s);
658 * Function that queries MHD's select sets and
659 * starts the task waiting for them.
660 * @param plugin plugin
661 * @param daemon_handle the MHD daemon handle
662 * @return gnunet task identifier
664 static GNUNET_SCHEDULER_TaskIdentifier
665 server_schedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *daemon_handle,
669 * Reschedule the execution of both IPv4 and IPv6 server
670 * @param plugin the plugin
671 * @param server which server to schedule v4 or v6?
672 * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait
676 server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
678 if ((server == plugin->server_v4) && (plugin->server_v4 != NULL))
680 if (GNUNET_YES == plugin->server_v4_immediately)
681 return; /* No rescheduling, server will run asap */
683 if (GNUNET_YES == now)
684 plugin->server_v4_immediately = GNUNET_YES;
686 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
688 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
689 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
691 plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now);
694 if ((server == plugin->server_v6) && (plugin->server_v6 != NULL))
696 if (GNUNET_YES == plugin->server_v6_immediately)
697 return; /* No rescheduling, server will run asap */
699 if (GNUNET_YES == now)
700 plugin->server_v6_immediately = GNUNET_YES;
702 if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
704 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
705 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
707 plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
712 server_disconnect (struct Session *s)
714 struct ServerConnection * send;
715 struct ServerConnection * recv;
717 send = (struct ServerConnection *) s->server_send;
718 if (s->server_send != NULL)
720 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
721 "Server: %p / %p Terminating inbound PUT session to peer `%s'\n",
722 s, s->server_send, GNUNET_i2s (&s->target));
724 send->disconnect = GNUNET_YES;
725 #if MHD_VERSION >= 0x00090E00
726 MHD_set_connection_option (send->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
729 server_reschedule (s->plugin, send->mhd_daemon, GNUNET_YES);
732 recv = (struct ServerConnection *) s->server_recv;
735 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
736 "Server: %p / %p Terminating inbound GET session to peer `%s'\n",
737 s, s->server_recv, GNUNET_i2s (&s->target));
739 recv->disconnect = GNUNET_YES;
740 #if MHD_VERSION >= 0x00090E00
741 MHD_set_connection_option (recv->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
744 server_reschedule (s->plugin, recv->mhd_daemon, GNUNET_YES);
750 server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, struct Session *s, int to)
752 #if MHD_VERSION >= 0x00090E00
753 /* Setting timeouts for other connections */
754 if (s->server_recv != NULL)
756 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
757 "Setting timeout for %p to %u sec.\n", s->server_recv, to);
758 MHD_set_connection_option (s->server_recv->mhd_conn,
759 MHD_CONNECTION_OPTION_TIMEOUT,
761 server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO);
763 if (s->server_send != NULL)
765 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
766 "Setting timeout for %p to %u sec.\n", s->server_send, to);
767 MHD_set_connection_option (s->server_send->mhd_conn,
768 MHD_CONNECTION_OPTION_TIMEOUT,
770 server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO);
776 static struct ServerConnection *
777 server_lookup_connection (struct HTTP_Server_Plugin *plugin,
778 struct MHD_Connection *mhd_connection, const char *url,
781 struct Session *s = NULL;
782 struct ServerConnection *sc = NULL;
783 const union MHD_ConnectionInfo *conn_info;
784 struct GNUNET_ATS_Information ats;
789 struct GNUNET_PeerIdentity target;
791 int direction = GNUNET_SYSERR;
794 /* url parsing variables */
802 conn_info = MHD_get_connection_info (mhd_connection,
803 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
804 if ((conn_info->client_addr->sa_family != AF_INET) &&
805 (conn_info->client_addr->sa_family != AF_INET6))
808 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
809 "New %s connection from %s\n", method, url);
811 * URL is valid if it is in the form [peerid[103];tag]*/
812 url_len = strlen (url);
813 url_end = (char *) &url[url_len];
817 goto error; /* too short */
819 hash_start = strrchr (url, '/');
820 if (NULL == hash_start)
822 goto error; /* '/' delimiter not found */
824 if (hash_start >= url_end)
826 goto error; /* mal formed */
830 hash_end = strrchr (hash_start, ';');
831 if (NULL == hash_end)
832 goto error; /* ';' delimiter not found */
833 if (hash_end >= url_end)
835 goto error; /* mal formed */
838 if (hash_start >= hash_end)
840 goto error; /* mal formed */
843 if ((strlen(hash_start) - strlen(hash_end)) != 103)
845 goto error; /* invalid hash length */
849 memcpy (hash, hash_start, 103);
851 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((const char *) hash, &(target.hashPubKey)))
853 goto error; /* mal formed */
856 if (hash_end >= url_end)
858 goto error; /* mal formed */
861 tag_start = &hash_end[1];
864 tag = strtoul (tag_start, &tag_end, 10);
867 goto error; /* mal formed */
871 goto error; /* mal formed */
873 if (tag_end != url_end)
875 goto error; /* mal formed */
878 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
879 direction = _RECEIVE;
880 else if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
887 plugin->cur_connections++;
888 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
889 "New %s connection from %s with tag %u (%u of %u)\n",
891 GNUNET_i2s (&target), tag,
892 plugin->cur_connections, plugin->max_connections);
894 /* find duplicate session */
898 if ((0 == memcmp (&s->target, &target, sizeof (struct GNUNET_PeerIdentity))) &&
905 if ((_RECEIVE == direction) && (NULL != s->server_recv))
907 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
908 "Duplicate PUT connection from `%s' tag %u, dismissing new connection\n",
909 GNUNET_i2s (&target),
913 if ((_SEND == direction) && (NULL != s->server_send))
915 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
916 "Duplicate GET connection from `%s' tag %u, dismissing new connection\n",
917 GNUNET_i2s (&target),
924 /* create new session */
925 switch (conn_info->client_addr->sa_family)
928 addr = http_common_address_from_socket (plugin->protocol, conn_info->client_addr, sizeof (struct sockaddr_in));
929 addr_len = http_common_address_get_size (addr);
930 ats = plugin->env->get_address_type (plugin->env->cls, conn_info->client_addr, sizeof (struct sockaddr_in));
933 addr = http_common_address_from_socket (plugin->protocol, conn_info->client_addr, sizeof (struct sockaddr_in6));
934 addr_len = http_common_address_get_size (addr);
935 ats = plugin->env->get_address_type (plugin->env->cls, conn_info->client_addr, sizeof (struct sockaddr_in6));
942 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
943 "Creating new session for peer `%s' connecting from `%s'\n",
944 GNUNET_i2s (&target),
945 http_common_plugin_address_to_string (NULL, addr, addr_len));
947 s = GNUNET_malloc (sizeof (struct Session));
948 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity));
951 s->addrlen = addr_len;
952 s->ats_address_network_type = ats.value;
953 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS;
955 s->server_recv = NULL;
956 s->server_send = NULL;
957 s->session_passed = GNUNET_NO;
958 server_start_session_timeout(s);
959 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
962 sc = GNUNET_malloc (sizeof (struct ServerConnection));
963 if (conn_info->client_addr->sa_family == AF_INET)
964 sc->mhd_daemon = plugin->server_v4;
965 if (conn_info->client_addr->sa_family == AF_INET6)
966 sc->mhd_daemon = plugin->server_v6;
967 sc->mhd_conn = mhd_connection;
968 sc->direction = direction;
970 if (direction == _SEND)
972 if (direction == _RECEIVE)
975 #if MHD_VERSION >= 0x00090E00
976 if ((NULL == s->server_recv) || (NULL == s->server_send))
978 to = (HTTP_NOT_VALIDATED_TIMEOUT.rel_value / 1000);
979 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to);
980 server_reschedule (plugin, sc->mhd_daemon, GNUNET_NO);
984 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
985 "Session %p for peer `%s' fully connected\n",
986 s, GNUNET_i2s (&target));
987 to = (TIMEOUT.rel_value / 1000);
988 server_mhd_connection_timeout (plugin, s, to);
991 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
992 "Setting timeout for %p to %u sec.\n", sc, to);
996 /* Error condition */
998 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
999 "Invalid connection request\n");
1003 static struct Session *
1004 server_lookup_session (struct HTTP_Server_Plugin *plugin,
1005 struct ServerConnection * sc)
1009 for (s = plugin->head; NULL != s; s = s->next)
1010 if ((s->server_recv == sc) || (s->server_send == sc))
1016 server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s)
1018 struct Session * head;
1020 GNUNET_assert (NULL != plugin);
1021 GNUNET_assert (NULL != s);
1023 for (head = plugin->head; head != NULL; head = head->next)
1033 * Callback called by MHD when it needs data to send
1034 * @param cls current session
1035 * @param pos position in buffer
1036 * @param buf the buffer to write data to
1037 * @param max max number of bytes available in buffer
1038 * @return bytes written to buffer
1041 server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1043 struct Session *s = cls;
1044 ssize_t bytes_read = 0;
1045 struct HTTP_Message *msg;
1047 GNUNET_assert (NULL != p);
1048 if (GNUNET_NO == server_exist_session (p, s))
1054 bytes_read = GNUNET_MIN (msg->size - msg->pos,
1056 memcpy (buf, &msg->buf[msg->pos], bytes_read);
1057 msg->pos += bytes_read;
1059 /* removing message */
1060 if (msg->pos == msg->size)
1062 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
1063 if (NULL != msg->transmit_cont)
1064 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
1068 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
1069 "Sent %u bytes\n", s, bytes_read);
1077 * Callback called by MessageStreamTokenizer when a message has arrived
1078 * @param cls current session as closure
1079 * @param client clien
1080 * @param message the message to be forwarded to transport service
1083 server_receive_mst_cb (void *cls, void *client,
1084 const struct GNUNET_MessageHeader *message)
1086 struct Session *s = cls;
1087 struct GNUNET_ATS_Information atsi[2];
1088 struct GNUNET_TIME_Relative delay;
1090 GNUNET_assert (NULL != p);
1091 if (GNUNET_NO == server_exist_session(p, s))
1094 struct HTTP_Server_Plugin *plugin = s->plugin;
1096 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1097 atsi[0].value = htonl (1);
1098 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1099 atsi[1].value = s->ats_address_network_type;
1100 GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
1102 delay = plugin->env->receive (plugin->env->cls,
1105 (const struct GNUNET_ATS_Information *) &atsi, 2,
1106 s, s->addr, s->addrlen);
1107 s->session_passed = GNUNET_YES;
1108 s->next_receive = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
1109 if (delay.rel_value > 0)
1111 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1112 "Peer `%s' address `%s' next read delayed for %llu ms\n",
1113 GNUNET_i2s (&s->target),
1114 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen),
1117 server_reschedule_session_timeout (s);
1122 server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1123 const char *url, const char *method, const char *version,
1124 const char *upload_data, size_t * upload_data_size,
1125 void **httpSessionCache)
1127 struct HTTP_Server_Plugin *plugin = cls;
1130 struct ServerConnection *sc = *httpSessionCache;
1132 struct MHD_Response *response;
1134 GNUNET_assert (cls != NULL);
1137 /* new connection */
1138 sc = server_lookup_connection (plugin, mhd_connection, url, method);
1140 (*httpSessionCache) = sc;
1143 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
1144 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
1145 MHD_destroy_response (response);
1151 /* 'old' connection */
1152 if (NULL == server_lookup_session (plugin, sc))
1154 /* Session was already disconnected */
1159 /* existing connection */
1160 sc = (*httpSessionCache);
1163 GNUNET_assert (NULL != s);
1164 /* connection is to be disconnected */
1165 if (sc->disconnect == GNUNET_YES)
1167 /* Sent HTTP/1.1: 200 OK as PUT Response\ */
1168 response = MHD_create_response_from_data (strlen ("Thank you!"),
1171 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1172 MHD_destroy_response (response);
1176 GNUNET_assert (s != NULL);
1177 /* Check if both directions are connected */
1178 if ((sc->session->server_recv == NULL) || (sc->session->server_send == NULL))
1180 /* Delayed read from since not both semi-connections are connected */
1184 if (sc->direction == _SEND)
1186 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
1188 &server_send_callback, s,
1190 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1191 MHD_destroy_response (response);
1194 if (sc->direction == _RECEIVE)
1196 if (*upload_data_size == 0)
1198 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1199 "Peer `%s' PUT on address `%s' connected\n",
1200 GNUNET_i2s (&s->target),
1201 http_common_plugin_address_to_string (NULL,
1207 /* Receiving data */
1208 if ((*upload_data_size > 0))
1210 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1211 "Peer `%s' PUT on address `%s' received %u bytes\n",
1212 GNUNET_i2s (&s->target),
1213 http_common_plugin_address_to_string (NULL,
1217 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1219 if ((s->next_receive.abs_value <= now.abs_value))
1221 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1222 "PUT with %u bytes forwarded to MST\n", s,
1224 if (s->msg_tk == NULL)
1226 s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s);
1228 GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data,
1229 *upload_data_size, GNUNET_NO, GNUNET_NO);
1230 #if MHD_VERSION >= 0x00090E00
1231 server_mhd_connection_timeout (plugin, s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
1233 (*upload_data_size) = 0;
1237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1238 "%p no inbound bandwidth available! Next read was delayed by %llu ms\n",
1239 s, now.abs_value - s->next_receive.abs_value);
1250 server_disconnect_cb (void *cls, struct MHD_Connection *connection,
1251 void **httpSessionCache)
1253 struct ServerConnection *sc = *httpSessionCache;
1254 struct Session *s = NULL;
1255 struct Session *t = NULL;
1256 struct HTTP_Server_Plugin *plugin = NULL;
1261 if (NULL == (s = server_lookup_session (p, sc)))
1264 GNUNET_assert (NULL != p);
1265 for (t = p->head; t != NULL; t = t->next)
1274 if (sc->direction == _SEND)
1277 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1278 "Peer `%s' connection %p, GET on address `%s' disconnected\n",
1279 GNUNET_i2s (&s->target), s->server_send,
1280 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen));
1281 s->server_send = NULL;
1282 if (NULL != (s->server_recv))
1284 s->server_recv->disconnect = GNUNET_YES;
1285 GNUNET_assert (NULL != s->server_recv->mhd_conn);
1286 #if MHD_VERSION >= 0x00090E00
1287 MHD_set_connection_option (s->server_recv->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
1290 server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO);
1293 if (sc->direction == _RECEIVE)
1295 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1296 "Peer `%s' connection %p PUT on address `%s' disconnected\n",
1297 GNUNET_i2s (&s->target), s->server_recv,
1298 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen));
1299 s->server_recv = NULL;
1300 if (NULL != (s->server_send))
1302 s->server_send->disconnect = GNUNET_YES;
1303 GNUNET_assert (NULL != s->server_send->mhd_conn);
1304 #if MHD_VERSION >= 0x00090E00
1305 MHD_set_connection_option (s->server_send->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
1308 server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO);
1310 if (s->msg_tk != NULL)
1312 GNUNET_SERVER_mst_destroy (s->msg_tk);
1318 plugin->cur_connections--;
1319 if ((s->server_send == NULL) && (s->server_recv == NULL))
1321 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1322 "Peer `%s' on address `%s' disconnected\n",
1323 GNUNET_i2s (&s->target),
1324 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen));
1326 server_delete_session (s);
1331 * Check if incoming connection is accepted.
1332 * NOTE: Here every connection is accepted
1333 * @param cls plugin as closure
1334 * @param addr address of incoming connection
1335 * @param addr_len address length of incoming connection
1336 * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected
1340 server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
1342 struct HTTP_Server_Plugin *plugin = cls;
1344 if (plugin->cur_connections <= plugin->max_connections)
1348 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
1349 _("Server reached maximum number connections (%u), rejecting new connection\n"),
1350 plugin->max_connections);
1356 server_log (void *arg, const char *fmt, va_list ap)
1360 vsnprintf (text, sizeof (text), fmt, ap);
1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: %s\n", text);
1367 * Call MHD IPv4 to process pending requests and then go back
1368 * and schedule the next run.
1369 * @param cls plugin as closure
1370 * @param tc task context
1373 server_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1375 struct HTTP_Server_Plugin *plugin = cls;
1377 GNUNET_assert (cls != NULL);
1379 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
1380 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1383 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1384 "Running IPv4 server\n");
1386 plugin->server_v4_immediately = GNUNET_NO;
1387 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
1388 server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
1393 * Call MHD IPv6 to process pending requests and then go back
1394 * and schedule the next run.
1395 * @param cls plugin as closure
1396 * @param tc task context
1399 server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1401 struct HTTP_Server_Plugin *plugin = cls;
1403 GNUNET_assert (cls != NULL);
1404 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
1405 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1408 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1409 "Running IPv6 server\n");
1411 plugin->server_v6_immediately = GNUNET_NO;
1412 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
1413 server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
1418 * Function that queries MHD's select sets and
1419 * starts the task waiting for them.
1420 * @param plugin plugin
1421 * @param daemon_handle the MHD daemon handle
1422 * @return gnunet task identifier
1424 static GNUNET_SCHEDULER_TaskIdentifier
1425 server_schedule (struct HTTP_Server_Plugin *plugin,
1426 struct MHD_Daemon *daemon_handle,
1429 GNUNET_SCHEDULER_TaskIdentifier ret;
1433 struct GNUNET_NETWORK_FDSet *wrs;
1434 struct GNUNET_NETWORK_FDSet *wws;
1435 struct GNUNET_NETWORK_FDSet *wes;
1437 unsigned MHD_LONG_LONG timeout;
1438 static unsigned long long last_timeout = 0;
1441 struct GNUNET_TIME_Relative tv;
1443 ret = GNUNET_SCHEDULER_NO_TASK;
1447 wrs = GNUNET_NETWORK_fdset_create ();
1448 wes = GNUNET_NETWORK_fdset_create ();
1449 wws = GNUNET_NETWORK_fdset_create ();
1451 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
1452 haveto = MHD_get_timeout (daemon_handle, &timeout);
1453 if (haveto == MHD_YES)
1455 if (timeout != last_timeout)
1458 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1459 "SELECT Timeout changed from %llu to %llu\n",
1460 last_timeout, timeout);
1462 last_timeout = timeout;
1464 tv.rel_value = (uint64_t) timeout;
1467 tv = GNUNET_TIME_UNIT_SECONDS;
1468 /* Force immediate run, since we have outbound data to send */
1469 if (now == GNUNET_YES)
1470 tv = GNUNET_TIME_UNIT_MILLISECONDS;
1471 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
1472 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
1473 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
1475 if (daemon_handle == plugin->server_v4)
1477 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
1479 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
1480 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
1483 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1484 "Scheduling IPv4 server task in %llu ms\n", tv);
1487 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1489 &server_v4_run, plugin);
1491 if (daemon_handle == plugin->server_v6)
1493 if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
1495 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
1496 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
1499 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1500 "Scheduling IPv6 server task in %llu ms\n", tv);
1503 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1505 &server_v6_run, plugin);
1507 GNUNET_NETWORK_fdset_destroy (wrs);
1508 GNUNET_NETWORK_fdset_destroy (wws);
1509 GNUNET_NETWORK_fdset_destroy (wes);
1516 server_load_file (const char *file)
1518 struct GNUNET_DISK_FileHandle *gn_file;
1522 if (GNUNET_OK != GNUNET_DISK_file_size (file,
1523 &fsize, GNUNET_NO, GNUNET_YES))
1525 text = GNUNET_malloc (fsize + 1);
1527 GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
1528 GNUNET_DISK_PERM_USER_READ);
1529 if (gn_file == NULL)
1534 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize))
1537 GNUNET_DISK_file_close (gn_file);
1541 GNUNET_DISK_file_close (gn_file);
1550 server_load_certificate (struct HTTP_Server_Plugin *plugin)
1552 int res = GNUNET_OK;
1557 /* Get crypto init string from config
1558 * If not present just use default values */
1561 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
1564 &plugin->crypto_init))
1565 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1566 "Using crypto init string `%s'\n",
1567 plugin->crypto_init);
1569 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1570 "Using default crypto init string \n");
1573 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
1574 "KEY_FILE", &key_file))
1576 key_file = GNUNET_strdup ("https_key.key");
1580 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, plugin->name,
1581 "CERT_FILE", &cert_file))
1583 GNUNET_asprintf (&cert_file, "%s", "https_cert.crt");
1586 /* read key & certificates from file */
1587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1588 "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n",
1589 key_file, cert_file);
1591 plugin->key = server_load_file (key_file);
1592 plugin->cert = server_load_file (cert_file);
1594 if ((plugin->key == NULL) || (plugin->cert == NULL))
1596 struct GNUNET_OS_Process *cert_creation;
1598 GNUNET_free_non_null (plugin->key);
1600 GNUNET_free_non_null (plugin->cert);
1601 plugin->cert = NULL;
1603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1604 "No usable TLS certificate found, creating certificate\n");
1607 GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL,
1608 "gnunet-transport-certificate-creation",
1609 "gnunet-transport-certificate-creation",
1610 key_file, cert_file, NULL);
1611 if (cert_creation == NULL)
1613 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1615 ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
1616 GNUNET_free (key_file);
1617 GNUNET_free (cert_file);
1619 GNUNET_free_non_null (plugin->key);
1621 GNUNET_free_non_null (plugin->cert);
1622 plugin->cert = NULL;
1623 GNUNET_free_non_null (plugin->crypto_init);
1624 plugin->crypto_init = NULL;
1626 return GNUNET_SYSERR;
1628 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation));
1629 GNUNET_OS_process_destroy (cert_creation);
1631 plugin->key = server_load_file (key_file);
1632 plugin->cert = server_load_file (cert_file);
1635 if ((plugin->key == NULL) || (plugin->cert == NULL))
1637 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1639 ("No usable TLS certificate found and creating one failed!\n"),
1641 GNUNET_free (key_file);
1642 GNUNET_free (cert_file);
1644 GNUNET_free_non_null (plugin->key);
1646 GNUNET_free_non_null (plugin->cert);
1647 plugin->cert = NULL;
1648 GNUNET_free_non_null (plugin->crypto_init);
1649 plugin->crypto_init = NULL;
1651 return GNUNET_SYSERR;
1653 GNUNET_free (key_file);
1654 GNUNET_free (cert_file);
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
1661 server_start (struct HTTP_Server_Plugin *plugin)
1663 unsigned int timeout;
1664 GNUNET_assert (NULL != plugin);
1667 if (GNUNET_SYSERR == server_load_certificate (plugin))
1669 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1670 "Could not load or create server certificate! Loading plugin failed!\n");
1671 return GNUNET_SYSERR;
1676 #if MHD_VERSION >= 0x00090E00
1677 timeout = HTTP_NOT_VALIDATED_TIMEOUT.rel_value / 1000;
1678 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1679 "MHD can set timeout per connection! Default time out %u sec.\n",
1682 timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000;
1683 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
1684 "MHD cannot set timeout per connection! Default time out %u sec.\n",
1687 plugin->server_v4 = NULL;
1688 if (plugin->use_ipv4 == GNUNET_YES)
1690 plugin->server_v4 = MHD_start_daemon (
1697 MHD_NO_FLAG, plugin->port,
1698 &server_accept_cb, plugin,
1699 &server_access_cb, plugin,
1700 MHD_OPTION_SOCK_ADDR,
1701 (struct sockaddr_in *)
1702 plugin->server_addr_v4,
1703 MHD_OPTION_CONNECTION_LIMIT,
1705 plugin->max_connections,
1707 MHD_OPTION_HTTPS_PRIORITIES,
1708 plugin->crypto_init,
1709 MHD_OPTION_HTTPS_MEM_KEY,
1711 MHD_OPTION_HTTPS_MEM_CERT,
1714 MHD_OPTION_CONNECTION_TIMEOUT,
1716 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
1718 GNUNET_SERVER_MAX_MESSAGE_SIZE),
1719 MHD_OPTION_NOTIFY_COMPLETED,
1720 &server_disconnect_cb, plugin,
1721 MHD_OPTION_EXTERNAL_LOGGER,
1722 server_log, NULL, MHD_OPTION_END);
1724 plugin->server_v6 = NULL;
1725 if (plugin->use_ipv6 == GNUNET_YES)
1727 plugin->server_v6 = MHD_start_daemon (
1734 MHD_USE_IPv6, plugin->port,
1735 &server_accept_cb, plugin,
1736 &server_access_cb, plugin,
1737 MHD_OPTION_SOCK_ADDR,
1738 (struct sockaddr_in6 *)
1739 plugin->server_addr_v6,
1740 MHD_OPTION_CONNECTION_LIMIT,
1742 plugin->max_connections,
1744 MHD_OPTION_HTTPS_PRIORITIES,
1745 plugin->crypto_init,
1746 MHD_OPTION_HTTPS_MEM_KEY,
1748 MHD_OPTION_HTTPS_MEM_CERT,
1751 MHD_OPTION_CONNECTION_TIMEOUT,
1753 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
1755 GNUNET_SERVER_MAX_MESSAGE_SIZE),
1756 MHD_OPTION_NOTIFY_COMPLETED,
1757 &server_disconnect_cb, plugin,
1758 MHD_OPTION_EXTERNAL_LOGGER,
1759 server_log, NULL, MHD_OPTION_END);
1763 if ((plugin->use_ipv4 == GNUNET_YES) && (plugin->server_v4 == NULL))
1765 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1766 "Failed to start %s IPv4 server component on port %u\n",
1767 plugin->name, plugin->port);
1768 return GNUNET_SYSERR;
1770 server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
1772 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->server_v6 == NULL))
1774 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1775 "Failed to start %s IPv6 server component on port %u\n",
1776 plugin->name, plugin->port);
1777 return GNUNET_SYSERR;
1779 server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
1780 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1781 "%s server component started on port %u\n", plugin->name,
1788 server_stop (struct HTTP_Server_Plugin *plugin)
1790 struct MHD_Daemon *server_v4_tmp = plugin->server_v4;
1791 plugin->server_v4 = NULL;
1793 struct MHD_Daemon *server_v6_tmp = plugin->server_v6;
1794 plugin->server_v6 = NULL;
1796 if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
1798 GNUNET_SCHEDULER_cancel (plugin->server_v4_task);
1799 plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
1802 if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
1804 GNUNET_SCHEDULER_cancel (plugin->server_v6_task);
1805 plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
1808 if (server_v6_tmp != NULL)
1810 MHD_stop_daemon (server_v4_tmp);
1812 if (server_v6_tmp != NULL)
1814 MHD_stop_daemon (server_v6_tmp);
1820 GNUNET_free_non_null (plugin->crypto_init);
1821 GNUNET_free_non_null (plugin->cert);
1822 GNUNET_free_non_null (plugin->key);
1825 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1826 "%s server component stopped\n", plugin->name);
1830 server_add_address (void *cls, int add_remove, const struct sockaddr *addr,
1833 struct HTTP_Server_Plugin *plugin = cls;
1834 struct HttpAddressWrapper *w = NULL;
1836 if ((AF_INET == addr->sa_family) && (GNUNET_NO == plugin->use_ipv4))
1839 if ((AF_INET6 == addr->sa_family) && (GNUNET_NO == plugin->use_ipv6))
1842 w = GNUNET_malloc (sizeof (struct HttpAddressWrapper));
1843 w->addr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
1844 if (NULL == w->addr)
1849 w->addrlen = http_common_address_get_size (w->addr);
1851 GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w);
1852 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1853 "Notifying transport to add address `%s'\n",
1854 http_common_plugin_address_to_string(NULL, w->addr, w->addrlen));
1856 plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen);
1861 server_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
1864 struct HTTP_Server_Plugin *plugin = cls;
1865 struct HttpAddressWrapper *w = plugin->addr_head;
1867 void * saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen);
1870 saddr_len = http_common_address_get_size (saddr);
1874 if (GNUNET_YES == http_common_cmp_addresses(w->addr, w->addrlen, saddr, saddr_len))
1878 GNUNET_free (saddr);
1883 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1884 "Notifying transport to remove address `%s'\n",
1885 http_common_plugin_address_to_string (NULL, w->addr, w->addrlen));
1886 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
1887 plugin->env->notify_address (plugin->env->cls, add_remove, w->addr, w->addrlen);
1888 GNUNET_free (w->addr);
1895 * Our external IP address/port mapping has changed.
1897 * @param cls closure, the 'struct LocalAddrList'
1898 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
1899 * the previous (now invalid) one
1900 * @param addr either the previous or the new public IP address
1901 * @param addrlen actual lenght of the address
1904 server_nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
1907 GNUNET_assert (cls != NULL);
1908 struct HTTP_Server_Plugin *plugin = cls;
1910 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1911 "NPMC called %s to address `%s'\n",
1912 (add_remove == GNUNET_NO) ? "remove" : "add",
1913 GNUNET_a2s (addr, addrlen));
1918 server_add_address (cls, add_remove, addr, addrlen);
1921 server_remove_address (cls, add_remove, addr, addrlen);
1928 server_get_addresses (struct HTTP_Server_Plugin *plugin,
1929 const char *serviceName,
1930 const struct GNUNET_CONFIGURATION_Handle *cfg,
1931 struct sockaddr ***addrs, socklen_t ** addr_lens)
1934 unsigned long long port;
1935 struct addrinfo hints;
1936 struct addrinfo *res;
1937 struct addrinfo *pos;
1938 struct addrinfo *next;
1942 struct sockaddr **saddrs;
1943 socklen_t *saddrlens;
1949 disablev6 = !plugin->use_ipv6;
1952 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
1954 GNUNET_break (GNUNET_OK ==
1955 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
1959 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1961 ("Require valid port number for service in configuration!\n"));
1962 return GNUNET_SYSERR;
1967 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name,
1968 "Starting in listen only mode\n");
1969 return -1; /* listen only */
1973 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
1975 GNUNET_break (GNUNET_OK ==
1976 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
1977 "BINDTO", &hostname));
1982 if (hostname != NULL)
1984 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1985 "Resolving `%s' since that is where `%s' will bind to.\n",
1986 hostname, serviceName);
1987 memset (&hints, 0, sizeof (struct addrinfo));
1989 hints.ai_family = AF_INET;
1990 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1993 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
1994 hostname, gai_strerror (ret));
1995 GNUNET_free (hostname);
1996 return GNUNET_SYSERR;
2000 while (NULL != (pos = next))
2002 next = pos->ai_next;
2003 if ((disablev6) && (pos->ai_family == AF_INET6))
2009 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2010 _("Failed to find %saddress for `%s'.\n"),
2011 disablev6 ? "IPv4 " : "", hostname);
2013 GNUNET_free (hostname);
2014 return GNUNET_SYSERR;
2017 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2018 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2021 while (NULL != (pos = next))
2023 next = pos->ai_next;
2024 if ((disablev6) && (pos->ai_family == AF_INET6))
2026 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
2027 continue; /* not TCP */
2028 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
2029 continue; /* huh? */
2030 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2031 "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
2033 if (pos->ai_family == AF_INET)
2035 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
2036 saddrlens[i] = pos->ai_addrlen;
2037 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2038 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2039 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2043 GNUNET_assert (pos->ai_family == AF_INET6);
2044 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
2045 saddrlens[i] = pos->ai_addrlen;
2046 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2047 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2048 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2052 GNUNET_free (hostname);
2058 /* will bind against everything, just set port */
2064 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2065 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2067 saddrlens[i] = sizeof (struct sockaddr_in);
2068 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2069 #if HAVE_SOCKADDR_IN_SIN_LEN
2070 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
2072 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
2073 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2079 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2080 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2082 saddrlens[i] = sizeof (struct sockaddr_in6);
2083 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2084 #if HAVE_SOCKADDR_IN_SIN_LEN
2085 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
2087 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
2088 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2090 saddrlens[i] = sizeof (struct sockaddr_in);
2091 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2092 #if HAVE_SOCKADDR_IN_SIN_LEN
2093 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
2095 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
2096 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2100 *addr_lens = saddrlens;
2105 server_start_report_addresses (struct HTTP_Server_Plugin *plugin)
2107 int res = GNUNET_OK;
2108 struct sockaddr **addrs;
2109 socklen_t *addrlens;
2111 res = server_get_addresses (plugin,
2112 plugin->name, plugin->env->cfg,
2114 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2115 _("Found %u addresses to report to NAT service\n"), res);
2117 if (GNUNET_SYSERR == res)
2124 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
2126 (const struct sockaddr **) addrs, addrlens,
2127 &server_nat_port_map_callback, NULL, plugin);
2131 GNUNET_assert (addrs[res] != NULL);
2132 GNUNET_free (addrs[res]);
2134 GNUNET_free_non_null (addrs);
2135 GNUNET_free_non_null (addrlens);
2140 server_stop_report_addresses (struct HTTP_Server_Plugin *plugin)
2142 /* Stop NAT handle */
2143 if (NULL != plugin->nat)
2144 GNUNET_NAT_unregister (plugin->nat);
2146 /* Clean up addresses */
2147 struct HttpAddressWrapper *w;
2149 while (plugin->addr_head != NULL)
2151 w = plugin->addr_head;
2152 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w);
2153 GNUNET_free (w->addr);
2160 * Check if IPv6 supported on this system
2163 server_check_ipv6_support (struct HTTP_Server_Plugin *plugin)
2165 struct GNUNET_NETWORK_Handle *desc = NULL;
2166 int res = GNUNET_NO;
2168 /* Probe IPv6 support */
2169 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
2172 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
2175 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
2177 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
2179 ("Disabling IPv6 since it is not supported on this system!\n"));
2184 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
2188 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2189 "Testing IPv6 on this system: %s\n",
2190 (res == GNUNET_YES) ? "successful" : "failed");
2196 * Function called when the service shuts down. Unloads our plugins
2197 * and cancels pending validations.
2199 * @param cls closure, unused
2200 * @param tc task context (unused)
2203 server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2205 struct HTTP_Server_Plugin *plugin = cls;
2207 plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
2209 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2212 GNUNET_asprintf(&plugin->ext_addr, "%s://%s", plugin->protocol, plugin->external_hostname);
2213 plugin->ext_addr_len = strlen (plugin->ext_addr) + 1;
2214 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2215 "Notifying transport about external hostname address `%s'\n", plugin->ext_addr);
2216 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr, plugin->ext_addr_len );
2221 server_configure_plugin (struct HTTP_Server_Plugin *plugin)
2223 unsigned long long port;
2224 unsigned long long max_connections;
2225 char *bind4_address = NULL;
2226 char *bind6_address = NULL;
2229 if (GNUNET_CONFIGURATION_have_value
2230 (plugin->env->cfg, plugin->name, "USE_IPv4"))
2233 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
2237 plugin->use_ipv4 = GNUNET_YES;
2238 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2239 _("IPv4 support is %s\n"),
2240 (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled");
2243 if (GNUNET_CONFIGURATION_have_value
2244 (plugin->env->cfg, plugin->name, "USE_IPv6"))
2247 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
2251 plugin->use_ipv6 = GNUNET_YES;
2252 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2253 _("IPv6 support is %s\n"),
2254 (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled");
2256 if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO))
2258 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
2260 ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"),
2262 return GNUNET_SYSERR;
2265 /* Reading port number from config file */
2267 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
2268 "PORT", &port)) || (port > 65535))
2270 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
2271 _("Port is required! Fix in configuration\n"),
2273 return GNUNET_SYSERR;
2275 plugin->port = port;
2277 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2278 _("Using port %u\n"), plugin->port);
2280 if ((plugin->use_ipv4 == GNUNET_YES) &&
2281 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2282 plugin->name, "BINDTO", &bind4_address)))
2284 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2285 "Binding %s plugin to specific IPv4 address: `%s'\n",
2286 plugin->protocol, bind4_address);
2287 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
2288 if (1 != inet_pton (AF_INET, bind4_address,
2289 &plugin->server_addr_v4->sin_addr))
2291 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
2293 ("Specific IPv4 address `%s' in configuration file is invalid!\n"),
2295 GNUNET_free (bind4_address);
2296 GNUNET_free (plugin->server_addr_v4);
2297 plugin->server_addr_v4 = NULL;
2298 return GNUNET_SYSERR;
2302 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2303 _("Binding to IPv4 address %s\n"), bind4_address);
2304 plugin->server_addr_v4->sin_family = AF_INET;
2305 plugin->server_addr_v4->sin_port = htons (plugin->port);
2307 GNUNET_free (bind4_address);
2310 if ((plugin->use_ipv6 == GNUNET_YES) &&
2312 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
2313 "BINDTO6", &bind6_address)))
2315 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2316 "Binding %s plugin to specific IPv6 address: `%s'\n",
2317 plugin->protocol, bind6_address);
2318 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
2320 inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
2322 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
2324 ("Specific IPv6 address `%s' in configuration file is invalid!\n"),
2326 GNUNET_free (bind6_address);
2327 GNUNET_free (plugin->server_addr_v6);
2328 plugin->server_addr_v6 = NULL;
2329 return GNUNET_SYSERR;
2333 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2334 _("Binding to IPv6 address %s\n"), bind6_address);
2335 plugin->server_addr_v6->sin6_family = AF_INET6;
2336 plugin->server_addr_v6->sin6_port = htons (plugin->port);
2338 GNUNET_free (bind6_address);
2341 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
2342 "EXTERNAL_HOSTNAME", &plugin->external_hostname))
2344 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2345 _("Using external hostname `%s'\n"), plugin->external_hostname);
2346 plugin->notify_ext_task = GNUNET_SCHEDULER_add_now (&server_notify_external_hostname, plugin);
2349 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2350 "No external hostname configured\n");
2353 /* Optional parameters */
2354 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
2356 "MAX_CONNECTIONS", &max_connections))
2357 max_connections = 128;
2358 plugin->max_connections = max_connections;
2360 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2361 _("Maximum number of connections is %u\n"),
2362 plugin->max_connections);
2367 * Session was idle, so disconnect it
2371 server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2373 GNUNET_assert (NULL != cls);
2374 struct Session *s = cls;
2376 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2377 GNUNET_log (TIMEOUT_LOG,
2378 "Session %p was idle for %llu ms, disconnecting\n",
2379 s, (unsigned long long) TIMEOUT.rel_value);
2381 /* call session destroy function */
2382 GNUNET_assert (GNUNET_OK == server_disconnect (s));
2386 * Start session timeout
2389 server_start_session_timeout (struct Session *s)
2391 GNUNET_assert (NULL != s);
2392 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
2393 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
2394 &server_session_timeout,
2396 GNUNET_log (TIMEOUT_LOG,
2397 "Timeout for session %p set to %llu ms\n",
2398 s, (unsigned long long) TIMEOUT.rel_value);
2403 * Increment session timeout due to activity
2406 server_reschedule_session_timeout (struct Session *s)
2408 GNUNET_assert (NULL != s);
2409 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
2411 GNUNET_SCHEDULER_cancel (s->timeout_task);
2412 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
2413 &server_session_timeout,
2415 GNUNET_log (TIMEOUT_LOG,
2416 "Timeout rescheduled for session %p set to %llu ms\n",
2417 s, (unsigned long long) TIMEOUT.rel_value);
2421 * Exit point from the plugin.
2424 LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2426 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2427 struct HTTP_Server_Plugin *plugin = api->cls;
2428 struct Session *pos;
2429 struct Session *next;
2431 if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task)
2433 GNUNET_SCHEDULER_cancel (plugin->notify_ext_task);
2434 plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK;
2437 if (NULL != plugin->ext_addr)
2439 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
2440 "Notifying transport to remove address `%s'\n",
2441 http_common_plugin_address_to_string (NULL,
2443 plugin->ext_addr_len));
2444 plugin->env->notify_address (plugin->env->cls,
2447 plugin->ext_addr_len);
2450 /* Stop to report addresses to transport service */
2451 server_stop_report_addresses (plugin);
2453 server_stop (plugin);
2455 next = plugin->head;
2456 while (NULL != (pos = next))
2459 GNUNET_CONTAINER_DLL_remove( plugin->head, plugin->tail, pos);
2460 server_delete_session (pos);
2464 GNUNET_free_non_null (plugin->external_hostname);
2465 GNUNET_free_non_null (plugin->ext_addr);
2466 GNUNET_free_non_null (plugin->server_addr_v4);
2467 GNUNET_free_non_null (plugin->server_addr_v6);
2469 GNUNET_free (plugin);
2476 * Entry point for the plugin.
2479 LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2481 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2482 struct GNUNET_TRANSPORT_PluginFunctions *api;
2483 struct HTTP_Server_Plugin *plugin;
2485 plugin = GNUNET_malloc (sizeof (struct HTTP_Server_Plugin));
2488 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2490 api->send = &http_server_plugin_send;
2491 api->disconnect = &http_server_plugin_disconnect;
2492 api->check_address = &http_server_plugin_address_suggested;
2493 api->get_session = &http_server_plugin_get_session;
2495 api->address_to_string = &http_common_plugin_address_to_string;
2496 api->string_to_address = &http_common_plugin_string_to_address;
2497 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
2500 plugin->name = "transport-https_server";
2501 plugin->protocol = "https";
2503 plugin->name = "transport-http_server";
2504 plugin->protocol = "http";
2507 /* Configure plugin */
2508 if (GNUNET_SYSERR == server_configure_plugin (plugin))
2510 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
2514 /* Check IPv6 support */
2515 if (GNUNET_YES == plugin->use_ipv6)
2516 plugin->use_ipv6 = server_check_ipv6_support (plugin);
2518 /* Report addresses to transport service */
2519 server_start_report_addresses (plugin);
2521 if (GNUNET_SYSERR == server_start (plugin))
2523 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
2533 /* end of plugin_transport_http_server.c */