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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 /* Just included for the right curl.h */
45 #include "gnunet_curl_lib.h"
48 #define DEBUG_HTTP GNUNET_EXTRA_LOGGING
49 #define VERBOSE_SERVER GNUNET_EXTRA_LOGGING
50 #define VERBOSE_CLIENT GNUNET_EXTRA_LOGGING
51 #define VERBOSE_CURL GNUNET_NO
54 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
55 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
57 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
58 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
61 #define INBOUND GNUNET_YES
62 #define OUTBOUND GNUNET_NO
65 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
66 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;
268 GNUNET_NETWORK_STRUCT_BEGIN
271 * HTTP addresses including a full URI
276 * Length of the address following in NBO
278 uint32_t addr_len GNUNET_PACKED;
283 void *addr GNUNET_PACKED;
289 struct IPv4HttpAddress
292 * IPv4 address, in network byte order.
294 uint32_t ipv4_addr GNUNET_PACKED;
297 * Port number, in network byte order.
299 uint16_t u4_port GNUNET_PACKED;
305 struct IPv6HttpAddress
310 struct in6_addr ipv6_addr GNUNET_PACKED;
313 * Port number, in network byte order.
315 uint16_t u6_port GNUNET_PACKED;
317 GNUNET_NETWORK_STRUCT_END
328 * Should this connection get disconnected? #GNUNET_YES / #GNUNET_NO
333 * The session this server connection belongs to
335 struct GNUNET_ATS_Session *session;
340 struct MHD_Connection *mhd_conn;
345 * Session handle for connections.
347 struct GNUNET_ATS_Session
350 * To whom are we talking to
352 struct GNUNET_PeerIdentity target;
355 * Stored in a linked list.
357 struct GNUNET_ATS_Session *next;
360 * Stored in a linked list.
362 struct GNUNET_ATS_Session *prev;
365 * Pointer to the global plugin struct.
367 struct Plugin *plugin;
380 * ATS network type in NBO
382 uint32_t ats_address_network_type;
385 * next pointer for double linked list
387 struct HTTP_Message *msg_head;
390 * previous pointer for double linked list
392 struct HTTP_Message *msg_tail;
395 * Message stream tokenizer for incoming data
397 struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk;
400 * Absolute time when to receive data again
401 * Used for receive throttling
403 struct GNUNET_TIME_Absolute next_receive;
406 * Inbound or outbound connection
407 * Outbound: #GNUNET_NO (client is used to send and receive)
408 * Inbound : #GNUNET_YES (server is used to send and receive)
413 * Unique HTTP/S connection tag for this connection
423 * Client receive handle
428 * Task to wake up client receive handle when receiving is allowed again
430 struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
433 * Session timeout task
435 struct GNUNET_SCHEDULER_Task *timeout_task;
438 * Is client send handle paused since there are no data to send?
439 * #GNUNET_YES or #GNUNET_NO
441 int client_put_paused;
446 struct ServerRequest *server_recv;
451 struct ServerRequest *server_send;
456 * Message to send using http
461 * next pointer for double linked list
463 struct HTTP_Message *next;
466 * previous pointer for double linked list
468 struct HTTP_Message *prev;
471 * buffer containing data to send
476 * amount of data already sent
486 * Continuation function to call once the transmission buffer
487 * has again space available. NULL if there is no
488 * continuation to call.
490 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
493 * Closure for @e transmit_cont.
495 void *transmit_cont_cls;
499 struct GNUNET_ATS_Session *
500 create_session (struct Plugin *plugin,
501 const struct GNUNET_PeerIdentity *target,
507 exist_session (struct Plugin *plugin,
508 struct GNUNET_ATS_Session *s);
512 delete_session (struct GNUNET_ATS_Session *s);
516 exist_session (struct Plugin *plugin,
517 struct GNUNET_ATS_Session *s);
520 struct GNUNET_TIME_Relative
521 http_plugin_receive (void *cls,
522 const struct GNUNET_PeerIdentity *peer,
523 const struct GNUNET_MessageHeader *message,
524 struct GNUNET_ATS_Session *session,
525 const char *sender_address,
526 uint16_t sender_address_len);
530 http_plugin_address_to_string (void *cls,
536 client_disconnect (struct GNUNET_ATS_Session *s);
540 client_connect (struct GNUNET_ATS_Session *s);
544 client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
548 client_start (struct Plugin *plugin);
552 client_stop (struct Plugin *plugin);
556 server_disconnect (struct GNUNET_ATS_Session *s);
560 server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
564 server_start (struct Plugin *plugin);
568 server_stop (struct Plugin *plugin);
572 notify_session_end (void *cls,
573 const struct GNUNET_PeerIdentity *peer,
574 struct GNUNET_ATS_Session *s);
577 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
579 /* end of plugin_transport_http.h */