GNUnet  0.10.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 (GNUNET_TIME_UNIT_SECONDS, 15)
66 
70 struct Plugin
71 {
76 
81 
86 
91 
96 
101 
107 
113 
117  size_t ext_addr_len;
118 
123 
128  char *name;
129 
134  char *protocol;
135 
139  int ipv4;
140 
144  int ipv6;
145 
150 
154  uint16_t port;
155 
161 
165  unsigned int outbound_sessions;
166 
170  unsigned int inbound_sessions;
171 
180  char *crypto_init;
181 
185  char *key;
186 
190  char *cert;
191 
196 
200  uint32_t last_tag;
201 
205  struct MHD_Daemon *server_v4;
206 
211 
216 
220  struct MHD_Daemon *server_v6;
221 
226 
231 
235  struct sockaddr_in *server_addr_v4;
236 
240  struct sockaddr_in6 *server_addr_v6;
241 
248 
255 
259  CURLM *client_mh;
260 
265 
266 };
267 
269 
274 {
278  uint32_t addr_len GNUNET_PACKED;
279 
283  void *addr GNUNET_PACKED;
284 };
285 
290 {
294  uint32_t ipv4_addr GNUNET_PACKED;
295 
299  uint16_t u4_port GNUNET_PACKED;
300 };
301 
306 {
310  struct in6_addr ipv6_addr GNUNET_PACKED;
311 
315  uint16_t u6_port GNUNET_PACKED;
316 };
318 
319 
321 {
326 
331 
336 
340  struct MHD_Connection *mhd_conn;
341 };
342 
343 
347 struct GNUNET_ATS_Session
348 {
352  struct GNUNET_PeerIdentity target;
353 
358 
363 
367  struct Plugin *plugin;
368 
372  void *addr;
373 
377  size_t addrlen;
378 
383 
388 
393 
398 
403  struct GNUNET_TIME_Absolute next_receive;
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 *
500 create_session (struct Plugin *plugin,
501  const struct GNUNET_PeerIdentity *target,
502  const void *addr,
503  size_t addrlen);
504 
505 
506 int
507 exist_session (struct Plugin *plugin,
508  struct GNUNET_ATS_Session *s);
509 
510 
511 void
513 
514 
515 int
516 exist_session (struct Plugin *plugin,
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
544 client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
545 
546 
547 int
548 client_start (struct Plugin *plugin);
549 
550 
551 void
552 client_stop (struct Plugin *plugin);
553 
554 
555 int
557 
558 
559 int
560 server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
561 
562 
563 int
564 server_start (struct Plugin *plugin);
565 
566 
567 void
568 server_stop (struct Plugin *plugin);
569 
570 
571 void
572 notify_session_end (void *cls,
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 */
void * client_put
Client send handle.
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
Wrapper to manage addresses.
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 max_connections
Maximum number of sockets the plugin can use Each http inbound /outbound connections are two connecti...
char * name
Plugin name.
struct ServerRequest * server_recv
Client send handle.
Handle for active NAT registrations.
Definition: nat_api.c:72
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
int client_connect(struct GNUNET_ATS_Session *s)
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
size_t addrlen
Address length.
char * buf
buffer containing data to send
void notify_session_end(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *s)
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct HTTP_Message * msg_tail
previous pointer for double linked list
library to make it easy to download JSON replies over HTTP
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_ATS_Session * next
Stored in a linked list.
int client_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg)
struct GNUNET_ATS_Session * prev
Stored in a linked list.
size_t pos
amount of data already sent
char * protocol
Plugin protocol http, https.
int inbound
Inbound or outbound connection Outbound: GNUNET_NO (client is used to send and receive) Inbound : GNU...
int exist_session(struct Plugin *plugin, struct GNUNET_ATS_Session *s)
char * key
TLS key.
Message to send using http.
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
struct HTTP_Message * next
next pointer for double linked list
int client_start(struct Plugin *plugin)
int server_disconnect(struct GNUNET_ATS_Session *s)
uint32_t ats_address_network_type
ATS network type in NBO.
struct GNUNET_SCHEDULER_Task * server_v6_task
MHD IPv4 task.
int server_v4_immediately
The IPv4 server is scheduled to run asap.
int client_only
Does plugin just use outbound connections and not accept inbound?
struct HTTP_Message * msg_head
next pointer for double linked list
unsigned int outbound_sessions
Number of outbound sessions.
int ipv4
Use IPv4? GNUNET_YES or GNUNET_NO.
void client_stop(struct Plugin *plugin)
int direction
_RECV or _SEND
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
void * transmit_cont_cls
Closure for transmit_cont.
int cur_connections
Current number of establishes connections.
struct HttpAddressWrapper * addr_head
Our own IPv4 addresses DLL head.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
Handle to a message stream tokenizer.
struct GNUNET_ATS_Session * head
Head of linked list of open sessions.
struct HttpAddress * ext_addr
External hostname the plugin can be connected to, can be different to the host&#39;s FQDN, used e.g.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
const char * http_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
int disconnect
Should this connection get disconnected? GNUNET_YES / GNUNET_NO.
CURLM * client_mh
cURL Multihandle
struct sockaddr_in * server_addr_v4
IPv4 server socket to bind to.
struct HttpAddressWrapper * addr_tail
Our own IPv4 addresses DLL tail.
Information about ongoing sessions of the transport client.
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
struct GNUNET_SCHEDULER_Task * notify_ext_task
Task calling transport service about external address.
int client_disconnect(struct GNUNET_ATS_Session *s)
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct GNUNET_ATS_Session * create_session(struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, const void *addr, size_t addrlen)
char * crypto_init
libCurl TLS crypto init string, can be set to enhance performance
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
char * cert
TLS certificate.
int client_put_paused
Is client send handle paused since there are no data to send? GNUNET_YES or GNUNET_NO.
int server_start(struct Plugin *plugin)
struct MHD_Connection * mhd_conn
The MHD connection.
size_t size
buffer length
int server_v6_immediately
The IPv6 server is scheduled to run asap.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int ipv6
Use IPv6? GNUNET_YES or GNUNET_NO.
uint32_t tag
Unique HTTP/S connection tag for this connection.
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".
void server_stop(struct Plugin *plugin)
struct MHD_Daemon * server_v6
MHD IPv6 daemon.
struct GNUNET_SCHEDULER_Task * server_v4_task
MHD IPv4 task.
unsigned int inbound_sessions
Number of inbound sessions.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
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)
The identity of the host (wraps the signing key of the peer).
Information we keep with MHD for an HTTP request.
#define GNUNET_PACKED
gcc-ism to get packed structs.
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
size_t ext_addr_len
External address length.
Entry in list of pending tasks.
Definition: scheduler.c:134
struct HTTP_Message * prev
previous pointer for double linked list
uint16_t port
Port used.
IPv4 addresses.
int server_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg)
uint32_t last_tag
Last used unique HTTP connection tag.
struct ServerRequest * server_send
Client send handle.
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
Header for all communications.
void delete_session(struct GNUNET_ATS_Session *s)
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_ATS_Session * tail
Tail of linked list of open sessions.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
struct sockaddr_in6 * server_addr_v6
IPv6 server socket to bind to.
IPv4 addresses.
HTTP addresses including a full URI.
char * external_hostname
External hostname the plugin can be connected to, can be different to the host&#39;s FQDN, used e.g.
Time for relative time used by GNUnet, in microseconds.
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...
void * client_get
Client receive handle.