GNUnet  0.11.x
plugin_transport_http.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 GNUnet e.V.
4 
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.
9 
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.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #ifndef PLUGIN_TRANSPORT_HTTP_H
27 #define PLUGIN_TRANSPORT_HTTP_H
28 
29 #include "platform.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"
38 #include "gnunet_server_lib.h"
39 #include "gnunet_container_lib.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"
46 
47 
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
52 
53 #if BUILD_HTTPS
54 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
55 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_https_done
56 #else
57 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
58 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_done
59 #endif
60 
61 #define INBOUND GNUNET_YES
62 #define OUTBOUND GNUNET_NO
63 
64 
65 #define HTTP_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply ( \
66  GNUNET_TIME_UNIT_SECONDS, 15)
67 
71 struct Plugin
72 {
77 
82 
87 
92 
97 
102 
108 
114 
118  size_t ext_addr_len;
119 
124 
129  char *name;
130 
135  char *protocol;
136 
140  int ipv4;
141 
145  int ipv6;
146 
151 
155  uint16_t port;
156 
162 
166  unsigned int outbound_sessions;
167 
171  unsigned int inbound_sessions;
172 
181  char *crypto_init;
182 
186  char *key;
187 
191  char *cert;
192 
197 
201  uint32_t last_tag;
202 
206  struct MHD_Daemon *server_v4;
207 
212 
217 
221  struct MHD_Daemon *server_v6;
222 
227 
232 
236  struct sockaddr_in *server_addr_v4;
237 
241  struct sockaddr_in6 *server_addr_v6;
242 
249 
256 
260  CURLM *client_mh;
261 
266 };
267 
269 
274 {
279 
284 };
285 
290 {
295 
300 };
301 
306 {
310  struct in6_addr ipv6_addr GNUNET_PACKED;
311 
316 };
318 
319 
321 {
326 
331 
336 
340  struct MHD_Connection *mhd_conn;
341 };
342 
343 
348 {
353 
358 
363 
367  struct Plugin *plugin;
368 
372  void *addr;
373 
377  size_t addrlen;
378 
383 
388 
393 
398 
404 
410  int inbound;
411 
415  uint32_t tag;
416 
420  void *client_put;
421 
425  void *client_get;
426 
431 
436 
442 
447 
452 };
453 
454 
459 {
464 
469 
473  char *buf;
474 
478  size_t pos;
479 
483  size_t size;
484 
491 
496 };
497 
498 
499 struct GNUNET_ATS_Session *
501  const struct GNUNET_PeerIdentity *target,
502  const void *addr,
503  size_t addrlen);
504 
505 
506 int
508  struct GNUNET_ATS_Session *s);
509 
510 
511 void
513 
514 
515 int
517  struct GNUNET_ATS_Session *s);
518 
519 
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);
527 
528 
529 const char *
531  const void *addr,
532  size_t addrlen);
533 
534 
535 int
537 
538 
539 int
541 
542 
543 int
545 
546 
547 int
549 
550 
551 void
553 
554 
555 int
557 
558 
559 int
561 
562 
563 int
565 
566 
567 void
569 
570 
571 void
573  const struct GNUNET_PeerIdentity *peer,
574  struct GNUNET_ATS_Session *s);
575 
576 
577 /*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
578 #endif
579 /* end of plugin_transport_http.h */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct Plugin * plugin
The process handle to the testbed service.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
library to make it easy to download JSON replies over HTTP
void(* GNUNET_TRANSPORT_TransmitContinuation)(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
Function called by the GNUNET_TRANSPORT_TransmitFunction upon "completion".
const char * http_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
int client_start(struct Plugin *plugin)
int server_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg)
void client_stop(struct Plugin *plugin)
struct GNUNET_TIME_Relative http_plugin_receive(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, struct GNUNET_ATS_Session *session, const char *sender_address, uint16_t sender_address_len)
int server_start(struct Plugin *plugin)
int client_connect(struct GNUNET_ATS_Session *s)
void notify_session_end(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *s)
int server_disconnect(struct GNUNET_ATS_Session *s)
void server_stop(struct Plugin *plugin)
int exist_session(struct Plugin *plugin, struct GNUNET_ATS_Session *s)
struct GNUNET_ATS_Session * create_session(struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, const void *addr, size_t addrlen)
int client_disconnect(struct GNUNET_ATS_Session *s)
int client_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg)
void delete_session(struct GNUNET_ATS_Session *s)
Session handle for connections.
void * client_get
Client receive handle.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct Plugin * plugin
Pointer to the global plugin struct.
struct ServerRequest * server_recv
Client send handle.
int inbound
Inbound or outbound connection Outbound: GNUNET_NO (client is used to send and receive) Inbound : GNU...
uint32_t ats_address_network_type
ATS network type in NBO.
struct ServerRequest * server_send
Client send handle.
struct HTTP_Message * msg_tail
previous pointer for double linked list
uint32_t tag
Unique HTTP/S connection tag for this connection.
int client_put_paused
Is client send handle paused since there are no data to send? GNUNET_YES or GNUNET_NO.
struct GNUNET_ATS_Session * next
Stored in a linked list.
size_t addrlen
Address length.
struct HTTP_Message * msg_head
next pointer for double linked list
void * client_put
Client send handle.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct GNUNET_ATS_Session * prev
Stored in a linked list.
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
Header for all communications.
Handle for active NAT registrations.
Definition: nat_api.c:72
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:135
Handle to a message stream tokenizer.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
Message to send using http.
size_t size
buffer length
struct HTTP_Message * next
next pointer for double linked list
size_t pos
amount of data already sent
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
void * transmit_cont_cls
Closure for transmit_cont.
char * buf
buffer containing data to send
struct HTTP_Message * prev
previous pointer for double linked list
Wrapper to manage addresses.
HTTP addresses including a full URI.
void * addr
Address following.
uint32_t addr_len
Length of the address following in NBO.
uint16_t u4_port
Port number, in network byte order.
uint32_t ipv4_addr
IPv4 address, in network byte order.
uint16_t u6_port
Port number, in network byte order.
struct in6_addr ipv6_addr
IPv6 address.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_ATS_Session * tail
Tail of linked list of open sessions.
struct sockaddr_in * server_addr_v4
IPv4 server socket to bind to.
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
struct GNUNET_SCHEDULER_Task * server_v6_task
MHD IPv4 task.
char * crypto_init
libCurl TLS crypto init string, can be set to enhance performance
uint32_t last_tag
Last used unique HTTP connection tag.
char * key
TLS key.
int cur_connections
Current number of establishes connections.
struct MHD_Daemon * server_v6
MHD IPv6 daemon.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct GNUNET_SCHEDULER_Task * server_v4_task
MHD IPv4 task.
struct HttpAddressWrapper * addr_head
Our own IPv4 addresses DLL head.
CURLM * client_mh
cURL Multihandle
int ipv6
Use IPv6? GNUNET_YES or GNUNET_NO.
struct HttpAddress * ext_addr
External hostname the plugin can be connected to, can be different to the host's FQDN,...
int ipv4
Use IPv4? GNUNET_YES or GNUNET_NO.
struct GNUNET_ATS_Session * head
Head of linked list of open sessions.
int client_only
Does plugin just use outbound connections and not accept inbound?
char * name
Plugin name.
char * cert
TLS certificate.
struct GNUNET_ATS_Session * server_semi_tail
Tail of server semi connections A full session consists of 2 semi-connections: send and receive If no...
int server_v4_immediately
The IPv4 server is scheduled to run asap.
struct GNUNET_SCHEDULER_Task * notify_ext_task
Task calling transport service about external address.
size_t ext_addr_len
External address length.
char * protocol
Plugin protocol http, https.
char * external_hostname
External hostname the plugin can be connected to, can be different to the host's FQDN,...
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
struct sockaddr_in6 * server_addr_v6
IPv6 server socket to bind to.
uint16_t port
Port used.
int max_connections
Maximum number of sockets the plugin can use Each http inbound /outbound connections are two connecti...
int server_v6_immediately
The IPv6 server is scheduled to run asap.
struct GNUNET_ATS_Session * server_semi_head
Head of server semi connections A full session consists of 2 semi-connections: send and receive If no...
unsigned int outbound_sessions
Number of outbound sessions.
unsigned int inbound_sessions
Number of inbound sessions.
struct HttpAddressWrapper * addr_tail
Our own IPv4 addresses DLL tail.
Information we keep with MHD for an HTTP request.
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
int disconnect
Should this connection get disconnected? GNUNET_YES / GNUNET_NO.
int direction
_RECV or _SEND
struct MHD_Connection * mhd_conn
The MHD connection.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.