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.h
23 * @brief http transport service plugin
24 * @author Matthias Wachs
28 #include "gnunet_common.h"
29 #include "gnunet_constants.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_connection_lib.h"
32 #include "gnunet_service_lib.h"
33 #include "gnunet_statistics_service.h"
34 #include "gnunet_transport_service.h"
35 #include "gnunet_resolver_service.h"
36 #include "gnunet_server_lib.h"
37 #include "gnunet_container_lib.h"
38 #include "gnunet_transport_plugin.h"
39 #include "gnunet_os_lib.h"
40 #include "gnunet_nat_lib.h"
41 #include "microhttpd.h"
42 #include <curl/curl.h>
45 #define DEBUG_HTTP GNUNET_EXTRA_LOGGING
46 #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
47 #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
48 #define VERBOSE_CURL GNUNET_NO
51 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
52 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
54 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
55 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
58 #define INBOUND GNUNET_YES
59 #define OUTBOUND GNUNET_NO
62 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
65 * Encapsulation of all of the state of the plugin.
77 struct GNUNET_TRANSPORT_PluginEnvironment *env;
80 * Linked list of open sessions.
88 * NAT handle & address management
90 struct GNUNET_NAT_Handle *nat;
93 * List of own addresses
97 * IPv4 addresses DLL head
99 struct IPv4HttpAddressWrapper *ipv4_addr_head;
102 * IPv4 addresses DLL tail
104 struct IPv4HttpAddressWrapper *ipv4_addr_tail;
107 * IPv6 addresses DLL head
109 struct IPv6HttpAddressWrapper *ipv6_addr_head;
112 * IPv6 addresses DLL tail
114 struct IPv6HttpAddressWrapper *ipv6_addr_tail;
117 * Plugin configuration
118 * --------------------
123 * Equals configuration section: transport-http, transport-https
135 * GNUNET_YES or GNUNET_NO
141 * GNUNET_YES or GNUNET_NO
146 * Does plugin just use outbound connections and not accept inbound?
157 * Maximum number of sockets the plugin can use
158 * Each http inbound /outbound connections are two connections
163 * Number of outbound sessions
165 unsigned int outbound_sessions;
168 * Number of inbound sessions
170 unsigned int inbound_sessions;
173 * Plugin HTTPS SSL/TLS options
174 * ----------------------------
178 * libCurl TLS crypto init string, can be set to enhance performance
182 * Use RC4-128 instead of AES:
183 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
204 * Current number of establishes connections
209 * Last used unique HTTP connection tag
221 struct MHD_Daemon *server_v4;
226 GNUNET_SCHEDULER_TaskIdentifier server_v4_task;
229 * The IPv4 server is scheduled to run asap
231 int server_v4_immediately;
236 struct MHD_Daemon *server_v6;
241 GNUNET_SCHEDULER_TaskIdentifier server_v6_task;
244 * The IPv6 server is scheduled to run asap
247 int server_v6_immediately;
250 * IPv4 server socket to bind to
252 struct sockaddr_in *server_addr_v4;
255 * IPv6 server socket to bind to
257 struct sockaddr_in6 *server_addr_v6;
260 * Server semi connections
261 * A full session consists of 2 semi-connections: send and receive
262 * If not both directions are established the server keeps this sessions here
264 struct Session *server_semi_head;
266 struct Session *server_semi_tail;
280 GNUNET_SCHEDULER_TaskIdentifier client_perform_task;
284 GNUNET_NETWORK_STRUCT_BEGIN
289 struct IPv4HttpAddress
292 * IPv4 address, in network byte order.
294 uint32_t ipv4_addr GNUNET_PACKED;
297 * Port number, in network byte order.
299 uint16_t u4_port GNUNET_PACKED;
305 struct IPv6HttpAddress
310 struct in6_addr ipv6_addr GNUNET_PACKED;
313 * Port number, in network byte order.
315 uint16_t u6_port GNUNET_PACKED;
317 GNUNET_NETWORK_STRUCT_END
320 struct ServerConnection
325 /* Should this connection get disconnected? GNUNET_YES/NO */
328 /* The session this server connection belongs to */
329 struct Session *session;
331 /* The MHD connection */
332 struct MHD_Connection *mhd_conn;
338 * Session handle for connections.
344 * Stored in a linked list.
346 struct Session *next;
349 * Stored in a linked list.
351 struct Session *prev;
354 * Pointer to the global plugin struct.
356 struct Plugin *plugin;
369 * ATS network type in NBO
371 uint32_t ats_address_network_type;
374 * To whom are we talking to
376 struct GNUNET_PeerIdentity target;
379 * next pointer for double linked list
381 struct HTTP_Message *msg_head;
384 * previous pointer for double linked list
386 struct HTTP_Message *msg_tail;
390 * Message stream tokenizer for incoming data
392 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
395 * Absolute time when to receive data again
396 * Used for receive throttling
398 struct GNUNET_TIME_Absolute next_receive;
401 * Inbound or outbound connection
402 * Outbound: GNUNET_NO (client is used to send and receive)
403 * Inbound : GNUNET_YES (server is used to send and receive)
408 * Unique HTTP/S connection tag for this connection
422 * Client receive handle
427 * Task to wake up client receive handle when receiving is allowed again
429 GNUNET_SCHEDULER_TaskIdentifier recv_wakeup_task;
432 * Session timeout task
434 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
437 * Is client send handle paused since there are no data to send?
440 int client_put_paused;
449 struct ServerConnection *server_recv;
454 struct ServerConnection *server_send;
458 * Message to send using http
463 * next pointer for double linked list
465 struct HTTP_Message *next;
468 * previous pointer for double linked list
470 struct HTTP_Message *prev;
473 * buffer containing data to send
478 * amount of data already sent
488 * Continuation function to call once the transmission buffer
489 * has again space available. NULL if there is no
490 * continuation to call.
492 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
495 * Closure for transmit_cont.
497 void *transmit_cont_cls;
501 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
502 const void *addr, size_t addrlen);
505 exist_session (struct Plugin *plugin, struct Session *s);
508 delete_session (struct Session *s);
511 exist_session (struct Plugin *plugin, struct Session *s);
513 struct GNUNET_TIME_Relative
514 http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
515 const struct GNUNET_MessageHeader *message,
516 struct Session *session, const char *sender_address,
517 uint16_t sender_address_len);
520 http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen);
523 client_disconnect (struct Session *s);
526 client_connect (struct Session *s);
529 client_send (struct Session *s, struct HTTP_Message *msg);
532 client_start (struct Plugin *plugin);
535 client_stop (struct Plugin *plugin);
538 server_disconnect (struct Session *s);
541 server_send (struct Session *s, struct HTTP_Message *msg);
544 server_start (struct Plugin *plugin);
547 server_stop (struct Plugin *plugin);
550 notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
553 /* end of plugin_transport_http.h */