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 Affero 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.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file transport/plugin_transport_http.h
21 * @brief http transport service plugin
22 * @author Matthias Wachs
24 #ifndef PLUGIN_TRANSPORT_HTTP_H
25 #define PLUGIN_TRANSPORT_HTTP_H
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"
43 #include <curl/curl.h>
44 #elif HAVE_GNURL_CURL_H
45 #include <gnurl/curl.h>
49 #define DEBUG_HTTP GNUNET_EXTRA_LOGGING
50 #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
51 #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
52 #define VERBOSE_CURL GNUNET_NO
55 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
56 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
58 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
59 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
62 #define INBOUND GNUNET_YES
63 #define OUTBOUND GNUNET_NO
66 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
69 * Encapsulation of all of the state of the plugin.
76 struct GNUNET_TRANSPORT_PluginEnvironment *env;
79 * Head of linked list of open sessions.
81 struct GNUNET_ATS_Session *head;
84 * Tail of linked list of open sessions.
86 struct GNUNET_ATS_Session *tail;
89 * NAT handle & address management
91 struct GNUNET_NAT_Handle *nat;
94 * Our own IPv4 addresses DLL head
96 struct HttpAddressWrapper *addr_head;
99 * Our own IPv4 addresses DLL tail
101 struct HttpAddressWrapper *addr_tail;
104 * External hostname the plugin can be connected to, can be different to
105 * the host's FQDN, used e.g. for reverse proxying
107 char *external_hostname;
110 * External hostname the plugin can be connected to, can be different to
111 * the host's FQDN, used e.g. for reverse proxying
113 struct HttpAddress *ext_addr;
116 * External address length
121 * Task calling transport service about external address
123 struct GNUNET_SCHEDULER_Task * notify_ext_task;
127 * Equals configuration section: transport-http, transport-https
138 * Use IPv4? #GNUNET_YES or #GNUNET_NO
143 * Use IPv6? #GNUNET_YES or #GNUNET_NO
148 * Does plugin just use outbound connections and not accept inbound?
158 * Maximum number of sockets the plugin can use
159 * Each http inbound /outbound connections are two connections
164 * Number of outbound sessions
166 unsigned int outbound_sessions;
169 * Number of inbound sessions
171 unsigned int inbound_sessions;
174 * libCurl TLS crypto init string, can be set to enhance performance
178 * Use RC4-128 instead of AES:
179 * NONE:+VERS-TLS1.0:+ARCFOUR-128:+SHA1:+RSA:+COMP-NULL
194 * Current number of establishes connections
199 * Last used unique HTTP connection tag
206 struct MHD_Daemon *server_v4;
211 struct GNUNET_SCHEDULER_Task * server_v4_task;
214 * The IPv4 server is scheduled to run asap
216 int server_v4_immediately;
221 struct MHD_Daemon *server_v6;
226 struct GNUNET_SCHEDULER_Task * server_v6_task;
229 * The IPv6 server is scheduled to run asap
231 int server_v6_immediately;
234 * IPv4 server socket to bind to
236 struct sockaddr_in *server_addr_v4;
239 * IPv6 server socket to bind to
241 struct sockaddr_in6 *server_addr_v6;
244 * Head of server semi connections
245 * A full session consists of 2 semi-connections: send and receive
246 * If not both directions are established the server keeps this sessions here
248 struct GNUNET_ATS_Session *server_semi_head;
251 * Tail of server semi connections
252 * A full session consists of 2 semi-connections: send and receive
253 * If not both directions are established the server keeps this sessions here
255 struct GNUNET_ATS_Session *server_semi_tail;
265 struct GNUNET_SCHEDULER_Task * client_perform_task;
269 GNUNET_NETWORK_STRUCT_BEGIN
272 * HTTP addresses including a full URI
277 * Length of the address following in NBO
279 uint32_t addr_len GNUNET_PACKED;
284 void *addr GNUNET_PACKED;
290 struct IPv4HttpAddress
293 * IPv4 address, in network byte order.
295 uint32_t ipv4_addr GNUNET_PACKED;
298 * Port number, in network byte order.
300 uint16_t u4_port GNUNET_PACKED;
306 struct IPv6HttpAddress
311 struct in6_addr ipv6_addr GNUNET_PACKED;
314 * Port number, in network byte order.
316 uint16_t u6_port GNUNET_PACKED;
318 GNUNET_NETWORK_STRUCT_END
329 * Should this connection get disconnected? #GNUNET_YES / #GNUNET_NO
334 * The session this server connection belongs to
336 struct GNUNET_ATS_Session *session;
341 struct MHD_Connection *mhd_conn;
346 * Session handle for connections.
348 struct GNUNET_ATS_Session
351 * To whom are we talking to
353 struct GNUNET_PeerIdentity target;
356 * Stored in a linked list.
358 struct GNUNET_ATS_Session *next;
361 * Stored in a linked list.
363 struct GNUNET_ATS_Session *prev;
366 * Pointer to the global plugin struct.
368 struct Plugin *plugin;
381 * ATS network type in NBO
383 uint32_t ats_address_network_type;
386 * next pointer for double linked list
388 struct HTTP_Message *msg_head;
391 * previous pointer for double linked list
393 struct HTTP_Message *msg_tail;
396 * Message stream tokenizer for incoming data
398 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
401 * Absolute time when to receive data again
402 * Used for receive throttling
404 struct GNUNET_TIME_Absolute next_receive;
407 * Inbound or outbound connection
408 * Outbound: #GNUNET_NO (client is used to send and receive)
409 * Inbound : #GNUNET_YES (server is used to send and receive)
414 * Unique HTTP/S connection tag for this connection
424 * Client receive handle
429 * Task to wake up client receive handle when receiving is allowed again
431 struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
434 * Session timeout task
436 struct GNUNET_SCHEDULER_Task * timeout_task;
439 * Is client send handle paused since there are no data to send?
440 * #GNUNET_YES or #GNUNET_NO
442 int client_put_paused;
447 struct ServerRequest *server_recv;
452 struct ServerRequest *server_send;
457 * Message to send using http
462 * next pointer for double linked list
464 struct HTTP_Message *next;
467 * previous pointer for double linked list
469 struct HTTP_Message *prev;
472 * buffer containing data to send
477 * amount of data already sent
487 * Continuation function to call once the transmission buffer
488 * has again space available. NULL if there is no
489 * continuation to call.
491 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
494 * Closure for @e transmit_cont.
496 void *transmit_cont_cls;
500 struct GNUNET_ATS_Session *
501 create_session (struct Plugin *plugin,
502 const struct GNUNET_PeerIdentity *target,
508 exist_session (struct Plugin *plugin,
509 struct GNUNET_ATS_Session *s);
513 delete_session (struct GNUNET_ATS_Session *s);
517 exist_session (struct Plugin *plugin,
518 struct GNUNET_ATS_Session *s);
521 struct GNUNET_TIME_Relative
522 http_plugin_receive (void *cls,
523 const struct GNUNET_PeerIdentity *peer,
524 const struct GNUNET_MessageHeader *message,
525 struct GNUNET_ATS_Session *session,
526 const char *sender_address,
527 uint16_t sender_address_len);
531 http_plugin_address_to_string (void *cls,
537 client_disconnect (struct GNUNET_ATS_Session *s);
541 client_connect (struct GNUNET_ATS_Session *s);
545 client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
549 client_start (struct Plugin *plugin);
553 client_stop (struct Plugin *plugin);
557 server_disconnect (struct GNUNET_ATS_Session *s);
561 server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
565 server_start (struct Plugin *plugin);
569 server_stop (struct Plugin *plugin);
573 notify_session_end (void *cls,
574 const struct GNUNET_PeerIdentity *peer,
575 struct GNUNET_ATS_Session *s);
578 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
580 /* end of plugin_transport_http.h */