2 This file is part of GNUnet
3 Copyright (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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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"
45 #include <curl/curl.h>
46 #elif HAVE_GNURL_CURL_H
47 #include <gnurl/curl.h>
51 #define DEBUG_HTTP GNUNET_EXTRA_LOGGING
52 #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
53 #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
54 #define VERBOSE_CURL GNUNET_NO
57 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
58 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
60 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
61 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
64 #define INBOUND GNUNET_YES
65 #define OUTBOUND GNUNET_NO
68 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
71 * Encapsulation of all of the state of the plugin.
78 struct GNUNET_TRANSPORT_PluginEnvironment *env;
81 * Head of linked list of open sessions.
86 * Tail of linked list of open sessions.
91 * NAT handle & address management
93 struct GNUNET_NAT_Handle *nat;
96 * Our own IPv4 addresses DLL head
98 struct HttpAddressWrapper *addr_head;
101 * Our own IPv4 addresses DLL tail
103 struct HttpAddressWrapper *addr_tail;
106 * External hostname the plugin can be connected to, can be different to
107 * the host's FQDN, used e.g. for reverse proxying
109 char *external_hostname;
112 * External hostname the plugin can be connected to, can be different to
113 * the host's FQDN, used e.g. for reverse proxying
115 struct HttpAddress *ext_addr;
118 * External address length
123 * Task calling transport service about external address
125 struct GNUNET_SCHEDULER_Task * notify_ext_task;
129 * Equals configuration section: transport-http, transport-https
140 * Use IPv4? #GNUNET_YES or #GNUNET_NO
145 * Use IPv6? #GNUNET_YES or #GNUNET_NO
150 * Does plugin just use outbound connections and not accept inbound?
160 * Maximum number of sockets the plugin can use
161 * Each http inbound /outbound connections are two connections
166 * Number of outbound sessions
168 unsigned int outbound_sessions;
171 * Number of inbound sessions
173 unsigned int inbound_sessions;
176 * libCurl TLS crypto init string, can be set to enhance performance
180 * Use RC4-128 instead of AES:
181 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
196 * Current number of establishes connections
201 * Last used unique HTTP connection tag
208 struct MHD_Daemon *server_v4;
213 struct GNUNET_SCHEDULER_Task * server_v4_task;
216 * The IPv4 server is scheduled to run asap
218 int server_v4_immediately;
223 struct MHD_Daemon *server_v6;
228 struct GNUNET_SCHEDULER_Task * server_v6_task;
231 * The IPv6 server is scheduled to run asap
233 int server_v6_immediately;
236 * IPv4 server socket to bind to
238 struct sockaddr_in *server_addr_v4;
241 * IPv6 server socket to bind to
243 struct sockaddr_in6 *server_addr_v6;
246 * Head of server semi connections
247 * A full session consists of 2 semi-connections: send and receive
248 * If not both directions are established the server keeps this sessions here
250 struct Session *server_semi_head;
253 * Tail of server semi connections
254 * A full session consists of 2 semi-connections: send and receive
255 * If not both directions are established the server keeps this sessions here
257 struct Session *server_semi_tail;
267 struct GNUNET_SCHEDULER_Task * client_perform_task;
271 GNUNET_NETWORK_STRUCT_BEGIN
274 * HTTP addresses including a full URI
279 * Length of the address following in NBO
281 uint32_t addr_len GNUNET_PACKED;
286 void *addr GNUNET_PACKED;
292 struct IPv4HttpAddress
295 * IPv4 address, in network byte order.
297 uint32_t ipv4_addr GNUNET_PACKED;
300 * Port number, in network byte order.
302 uint16_t u4_port GNUNET_PACKED;
308 struct IPv6HttpAddress
313 struct in6_addr ipv6_addr GNUNET_PACKED;
316 * Port number, in network byte order.
318 uint16_t u6_port GNUNET_PACKED;
320 GNUNET_NETWORK_STRUCT_END
331 * Should this connection get disconnected? #GNUNET_YES / #GNUNET_NO
336 * The session this server connection belongs to
338 struct Session *session;
343 struct MHD_Connection *mhd_conn;
348 * Session handle for connections.
353 * To whom are we talking to
355 struct GNUNET_PeerIdentity target;
358 * Stored in a linked list.
360 struct Session *next;
363 * Stored in a linked list.
365 struct Session *prev;
368 * Pointer to the global plugin struct.
370 struct Plugin *plugin;
383 * ATS network type in NBO
385 uint32_t ats_address_network_type;
388 * next pointer for double linked list
390 struct HTTP_Message *msg_head;
393 * previous pointer for double linked list
395 struct HTTP_Message *msg_tail;
398 * Message stream tokenizer for incoming data
400 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
403 * Absolute time when to receive data again
404 * Used for receive throttling
406 struct GNUNET_TIME_Absolute next_receive;
409 * Inbound or outbound connection
410 * Outbound: #GNUNET_NO (client is used to send and receive)
411 * Inbound : #GNUNET_YES (server is used to send and receive)
416 * Unique HTTP/S connection tag for this connection
426 * Client receive handle
431 * Task to wake up client receive handle when receiving is allowed again
433 struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
436 * Session timeout task
438 struct GNUNET_SCHEDULER_Task * timeout_task;
441 * Is client send handle paused since there are no data to send?
442 * #GNUNET_YES or #GNUNET_NO
444 int client_put_paused;
449 struct ServerRequest *server_recv;
454 struct ServerRequest *server_send;
459 * Message to send using http
464 * next pointer for double linked list
466 struct HTTP_Message *next;
469 * previous pointer for double linked list
471 struct HTTP_Message *prev;
474 * buffer containing data to send
479 * amount of data already sent
489 * Continuation function to call once the transmission buffer
490 * has again space available. NULL if there is no
491 * continuation to call.
493 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
496 * Closure for @e transmit_cont.
498 void *transmit_cont_cls;
503 create_session (struct Plugin *plugin,
504 const struct GNUNET_PeerIdentity *target,
510 exist_session (struct Plugin *plugin,
515 delete_session (struct Session *s);
519 exist_session (struct Plugin *plugin,
523 struct GNUNET_TIME_Relative
524 http_plugin_receive (void *cls,
525 const struct GNUNET_PeerIdentity *peer,
526 const struct GNUNET_MessageHeader *message,
527 struct Session *session,
528 const char *sender_address,
529 uint16_t sender_address_len);
533 http_plugin_address_to_string (void *cls,
539 client_disconnect (struct Session *s);
543 client_connect (struct Session *s);
547 client_send (struct Session *s, struct HTTP_Message *msg);
551 client_start (struct Plugin *plugin);
555 client_stop (struct Plugin *plugin);
559 server_disconnect (struct Session *s);
563 server_send (struct Session *s, struct HTTP_Message *msg);
567 server_start (struct Plugin *plugin);
571 server_stop (struct Plugin *plugin);
575 notify_session_end (void *cls,
576 const struct GNUNET_PeerIdentity *peer,
580 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
582 /* end of plugin_transport_http.h */