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.
74 struct GNUNET_TRANSPORT_PluginEnvironment *env;
77 * Head of linked list of open sessions.
82 * Tail of linked list of open sessions.
87 * NAT handle & address management
89 struct GNUNET_NAT_Handle *nat;
92 * Our own IPv4 addresses DLL head
94 struct HttpAddressWrapper *addr_head;
97 * Our own IPv4 addresses DLL tail
99 struct HttpAddressWrapper *addr_tail;
102 * External hostname the plugin can be connected to, can be different to
103 * the host's FQDN, used e.g. for reverse proxying
105 char *external_hostname;
108 * External hostname the plugin can be connected to, can be different to
109 * the host's FQDN, used e.g. for reverse proxying
111 struct HttpAddress *ext_addr;
114 * External address length
119 * Task calling transport service about external address
121 struct GNUNET_SCHEDULER_Task * notify_ext_task;
125 * Equals configuration section: transport-http, transport-https
136 * Use IPv4? #GNUNET_YES or #GNUNET_NO
141 * Use IPv6? #GNUNET_YES or #GNUNET_NO
146 * Does plugin just use outbound connections and not accept inbound?
156 * Maximum number of sockets the plugin can use
157 * Each http inbound /outbound connections are two connections
162 * Number of outbound sessions
164 unsigned int outbound_sessions;
167 * Number of inbound sessions
169 unsigned int inbound_sessions;
172 * libCurl TLS crypto init string, can be set to enhance performance
176 * Use RC4-128 instead of AES:
177 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
192 * Current number of establishes connections
197 * Last used unique HTTP connection tag
204 struct MHD_Daemon *server_v4;
209 struct GNUNET_SCHEDULER_Task * server_v4_task;
212 * The IPv4 server is scheduled to run asap
214 int server_v4_immediately;
219 struct MHD_Daemon *server_v6;
224 struct GNUNET_SCHEDULER_Task * server_v6_task;
227 * The IPv6 server is scheduled to run asap
229 int server_v6_immediately;
232 * IPv4 server socket to bind to
234 struct sockaddr_in *server_addr_v4;
237 * IPv6 server socket to bind to
239 struct sockaddr_in6 *server_addr_v6;
242 * Head of server semi connections
243 * A full session consists of 2 semi-connections: send and receive
244 * If not both directions are established the server keeps this sessions here
246 struct Session *server_semi_head;
249 * Tail of server semi connections
250 * A full session consists of 2 semi-connections: send and receive
251 * If not both directions are established the server keeps this sessions here
253 struct Session *server_semi_tail;
263 struct GNUNET_SCHEDULER_Task * client_perform_task;
267 GNUNET_NETWORK_STRUCT_BEGIN
270 * HTTP addresses including a full URI
275 * Length of the address following in NBO
277 uint32_t addr_len GNUNET_PACKED;
282 void *addr GNUNET_PACKED;
288 struct IPv4HttpAddress
291 * IPv4 address, in network byte order.
293 uint32_t ipv4_addr GNUNET_PACKED;
296 * Port number, in network byte order.
298 uint16_t u4_port GNUNET_PACKED;
304 struct IPv6HttpAddress
309 struct in6_addr ipv6_addr GNUNET_PACKED;
312 * Port number, in network byte order.
314 uint16_t u6_port GNUNET_PACKED;
316 GNUNET_NETWORK_STRUCT_END
327 * Should this connection get disconnected? #GNUNET_YES / #GNUNET_NO
332 * The session this server connection belongs to
334 struct Session *session;
339 struct MHD_Connection *mhd_conn;
344 * Session handle for connections.
349 * To whom are we talking to
351 struct GNUNET_PeerIdentity target;
354 * Stored in a linked list.
356 struct Session *next;
359 * Stored in a linked list.
361 struct Session *prev;
364 * Pointer to the global plugin struct.
366 struct Plugin *plugin;
379 * ATS network type in NBO
381 uint32_t ats_address_network_type;
384 * next pointer for double linked list
386 struct HTTP_Message *msg_head;
389 * previous pointer for double linked list
391 struct HTTP_Message *msg_tail;
394 * Message stream tokenizer for incoming data
396 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
399 * Absolute time when to receive data again
400 * Used for receive throttling
402 struct GNUNET_TIME_Absolute next_receive;
405 * Inbound or outbound connection
406 * Outbound: #GNUNET_NO (client is used to send and receive)
407 * Inbound : #GNUNET_YES (server is used to send and receive)
412 * 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 struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
432 * Session timeout task
434 struct GNUNET_SCHEDULER_Task * timeout_task;
437 * Is client send handle paused since there are no data to send?
438 * #GNUNET_YES or #GNUNET_NO
440 int client_put_paused;
445 struct ServerRequest *server_recv;
450 struct ServerRequest *server_send;
455 * Message to send using http
460 * next pointer for double linked list
462 struct HTTP_Message *next;
465 * previous pointer for double linked list
467 struct HTTP_Message *prev;
470 * buffer containing data to send
475 * amount of data already sent
485 * Continuation function to call once the transmission buffer
486 * has again space available. NULL if there is no
487 * continuation to call.
489 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
492 * Closure for @e transmit_cont.
494 void *transmit_cont_cls;
499 create_session (struct Plugin *plugin,
500 const struct GNUNET_PeerIdentity *target,
506 exist_session (struct Plugin *plugin,
511 delete_session (struct Session *s);
515 exist_session (struct Plugin *plugin,
519 struct GNUNET_TIME_Relative
520 http_plugin_receive (void *cls,
521 const struct GNUNET_PeerIdentity *peer,
522 const struct GNUNET_MessageHeader *message,
523 struct Session *session,
524 const char *sender_address,
525 uint16_t sender_address_len);
529 http_plugin_address_to_string (void *cls,
535 client_disconnect (struct Session *s);
539 client_connect (struct Session *s);
543 client_send (struct Session *s, struct HTTP_Message *msg);
547 client_start (struct Plugin *plugin);
551 client_stop (struct Plugin *plugin);
555 server_disconnect (struct Session *s);
559 server_send (struct Session *s, struct HTTP_Message *msg);
563 server_start (struct Plugin *plugin);
567 server_stop (struct Plugin *plugin);
571 notify_session_end (void *cls,
572 const struct GNUNET_PeerIdentity *peer,
576 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
578 /* end of plugin_transport_http.h */