2 This file is part of GNUnet
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
17 * @file transport/plugin_transport_http.h
18 * @brief http transport service plugin
19 * @author Matthias Wachs
21 #ifndef PLUGIN_TRANSPORT_HTTP_H
22 #define PLUGIN_TRANSPORT_HTTP_H
25 #include "gnunet_common.h"
26 #include "gnunet_constants.h"
27 #include "gnunet_protocols.h"
28 #include "gnunet_connection_lib.h"
29 #include "gnunet_service_lib.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet_transport_service.h"
32 #include "gnunet_resolver_service.h"
33 #include "gnunet_server_lib.h"
34 #include "gnunet_container_lib.h"
35 #include "gnunet_transport_plugin.h"
36 #include "gnunet_os_lib.h"
37 #include "gnunet_nat_lib.h"
38 #include "microhttpd.h"
40 #include <curl/curl.h>
41 #elif HAVE_GNURL_CURL_H
42 #include <gnurl/curl.h>
46 #define DEBUG_HTTP GNUNET_EXTRA_LOGGING
47 #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
48 #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
49 #define VERBOSE_CURL GNUNET_NO
52 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
53 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
55 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
56 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
59 #define INBOUND GNUNET_YES
60 #define OUTBOUND GNUNET_NO
63 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
66 * Encapsulation of all of the state of the plugin.
73 struct GNUNET_TRANSPORT_PluginEnvironment *env;
76 * Head of linked list of open sessions.
78 struct GNUNET_ATS_Session *head;
81 * Tail of linked list of open sessions.
83 struct GNUNET_ATS_Session *tail;
86 * NAT handle & address management
88 struct GNUNET_NAT_Handle *nat;
91 * Our own IPv4 addresses DLL head
93 struct HttpAddressWrapper *addr_head;
96 * Our own IPv4 addresses DLL tail
98 struct HttpAddressWrapper *addr_tail;
101 * External hostname the plugin can be connected to, can be different to
102 * the host's FQDN, used e.g. for reverse proxying
104 char *external_hostname;
107 * External hostname the plugin can be connected to, can be different to
108 * the host's FQDN, used e.g. for reverse proxying
110 struct HttpAddress *ext_addr;
113 * External address length
118 * Task calling transport service about external address
120 struct GNUNET_SCHEDULER_Task * notify_ext_task;
124 * Equals configuration section: transport-http, transport-https
135 * Use IPv4? #GNUNET_YES or #GNUNET_NO
140 * Use IPv6? #GNUNET_YES or #GNUNET_NO
145 * Does plugin just use outbound connections and not accept inbound?
155 * Maximum number of sockets the plugin can use
156 * Each http inbound /outbound connections are two connections
161 * Number of outbound sessions
163 unsigned int outbound_sessions;
166 * Number of inbound sessions
168 unsigned int inbound_sessions;
171 * libCurl TLS crypto init string, can be set to enhance performance
175 * Use RC4-128 instead of AES:
176 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
191 * Current number of establishes connections
196 * Last used unique HTTP connection tag
203 struct MHD_Daemon *server_v4;
208 struct GNUNET_SCHEDULER_Task * server_v4_task;
211 * The IPv4 server is scheduled to run asap
213 int server_v4_immediately;
218 struct MHD_Daemon *server_v6;
223 struct GNUNET_SCHEDULER_Task * server_v6_task;
226 * The IPv6 server is scheduled to run asap
228 int server_v6_immediately;
231 * IPv4 server socket to bind to
233 struct sockaddr_in *server_addr_v4;
236 * IPv6 server socket to bind to
238 struct sockaddr_in6 *server_addr_v6;
241 * Head of server semi connections
242 * A full session consists of 2 semi-connections: send and receive
243 * If not both directions are established the server keeps this sessions here
245 struct GNUNET_ATS_Session *server_semi_head;
248 * Tail of server semi connections
249 * A full session consists of 2 semi-connections: send and receive
250 * If not both directions are established the server keeps this sessions here
252 struct GNUNET_ATS_Session *server_semi_tail;
262 struct GNUNET_SCHEDULER_Task * client_perform_task;
266 GNUNET_NETWORK_STRUCT_BEGIN
269 * HTTP addresses including a full URI
274 * Length of the address following in NBO
276 uint32_t addr_len GNUNET_PACKED;
281 void *addr GNUNET_PACKED;
287 struct IPv4HttpAddress
290 * IPv4 address, in network byte order.
292 uint32_t ipv4_addr GNUNET_PACKED;
295 * Port number, in network byte order.
297 uint16_t u4_port GNUNET_PACKED;
303 struct IPv6HttpAddress
308 struct in6_addr ipv6_addr GNUNET_PACKED;
311 * Port number, in network byte order.
313 uint16_t u6_port GNUNET_PACKED;
315 GNUNET_NETWORK_STRUCT_END
326 * Should this connection get disconnected? #GNUNET_YES / #GNUNET_NO
331 * The session this server connection belongs to
333 struct GNUNET_ATS_Session *session;
338 struct MHD_Connection *mhd_conn;
343 * Session handle for connections.
345 struct GNUNET_ATS_Session
348 * To whom are we talking to
350 struct GNUNET_PeerIdentity target;
353 * Stored in a linked list.
355 struct GNUNET_ATS_Session *next;
358 * Stored in a linked list.
360 struct GNUNET_ATS_Session *prev;
363 * Pointer to the global plugin struct.
365 struct Plugin *plugin;
378 * ATS network type in NBO
380 uint32_t ats_address_network_type;
383 * next pointer for double linked list
385 struct HTTP_Message *msg_head;
388 * previous pointer for double linked list
390 struct HTTP_Message *msg_tail;
393 * Message stream tokenizer for incoming data
395 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
398 * Absolute time when to receive data again
399 * Used for receive throttling
401 struct GNUNET_TIME_Absolute next_receive;
404 * Inbound or outbound connection
405 * Outbound: #GNUNET_NO (client is used to send and receive)
406 * Inbound : #GNUNET_YES (server is used to send and receive)
411 * Unique HTTP/S connection tag for this connection
421 * Client receive handle
426 * Task to wake up client receive handle when receiving is allowed again
428 struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
431 * Session timeout task
433 struct GNUNET_SCHEDULER_Task * timeout_task;
436 * Is client send handle paused since there are no data to send?
437 * #GNUNET_YES or #GNUNET_NO
439 int client_put_paused;
444 struct ServerRequest *server_recv;
449 struct ServerRequest *server_send;
454 * Message to send using http
459 * next pointer for double linked list
461 struct HTTP_Message *next;
464 * previous pointer for double linked list
466 struct HTTP_Message *prev;
469 * buffer containing data to send
474 * amount of data already sent
484 * Continuation function to call once the transmission buffer
485 * has again space available. NULL if there is no
486 * continuation to call.
488 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
491 * Closure for @e transmit_cont.
493 void *transmit_cont_cls;
497 struct GNUNET_ATS_Session *
498 create_session (struct Plugin *plugin,
499 const struct GNUNET_PeerIdentity *target,
505 exist_session (struct Plugin *plugin,
506 struct GNUNET_ATS_Session *s);
510 delete_session (struct GNUNET_ATS_Session *s);
514 exist_session (struct Plugin *plugin,
515 struct GNUNET_ATS_Session *s);
518 struct GNUNET_TIME_Relative
519 http_plugin_receive (void *cls,
520 const struct GNUNET_PeerIdentity *peer,
521 const struct GNUNET_MessageHeader *message,
522 struct GNUNET_ATS_Session *session,
523 const char *sender_address,
524 uint16_t sender_address_len);
528 http_plugin_address_to_string (void *cls,
534 client_disconnect (struct GNUNET_ATS_Session *s);
538 client_connect (struct GNUNET_ATS_Session *s);
542 client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
546 client_start (struct Plugin *plugin);
550 client_stop (struct Plugin *plugin);
554 server_disconnect (struct GNUNET_ATS_Session *s);
558 server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
562 server_start (struct Plugin *plugin);
566 server_stop (struct Plugin *plugin);
570 notify_session_end (void *cls,
571 const struct GNUNET_PeerIdentity *peer,
572 struct GNUNET_ATS_Session *s);
575 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
577 /* end of plugin_transport_http.h */