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
26 #ifndef PLUGIN_TRANSPORT_HTTP_H
27 #define PLUGIN_TRANSPORT_HTTP_H
30 #include "gnunet_common.h"
31 #include "gnunet_constants.h"
32 #include "gnunet_protocols.h"
33 #include "gnunet_connection_lib.h"
34 #include "gnunet_service_lib.h"
35 #include "gnunet_statistics_service.h"
36 #include "gnunet_transport_service.h"
37 #include "gnunet_resolver_service.h"
38 #include "gnunet_server_lib.h"
39 #include "gnunet_container_lib.h"
40 #include "gnunet_transport_plugin.h"
41 #include "gnunet_os_lib.h"
42 #include "gnunet_nat_lib.h"
43 #include "microhttpd.h"
44 #include <curl/curl.h>
47 #define DEBUG_HTTP GNUNET_EXTRA_LOGGING
48 #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
49 #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
50 #define VERBOSE_CURL GNUNET_NO
53 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
54 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
56 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
57 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
60 #define INBOUND GNUNET_YES
61 #define OUTBOUND GNUNET_NO
64 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
67 * Encapsulation of all of the state of the plugin.
79 struct GNUNET_TRANSPORT_PluginEnvironment *env;
82 * Linked list of open sessions.
90 * NAT handle & address management
92 struct GNUNET_NAT_Handle *nat;
95 * List of own addresses
99 * IPv4 addresses DLL head
101 struct HttpAddressWrapper *addr_head;
104 * IPv4 addresses DLL tail
106 struct HttpAddressWrapper *addr_tail;
110 * Plugin configuration
111 * --------------------
115 * External hostname the plugin can be connected to, can be different to
116 * the host's FQDN, used e.g. for reverse proxying
118 char *external_hostname;
121 * External hostname the plugin can be connected to, can be different to
122 * the host's FQDN, used e.g. for reverse proxying
124 struct HttpAddress *ext_addr;
127 * External address length
132 * Task calling transport service about external address
134 GNUNET_SCHEDULER_TaskIdentifier notify_ext_task;
139 * Equals configuration section: transport-http, transport-https
151 * GNUNET_YES or GNUNET_NO
157 * GNUNET_YES or GNUNET_NO
162 * Does plugin just use outbound connections and not accept inbound?
173 * Maximum number of sockets the plugin can use
174 * Each http inbound /outbound connections are two connections
179 * Number of outbound sessions
181 unsigned int outbound_sessions;
184 * Number of inbound sessions
186 unsigned int inbound_sessions;
189 * Plugin HTTPS SSL/TLS options
190 * ----------------------------
194 * libCurl TLS crypto init string, can be set to enhance performance
198 * Use RC4-128 instead of AES:
199 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
220 * Current number of establishes connections
225 * Last used unique HTTP connection tag
237 struct MHD_Daemon *server_v4;
242 GNUNET_SCHEDULER_TaskIdentifier server_v4_task;
245 * The IPv4 server is scheduled to run asap
247 int server_v4_immediately;
252 struct MHD_Daemon *server_v6;
257 GNUNET_SCHEDULER_TaskIdentifier server_v6_task;
260 * The IPv6 server is scheduled to run asap
263 int server_v6_immediately;
266 * IPv4 server socket to bind to
268 struct sockaddr_in *server_addr_v4;
271 * IPv6 server socket to bind to
273 struct sockaddr_in6 *server_addr_v6;
276 * Server semi connections
277 * A full session consists of 2 semi-connections: send and receive
278 * If not both directions are established the server keeps this sessions here
280 struct Session *server_semi_head;
282 struct Session *server_semi_tail;
296 GNUNET_SCHEDULER_TaskIdentifier client_perform_task;
300 GNUNET_NETWORK_STRUCT_BEGIN
303 * HTTP addresses including a full URI
308 * Length of the address following in NBO
310 uint32_t addr_len GNUNET_PACKED;
315 void *addr GNUNET_PACKED;
321 struct IPv4HttpAddress
324 * IPv4 address, in network byte order.
326 uint32_t ipv4_addr GNUNET_PACKED;
329 * Port number, in network byte order.
331 uint16_t u4_port GNUNET_PACKED;
337 struct IPv6HttpAddress
342 struct in6_addr ipv6_addr GNUNET_PACKED;
345 * Port number, in network byte order.
347 uint16_t u6_port GNUNET_PACKED;
349 GNUNET_NETWORK_STRUCT_END
352 struct ServerConnection
357 /* Should this connection get disconnected? GNUNET_YES/NO */
360 /* The session this server connection belongs to */
361 struct Session *session;
363 /* The MHD connection */
364 struct MHD_Connection *mhd_conn;
370 * Session handle for connections.
375 * To whom are we talking to
377 struct GNUNET_PeerIdentity target;
380 * Stored in a linked list.
382 struct Session *next;
385 * Stored in a linked list.
387 struct Session *prev;
390 * Pointer to the global plugin struct.
392 struct Plugin *plugin;
405 * ATS network type in NBO
407 uint32_t ats_address_network_type;
410 * next pointer for double linked list
412 struct HTTP_Message *msg_head;
415 * previous pointer for double linked list
417 struct HTTP_Message *msg_tail;
421 * Message stream tokenizer for incoming data
423 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
426 * Absolute time when to receive data again
427 * Used for receive throttling
429 struct GNUNET_TIME_Absolute next_receive;
432 * Inbound or outbound connection
433 * Outbound: GNUNET_NO (client is used to send and receive)
434 * Inbound : GNUNET_YES (server is used to send and receive)
439 * Unique HTTP/S connection tag for this connection
453 * Client receive handle
458 * Task to wake up client receive handle when receiving is allowed again
460 GNUNET_SCHEDULER_TaskIdentifier recv_wakeup_task;
463 * Session timeout task
465 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
468 * Is client send handle paused since there are no data to send?
471 int client_put_paused;
480 struct ServerConnection *server_recv;
485 struct ServerConnection *server_send;
489 * Message to send using http
494 * next pointer for double linked list
496 struct HTTP_Message *next;
499 * previous pointer for double linked list
501 struct HTTP_Message *prev;
504 * buffer containing data to send
509 * amount of data already sent
519 * Continuation function to call once the transmission buffer
520 * has again space available. NULL if there is no
521 * continuation to call.
523 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
526 * Closure for transmit_cont.
528 void *transmit_cont_cls;
532 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
533 const void *addr, size_t addrlen);
536 exist_session (struct Plugin *plugin, struct Session *s);
539 delete_session (struct Session *s);
542 exist_session (struct Plugin *plugin, struct Session *s);
544 struct GNUNET_TIME_Relative
545 http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
546 const struct GNUNET_MessageHeader *message,
547 struct Session *session, const char *sender_address,
548 uint16_t sender_address_len);
551 http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen);
554 client_disconnect (struct Session *s);
557 client_connect (struct Session *s);
560 client_send (struct Session *s, struct HTTP_Message *msg);
563 client_start (struct Plugin *plugin);
566 client_stop (struct Plugin *plugin);
569 server_disconnect (struct Session *s);
572 server_send (struct Session *s, struct HTTP_Message *msg);
575 server_start (struct Plugin *plugin);
578 server_stop (struct Plugin *plugin);
581 notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
584 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
586 /* end of plugin_transport_http.h */