GNUnet  0.10.x
Data Structures | Macros | Functions
plugin_transport_http_server.c File Reference

HTTP/S server transport plugin. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_plugin.h"
#include "gnunet_nat_service.h"
#include "plugin_transport_http_common.h"
#include <microhttpd.h>
#include <regex.h>
Include dependency graph for plugin_transport_http_server.c:

Go to the source code of this file.

Data Structures

struct  ServerRequest
 Information we keep with MHD for an HTTP request. More...
 
struct  HttpAddressWrapper
 Wrapper to manage addresses. More...
 
struct  HTTP_Message
 Message to send using http. More...
 
struct  GNUNET_ATS_Session
 Information about ongoing sessions of the transport client. More...
 
struct  HTTP_Server_Plugin
 Encapsulation of all of the state of the plugin. More...
 
struct  GNUNET_ATS_SessionTagContext
 Closure for session_tag_it(). More...
 

Macros

#define PLUGIN_NAME   "http_server"
 
#define LIBGNUNET_PLUGIN_TRANSPORT_INIT   libgnunet_plugin_transport_http_server_init
 
#define LIBGNUNET_PLUGIN_TRANSPORT_DONE   libgnunet_plugin_transport_http_server_done
 
#define HTTP_ERROR_RESPONSE   "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>"
 
#define _RECEIVE   0
 
#define _SEND   1
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-" PLUGIN_NAME,__VA_ARGS__)
 
#define OPTION_LONG_POLL   1 /* GET request wants long-poll semantics */
 
#define URL_REGEX   ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$")
 

Functions

static void notify_session_monitor (struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
 If a session monitor is attached, notify it about the new session state. More...
 
static void server_wake_up (void *cls)
 Wake up an MHD connection which was suspended. More...
 
static void server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
 Reschedule the execution of both IPv4 and IPv6 server. More...
 
static void server_delete_session (struct GNUNET_ATS_Session *s)
 Deletes the session. More...
 
static int http_server_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
 Disconnect session s by telling MHD to close the connections (reducing timeout, etc.). More...
 
static void server_session_timeout (void *cls)
 Session was idle, so disconnect it. More...
 
static void server_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
 Increment session timeout due to activity session s. More...
 
static ssize_t http_server_plugin_send (void *cls, struct GNUNET_ATS_Session *session, const char *msgbuf, size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
 Function that can be used by the transport service to transmit a message using the plugin. More...
 
static int destroy_session_shutdown_cb (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Terminate session during shutdown. More...
 
static int destroy_session_cb (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Terminate session. More...
 
static void http_server_plugin_disconnect_peer (void *cls, const struct GNUNET_PeerIdentity *target)
 Function that can be used to force the plugin to disconnect from the given peer and cancel all previous transmissions (and their continuationc). More...
 
static int http_server_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
 Another peer has suggested an address for this peer and transport plugin. More...
 
static struct GNUNET_ATS_Sessionhttp_server_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
 Creates a new outbound session the transport service will use to send data to the peer. More...
 
static void server_v4_run (void *cls)
 Call MHD IPv4 to process pending requests and then go back and schedule the next run. More...
 
static void server_v6_run (void *cls)
 Call MHD IPv6 to process pending requests and then go back and schedule the next run. More...
 
static struct GNUNET_SCHEDULER_Taskserver_schedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *daemon_handle, int now)
 Function that queries MHD's select sets and starts the task waiting for them. More...
 
static unsigned int http_server_query_keepalive_factor (void *cls)
 Function that is called to get the keepalive factor. More...
 
static void http_server_plugin_update_session_timeout (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
 Function that will be called whenever the transport service wants to notify the plugin that a session is still active and in use and therefore the session timeout for this session has to be updated. More...
 
static void server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *s, unsigned int to)
 Tell MHD that the connection should timeout after to seconds. More...
 
static int server_parse_url (struct HTTP_Server_Plugin *plugin, const char *url, struct GNUNET_PeerIdentity *target, uint32_t *tag, uint32_t *options)
 Parse incoming URL for tag and target. More...
 
static int session_tag_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find a session with a matching tag. More...
 
static struct ServerRequestserver_lookup_connection (struct HTTP_Server_Plugin *plugin, struct MHD_Connection *mhd_connection, const char *url, const char *method)
 Lookup a mhd connection and create one if none is found. More...
 
static ssize_t server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
 Callback called by MHD when it needs data to send. More...
 
static int server_receive_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
 Callback called by MessageStreamTokenizer when a message has arrived. More...
 
static void add_cors_headers (struct MHD_Response *response)
 Add headers to a request indicating that we allow Cross-Origin Resource Sharing. More...
 
static int server_access_cb (void *cls, struct MHD_Connection *mhd_connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **httpSessionCache)
 MHD callback for a new incoming connection. More...
 
static void server_disconnect_cb (void *cls, struct MHD_Connection *connection, void **httpSessionCache)
 Callback from MHD when a connection disconnects. More...
 
static void server_connection_cb (void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
 Callback from MHD when a connection starts/stops. More...
 
static int server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
 Check if incoming connection is accepted. More...
 
static void server_log (void *arg, const char *fmt, va_list ap)
 Log function called by MHD. More...
 
static struct MHD_Daemon * run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin, const struct sockaddr_in *addr, int v6)
 Invoke MHD_start_daemon with the various options we need to setup the HTTP server with the given listen address. More...
 
static int server_start (struct HTTP_Server_Plugin *plugin)
 Start the HTTP server. More...
 
static void server_add_address (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen)
 Add an address to the server's set of addresses and notify transport. More...
 
static void server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen)
 Remove an address from the server's set of addresses and notify transport. More...
 
static void server_nat_port_map_callback (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Our external IP address/port mapping has changed. More...
 
static int server_get_addresses (struct HTTP_Server_Plugin *plugin, const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, socklen_t **addr_lens)
 Get valid server addresses. More...
 
static void server_start_report_addresses (struct HTTP_Server_Plugin *plugin)
 Ask NAT for addresses. More...
 
static void server_stop_report_addresses (struct HTTP_Server_Plugin *plugin)
 Stop NAT for addresses. More...
 
static int server_check_ipv6_support (struct HTTP_Server_Plugin *plugin)
 Check if IPv6 supported on this system. More...
 
static void server_notify_external_hostname (void *cls)
 Notify server about our external hostname. More...
 
static int server_configure_plugin (struct HTTP_Server_Plugin *plugin)
 Configure the plugin. More...
 
void * libgnunet_plugin_transport_http_server_done (void *cls)
 Exit point from the plugin. More...
 
static const char * http_server_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
 Function called for a quick conversion of the binary address to a numeric address. More...
 
static enum GNUNET_NetworkType http_server_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
 Function obtain the network type for a session. More...
 
static enum GNUNET_NetworkType http_server_plugin_get_network_for_address (void *cls, const struct GNUNET_HELLO_Address *address)
 Function obtain the network type for an address. More...
 
static void http_server_plugin_update_inbound_delay (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session, struct GNUNET_TIME_Relative delay)
 Function that will be called whenever the transport service wants to notify the plugin that the inbound quota changed and that the plugin should update it's delay for the next receive value. More...
 
static int send_session_info_iter (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Return information about the given session to the monitor callback. More...
 
static void http_server_plugin_setup_monitor (void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
 Begin monitoring sessions of a plugin. More...
 
void * libgnunet_plugin_transport_http_server_init (void *cls)
 Entry point for the plugin. More...
 

Detailed Description

HTTP/S server transport plugin.

Author
Matthias Wachs
David Barksdale
Christian Grothoff

Definition in file plugin_transport_http_server.c.

Macro Definition Documentation

◆ PLUGIN_NAME

#define PLUGIN_NAME   "http_server"

◆ LIBGNUNET_PLUGIN_TRANSPORT_INIT

#define LIBGNUNET_PLUGIN_TRANSPORT_INIT   libgnunet_plugin_transport_http_server_init

Definition at line 45 of file plugin_transport_http_server.c.

◆ LIBGNUNET_PLUGIN_TRANSPORT_DONE

#define LIBGNUNET_PLUGIN_TRANSPORT_DONE   libgnunet_plugin_transport_http_server_done

◆ HTTP_ERROR_RESPONSE

#define HTTP_ERROR_RESPONSE   "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested URL was not found on this server.<P><HR><ADDRESS></ADDRESS></BODY></HTML>"

Definition at line 49 of file plugin_transport_http_server.c.

Referenced by server_access_cb().

◆ _RECEIVE

#define _RECEIVE   0

◆ _SEND

#define _SEND   1

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "transport-" PLUGIN_NAME,__VA_ARGS__)

◆ OPTION_LONG_POLL

#define OPTION_LONG_POLL   1 /* GET request wants long-poll semantics */

Definition at line 82 of file plugin_transport_http_server.c.

Referenced by server_send_callback().

◆ URL_REGEX

#define URL_REGEX   ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$")

Function Documentation

◆ notify_session_monitor()

static void notify_session_monitor ( struct HTTP_Server_Plugin plugin,
struct GNUNET_ATS_Session session,
enum GNUNET_TRANSPORT_SessionState  state 
)
static

If a session monitor is attached, notify it about the new session state.

Parameters
pluginour plugin
sessionsession that changed state
statenew state of the session

Definition at line 473 of file plugin_transport_http_server.c.

References GNUNET_ATS_Session::address, GNUNET_TRANSPORT_SessionInfo::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_YES, GNUNET_TRANSPORT_SessionInfo::is_inbound, GNUNET_ATS_Session::msgs_in_queue, GNUNET_ATS_Session::next_receive, GNUNET_TRANSPORT_SessionInfo::num_bytes_pending, GNUNET_TRANSPORT_SessionInfo::num_msg_pending, GNUNET_TRANSPORT_SessionInfo::receive_delay, GNUNET_TRANSPORT_SessionInfo::session_timeout, HTTP_Server_Plugin::sic, HTTP_Server_Plugin::sic_cls, state, GNUNET_TRANSPORT_SessionInfo::state, and GNUNET_ATS_Session::timeout.

Referenced by http_server_plugin_send(), send_session_info_iter(), server_delete_session(), server_lookup_connection(), server_receive_mst_cb(), server_send_callback(), and server_session_timeout().

476 {
477  struct GNUNET_TRANSPORT_SessionInfo info;
478 
479  if (NULL == plugin->sic)
480  return;
481  memset (&info, 0, sizeof (info));
482  info.state = state;
483  info.is_inbound = GNUNET_YES;
484  info.num_msg_pending = session->msgs_in_queue;
485  info.num_bytes_pending = session->bytes_in_queue;
486  info.receive_delay = session->next_receive;
487  info.session_timeout = session->timeout;
488  info.address = session->address;
489  plugin->sic (plugin->sic_cls,
490  session,
491  &info);
492 }
void * sic_cls
Closure for sic.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
struct GNUNET_HELLO_Address * address
Address.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
Information about a plugin&#39;s session.
enum State state
current state of profiling
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ server_wake_up()

static void server_wake_up ( void *  cls)
static

Wake up an MHD connection which was suspended.

Parameters
clsthe session

Definition at line 501 of file plugin_transport_http_server.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, ServerRequest::mhd_conn, plugin, GNUNET_ATS_Session::recv_wakeup_task, GNUNET_ATS_Session::server_recv, server_reschedule(), and ServerRequest::suspended.

Referenced by http_server_plugin_update_inbound_delay(), and server_access_cb().

502 {
503  struct GNUNET_ATS_Session *s = cls;
504 
505  s->recv_wakeup_task = NULL;
507  "Session %p: Waking up PUT handle\n",
508  s);
510  MHD_resume_connection (s->server_recv->mhd_conn);
511  s->server_recv->suspended = false;
512 }
struct ServerRequest * server_recv
Client send handle.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
bool suspended
Currently suspended.
Information about ongoing sessions of the transport client.
struct MHD_Connection * mhd_conn
The MHD connection.
#define LOG(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_reschedule()

static void server_reschedule ( struct HTTP_Server_Plugin plugin,
struct MHD_Daemon *  server,
int  now 
)
static

Reschedule the execution of both IPv4 and IPv6 server.

Parameters
pluginthe plugin
serverwhich server to schedule v4 or v6?
nowGNUNET_YES to schedule execution immediately, GNUNET_NO to wait until timeout

Definition at line 1080 of file plugin_transport_http_server.c.

References GNUNET_SCHEDULER_cancel(), GNUNET_YES, server_schedule(), HTTP_Server_Plugin::server_v4, HTTP_Server_Plugin::server_v4_immediately, HTTP_Server_Plugin::server_v4_task, HTTP_Server_Plugin::server_v6, HTTP_Server_Plugin::server_v6_immediately, and HTTP_Server_Plugin::server_v6_task.

Referenced by http_server_plugin_send(), server_connection_cb(), server_delete_session(), server_mhd_connection_timeout(), server_start(), server_v4_run(), server_v6_run(), and server_wake_up().

1083 {
1084  if ((server == plugin->server_v4) && (plugin->server_v4 != NULL))
1085  {
1086  if (GNUNET_YES == plugin->server_v4_immediately)
1087  return; /* No rescheduling, server will run asap */
1088 
1089  if (GNUNET_YES == now)
1091 
1092  if (plugin->server_v4_task != NULL)
1093  {
1095  plugin->server_v4_task = NULL;
1096  }
1097  plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now);
1098  }
1099 
1100  if ((server == plugin->server_v6) && (plugin->server_v6 != NULL))
1101  {
1102  if (GNUNET_YES == plugin->server_v6_immediately)
1103  return; /* No rescheduling, server will run asap */
1104 
1105  if (GNUNET_YES == now)
1107 
1108  if (plugin->server_v6_task != NULL)
1109  {
1111  plugin->server_v6_task = NULL;
1112  }
1113  plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
1114  }
1115 }
struct GNUNET_SCHEDULER_Task * server_v6_task
MHD IPv6 task.
struct GNUNET_SCHEDULER_Task * server_v4_task
MHD IPv4 task.
int server_v4_immediately
The IPv4 server is scheduled to run asap.
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
static struct GNUNET_SCHEDULER_Task * server_schedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *daemon_handle, int now)
Function that queries MHD&#39;s select sets and starts the task waiting for them.
int server_v6_immediately
The IPv6 server is scheduled to run asap.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct MHD_Daemon * server_v6
MHD IPv4 daemon.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_delete_session()

static void server_delete_session ( struct GNUNET_ATS_Session s)
static

Deletes the session.

Must not be used afterwards.

Parameters
sthe session to delete

Definition at line 535 of file plugin_transport_http_server.c.

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_TRANSPORT_PluginEnvironment::cls, HTTP_Server_Plugin::env, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_free, GNUNET_i2s(), GNUNET_MST_destroy(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_SS_DONE, GNUNET_YES, GNUNET_ATS_Session::known_to_service, LOG, ServerRequest::mhd_conn, ServerRequest::mhd_daemon, msg, GNUNET_ATS_Session::msg_head, GNUNET_ATS_Session::msg_tail, GNUNET_ATS_Session::msg_tk, GNUNET_ATS_Session::msgs_in_queue, notify_session_monitor(), HTTP_Message::overhead, GNUNET_ATS_Session::plugin, HTTP_Message::pos, GNUNET_ATS_Session::recv_wakeup_task, GNUNET_ATS_Session::server_recv, server_reschedule(), GNUNET_ATS_Session::server_send, ServerRequest::session, GNUNET_TRANSPORT_PluginEnvironment::session_end, HTTP_Server_Plugin::sessions, HTTP_Message::size, ServerRequest::suspended, GNUNET_ATS_Session::target, GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, HTTP_Message::transmit_cont, and HTTP_Message::transmit_cont_cls.

Referenced by destroy_session_cb(), destroy_session_shutdown_cb(), http_server_plugin_disconnect_session(), and server_session_timeout().

536 {
537  struct HTTP_Server_Plugin *plugin = s->plugin;
538  struct HTTP_Message *msg;
539 
540  if (NULL != s->timeout_task)
541  {
543  s->timeout_task = NULL;
545  }
546  if (NULL != s->recv_wakeup_task)
547  {
549  s->recv_wakeup_task = NULL;
550  if (NULL != s->server_recv)
551  {
553  s->server_recv->suspended = false;
554  MHD_resume_connection (s->server_recv->mhd_conn);
555  }
556  }
559  &s->target,
560  s));
561  while (NULL != (msg = s->msg_head))
562  {
564  s->msg_tail,
565  msg);
566  if (NULL != msg->transmit_cont)
567  msg->transmit_cont (msg->transmit_cont_cls,
568  &s->target,
570  msg->size,
571  msg->pos + msg->overhead);
572  GNUNET_assert (s->msgs_in_queue > 0);
573  s->msgs_in_queue--;
574  GNUNET_assert (s->bytes_in_queue >= msg->size);
575  s->bytes_in_queue -= msg->size;
576  GNUNET_free (msg);
577  }
578 
579  GNUNET_assert (0 == s->msgs_in_queue);
580  GNUNET_assert (0 == s->bytes_in_queue);
581 
582  if (NULL != s->server_send)
583  {
585  "Server: %p / %p Terminating inbound PUT session to peer `%s'\n",
586  s, s->server_send,
587  GNUNET_i2s (&s->target));
588  s->server_send->session = NULL;
589  MHD_set_connection_option (s->server_send->mhd_conn,
590  MHD_CONNECTION_OPTION_TIMEOUT,
591  1 /* 0 = no timeout, so this is MIN */);
592  if (s->server_send->suspended)
593  {
594  s->server_send->suspended = false;
595  MHD_resume_connection (s->server_send->mhd_conn);
596  }
597  server_reschedule (plugin,
599  GNUNET_YES);
600  }
601 
602  if (NULL != s->server_recv)
603  {
605  "Server: %p / %p Terminating inbound GET session to peer `%s'\n",
606  s, s->server_recv, GNUNET_i2s (&s->target));
607  s->server_recv->session = NULL;
608  MHD_set_connection_option (s->server_recv->mhd_conn,
609  MHD_CONNECTION_OPTION_TIMEOUT,
610  1 /* 0 = no timeout, so this is MIN */);
611  server_reschedule (plugin,
613  GNUNET_YES);
614  }
615  notify_session_monitor (plugin,
616  s,
618  if (GNUNET_YES == s->known_to_service)
619  {
620  plugin->env->session_end (plugin->env->cls,
621  s->address,
622  s);
624  }
625  if (NULL != s->msg_tk)
626  {
628  s->msg_tk = NULL;
629  }
632  "Session %p destroyed\n",
633  s);
634  GNUNET_free (s);
635 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Session is being torn down and about to disappear.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct ServerRequest * server_recv
Client send handle.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct Plugin * plugin
Pointer to the global plugin struct.
size_t pos
amount of data already sent
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Message to send using http.
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Hash map of open sessions.
bool suspended
Currently suspended.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
static void notify_session_monitor(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
struct HTTP_Message * msg_head
next pointer for double linked list
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
void * transmit_cont_cls
Closure for transmit_cont.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
struct MHD_Daemon * mhd_daemon
The MHD daemon.
GNUNET_TRANSPORT_SessionEnd session_end
Function that must be called by the plugin when a non-NULL session handle stops being valid (is destr...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void * cls
Closure for the various callbacks.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
int known_to_service
GNUNET_YES if this session is known to the service.
size_t overhead
HTTP/S specific overhead.
struct MHD_Connection * mhd_conn
The MHD connection.
size_t size
buffer length
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
Encapsulation of all of the state of the plugin.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct ServerRequest * server_send
Client send handle.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_HELLO_address_free(addr)
Free an address.
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_server_plugin_disconnect_session()

static int http_server_plugin_disconnect_session ( void *  cls,
struct GNUNET_ATS_Session s 
)
static

Disconnect session s by telling MHD to close the connections (reducing timeout, etc.).

Parameters
clsclosure with the struct HTTP_Server_Plugin
sthe session
Returns
GNUNET_OK on success

Definition at line 647 of file plugin_transport_http_server.c.

References GNUNET_OK, and server_delete_session().

Referenced by libgnunet_plugin_transport_http_server_init().

649 {
651  return GNUNET_OK;
652 }
static void server_delete_session(struct GNUNET_ATS_Session *s)
Deletes the session.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_session_timeout()

static void server_session_timeout ( void *  cls)
static

Session was idle, so disconnect it.

Parameters
clsthe session

Definition at line 661 of file plugin_transport_http_server.c.

References GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TRANSPORT_SS_UP, GNUNET_YES, HTTP_SERVER_SESSION_TIMEOUT, notify_session_monitor(), GNUNET_ATS_Session::plugin, GNUNET_TIME_Relative::rel_value_us, server_delete_session(), GNUNET_ATS_Session::timeout, TIMEOUT_LOG, and GNUNET_ATS_Session::timeout_task.

Referenced by server_lookup_connection().

662 {
663  struct GNUNET_ATS_Session *s = cls;
664  struct GNUNET_TIME_Relative left;
665 
666  s->timeout_task = NULL;
668  if (0 != left.rel_value_us)
669  {
670  /* not actually our turn yet, but let's at least update
671  the monitor, it may think we're about to die ... */
673  s,
677  s);
678  return;
679  }
681  "Session %p was idle for %s, disconnecting\n",
682  s,
684  GNUNET_YES));
686 }
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
static void server_delete_session(struct GNUNET_ATS_Session *s)
Deletes the session.
static void server_session_timeout(void *cls)
Session was idle, so disconnect it.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
static void notify_session_monitor(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
Information about ongoing sessions of the transport client.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
#define HTTP_SERVER_SESSION_TIMEOUT
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:80
#define TIMEOUT_LOG
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_reschedule_session_timeout()

static void server_reschedule_session_timeout ( struct GNUNET_ATS_Session s)
static

Increment session timeout due to activity session s.

Parameters
sthe session

Definition at line 695 of file plugin_transport_http_server.c.

References GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_TIME_relative_to_absolute(), GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by http_server_plugin_update_session_timeout(), and server_receive_mst_cb().

696 {
697  GNUNET_assert (NULL != s->timeout_task);
699 }
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_server_plugin_send()

static ssize_t http_server_plugin_send ( void *  cls,
struct GNUNET_ATS_Session session,
const char *  msgbuf,
size_t  msgbuf_size,
unsigned int  priority,
struct GNUNET_TIME_Relative  to,
GNUNET_TRANSPORT_TransmitContinuation  cont,
void *  cont_cls 
)
static

Function that can be used by the transport service to transmit a message using the plugin.

Note that in the case of a peer disconnecting, the continuation MUST be called prior to the disconnect notification itself. This function will be called with this peer's HELLO message to initiate a fresh connection to another peer.

Parameters
clsclosure
sessionwhich session must be used
msgbufthe message to transmit
msgbuf_sizenumber of bytes in msgbuf
priorityhow important is the message (most plugins will ignore message priority and just FIFO)
tohow long to wait at most for the transmission (does not require plugins to discard the message after the timeout, just advisory for the desired delay; most plugins will ignore this as well)
contcontinuation to call once the message has been transmitted (or if the transport is ready for the next transmission call; or if the peer disconnected...); can be NULL
cont_clsclosure for cont
Returns
number of bytes used (on the physical network, with overheads); -1 on hard errors (i.e. address invalid); 0 is a legal value and does NOT mean that the message was not transmitted (DV)

Definition at line 730 of file plugin_transport_http_server.c.

References GNUNET_ATS_Session::bytes_in_queue, HTTP_Server_Plugin::env, GNUNET_asprintf(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TRANSPORT_SS_UP, GNUNET_YES, LOG, ServerRequest::mhd_conn, ServerRequest::mhd_daemon, msg, GNUNET_ATS_Session::msg_head, GNUNET_ATS_Session::msg_tail, GNUNET_ATS_Session::msgs_in_queue, notify_session_monitor(), GNUNET_ATS_Session::plugin, HTTP_Message::pos, HTTP_Server_Plugin::protocol, server_reschedule(), GNUNET_ATS_Session::server_send, GNUNET_TRANSPORT_PluginEnvironment::stats, ServerRequest::suspended, and GNUNET_ATS_Session::target.

Referenced by libgnunet_plugin_transport_http_server_init().

738 {
739  struct HTTP_Server_Plugin *plugin = cls;
740  struct HTTP_Message *msg;
741  ssize_t bytes_sent = 0;
742  char *stat_txt;
743 
745  "Session %p/request %p: Sending message with %u to peer `%s'\n",
746  session,
747  session->server_send,
748  msgbuf_size,
749  GNUNET_i2s (&session->target));
750 
751  /* create new message and schedule */
752  bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size;
753  msg = GNUNET_malloc (bytes_sent);
754  msg->next = NULL;
755  msg->size = msgbuf_size;
756  msg->pos = 0;
757  msg->buf = (char *) &msg[1];
758  msg->transmit_cont = cont;
759  msg->transmit_cont_cls = cont_cls;
760  GNUNET_memcpy (msg->buf,
761  msgbuf,
762  msgbuf_size);
764  session->msg_tail,
765  msg);
766  session->msgs_in_queue++;
767  session->bytes_in_queue += msg->size;
768  notify_session_monitor (plugin,
769  session,
771  GNUNET_asprintf (&stat_txt,
772  "# bytes currently in %s_server buffers",
773  plugin->protocol);
775  stat_txt, msgbuf_size, GNUNET_NO);
776  GNUNET_free (stat_txt);
777 
778  if (NULL != session->server_send)
779  {
780  if (session->server_send->suspended)
781  {
782  MHD_resume_connection (session->server_send->mhd_conn);
783  session->server_send->suspended = false;
784  }
785  server_reschedule (session->plugin,
786  session->server_send->mhd_daemon,
787  GNUNET_YES);
788  }
789  return bytes_sent;
790 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct Plugin * plugin
Pointer to the global plugin struct.
Message to send using http.
bool suspended
Currently suspended.
#define GNUNET_NO
Definition: gnunet_common.h:81
static void notify_session_monitor(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
struct HTTP_Message * msg_head
next pointer for double linked list
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
struct MHD_Daemon * mhd_daemon
The MHD daemon.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_memcpy(dst, src, n)
struct MHD_Connection * mhd_conn
The MHD connection.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
Encapsulation of all of the state of the plugin.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
struct ServerRequest * server_send
Client send handle.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_session_shutdown_cb()

static int destroy_session_shutdown_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Terminate session during shutdown.

Parameters
clsthe struct HTTP_Server_Plugin *
peerfor which this is a session
valuethe struct GNUNET_ATS_Session to clean up
Returns
GNUNET_OK (continue to iterate)

Definition at line 802 of file plugin_transport_http_server.c.

References GNUNET_OK, server_delete_session(), GNUNET_ATS_Session::server_recv, GNUNET_ATS_Session::server_send, ServerRequest::session, and value.

Referenced by libgnunet_plugin_transport_http_server_done().

805 {
806  struct GNUNET_ATS_Session *s = value;
807  struct ServerRequest *sc_send;
808  struct ServerRequest *sc_recv;
809 
810  sc_send = s->server_send;
811  sc_recv = s->server_recv;
813  if (NULL != sc_send)
814  sc_send->session = NULL;
815  if (NULL != sc_recv)
816  sc_recv->session = NULL;
817 
818  return GNUNET_OK;
819 }
struct ServerRequest * server_recv
Client send handle.
static void server_delete_session(struct GNUNET_ATS_Session *s)
Deletes the session.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
Information we keep with MHD for an HTTP request.
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
struct ServerRequest * server_send
Client send handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_session_cb()

static int destroy_session_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Terminate session.

Parameters
clsthe struct HTTP_Server_Plugin *
peerfor which this is a session
valuethe struct GNUNET_ATS_Session to clean up
Returns
GNUNET_OK (continue to iterate)

Definition at line 831 of file plugin_transport_http_server.c.

References GNUNET_OK, server_delete_session(), and value.

Referenced by http_server_plugin_disconnect_peer().

834 {
835  struct GNUNET_ATS_Session *s = value;
836 
838  return GNUNET_OK;
839 }
static void server_delete_session(struct GNUNET_ATS_Session *s)
Deletes the session.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_server_plugin_disconnect_peer()

static void http_server_plugin_disconnect_peer ( void *  cls,
const struct GNUNET_PeerIdentity target 
)
static

Function that can be used to force the plugin to disconnect from the given peer and cancel all previous transmissions (and their continuationc).

Parameters
clsclosure
targetpeer from which to disconnect

Definition at line 851 of file plugin_transport_http_server.c.

References destroy_session_cb(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, and HTTP_Server_Plugin::sessions.

Referenced by libgnunet_plugin_transport_http_server_init().

853 {
854  struct HTTP_Server_Plugin *plugin = cls;
855 
857  "Transport tells me to disconnect `%s'\n",
858  GNUNET_i2s (target));
860  target,
862  plugin);
863 }
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Hash map of open sessions.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static int destroy_session_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Terminate session.
Encapsulation of all of the state of the plugin.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_server_plugin_address_suggested()

static int http_server_plugin_address_suggested ( void *  cls,
const void *  addr,
size_t  addrlen 
)
static

Another peer has suggested an address for this peer and transport plugin.

Check that this could be a valid address. If so, consider adding it to the list of addresses.

Parameters
clsclosure
addrpointer to the address
addrlenlength of addr
Returns
GNUNET_OK if this is a plausible address for this peer and transport

Definition at line 879 of file plugin_transport_http_server.c.

References HttpAddress::addr, HTTP_Server_Plugin::addr_head, GNUNET_HELLO_Address::address, HttpAddressWrapper::address, GNUNET_HELLO_Address::address_length, HttpAddressWrapper::addrlen, HTTP_Server_Plugin::ext_addr, GNUNET_NO, GNUNET_OK, GNUNET_YES, http_common_cmp_addresses(), HTTP_OPTIONS_VERIFY_CERTIFICATE, HttpAddressWrapper::next, HttpAddress::options, and HTTP_Server_Plugin::options.

Referenced by libgnunet_plugin_transport_http_server_init().

882 {
883  struct HTTP_Server_Plugin *plugin = cls;
884  struct HttpAddressWrapper *next;
885  struct HttpAddressWrapper *pos;
886  const struct HttpAddress *haddr = addr;
887 
888  if ((NULL != plugin->ext_addr) &&
890  plugin->ext_addr->address,
891  plugin->ext_addr->address_length)))
892  {
893  /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */
894  if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) !=
896  return GNUNET_NO; /* VERIFY option not set as required! */
897  return GNUNET_OK;
898  }
899  next = plugin->addr_head;
900  while (NULL != (pos = next))
901  {
902  next = pos->next;
904  addrlen,
905  pos->address,
906  pos->addrlen)))
907  return GNUNET_OK;
908  }
909  return GNUNET_NO;
910 }
size_t address_length
Number of bytes in address.
Wrapper to manage addresses.
uint32_t options
Address options see enum HttpAddressOptions
const void * address
Binary representation of the address (plugin-specific).
uint32_t options
My options to be included in the address.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * ext_addr
External hostname the plugin can be connected to, can be different to the host&#39;s FQDN, used e.g.
struct HttpAddressWrapper * next
Linked list next.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void * addr
Address following.
struct HttpAddress * address
An address we are using.
size_t http_common_cmp_addresses(const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2)
Compare addr1 to addr2.
Encapsulation of all of the state of the plugin.
Verify X509 server certificate, it should be valid.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct HttpAddressWrapper * addr_head
IPv4 addresses DLL head.
HTTP addresses including a full URI.
size_t addrlen
Length of the address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_server_plugin_get_session()

static struct GNUNET_ATS_Session* http_server_plugin_get_session ( void *  cls,
const struct GNUNET_HELLO_Address address 
)
static

Creates a new outbound session the transport service will use to send data to the peer.

Since HTTP/S server cannot create sessions, always returns NULL.

Parameters
clsthe plugin
addressthe address
Returns
always NULL

Definition at line 924 of file plugin_transport_http_server.c.

Referenced by libgnunet_plugin_transport_http_server_init().

926 {
927  return NULL;
928 }
Here is the caller graph for this function:

◆ server_v4_run()

static void server_v4_run ( void *  cls)
static

Call MHD IPv4 to process pending requests and then go back and schedule the next run.

Parameters
clsplugin as closure

Definition at line 938 of file plugin_transport_http_server.c.

References GNUNET_assert, GNUNET_NO, server_reschedule(), HTTP_Server_Plugin::server_v4, HTTP_Server_Plugin::server_v4_immediately, and HTTP_Server_Plugin::server_v4_task.

Referenced by server_schedule().

939 {
940  struct HTTP_Server_Plugin *plugin = cls;
941 
942  plugin->server_v4_task = NULL;
944  GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
945  server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
946 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * server_v4_task
MHD IPv4 task.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int server_v4_immediately
The IPv4 server is scheduled to run asap.
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
Encapsulation of all of the state of the plugin.
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_v6_run()

static void server_v6_run ( void *  cls)
static

Call MHD IPv6 to process pending requests and then go back and schedule the next run.

Parameters
clsplugin as closure

Definition at line 956 of file plugin_transport_http_server.c.

References GNUNET_assert, GNUNET_NO, server_reschedule(), HTTP_Server_Plugin::server_v6, HTTP_Server_Plugin::server_v6_immediately, and HTTP_Server_Plugin::server_v6_task.

Referenced by server_schedule().

957 {
958  struct HTTP_Server_Plugin *plugin = cls;
959 
960  plugin->server_v6_task = NULL;
962  GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
963  server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
964 }
struct GNUNET_SCHEDULER_Task * server_v6_task
MHD IPv6 task.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Encapsulation of all of the state of the plugin.
int server_v6_immediately
The IPv6 server is scheduled to run asap.
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
struct MHD_Daemon * server_v6
MHD IPv4 daemon.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_schedule()

static struct GNUNET_SCHEDULER_Task* server_schedule ( struct HTTP_Server_Plugin plugin,
struct MHD_Daemon *  daemon_handle,
int  now 
)
static

Function that queries MHD's select sets and starts the task waiting for them.

Parameters
pluginplugin
daemon_handlethe MHD daemon handle
nowschedule now
Returns
gnunet task identifier

Definition at line 977 of file plugin_transport_http_server.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, HTTP_Server_Plugin::in_shutdown, LOG, GNUNET_TIME_Relative::rel_value_us, ret, HTTP_Server_Plugin::server_v4, server_v4_run(), HTTP_Server_Plugin::server_v4_task, HTTP_Server_Plugin::server_v6, server_v6_run(), HTTP_Server_Plugin::server_v6_task, and timeout.

Referenced by server_reschedule().

980 {
981  struct GNUNET_SCHEDULER_Task * ret;
982  fd_set rs;
983  fd_set ws;
984  fd_set es;
985  struct GNUNET_NETWORK_FDSet *wrs;
986  struct GNUNET_NETWORK_FDSet *wws;
987  int max;
988  MHD_UNSIGNED_LONG_LONG timeout;
989  static unsigned long long last_timeout = 0;
990  int haveto;
991  struct GNUNET_TIME_Relative tv;
992 
993  if (GNUNET_YES == plugin->in_shutdown)
994  return NULL;
995 
996  ret = NULL;
997  FD_ZERO (&rs);
998  FD_ZERO (&ws);
999  FD_ZERO (&es);
1000  wrs = GNUNET_NETWORK_fdset_create ();
1001  wws = GNUNET_NETWORK_fdset_create ();
1002  max = -1;
1003  GNUNET_assert (MHD_YES ==
1004  MHD_get_fdset (daemon_handle,
1005  &rs,
1006  &ws,
1007  &es,
1008  &max));
1009  haveto = MHD_get_timeout (daemon_handle, &timeout);
1010  if (haveto == MHD_YES)
1011  {
1012  if (timeout != last_timeout)
1013  {
1015  "SELECT Timeout changed from %llu to %llu (ms)\n",
1016  last_timeout, timeout);
1017  last_timeout = timeout;
1018  }
1019  if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL)
1020  tv.rel_value_us = (uint64_t) timeout * 1000LL;
1021  else
1023  }
1024  else
1026  /* Force immediate run, since we have outbound data to send */
1027  if (now == GNUNET_YES)
1029  GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
1030  GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
1031 
1032  if (daemon_handle == plugin->server_v4)
1033  {
1034  if (plugin->server_v4_task != NULL)
1035  {
1037  plugin->server_v4_task = NULL;
1038  }
1039 #if 0
1041  "Scheduling IPv4 server task in %llu ms\n",
1042  tv);
1043 #endif
1044  ret =
1046  tv, wrs, wws,
1047  &server_v4_run, plugin);
1048  }
1049  if (daemon_handle == plugin->server_v6)
1050  {
1051  if (plugin->server_v6_task != NULL)
1052  {
1054  plugin->server_v6_task = NULL;
1055  }
1056 #if 0
1058  "Scheduling IPv6 server task in %llu ms\n", tv);
1059 #endif
1060  ret =
1062  tv, wrs, wws,
1063  &server_v6_run, plugin);
1064  }
1067  return ret;
1068 }
static struct MHD_Daemon * daemon_handle
Handle to the HTTP server as provided by libmicrohttpd.
Definition: gnunet-bcd.c:44
struct GNUNET_SCHEDULER_Task * server_v6_task
MHD IPv6 task.
uint64_t rel_value_us
The actual value.
static void server_v6_run(void *cls)
Call MHD IPv6 to process pending requests and then go back and schedule the next run.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_SCHEDULER_Task * server_v4_task
MHD IPv4 task.
static int ret
Final status code.
Definition: gnunet-arm.c:89
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1308
int in_shutdown
Did we immediately end the session in disconnect_cb.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1829
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
Entry in list of pending tasks.
Definition: scheduler.c:134
#define GNUNET_YES
Definition: gnunet_common.h:80
static void server_v4_run(void *cls)
Call MHD IPv4 to process pending requests and then go back and schedule the next run.
Run with the default priority (normal P2P operations).
#define LOG(kind,...)
struct MHD_Daemon * server_v6
MHD IPv4 daemon.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_server_query_keepalive_factor()

static unsigned int http_server_query_keepalive_factor ( void *  cls)
static

Function that is called to get the keepalive factor.

GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to calculate the interval between keepalive packets.

Parameters
clsclosure with the struct HTTP_Server_Plugin
Returns
keepalive factor

Definition at line 1127 of file plugin_transport_http_server.c.

Referenced by libgnunet_plugin_transport_http_server_init().

1128 {
1129  return 3;
1130 }
Here is the caller graph for this function:

◆ http_server_plugin_update_session_timeout()

static void http_server_plugin_update_session_timeout ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_ATS_Session session 
)
static

Function that will be called whenever the transport service wants to notify the plugin that a session is still active and in use and therefore the session timeout for this session has to be updated.

Parameters
clsclosure
peerwhich peer was the session for
sessionwhich session is being updated

Definition at line 1143 of file plugin_transport_http_server.c.

References server_reschedule_session_timeout().

Referenced by libgnunet_plugin_transport_http_server_init().

1146 {
1148 }
static void server_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity session s.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_mhd_connection_timeout()

static void server_mhd_connection_timeout ( struct HTTP_Server_Plugin plugin,
struct GNUNET_ATS_Session s,
unsigned int  to 
)
static

Tell MHD that the connection should timeout after to seconds.

Parameters
pluginour plugin
ssession for which the timeout changes
totimeout in seconds

Definition at line 1159 of file plugin_transport_http_server.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, LOG, ServerRequest::mhd_conn, ServerRequest::mhd_daemon, GNUNET_ATS_Session::server_recv, server_reschedule(), and GNUNET_ATS_Session::server_send.

Referenced by server_access_cb(), and server_lookup_connection().

1162 {
1163  /* Setting timeouts for other connections */
1164  if (NULL != s->server_recv)
1165  {
1167  "Setting timeout for %p to %u sec.\n",
1168  s->server_recv, to);
1169  MHD_set_connection_option (s->server_recv->mhd_conn,
1170  MHD_CONNECTION_OPTION_TIMEOUT,
1171  to);
1173  }
1174  if (NULL != s->server_send)
1175  {
1177  "Setting timeout for %p to %u sec.\n",
1178  s->server_send, to);
1179  MHD_set_connection_option (s->server_send->mhd_conn,
1180  MHD_CONNECTION_OPTION_TIMEOUT,
1181  to);
1183  }
1184 }
struct ServerRequest * server_recv
Client send handle.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct MHD_Daemon * mhd_daemon
The MHD daemon.
struct MHD_Connection * mhd_conn
The MHD connection.
struct ServerRequest * server_send
Client send handle.
#define LOG(kind,...)
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_parse_url()

static int server_parse_url ( struct HTTP_Server_Plugin plugin,
const char *  url,
struct GNUNET_PeerIdentity target,
uint32_t *  tag,
uint32_t *  options 
)
static

Parse incoming URL for tag and target.

Parameters
pluginplugin
urlincoming url
targetwhere to store the target
tagwhere to store the tag
optionswhere to store the options
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1198 of file plugin_transport_http_server.c.

References GNUNET_break, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s_full(), GNUNET_OK, GNUNET_SYSERR, LOG, HTTP_Server_Plugin::peer_id_length, GNUNET_PeerIdentity::public_key, and HTTP_Server_Plugin::url_regex.

Referenced by server_lookup_connection().

1203 {
1204  regmatch_t matches[4];
1205  const char *tag_start;
1206  const char *target_start;
1207  char *tag_end;
1208  char *options_end;
1209  size_t hash_length;
1210  unsigned long int rc;
1211 
1212  /* URL parsing */
1213 #define URL_REGEX \
1214  ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$")
1215 
1216  if (NULL == url)
1217  {
1218  GNUNET_break (0);
1219  return GNUNET_SYSERR;
1220  }
1221 
1222  if (regexec(&plugin->url_regex, url, 4, matches, 0))
1223  {
1225  "URL `%s' did not match regex\n", url);
1226  return GNUNET_SYSERR;
1227  }
1228 
1229  target_start = &url[matches[1].rm_so];
1230  tag_start = &url[matches[2].rm_so];
1231 
1232  /* convert tag */
1233  rc = strtoul (tag_start, &tag_end, 10);
1234  if (&url[matches[2].rm_eo] != tag_end)
1235  {
1237  "URL tag did not line up with submatch\n");
1238  return GNUNET_SYSERR;
1239  }
1240  if (rc == 0)
1241  {
1243  "URL tag is zero\n");
1244  return GNUNET_SYSERR;
1245  }
1246  if ((rc == ULONG_MAX) && (ERANGE == errno))
1247  {
1249  "URL tag > ULONG_MAX\n");
1250  return GNUNET_SYSERR;
1251  }
1252  if (rc > UINT32_MAX)
1253  {
1255  "URL tag > UINT32_MAX\n");
1256  return GNUNET_SYSERR;
1257  }
1258  (*tag) = (uint32_t)rc;
1260  "Found tag `%u' in url\n",
1261  *tag);
1262 
1263  /* convert peer id */
1264  hash_length = matches[1].rm_eo - matches[1].rm_so;
1265  if (hash_length != plugin->peer_id_length)
1266  {
1268  "URL target is %u bytes, expecting %u\n",
1269  hash_length, plugin->peer_id_length);
1270  return GNUNET_SYSERR;
1271  }
1272  if (GNUNET_OK !=
1274  hash_length,
1275  &target->public_key))
1276  {
1278  "URL target conversion failed\n");
1279  return GNUNET_SYSERR;
1280  }
1282  "Found target `%s' in URL\n",
1283  GNUNET_i2s_full (target));
1284 
1285  /* convert options */
1286  if (-1 == matches[3].rm_so)
1287  {
1288  *options = 0;
1289  }
1290  else
1291  {
1292  rc = strtoul (&url[matches[3].rm_so + 1], &options_end, 10);
1293  if (&url[matches[3].rm_eo] != options_end)
1294  {
1296  "URL options did not line up with submatch\n");
1297  return GNUNET_SYSERR;
1298  }
1299  if ((rc == ULONG_MAX) && (ERANGE == errno))
1300  {
1302  "URL options > ULONG_MAX\n");
1303  return GNUNET_SYSERR;
1304  }
1305  if (rc > UINT32_MAX)
1306  {
1308  "URL options > UINT32_MAX\n");
1309  return GNUNET_SYSERR;
1310  }
1311  (*options) = (uint32_t) rc;
1313  "Found options `%u' in url\n",
1314  *options);
1315  }
1316  return GNUNET_OK;
1317 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
regex_t url_regex
Regex for parsing URLs.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:501
#define LOG(kind,...)
int peer_id_length
Length of peer id.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_tag_it()

static int session_tag_it ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Find a session with a matching tag.

Parameters
clsthe struct GNUNET_ATS_SessionTagContext *
keypeer identity (unused)
valuethe struct GNUNET_ATS_Session *
Returns
GNUNET_NO if we found the session, GNUNET_OK if not

Definition at line 1346 of file plugin_transport_http_server.c.

References GNUNET_NO, GNUNET_YES, GNUNET_ATS_SessionTagContext::res, GNUNET_ATS_Session::tag, GNUNET_ATS_SessionTagContext::tag, and value.

Referenced by server_lookup_connection().

1349 {
1350  struct GNUNET_ATS_SessionTagContext *stc = cls;
1351  struct GNUNET_ATS_Session *s = value;
1352 
1353  if (s->tag == stc->tag)
1354  {
1355  stc->res = s;
1356  return GNUNET_NO;
1357  }
1358  return GNUNET_YES;
1359 }
#define GNUNET_NO
Definition: gnunet_common.h:81
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
struct GNUNET_ATS_Session * res
Set to session matching the tag.
Closure for session_tag_it().
uint32_t tag
Unique HTTP/S connection tag for this connection.
uint32_t tag
Tag we are looking for.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ server_lookup_connection()

static struct ServerRequest* server_lookup_connection ( struct HTTP_Server_Plugin plugin,
struct MHD_Connection *  mhd_connection,
const char *  url,
const char *  method 
)
static

Lookup a mhd connection and create one if none is found.

Parameters
pluginthe plugin handle
mhd_connectionthe incoming mhd_connection
urlincoming requested URL
methodPUT or GET
Returns
the server connecetion

Definition at line 1372 of file plugin_transport_http_server.c.

References _RECEIVE, _SEND, HttpAddress::addr, GNUNET_ATS_Session::address, GNUNET_TRANSPORT_PluginEnvironment::cls, ServerRequest::connected, HTTP_Server_Plugin::cur_request, ServerRequest::direction, HTTP_Server_Plugin::env, GNUNET_TRANSPORT_PluginEnvironment::get_address_type, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_SS_HANDSHAKE, GNUNET_TRANSPORT_SS_INIT, GNUNET_TRANSPORT_SS_UP, GNUNET_YES, http_common_address_from_socket(), http_common_address_get_size(), http_common_plugin_address_to_string(), HTTP_SERVER_SESSION_TIMEOUT, GNUNET_ATS_Session::known_to_service, LOG, HTTP_Server_Plugin::max_request, ServerRequest::mhd_conn, ServerRequest::mhd_daemon, GNUNET_ATS_Session::next_receive, notify_session_monitor(), ServerRequest::options, plugin, GNUNET_ATS_Session::plugin, PLUGIN_NAME, HTTP_Server_Plugin::protocol, GNUNET_ATS_SessionTagContext::res, sc, scope, GNUNET_ATS_Session::scope, server_mhd_connection_timeout(), server_parse_url(), GNUNET_ATS_Session::server_recv, GNUNET_ATS_Session::server_send, server_session_timeout(), HTTP_Server_Plugin::server_v4, HTTP_Server_Plugin::server_v6, ServerRequest::session, GNUNET_TRANSPORT_PluginEnvironment::session_start, session_tag_it(), HTTP_Server_Plugin::sessions, GNUNET_ATS_Session::tag, GNUNET_ATS_SessionTagContext::tag, GNUNET_ATS_Session::target, GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by server_access_cb().

1376 {
1377  struct GNUNET_ATS_Session *s = NULL;
1378  struct ServerRequest *sc = NULL;
1379  const union MHD_ConnectionInfo *conn_info;
1380  struct HttpAddress *addr;
1381  struct GNUNET_PeerIdentity target;
1382  size_t addr_len;
1383  struct GNUNET_ATS_SessionTagContext stc;
1384  uint32_t options;
1385  int direction = GNUNET_SYSERR;
1386  unsigned int to;
1388 
1389  conn_info = MHD_get_connection_info (mhd_connection,
1390  MHD_CONNECTION_INFO_CLIENT_ADDRESS);
1391  if ((conn_info->client_addr->sa_family != AF_INET) &&
1392  (conn_info->client_addr->sa_family != AF_INET6))
1393  return NULL;
1395  "New %s request from %s\n",
1396  method,
1397  url);
1398  stc.tag = 0;
1399  options = 0; /* make gcc happy */
1400  if (GNUNET_SYSERR ==
1401  server_parse_url (plugin, url, &target, &stc.tag, &options))
1402  {
1404  "Invalid url %s\n", url);
1405  return NULL;
1406  }
1407  if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
1408  direction = _RECEIVE;
1409  else if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
1410  direction = _SEND;
1411  else
1412  {
1414  "Invalid method %s for request from %s\n",
1415  method, url);
1416  return NULL;
1417  }
1418 
1419  plugin->cur_request++;
1421  "New %s request from %s with tag %u (%u of %u)\n",
1422  method,
1423  GNUNET_i2s (&target),
1424  stc.tag,
1425  plugin->cur_request, plugin->max_request);
1426  /* find existing session */
1427  stc.res = NULL;
1429  &target,
1430  &session_tag_it,
1431  &stc);
1432  if (NULL == (s = stc.res))
1433  {
1434  /* create new session */
1435  addr = NULL;
1436  switch (conn_info->client_addr->sa_family)
1437  {
1438  case (AF_INET):
1439  addr = http_common_address_from_socket (plugin->protocol,
1440  conn_info->client_addr,
1441  sizeof (struct sockaddr_in));
1442  addr_len = http_common_address_get_size (addr);
1443  scope = plugin->env->get_address_type (plugin->env->cls,
1444  conn_info->client_addr,
1445  sizeof (struct sockaddr_in));
1446  break;
1447  case (AF_INET6):
1448  addr = http_common_address_from_socket (plugin->protocol,
1449  conn_info->client_addr,
1450  sizeof (struct sockaddr_in6));
1451  addr_len = http_common_address_get_size (addr);
1452  scope = plugin->env->get_address_type (plugin->env->cls,
1453  conn_info->client_addr,
1454  sizeof (struct sockaddr_in6));
1455  break;
1456  default:
1457  /* external host name */
1458  return NULL;
1459  }
1460  s = GNUNET_new (struct GNUNET_ATS_Session);
1461  s->target = target;
1462  s->plugin = plugin;
1463  s->scope = scope;
1465  PLUGIN_NAME,
1466  addr,
1467  addr_len,
1470  s->tag = stc.tag;
1474  s);
1476  &s->target,
1477  s,
1479  notify_session_monitor (plugin,
1480  s,
1482  notify_session_monitor (plugin,
1483  s,
1486  "Creating new session %p for peer `%s' connecting from `%s'\n",
1487  s, GNUNET_i2s (&target),
1489  addr,
1490  addr_len));
1491  GNUNET_free_non_null (addr);
1492  }
1493 
1494  if ( (_RECEIVE == direction) &&
1495  (NULL != s->server_recv) )
1496  {
1498  "Duplicate PUT request from `%s' tag %u, dismissing new request\n",
1499  GNUNET_i2s (&target),
1500  stc.tag);
1501  return NULL;
1502  }
1503  if ((_SEND == direction) && (NULL != s->server_send))
1504  {
1506  "Duplicate GET request from `%s' tag %u, dismissing new request\n",
1507  GNUNET_i2s (&target),
1508  stc.tag);
1509  return NULL;
1510  }
1511  sc = GNUNET_new (struct ServerRequest);
1512  if (conn_info->client_addr->sa_family == AF_INET)
1513  sc->mhd_daemon = plugin->server_v4;
1514  if (conn_info->client_addr->sa_family == AF_INET6)
1515  sc->mhd_daemon = plugin->server_v6;
1516  sc->mhd_conn = mhd_connection;
1517  sc->direction = direction;
1518  sc->connected = GNUNET_NO;
1519  sc->session = s;
1520  sc->options = options;
1521  if (direction == _SEND)
1522  {
1523  s->server_send = sc;
1524  }
1525  if (direction == _RECEIVE)
1526  {
1527  s->server_recv = sc;
1528  }
1529 
1530  if ((GNUNET_NO == s->known_to_service) &&
1531  (NULL != s->server_send) &&
1532  (NULL != s->server_recv) )
1533  {
1535  notify_session_monitor (plugin,
1536  s,
1538  plugin->env->session_start (plugin->env->cls,
1539  s->address,
1540  s,
1541  s->scope);
1542  }
1543 
1544  to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL);
1545  server_mhd_connection_timeout (plugin, s, to);
1546  return sc;
1547 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct ServerRequest * server_recv
Client send handle.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
GNUNET_TRANSPORT_SessionStart session_start
Function called by the plugin when a new (incoming) session was created not explicitly created using ...
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
GNUNET_TRANSPORT_AddressToType get_address_type
Function that will be called to figure if an address is an loopback, LAN, WAN etc.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
unsigned int max_request
Maximum number of sockets the plugin can use Each http request /request connections are two connectio...
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Hash map of open sessions.
Initial session handshake is in progress.
static void server_session_timeout(void *cls)
Session was idle, so disconnect it.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define GNUNET_NO
Definition: gnunet_common.h:81
unsigned int cur_request
Current number of sockets the plugin can use Each http connection are two requests.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HELLO_Address * address
Address.
static void notify_session_monitor(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
int direction
_RECV or _SEND
struct MHD_Daemon * mhd_daemon
The MHD daemon.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
static int session_tag_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find a session with a matching tag.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
size_t http_common_address_get_size(const struct HttpAddress *addr)
Get the length of an address.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
void * cls
Closure for the various callbacks.
Information about ongoing sessions of the transport client.
This is an inbound address and cannot be used to initiate an outbound connection to another peer...
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
static int server_parse_url(struct HTTP_Server_Plugin *plugin, const char *url, struct GNUNET_PeerIdentity *target, uint32_t *tag, uint32_t *options)
Parse incoming URL for tag and target.
#define _RECEIVE
static enum GNUNET_NetworkType scope
Which network scope do we belong to?
void * addr
Address following.
static void server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *s, unsigned int to)
Tell MHD that the connection should timeout after to seconds.
int known_to_service
GNUNET_YES if this session is known to the service.
Closure for session_tag_it().
struct MHD_Connection * mhd_conn
The MHD connection.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
enum GNUNET_NetworkType scope
ATS network type.
uint32_t tag
Unique HTTP/S connection tag for this connection.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Allow multiple values with the same key.
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
The identity of the host (wraps the signing key of the peer).
Information we keep with MHD for an HTTP request.
#define HTTP_SERVER_SESSION_TIMEOUT
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
int connected
For PUT requests: Is this the first or last callback with size 0 For GET requests: Have we sent a mes...
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct HttpAddress * http_common_address_from_socket(const char *protocol, const struct sockaddr *addr, socklen_t addrlen)
Create a HTTP address from a socketaddr.
The session was created (first call for each session object).
uint32_t options
Options requested by peer.
struct ServerRequest * server_send
Client send handle.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define PLUGIN_NAME
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
HTTP addresses including a full URI.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
struct MHD_Daemon * server_v6
MHD IPv4 daemon.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_send_callback()

static ssize_t server_send_callback ( void *  cls,
uint64_t  pos,
char *  buf,
size_t  max 
)
static

Callback called by MHD when it needs data to send.

Parameters
clscurrent session
posposition in buffer
bufthe buffer to write data to
maxmax number of bytes available in buf
Returns
bytes written to buf

Definition at line 1560 of file plugin_transport_http_server.c.

References HTTP_Message::buf, GNUNET_ATS_Session::bytes_in_queue, ServerRequest::connected, Plugin::env, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, LOG, ServerRequest::mhd_conn, msg, GNUNET_ATS_Session::msg_head, GNUNET_ATS_Session::msg_tail, GNUNET_ATS_Session::msgs_in_queue, notify_session_monitor(), OPTION_LONG_POLL, ServerRequest::options, HTTP_Message::overhead, GNUNET_ATS_Session::plugin, HTTP_Message::pos, Plugin::protocol, sc, GNUNET_ATS_Session::server_send, ServerRequest::session, HTTP_Message::size, ServerRequest::suspended, GNUNET_ATS_Session::target, HTTP_Message::transmit_cont, and HTTP_Message::transmit_cont_cls.

Referenced by server_access_cb().

1564 {
1565  struct ServerRequest *sc = cls;
1566  struct GNUNET_ATS_Session *s = sc->session;
1567  ssize_t bytes_read = 0;
1568  struct HTTP_Message *msg;
1569  char *stat_txt;
1570 
1571  if (NULL == s)
1572  {
1573  /* session is disconnecting */
1574  return 0;
1575  }
1576 
1577  sc = s->server_send;
1578  if (NULL == sc)
1579  return 0;
1580  msg = s->msg_head;
1581  if (NULL != msg)
1582  {
1583  /* sending */
1584  bytes_read = GNUNET_MIN (msg->size - msg->pos,
1585  max);
1586  GNUNET_memcpy (buf, &msg->buf[msg->pos], bytes_read);
1587  msg->pos += bytes_read;
1588 
1589  /* removing message */
1590  if (msg->pos == msg->size)
1591  {
1593  s->msg_tail,
1594  msg);
1595  if (NULL != msg->transmit_cont)
1597  msg->size, msg->size + msg->overhead);
1598  GNUNET_assert (s->msgs_in_queue > 0);
1599  s->msgs_in_queue--;
1600  GNUNET_assert (s->bytes_in_queue >= msg->size);
1601  s->bytes_in_queue -= msg->size;
1602  GNUNET_free (msg);
1604  s,
1606  }
1607  }
1608  if (0 < bytes_read)
1609  {
1610  sc->connected = GNUNET_YES;
1612  "Sent %u bytes to peer `%s' with session %p \n",
1613  bytes_read,
1614  GNUNET_i2s (&s->target),
1615  s);
1616  GNUNET_asprintf (&stat_txt,
1617  "# bytes currently in %s_server buffers",
1618  s->plugin->protocol);
1619  GNUNET_STATISTICS_update (s->plugin->env->stats,
1620  stat_txt,
1621  - bytes_read,
1622  GNUNET_NO);
1623  GNUNET_free (stat_txt);
1624  GNUNET_asprintf (&stat_txt,
1625  "# bytes transmitted via %s_server",
1626  s->plugin->protocol);
1627  GNUNET_STATISTICS_update (s->plugin->env->stats,
1628  stat_txt, bytes_read, GNUNET_NO);
1629  GNUNET_free (stat_txt);
1630  }
1631  else if ((sc->options & OPTION_LONG_POLL) && sc->connected)
1632  {
1634  "Completing GET response to peer `%s' with session %p\n",
1635  GNUNET_i2s (&s->target),
1636  s);
1637  return MHD_CONTENT_READER_END_OF_STREAM;
1638  }
1639  else
1640  {
1641  MHD_suspend_connection (s->server_send->mhd_conn);
1642  s->server_send->suspended = true;
1643  return 0;
1644  }
1645  return bytes_read;
1646 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
char * buf
buffer containing data to send
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct Plugin * plugin
Pointer to the global plugin struct.
size_t pos
amount of data already sent
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
char * protocol
Plugin protocol http, https.
Message to send using http.
bool suspended
Currently suspended.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void notify_session_monitor(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
struct HTTP_Message * msg_head
next pointer for double linked list
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
void * transmit_cont_cls
Closure for transmit_cont.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_memcpy(dst, src, n)
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
static char buf[2048]
size_t overhead
HTTP/S specific overhead.
struct MHD_Connection * mhd_conn
The MHD connection.
size_t size
buffer length
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
This is just an update about the session, the state did not change.
Information we keep with MHD for an HTTP request.
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
int connected
For PUT requests: Is this the first or last callback with size 0 For GET requests: Have we sent a mes...
struct GNUNET_PeerIdentity target
To whom are we talking to.
uint32_t options
Options requested by peer.
struct ServerRequest * server_send
Client send handle.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
#define OPTION_LONG_POLL
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_receive_mst_cb()

static int server_receive_mst_cb ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Callback called by MessageStreamTokenizer when a message has arrived.

Parameters
clscurrent session as closure
messagethe message to be forwarded to transport service
Returns
GNUNET_OK (all OK)

Definition at line 1657 of file plugin_transport_http_server.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, GNUNET_TRANSPORT_PluginEnvironment::cls, HTTP_Server_Plugin::env, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_SS_UP, GNUNET_YES, http_common_plugin_address_to_string(), GNUNET_ATS_Session::known_to_service, LOG, GNUNET_ATS_Session::next_receive, notify_session_monitor(), GNUNET_ATS_Session::plugin, HTTP_Server_Plugin::protocol, GNUNET_TRANSPORT_PluginEnvironment::receive, GNUNET_TIME_Relative::rel_value_us, GNUNET_ATS_Session::scope, server_reschedule_session_timeout(), GNUNET_TRANSPORT_PluginEnvironment::session_start, GNUNET_MessageHeader::size, GNUNET_TRANSPORT_PluginEnvironment::stats, and GNUNET_ATS_Session::target.

Referenced by server_access_cb().

1659 {
1660  struct GNUNET_ATS_Session *s = cls;
1661  struct HTTP_Server_Plugin *plugin = s->plugin;
1662  struct GNUNET_TIME_Relative delay;
1663  char *stat_txt;
1664 
1665  if (GNUNET_NO == s->known_to_service)
1666  {
1668  plugin->env->session_start (plugin->env->cls,
1669  s->address,
1670  s,
1671  s->scope);
1672  notify_session_monitor (plugin,
1673  s,
1675  }
1676  delay = plugin->env->receive (plugin->env->cls,
1677  s->address,
1678  s,
1679  message);
1680  GNUNET_asprintf (&stat_txt,
1681  "# bytes received via %s_server",
1682  plugin->protocol);
1684  stat_txt,
1685  ntohs (message->size),
1686  GNUNET_NO);
1687  GNUNET_free (stat_txt);
1689  if (delay.rel_value_us > 0)
1690  {
1692  "Peer `%s' address `%s' next read delayed for %s\n",
1693  GNUNET_i2s (&s->target),
1695  s->address->address,
1696  s->address->address_length),
1698  GNUNET_YES));
1699  }
1701  return GNUNET_OK;
1702 }
size_t address_length
Number of bytes in address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
uint64_t rel_value_us
The actual value.
const void * address
Binary representation of the address (plugin-specific).
GNUNET_TRANSPORT_SessionStart session_start
Function called by the plugin when a new (incoming) session was created not explicitly created using ...
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static void notify_session_monitor(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
GNUNET_TRANSPORT_PluginReceiveCallback receive
Function that should be called by the transport plugin whenever a message is received.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void * cls
Closure for the various callbacks.
Information about ongoing sessions of the transport client.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
int known_to_service
GNUNET_YES if this session is known to the service.
enum GNUNET_NetworkType scope
ATS network type.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
Encapsulation of all of the state of the plugin.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void server_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity session s.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_cors_headers()

static void add_cors_headers ( struct MHD_Response *  response)
static

Add headers to a request indicating that we allow Cross-Origin Resource Sharing.

Parameters
responseresponse object to modify

Definition at line 1712 of file plugin_transport_http_server.c.

Referenced by server_access_cb().

1713 {
1714  MHD_add_response_header (response,
1715  "Access-Control-Allow-Origin",
1716  "*");
1717  MHD_add_response_header (response,
1718  "Access-Control-Allow-Methods",
1719  "GET, PUT, OPTIONS");
1720  MHD_add_response_header (response,
1721  "Access-Control-Max-Age",
1722  "86400");
1723 }
static struct MHD_Response * response
Our canonical response.
Here is the caller graph for this function:

◆ server_access_cb()

static int server_access_cb ( void *  cls,
struct MHD_Connection *  mhd_connection,
const char *  url,
const char *  method,
const char *  version,
const char *  upload_data,
size_t *  upload_data_size,
void **  httpSessionCache 
)
static

MHD callback for a new incoming connection.

Parameters
clsthe plugin handle
mhd_connectionthe mhd connection
urlthe requested URL
methodGET or PUT
versionHTTP version
upload_dataupload data
upload_data_sizesize of upload_data
httpSessionCachethe session cache to remember the connection
Returns
MHD_YES if connection is accepted, MHD_NO on reject

Definition at line 1740 of file plugin_transport_http_server.c.

References _, _RECEIVE, _SEND, add_cors_headers(), GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, ServerRequest::connected, HTTP_Server_Plugin::cur_request, ServerRequest::direction, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MST_create(), GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, http_common_plugin_address_to_string(), HTTP_ERROR_RESPONSE, LOG, HTTP_Server_Plugin::max_request, ServerRequest::mhd_conn, GNUNET_ATS_Session::msg_tk, GNUNET_ATS_Session::next_receive, HTTP_Server_Plugin::protocol, GNUNET_ATS_Session::recv_wakeup_task, GNUNET_TIME_Relative::rel_value_us, res, response, sc, server_lookup_connection(), server_mhd_connection_timeout(), server_receive_mst_cb(), GNUNET_ATS_Session::server_recv, server_send_callback(), server_wake_up(), ServerRequest::session, ServerRequest::suspended, and GNUNET_ATS_Session::target.

Referenced by run_mhd_start_daemon().

1748 {
1749  struct HTTP_Server_Plugin *plugin = cls;
1750  struct ServerRequest *sc = *httpSessionCache;
1751  struct GNUNET_ATS_Session *s;
1752  struct MHD_Response *response;
1753  int res = MHD_YES;
1754 
1756  _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"),
1757  sc,
1758  plugin->cur_request,
1759  plugin->max_request,
1760  method,
1761  version,
1762  url,
1763  (*upload_data_size));
1764  if (NULL == sc)
1765  {
1766  /* CORS pre-flight request */
1767  if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
1768  {
1769  response = MHD_create_response_from_buffer (0, NULL,
1770  MHD_RESPMEM_PERSISTENT);
1771  add_cors_headers(response);
1772  res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1773  MHD_destroy_response (response);
1774  return res;
1775  }
1776  /* new connection */
1777  sc = server_lookup_connection (plugin, mhd_connection, url, method);
1778  if (NULL != sc)
1779  {
1780  /* attach to new / existing session */
1781  (*httpSessionCache) = sc;
1782  }
1783  else
1784  {
1785  /* existing session already has matching connection, refuse */
1786  response = MHD_create_response_from_buffer (strlen (HTTP_ERROR_RESPONSE),
1788  MHD_RESPMEM_PERSISTENT);
1789  MHD_add_response_header (response,
1790  MHD_HTTP_HEADER_CONTENT_TYPE,
1791  "text/html");
1792  add_cors_headers(response);
1793  res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
1794  MHD_destroy_response (response);
1795  return res;
1796  }
1797  }
1798  /* 'old' connection */
1799  if (NULL == (s = sc->session))
1800  {
1801  /* Session was already disconnected;
1802  sent HTTP/1.1: 200 OK as response */
1803  response = MHD_create_response_from_buffer (strlen ("Thank you!"),
1804  "Thank you!",
1805  MHD_RESPMEM_PERSISTENT);
1806  add_cors_headers(response);
1807  MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1808  MHD_destroy_response (response);
1809  return MHD_YES;
1810  }
1811 
1812  if (sc->direction == _SEND)
1813  {
1814  response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 32 * 1024,
1815  &server_send_callback, sc, NULL);
1816  add_cors_headers(response);
1817  MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1818  MHD_destroy_response (response);
1819  return MHD_YES;
1820  }
1821  if (sc->direction == _RECEIVE)
1822  {
1823  if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO))
1824  {
1825  /* (*upload_data_size == 0) first callback when header are passed */
1827  "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n",
1828  s, sc,
1829  GNUNET_i2s (&s->target),
1831  s->address->address,
1832  s->address->address_length));
1833  sc->connected = GNUNET_YES;
1834  return MHD_YES;
1835  }
1836  else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES))
1837  {
1838  /* (*upload_data_size == 0) when upload is complete */
1840  "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n",
1841  s, sc,
1842  GNUNET_i2s (&s->target),
1844  s->address->address,
1845  s->address->address_length));
1846  sc->connected = GNUNET_NO;
1847  /* Sent HTTP/1.1: 200 OK as PUT Response\ */
1848  response = MHD_create_response_from_buffer (strlen ("Thank you!"),
1849  "Thank you!",
1850  MHD_RESPMEM_PERSISTENT);
1851  add_cors_headers(response);
1852  MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1853  MHD_destroy_response (response);
1854  return MHD_YES;
1855  }
1856  else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES))
1857  {
1858  struct GNUNET_TIME_Relative delay;
1859 
1860  /* (*upload_data_size > 0) for every segment received */
1862  "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n",
1863  s, sc,
1864  GNUNET_i2s (&s->target),
1866  s->address->address,
1867  s->address->address_length),
1868  *upload_data_size);
1870  if (0 == delay.rel_value_us)
1871  {
1873  "PUT with %u bytes forwarded to MST\n",
1874  *upload_data_size);
1875  if (s->msg_tk == NULL)
1876  {
1878  s);
1879  }
1881  upload_data,
1882  *upload_data_size,
1883  GNUNET_NO, GNUNET_NO);
1884  server_mhd_connection_timeout (plugin, s,
1885  GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL
1886  / 1000LL);
1887  (*upload_data_size) = 0;
1888  }
1889  else
1890  {
1891  /* delay processing */
1893  "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n",
1894  s,
1895  sc,
1897  GNUNET_YES));
1898  GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
1899  MHD_suspend_connection (s->server_recv->mhd_conn);
1900  s->server_recv->suspended = true;
1901  if (NULL == s->recv_wakeup_task)
1902  s->recv_wakeup_task
1904  &server_wake_up,
1905  s);
1906  }
1907  return MHD_YES;
1908  }
1909  else
1910  {
1911  GNUNET_break (0);
1912  return MHD_NO;
1913  }
1914  }
1915  return res;
1916 }
static int server_receive_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Callback called by MessageStreamTokenizer when a message has arrived.
size_t address_length
Number of bytes in address.
struct ServerRequest * server_recv
Client send handle.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
uint64_t rel_value_us
The actual value.
const void * address
Binary representation of the address (plugin-specific).
static void server_wake_up(void *cls)
Wake up an MHD connection which was suspended.
unsigned int max_request
Maximum number of sockets the plugin can use Each http request /request connections are two connectio...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
bool suspended
Currently suspended.
#define GNUNET_NO
Definition: gnunet_common.h:81
unsigned int cur_request
Current number of sockets the plugin can use Each http connection are two requests.
struct GNUNET_HELLO_Address * address
Address.
int direction
_RECV or _SEND
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
Information about ongoing sessions of the transport client.
#define _RECEIVE
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:87
static struct ServerRequest * server_lookup_connection(struct HTTP_Server_Plugin *plugin, struct MHD_Connection *mhd_connection, const char *url, const char *method)
Lookup a mhd connection and create one if none is found.
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:116
static void server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin, struct GNUNET_ATS_Session *s, unsigned int to)
Tell MHD that the connection should timeout after to seconds.
static int res
struct MHD_Connection * mhd_conn
The MHD connection.
static void add_cors_headers(struct MHD_Response *response)
Add headers to a request indicating that we allow Cross-Origin Resource Sharing.
#define HTTP_ERROR_RESPONSE
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
Information we keep with MHD for an HTTP request.
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
int connected
For PUT requests: Is this the first or last callback with size 0 For GET requests: Have we sent a mes...
Encapsulation of all of the state of the plugin.
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_log(kind,...)
static struct MHD_Response * response
Our canonical response.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
static ssize_t server_send_callback(void *cls, uint64_t pos, char *buf, size_t max)
Callback called by MHD when it needs data to send.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_disconnect_cb()

static void server_disconnect_cb ( void *  cls,
struct MHD_Connection *  connection,
void **  httpSessionCache 
)
static

Callback from MHD when a connection disconnects.

Parameters
clsclosure with the struct HTTP_Server_Plugin *
connectionthe disconnected MHD connection
httpSessionCachethe pointer to distinguish

Definition at line 1927 of file plugin_transport_http_server.c.

References _RECEIVE, _SEND, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, HTTP_Server_Plugin::cur_request, ServerRequest::direction, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_MST_destroy(), http_common_plugin_address_to_string(), LOG, GNUNET_ATS_Session::msg_tk, HTTP_Server_Plugin::protocol, sc, GNUNET_ATS_Session::server_recv, GNUNET_ATS_Session::server_send, ServerRequest::session, and GNUNET_ATS_Session::target.

Referenced by run_mhd_start_daemon().

1930 {
1931  struct HTTP_Server_Plugin *plugin = cls;
1932  struct ServerRequest *sc = *httpSessionCache;
1933 
1935  "Disconnect for connection %p\n",
1936  sc);
1937  if (NULL == sc)
1938  {
1939  /* CORS pre-flight request finished */
1940  return;
1941  }
1942 
1943  if (NULL != sc->session)
1944  {
1945  if (sc->direction == _SEND)
1946  {
1948  "Peer `%s' connection %p, GET on address `%s' disconnected\n",
1949  GNUNET_i2s (&sc->session->target),
1950  sc->session->server_send,
1952  sc->session->address->address,
1953  sc->session->address->address_length));
1954 
1955  sc->session->server_send = NULL;
1956  }
1957  else if (sc->direction == _RECEIVE)
1958  {
1960  "Peer `%s' connection %p PUT on address `%s' disconnected\n",
1961  GNUNET_i2s (&sc->session->target),
1962  sc->session->server_recv,
1964  sc->session->address->address,
1965  sc->session->address->address_length));
1966  sc->session->server_recv = NULL;
1967  if (NULL != sc->session->msg_tk)
1968  {
1970  sc->session->msg_tk = NULL;
1971  }
1972  }
1973  }
1974  GNUNET_free (sc);
1975  plugin->cur_request--;
1976 }
size_t address_length
Number of bytes in address.
struct ServerRequest * server_recv
Client send handle.
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
unsigned int cur_request
Current number of sockets the plugin can use Each http connection are two requests.
struct GNUNET_HELLO_Address * address
Address.
int direction
_RECV or _SEND
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
#define _RECEIVE
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
Information we keep with MHD for an HTTP request.
struct GNUNET_ATS_Session * session
The session this server connection belongs to.
Encapsulation of all of the state of the plugin.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct ServerRequest * server_send
Client send handle.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_connection_cb()

static void server_connection_cb ( void *  cls,
struct MHD_Connection *  connection,
void **  socket_context,
enum MHD_ConnectionNotificationCode  toe 
)
static

Callback from MHD when a connection starts/stops.

Parameters
clsclosure with the struct HTTP_Server_Plugin *
connectionconnection handle
socket_contextsocket-specific pointer
toereason for connection notification
See also
#MHD_OPTION_NOTIFY_CONNECTION

Definition at line 1989 of file plugin_transport_http_server.c.

References GNUNET_assert, GNUNET_YES, and server_reschedule().

Referenced by run_mhd_start_daemon().

1993 {
1994  struct HTTP_Server_Plugin *plugin = cls;
1995  const union MHD_ConnectionInfo *info;
1996 
1997  if (MHD_CONNECTION_NOTIFY_STARTED == toe)
1998  return;
1999 
2000  /* Reschedule to remove closed socket from our select set */
2001  info = MHD_get_connection_info (connection,
2002  MHD_CONNECTION_INFO_DAEMON);
2003  GNUNET_assert (NULL != info);
2004  server_reschedule (plugin,
2005  info->daemon,
2006  GNUNET_YES);
2007 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Encapsulation of all of the state of the plugin.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_accept_cb()

static int server_accept_cb ( void *  cls,
const struct sockaddr *  addr,
socklen_t  addr_len 
)
static

Check if incoming connection is accepted.

Parameters
clsplugin as closure
addraddress of incoming connection
addr_lennumber of bytes in addr
Returns
MHD_YES if connection is accepted, MHD_NO if connection is rejected

Definition at line 2019 of file plugin_transport_http_server.c.

References _, HTTP_Server_Plugin::cur_request, GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, LOG, and HTTP_Server_Plugin::max_request.

Referenced by run_mhd_start_daemon().

2022 {
2023  struct HTTP_Server_Plugin *plugin = cls;
2024 
2025  if (plugin->cur_request <= plugin->max_request)
2026  {
2028  _("Accepting connection (%u of %u) from `%s'\n"),
2029  plugin->cur_request, plugin->max_request,
2030  GNUNET_a2s (addr, addr_len));
2031  return MHD_YES;
2032  }
2033  else
2034  {
2036  _("Server reached maximum number connections (%u), rejecting new connection\n"),
2037  plugin->max_request);
2038  return MHD_NO;
2039  }
2040 }
unsigned int max_request
Maximum number of sockets the plugin can use Each http request /request connections are two connectio...
unsigned int cur_request
Current number of sockets the plugin can use Each http connection are two requests.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
Encapsulation of all of the state of the plugin.
#define LOG(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_log()

static void server_log ( void *  arg,
const char *  fmt,
va_list  ap 
)
static

Log function called by MHD.

Parameters
argNULL
fmtformat string
aparguments for the format string (va_start() and va_end() will be called by MHD)

Definition at line 2052 of file plugin_transport_http_server.c.

References _, GNUNET_TRANSPORT_PluginEnvironment::cfg, HTTP_Server_Plugin::env, GNUNET_assert, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_log_config_missing(), GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_OS_process_destroy(), GNUNET_OS_process_wait(), GNUNET_OS_start_process(), GNUNET_SYSERR, GNUNET_YES, LOG, HTTP_Server_Plugin::name, and res.

Referenced by run_mhd_start_daemon().

2055 {
2056  char text[1024];
2057 
2058  vsnprintf (text,
2059  sizeof (text),
2060  fmt,
2061  ap);
2063  "Server: %s\n",
2064  text);
2065 }
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_mhd_start_daemon()

static struct MHD_Daemon* run_mhd_start_daemon ( struct HTTP_Server_Plugin plugin,
const struct sockaddr_in *  addr,
int  v6 
)
static

Invoke MHD_start_daemon with the various options we need to setup the HTTP server with the given listen address.

Parameters
pluginour plugin
addrlisten address to use
v6MHD_NO_FLAG or MHD_USE_IPv6, depending on context
Returns
NULL on error

Definition at line 2242 of file plugin_transport_http_server.c.

References _, HTTP_Server_Plugin::env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, HTTP_OPTIONS_TCP_STEALTH, HTTP_SERVER_NOT_VALIDATED_TIMEOUT, HTTP_SERVER_SESSION_TIMEOUT, LOG, HTTP_Server_Plugin::max_request, GNUNET_TRANSPORT_PluginEnvironment::my_identity, HTTP_Server_Plugin::options, HTTP_Server_Plugin::port, server_accept_cb(), server_access_cb(), server_connection_cb(), server_disconnect_cb(), server_log(), timeout, and VERBOSE_SERVER.

Referenced by server_start().

2245 {
2246  struct MHD_Daemon *server;
2247  unsigned int timeout;
2248 
2249 #if MHD_VERSION >= 0x00090E00
2250  timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL;
2252  "MHD can set timeout per connection! Default time out %u sec.\n",
2253  timeout);
2254 #else
2255  timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL;
2257  "MHD cannot set timeout per connection! Default time out %u sec.\n",
2258  timeout);
2259 #endif
2260  server = MHD_start_daemon (
2261 #if VERBOSE_SERVER
2262  MHD_USE_DEBUG |
2263 #endif
2264 #if BUILD_HTTPS
2265  MHD_USE_SSL |
2266 #endif
2267  MHD_USE_SUSPEND_RESUME |
2268  v6,
2269  plugin->port,
2270  &server_accept_cb, plugin,
2271  &server_access_cb, plugin,
2272  MHD_OPTION_SOCK_ADDR,
2273  addr,
2274  MHD_OPTION_CONNECTION_LIMIT,
2275  (unsigned int) plugin->max_request,
2276 #if BUILD_HTTPS
2277  MHD_OPTION_HTTPS_PRIORITIES,
2278  plugin->crypto_init,
2279  MHD_OPTION_HTTPS_MEM_KEY,
2280  plugin->key,
2281  MHD_OPTION_HTTPS_MEM_CERT,
2282  plugin->cert,
2283 #endif
2284  MHD_OPTION_CONNECTION_TIMEOUT,
2285  timeout,
2286  MHD_OPTION_CONNECTION_MEMORY_LIMIT,
2287  (size_t) (2 *
2289  MHD_OPTION_NOTIFY_COMPLETED,
2290  &server_disconnect_cb, plugin,
2291  MHD_OPTION_NOTIFY_CONNECTION,
2292  &server_connection_cb, plugin,
2293  MHD_OPTION_EXTERNAL_LOGGER,
2294  &server_log, NULL,
2295  MHD_OPTION_END);
2296 #ifdef TCP_STEALTH
2297  if ( (NULL != server) &&
2298  (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH)) )
2299  {
2300  const union MHD_DaemonInfo *di;
2301 
2302  di = MHD_get_daemon_info (server,
2303  MHD_DAEMON_INFO_LISTEN_FD,
2304  NULL);
2305  if ( (0 != setsockopt ((int) di->listen_fd,
2306  IPPROTO_TCP,
2307  TCP_STEALTH,
2308  plugin->env->my_identity,
2309  sizeof (struct GNUNET_PeerIdentity))) )
2310  {
2312  _("TCP_STEALTH not supported on this platform.\n"));
2313  MHD_stop_daemon (server);
2314  server = NULL;
2315  }
2316  }
2317 #endif
2318  return server;
2319 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
unsigned int max_request
Maximum number of sockets the plugin can use Each http request /request connections are two connectio...
uint32_t options
My options to be included in the address.
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
static void server_log(void *arg, const char *fmt, va_list ap)
Log function called by MHD.
#define VERBOSE_SERVER
static int server_access_cb(void *cls, struct MHD_Connection *mhd_connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **httpSessionCache)
MHD callback for a new incoming connection.
Enable TCP Stealth-style port knocking.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
The identity of the host (wraps the signing key of the peer).
#define HTTP_SERVER_SESSION_TIMEOUT
static void server_connection_cb(void *cls, struct MHD_Connection *connection, void **socket_context, enum MHD_ConnectionNotificationCode toe)
Callback from MHD when a connection starts/stops.
static void server_disconnect_cb(void *cls, struct MHD_Connection *connection, void **httpSessionCache)
Callback from MHD when a connection disconnects.
#define GNUNET_log(kind,...)
static int server_accept_cb(void *cls, const struct sockaddr *addr, socklen_t addr_len)
Check if incoming connection is accepted.
#define LOG(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_start()

static int server_start ( struct HTTP_Server_Plugin plugin)
static

Start the HTTP server.

Parameters
pluginthe plugin handle
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 2329 of file plugin_transport_http_server.c.

References _, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, LOG, msg, HTTP_Server_Plugin::name, HTTP_Server_Plugin::port, run_mhd_start_daemon(), HTTP_Server_Plugin::server_addr_v4, HTTP_Server_Plugin::server_addr_v6, server_reschedule(), HTTP_Server_Plugin::server_v4, HTTP_Server_Plugin::server_v6, HTTP_Server_Plugin::use_ipv4, and HTTP_Server_Plugin::use_ipv6.

Referenced by libgnunet_plugin_transport_http_server_init().

2330 {
2331  const char *msg;
2332 
2333  GNUNET_assert (NULL != plugin);
2334 #if BUILD_HTTPS
2335  if (GNUNET_SYSERR == server_load_certificate (plugin))
2336  {
2338  _("Could not load or create server certificate! Loading plugin failed!\n"));
2339  return GNUNET_SYSERR;
2340  }
2341 #endif
2342 
2343 
2344 
2345  plugin->server_v4 = NULL;
2346  if (GNUNET_YES == plugin->use_ipv4)
2347  {
2348  plugin->server_v4
2349  = run_mhd_start_daemon (plugin,
2350  (const struct sockaddr_in *) plugin->server_addr_v4,
2351  MHD_NO_FLAG);
2352 
2353  if (NULL == plugin->server_v4)
2354  {
2356  "Failed to start %s IPv4 server component on port %u\n",
2357  plugin->name,
2358  plugin->port);
2359  }
2360  else
2361  server_reschedule (plugin,
2362  plugin->server_v4,
2363  GNUNET_NO);
2364  }
2365 
2366 
2367  plugin->server_v6 = NULL;
2368  if (GNUNET_YES == plugin->use_ipv6)
2369  {
2370  plugin->server_v6
2371  = run_mhd_start_daemon (plugin,
2372  (const struct sockaddr_in *) plugin->server_addr_v6,
2373  MHD_USE_IPv6);
2374  if (NULL == plugin->server_v6)
2375  {
2377  "Failed to start %s IPv6 server component on port %u\n",
2378  plugin->name,
2379  plugin->port);
2380  }
2381  else
2382  {
2383  server_reschedule (plugin,
2384  plugin->server_v6,
2385  GNUNET_NO);
2386  }
2387  }
2388  msg = "No";
2389  if ( (NULL == plugin->server_v6) &&
2390  (NULL == plugin->server_v4) )
2391  {
2393  "%s %s server component started on port %u\n",
2394  msg,
2395  plugin->name,
2396  plugin->port);
2397  return GNUNET_SYSERR;
2398  }
2399  if ((NULL != plugin->server_v6) &&
2400  (NULL != plugin->server_v4))
2401  msg = "IPv4 and IPv6";
2402  else if (NULL != plugin->server_v6)
2403  msg = "IPv6";
2404  else if (NULL != plugin->server_v4)
2405  msg = "IPv4";
2407  "%s %s server component started on port %u\n",
2408  msg,
2409  plugin->name,
2410  plugin->port);
2411  return GNUNET_OK;
2412 }
struct sockaddr_in6 * server_addr_v6
IPv6 server socket to bind to.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct MHD_Daemon * run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin, const struct sockaddr_in *addr, int v6)
Invoke MHD_start_daemon with the various options we need to setup the HTTP server with the given list...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct MHD_Daemon * server_v4
MHD IPv4 daemon.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct sockaddr_in * server_addr_v4
IPv4 server socket to bind to.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
static void server_reschedule(struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, int now)
Reschedule the execution of both IPv4 and IPv6 server.
struct MHD_Daemon * server_v6
MHD IPv4 daemon.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_add_address()

static void server_add_address ( void *  cls,
int  add_remove,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Add an address to the server's set of addresses and notify transport.

Parameters
clsthe plugin handle
add_removeGNUNET_YES on add, GNUNET_NO on remove
addrthe address
addrlenaddress length

Definition at line 2424 of file plugin_transport_http_server.c.

References HTTP_Server_Plugin::addr_head, HTTP_Server_Plugin::addr_tail, HttpAddressWrapper::address, address, HttpAddressWrapper::addrlen, GNUNET_TRANSPORT_PluginEnvironment::cls, HTTP_Server_Plugin::env, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_new, http_common_address_from_socket(), http_common_address_get_size(), http_common_plugin_address_to_string(), LOG, GNUNET_TRANSPORT_PluginEnvironment::my_identity, GNUNET_TRANSPORT_PluginEnvironment::notify_address, and HTTP_Server_Plugin::protocol.

Referenced by server_nat_port_map_callback().

2428 {
2429  struct HTTP_Server_Plugin *plugin = cls;
2430  struct GNUNET_HELLO_Address *address;
2431  struct HttpAddressWrapper *w = NULL;
2432 
2433  w = GNUNET_new (struct HttpAddressWrapper);
2435  addr,
2436  addrlen);
2437  if (NULL == w->address)
2438  {
2439  GNUNET_free (w);
2440  return;
2441  }
2443 
2445  plugin->addr_tail,
2446  w);
2448  "Notifying transport to add address `%s'\n",
2450  w->address,
2451  w->addrlen));
2452  /* modify our published address list */
2453 #if BUILD_HTTPS
2454  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2455  "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2456 #else
2457  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2458  "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2459 #endif
2460 
2461  plugin->env->notify_address (plugin->env->cls,
2462  add_remove,
2463  address);
2464  GNUNET_HELLO_address_free (address);
2465 }
Wrapper to manage addresses.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
size_t http_common_address_get_size(const struct HttpAddress *addr)
Get the length of an address.
void * cls
Closure for the various callbacks.
struct HttpAddress * address
An address we are using.
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
No additional information.
Encapsulation of all of the state of the plugin.
An address for communicating with a peer.
struct HttpAddress * http_common_address_from_socket(const char *protocol, const struct sockaddr *addr, socklen_t addrlen)
Create a HTTP address from a socketaddr.
struct HttpAddressWrapper * addr_tail
IPv4 addresses DLL tail.
GNUNET_TRANSPORT_AddressNotification notify_address
Function that must be called by each plugin to notify the transport service about the addresses under...
struct HttpAddressWrapper * addr_head
IPv4 addresses DLL head.
#define LOG(kind,...)
static char * address
GNS address for this phone.
#define GNUNET_HELLO_address_free(addr)
Free an address.
size_t addrlen
Length of the address.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_remove_address()

static void server_remove_address ( void *  cls,
int  add_remove,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Remove an address from the server's set of addresses and notify transport.

Parameters
clsthe plugin handle
add_removeGNUNET_YES on add, GNUNET_NO on remove
addrthe address
addrlenaddress length

Definition at line 2477 of file plugin_transport_http_server.c.

References HTTP_Server_Plugin::addr_head, HTTP_Server_Plugin::addr_tail, HttpAddressWrapper::address, address, HttpAddressWrapper::addrlen, GNUNET_TRANSPORT_PluginEnvironment::cls, HTTP_Server_Plugin::env, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_YES, http_common_address_from_socket(), http_common_address_get_size(), http_common_cmp_addresses(), http_common_plugin_address_to_string(), LOG, GNUNET_TRANSPORT_PluginEnvironment::my_identity, HttpAddressWrapper::next, GNUNET_TRANSPORT_PluginEnvironment::notify_address, and HTTP_Server_Plugin::protocol.

Referenced by server_nat_port_map_callback().

2481 {
2482  struct HTTP_Server_Plugin *plugin = cls;
2483  struct GNUNET_HELLO_Address *address;
2484  struct HttpAddressWrapper *w = plugin->addr_head;
2485  size_t saddr_len;
2486  void * saddr;
2487 
2488  saddr = http_common_address_from_socket (plugin->protocol,
2489  addr,
2490  addrlen);
2491  if (NULL == saddr)
2492  return;
2493  saddr_len = http_common_address_get_size (saddr);
2494 
2495  while (NULL != w)
2496  {
2497  if (GNUNET_YES ==
2499  w->addrlen,
2500  saddr,
2501  saddr_len))
2502  break;
2503  w = w->next;
2504  }
2505  GNUNET_free (saddr);
2506 
2507  if (NULL == w)
2508  return;
2509 
2511  "Notifying transport to remove address `%s'\n",
2513  w->address,
2514  w->addrlen));
2516  plugin->addr_tail,
2517  w);
2518  /* modify our published address list */
2519 #if BUILD_HTTPS
2520  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2521  "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2522 #else
2523  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
2524  "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2525 #endif
2526  plugin->env->notify_address (plugin->env->cls, add_remove, address);
2527  GNUNET_HELLO_address_free (address);
2528  GNUNET_free (w->address);
2529  GNUNET_free (w);
2530 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Wrapper to manage addresses.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
struct HttpAddressWrapper * next
Linked list next.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
size_t http_common_address_get_size(const struct HttpAddress *addr)
Get the length of an address.
void * cls
Closure for the various callbacks.
struct HttpAddress * address
An address we are using.
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
No additional information.
size_t http_common_cmp_addresses(const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2)
Compare addr1 to addr2.
Encapsulation of all of the state of the plugin.
An address for communicating with a peer.
struct HttpAddress * http_common_address_from_socket(const char *protocol, const struct sockaddr *addr, socklen_t addrlen)
Create a HTTP address from a socketaddr.
struct HttpAddressWrapper * addr_tail
IPv4 addresses DLL tail.
GNUNET_TRANSPORT_AddressNotification notify_address
Function that must be called by each plugin to notify the transport service about the addresses under...
#define GNUNET_YES
Definition: gnunet_common.h:80
struct HttpAddressWrapper * addr_head
IPv4 addresses DLL head.
#define LOG(kind,...)
static char * address
GNS address for this phone.
#define GNUNET_HELLO_address_free(addr)
Free an address.
size_t addrlen
Length of the address.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_nat_port_map_callback()

static void server_nat_port_map_callback ( void *  cls,
void **  app_ctx,
int  add_remove,
enum GNUNET_NAT_AddressClass  ac,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Our external IP address/port mapping has changed.

Parameters
clsclosure, the 'struct LocalAddrList'
app_ctx[in,out]location where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual lenght of the address

Definition at line 2547 of file plugin_transport_http_server.c.

References GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, server_add_address(), HTTP_Server_Plugin::server_addr_v4, HTTP_Server_Plugin::server_addr_v6, server_remove_address(), HTTP_Server_Plugin::use_ipv4, and HTTP_Server_Plugin::use_ipv6.

Referenced by server_start_report_addresses().

2553 {
2554  struct HTTP_Server_Plugin *plugin = cls;
2555 
2556  (void) app_ctx;
2558  "NAT called to %s address `%s'\n",
2559  (add_remove == GNUNET_NO) ? "remove" : "add",
2560  GNUNET_a2s (addr, addrlen));
2561 
2562  if (AF_INET == addr->sa_family)
2563  {
2564  struct sockaddr_in *s4 = (struct sockaddr_in *) addr;
2565 
2566  if (GNUNET_NO == plugin->use_ipv4)
2567  return;
2568 
2569  if ((NULL != plugin->server_addr_v4) &&
2570  (0 != memcmp (&plugin->server_addr_v4->sin_addr,
2571  &s4->sin_addr,
2572  sizeof (struct in_addr))))
2573  {
2575  "Skipping address `%s' (not bindto address)\n",
2576  GNUNET_a2s (addr, addrlen));
2577  return;
2578  }
2579  }
2580 
2581  if (AF_INET6 == addr->sa_family)
2582  {
2583  struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) addr;
2584  if (GNUNET_NO == plugin->use_ipv6)
2585  return;
2586 
2587  if ((NULL != plugin->server_addr_v6) &&
2588  (0 != memcmp (&plugin->server_addr_v6->sin6_addr,
2589  &s6->sin6_addr, sizeof (struct in6_addr))))
2590  {
2592  "Skipping address `%s' (not bindto address)\n",
2593  GNUNET_a2s (addr, addrlen));
2594  return;
2595  }
2596  }
2597 
2598  switch (add_remove)
2599  {
2600  case GNUNET_YES:
2601  server_add_address (cls, add_remove, addr, addrlen);
2602  break;
2603  case GNUNET_NO:
2604  server_remove_address (cls, add_remove, addr, addrlen);
2605  break;
2606  }
2607 }
static void server_remove_address(void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen)
Remove an address from the server&#39;s set of addresses and notify transport.
static void server_add_address(void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen)
Add an address to the server&#39;s set of addresses and notify transport.
struct sockaddr_in6 * server_addr_v6
IPv6 server socket to bind to.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
struct sockaddr_in * server_addr_v4
IPv4 server socket to bind to.
Encapsulation of all of the state of the plugin.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_get_addresses()

static int server_get_addresses ( struct HTTP_Server_Plugin plugin,
const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg,
struct sockaddr ***  addrs,
socklen_t **  addr_lens 
)
static

Get valid server addresses.

Parameters
pluginthe plugin handle
service_namethe servicename
cfgconfiguration handle
addrsaddresses
addr_lensaddress length
Returns
number of addresses

Definition at line 2621 of file plugin_transport_http_server.c.

References _, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, hostname, LOG, port, res, ret, and HTTP_Server_Plugin::use_ipv6.

Referenced by server_start_report_addresses().

2626 {
2627  int disablev6;
2628  unsigned long long port;
2629  struct addrinfo hints;
2630  struct addrinfo *res;
2631  struct addrinfo *pos;
2632  struct addrinfo *next;
2633  unsigned int i;
2634  int resi;
2635  int ret;
2636  struct sockaddr **saddrs;
2637  socklen_t *saddrlens;
2638  char *hostname;
2639 
2640  *addrs = NULL;
2641  *addr_lens = NULL;
2642 
2643  disablev6 = !plugin->use_ipv6;
2644 
2645  port = 0;
2646  if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
2647  {
2650  "PORT", &port));
2651  if (port > 65535)
2652  {
2654  _("Require valid port number for service in configuration!\n"));
2655  return GNUNET_SYSERR;
2656  }
2657  }
2658  if (0 == port)
2659  {
2661  "Starting in listen only mode\n");
2662  return -1; /* listen only */
2663  }
2664 
2665 
2667  "BINDTO"))
2668  {
2671  "BINDTO", &hostname));
2672  }
2673  else
2674  hostname = NULL;
2675 
2676  if (NULL != hostname)
2677  {
2679  "Resolving `%s' since that is where `%s' will bind to.\n",
2680  hostname, service_name);
2681  memset (&hints, 0, sizeof (struct addrinfo));
2682  if (disablev6)
2683  hints.ai_family = AF_INET;
2684  if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
2685  (NULL == res))
2686  {
2688  _("Failed to resolve `%s': %s\n"),
2689  hostname,
2690  gai_strerror (ret));
2691  GNUNET_free (hostname);
2692  return GNUNET_SYSERR;
2693  }
2694  next = res;
2695  i = 0;
2696  while (NULL != (pos = next))
2697  {
2698  next = pos->ai_next;
2699  if ((disablev6) && (pos->ai_family == AF_INET6))
2700  continue;
2701  i++;
2702  }
2703  if (0 == i)
2704  {
2706  _("Failed to find %saddress for `%s'.\n"),
2707  disablev6 ? "IPv4 " : "", hostname);
2708  freeaddrinfo (res);
2709  GNUNET_free (hostname);
2710  return GNUNET_SYSERR;
2711  }
2712  resi = i;
2713  saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2714  saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2715  i = 0;
2716  next = res;
2717  while (NULL != (pos = next))
2718  {
2719  next = pos->ai_next;
2720  if ((disablev6) && (pos->ai_family == AF_INET6))
2721  continue;
2722  if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol))
2723  continue; /* not TCP */
2724  if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype))
2725  continue; /* huh? */
2727  "Service will bind to `%s'\n",
2728  GNUNET_a2s (pos->ai_addr,
2729  pos->ai_addrlen));
2730  if (pos->ai_family == AF_INET)
2731  {
2732  GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
2733  saddrlens[i] = pos->ai_addrlen;
2734  saddrs[i] = GNUNET_malloc (saddrlens[i]);
2735  GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2736  ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2737  }
2738  else
2739  {
2740  GNUNET_assert (pos->ai_family == AF_INET6);
2741  GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
2742  saddrlens[i] = pos->ai_addrlen;
2743  saddrs[i] = GNUNET_malloc (saddrlens[i]);
2744  GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2745  ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2746  }
2747  i++;
2748  }
2749  GNUNET_free (hostname);
2750  freeaddrinfo (res);
2751  resi = i;
2752  }
2753  else
2754  {
2755  /* will bind against everything, just set port */
2756  if (disablev6)
2757  {
2758  /* V4-only */
2759  resi = 1;
2760  i = 0;
2761  saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2762  saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2763 
2764  saddrlens[i] = sizeof (struct sockaddr_in);
2765  saddrs[i] = GNUNET_malloc (saddrlens[i]);
2766 #if HAVE_SOCKADDR_IN_SIN_LEN
2767  ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
2768 #endif
2769  ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
2770  ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2771  }
2772  else
2773  {
2774  /* dual stack */
2775  resi = 2;
2776  saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2777  saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2778  i = 0;
2779  saddrlens[i] = sizeof (struct sockaddr_in6);
2780  saddrs[i] = GNUNET_malloc (saddrlens[i]);
2781 #if HAVE_SOCKADDR_IN_SIN_LEN
2782  ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
2783 #endif
2784  ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
2785  ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2786  i++;
2787  saddrlens[i] = sizeof (struct sockaddr_in);
2788  saddrs[i] = GNUNET_malloc (saddrlens[i]);
2789 #if HAVE_SOCKADDR_IN_SIN_LEN
2790  ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
2791 #endif
2792  ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
2793  ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2794  }
2795  }
2796  *addrs = saddrs;
2797  *addr_lens = saddrlens;
2798  return resi;
2799 }
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_memcpy(dst, src, n)
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static int res
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
#define GNUNET_log(kind,...)
#define LOG(kind,...)
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_start_report_addresses()

static void server_start_report_addresses ( struct HTTP_Server_Plugin plugin)
static

Ask NAT for addresses.

Parameters
pluginthe plugin handle

Definition at line 2808 of file plugin_transport_http_server.c.

References _, GNUNET_TRANSPORT_PluginEnvironment::cfg, HTTP_Server_Plugin::env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_NAT_register(), GNUNET_OK, GNUNET_SYSERR, LOG, HTTP_Server_Plugin::name, HTTP_Server_Plugin::nat, res, server_get_addresses(), and server_nat_port_map_callback().

Referenced by libgnunet_plugin_transport_http_server_init().

2809 {
2810  int res = GNUNET_OK;
2811  struct sockaddr **addrs;
2812  socklen_t *addrlens;
2813 
2814  res = server_get_addresses (plugin,
2815  plugin->name,
2816  plugin->env->cfg,
2817  &addrs, &addrlens);
2819  _("Found %u addresses to report to NAT service\n"),
2820  res);
2821 
2822  if (GNUNET_SYSERR == res)
2823  {
2824  plugin->nat = NULL;
2825  return;
2826  }
2827 
2828  plugin->nat
2829  = GNUNET_NAT_register (plugin->env->cfg,
2830  "transport-http_server",
2831  IPPROTO_TCP,
2832  (unsigned int) res,
2833  (const struct sockaddr **) addrs,
2834  addrlens,
2836  NULL,
2837  plugin);
2838  while (res > 0)
2839  {
2840  res--;
2841  GNUNET_assert (NULL != addrs[res]);
2842  GNUNET_free (addrs[res]);
2843  }
2844  GNUNET_free_non_null (addrs);
2845  GNUNET_free_non_null (addrlens);
2846 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static int server_get_addresses(struct HTTP_Server_Plugin *plugin, const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, socklen_t **addr_lens)
Get valid server addresses.
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
static int res
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition: nat_api.c:378
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define LOG(kind,...)
static void server_nat_port_map_callback(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Our external IP address/port mapping has changed.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_stop_report_addresses()

static void server_stop_report_addresses ( struct HTTP_Server_Plugin plugin)
static

Stop NAT for addresses.

Parameters
pluginthe plugin handle

Definition at line 2855 of file plugin_transport_http_server.c.

References HTTP_Server_Plugin::addr_head, HTTP_Server_Plugin::addr_tail, HttpAddressWrapper::address, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NAT_unregister(), and HTTP_Server_Plugin::nat.

Referenced by libgnunet_plugin_transport_http_server_done().

2856 {
2857  struct HttpAddressWrapper *w;
2858 
2859  /* Stop NAT handle */
2860  if (NULL != plugin->nat)
2861  {
2862  GNUNET_NAT_unregister (plugin->nat);
2863  plugin->nat = NULL;
2864  }
2865  /* Clean up addresses */
2866  while (NULL != plugin->addr_head)
2867  {
2868  w = plugin->addr_head;
2870  plugin->addr_tail,
2871  w);
2872  GNUNET_free (w->address);
2873  GNUNET_free (w);
2874  }
2875 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Wrapper to manage addresses.
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:690
struct HttpAddress * address
An address we are using.
struct HttpAddressWrapper * addr_tail
IPv4 addresses DLL tail.
struct HttpAddressWrapper * addr_head
IPv4 addresses DLL head.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_check_ipv6_support()

static int server_check_ipv6_support ( struct HTTP_Server_Plugin plugin)
static

Check if IPv6 supported on this system.

Parameters
pluginthe plugin handle
Returns
GNUNET_YES on success, else GNUNET_NO

Definition at line 2885 of file plugin_transport_http_server.c.

References _, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NO, GNUNET_OK, GNUNET_YES, LOG, and res.

Referenced by libgnunet_plugin_transport_http_server_init().

2886 {
2887  struct GNUNET_NETWORK_Handle *desc = NULL;
2888  int res = GNUNET_NO;
2889 
2890  /* Probe IPv6 support */
2891  desc = GNUNET_NETWORK_socket_create (PF_INET6,
2892  SOCK_STREAM,
2893  0);
2894  if (NULL == desc)
2895  {
2896  if ( (errno == ENOBUFS) ||
2897  (errno == ENOMEM) ||
2898  (errno == ENFILE) ||
2899  (errno == EACCES) )
2900  {
2902  "socket");
2903  }
2905  _("Disabling IPv6 since it is not supported on this system!\n"));
2906  res = GNUNET_NO;
2907  }
2908  else
2909  {
2912  desc = NULL;
2913  res = GNUNET_YES;
2914  }
2916  "Testing IPv6 on this system: %s\n",
2917  (res == GNUNET_YES) ? "successful" : "failed");
2918  return res;
2919 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static int res
handle to a socket
Definition: network.c:46
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:1037
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_notify_external_hostname()

static void server_notify_external_hostname ( void *  cls)
static

Notify server about our external hostname.

Parameters
clsplugin

Definition at line 2928 of file plugin_transport_http_server.c.

References GNUNET_TRANSPORT_PluginEnvironment::cls, HTTP_Server_Plugin::env, HTTP_Server_Plugin::ext_addr, HTTP_Server_Plugin::external_hostname, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_malloc, GNUNET_memcpy, GNUNET_YES, LOG, GNUNET_TRANSPORT_PluginEnvironment::my_identity, GNUNET_TRANSPORT_PluginEnvironment::notify_address, HTTP_Server_Plugin::notify_ext_task, HttpAddress::options, HTTP_Server_Plugin::options, HTTP_Server_Plugin::protocol, HttpAddress::urlen, and HTTP_Server_Plugin::verify_external_hostname.

Referenced by server_configure_plugin().

2929 {
2930  struct HTTP_Server_Plugin *plugin = cls;
2931  struct HttpAddress *ext_addr;
2932  size_t ext_addr_len;
2933  unsigned int urlen;
2934  char *url;
2935 
2936  plugin->notify_ext_task = NULL;
2937  GNUNET_asprintf (&url,
2938  "%s://%s",
2939  plugin->protocol,
2940  plugin->external_hostname);
2941  urlen = strlen (url) + 1;
2942  ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
2943  ext_addr->options = htonl (plugin->options);
2944  ext_addr->urlen = htonl (urlen);
2945  ext_addr_len = sizeof (struct HttpAddress) + urlen;
2946  GNUNET_memcpy (&ext_addr[1], url, urlen);
2947  GNUNET_free (url);
2948 
2950  "Notifying transport about external hostname address `%s'\n",
2951  plugin->external_hostname);
2952 
2953 #if BUILD_HTTPS
2954  if (GNUNET_YES == plugin->verify_external_hostname)
2956  "Enabling SSL verification for external hostname address `%s'\n",
2957  plugin->external_hostname);
2958  plugin->ext_addr
2960  "https_client",
2961  ext_addr,
2962  ext_addr_len,
2964  plugin->env->notify_address (plugin->env->cls,
2965  GNUNET_YES,
2966  plugin->ext_addr);
2967  GNUNET_free (ext_addr);
2968 #else
2969  plugin->ext_addr
2971  "http_client",
2972  ext_addr,
2973  ext_addr_len,
2975  plugin->env->notify_address (plugin->env->cls,
2976  GNUNET_YES,
2977  plugin->ext_addr);
2978  GNUNET_free (ext_addr);
2979 #endif
2980 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
int verify_external_hostname
Verify external address.
uint32_t options
Address options see enum HttpAddressOptions
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
uint32_t options
My options to be included in the address.
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
struct GNUNET_HELLO_Address * ext_addr
External hostname the plugin can be connected to, can be different to the host&#39;s FQDN, used e.g.
struct GNUNET_SCHEDULER_Task * notify_ext_task
Task calling transport service about external address.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void * cls
Closure for the various callbacks.
#define GNUNET_memcpy(dst, src, n)
uint32_t urlen
Length of URL located after struct.
No additional information.
Encapsulation of all of the state of the plugin.
GNUNET_TRANSPORT_AddressNotification notify_address
Function that must be called by each plugin to notify the transport service about the addresses under...
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
HTTP addresses including a full URI.
char * external_hostname
External address.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_configure_plugin()

static int server_configure_plugin ( struct HTTP_Server_Plugin plugin)
static

Configure the plugin.

Parameters
pluginplugin handle
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 2990 of file plugin_transport_http_server.c.

References _, GNUNET_TRANSPORT_PluginEnvironment::cfg, HTTP_Server_Plugin::env, HTTP_Server_Plugin::external_hostname, HTTP_Server_Plugin::external_only, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s_full(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, HTTP_OPTIONS_VERIFY_CERTIFICATE, inet_pton(), LOG, max_connections, HTTP_Server_Plugin::max_request, GNUNET_TRANSPORT_PluginEnvironment::my_identity, HTTP_Server_Plugin::name, HTTP_Server_Plugin::notify_ext_task, HTTP_Server_Plugin::options, HTTP_Server_Plugin::peer_id_length, port, HTTP_Server_Plugin::port, HTTP_Server_Plugin::protocol, HTTP_Server_Plugin::server_addr_v4, HTTP_Server_Plugin::server_addr_v6, server_notify_external_hostname(), HTTP_Server_Plugin::use_ipv4, HTTP_Server_Plugin::use_ipv6, and HTTP_Server_Plugin::verify_external_hostname.

Referenced by libgnunet_plugin_transport_http_server_init().

2991 {
2992  unsigned long long port;
2993  unsigned long long max_connections;
2994  char *bind4_address = NULL;
2995  char *bind6_address = NULL;
2996  char *eh_tmp = NULL;
2997  int external_hostname_use_port;
2998 
2999  /* Use IPv4? */
3001  (plugin->env->cfg, plugin->name, "USE_IPv4"))
3002  {
3003  plugin->use_ipv4 =
3005  plugin->name,
3006  "USE_IPv4");
3007  }
3008  else
3009  plugin->use_ipv4 = GNUNET_YES;
3011  _("IPv4 support is %s\n"),
3012  (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled");
3013 
3014  /* Use IPv6? */
3016  (plugin->env->cfg, plugin->name, "USE_IPv6"))
3017  {
3018  plugin->use_ipv6 =
3020  plugin->name,
3021  "USE_IPv6");
3022  }
3023  else
3024  plugin->use_ipv6 = GNUNET_YES;
3026  _("IPv6 support is %s\n"),
3027  (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled");
3028 
3029  if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO))
3030  {
3032  _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"));
3033  return GNUNET_SYSERR;
3034  }
3035 
3036  /* Reading port number from config file */
3037  if ((GNUNET_OK !=
3039  plugin->name,
3040  "PORT", &port)) || (port > 65535))
3041  {
3043  _("Port is required! Fix in configuration\n"));
3044  return GNUNET_SYSERR;
3045  }
3046  plugin->port = port;
3047 
3049  _("Using port %u\n"), plugin->port);
3050 
3051  if ( (plugin->use_ipv4 == GNUNET_YES) &&
3052  (GNUNET_YES ==
3054  plugin->name,
3055  "BINDTO",
3056  &bind4_address)))
3057  {
3059  "Binding %s plugin to specific IPv4 address: `%s'\n",
3060  plugin->protocol,
3061  bind4_address);
3062  plugin->server_addr_v4 = GNUNET_new (struct sockaddr_in);
3063  if (1 != inet_pton (AF_INET,
3064  bind4_address,
3065  &plugin->server_addr_v4->sin_addr))
3066  {
3068  _("Specific IPv4 address `%s' in configuration file is invalid!\n"),
3069  bind4_address);
3070  GNUNET_free (bind4_address);
3071  GNUNET_free (plugin->server_addr_v4);
3072  plugin->server_addr_v4 = NULL;
3073  return GNUNET_SYSERR;
3074  }
3075  else
3076  {
3078  "Binding to IPv4 address %s\n",
3079  bind4_address);
3080  plugin->server_addr_v4->sin_family = AF_INET;
3081  plugin->server_addr_v4->sin_port = htons (plugin->port);
3082  }
3083  GNUNET_free (bind4_address);
3084  }
3085 
3086  if ((plugin->use_ipv6 == GNUNET_YES) &&
3087  (GNUNET_YES ==
3089  plugin->name,
3090  "BINDTO6",
3091  &bind6_address)))
3092  {
3094  "Binding %s plugin to specific IPv6 address: `%s'\n",
3095  plugin->protocol, bind6_address);
3096  plugin->server_addr_v6 = GNUNET_new (struct sockaddr_in6);
3097  if (1 !=
3098  inet_pton (AF_INET6,
3099  bind6_address,
3100  &plugin->server_addr_v6->sin6_addr))
3101  {
3103  _("Specific IPv6 address `%s' in configuration file is invalid!\n"),
3104  bind6_address);
3105  GNUNET_free (bind6_address);
3106  GNUNET_free (plugin->server_addr_v6);
3107  plugin->server_addr_v6 = NULL;
3108  return GNUNET_SYSERR;
3109  }
3110  else
3111  {
3113  "Binding to IPv6 address %s\n",
3114  bind6_address);
3115  plugin->server_addr_v6->sin6_family = AF_INET6;
3116  plugin->server_addr_v6->sin6_port = htons (plugin->port);
3117  }
3118  GNUNET_free (bind6_address);
3119  }
3120 
3122 #if BUILD_HTTPS
3123  plugin->verify_external_hostname
3125  plugin->name,
3126  "VERIFY_EXTERNAL_HOSTNAME");
3127  if (GNUNET_SYSERR == plugin->verify_external_hostname)
3129  if (GNUNET_YES == plugin->verify_external_hostname)
3131 #endif
3132  external_hostname_use_port
3134  plugin->name,
3135  "EXTERNAL_HOSTNAME_USE_PORT");
3136  if (GNUNET_SYSERR == external_hostname_use_port)
3137  external_hostname_use_port = GNUNET_NO;
3138 
3139 
3140  if (GNUNET_YES ==
3142  plugin->name,
3143  "EXTERNAL_HOSTNAME",
3144  &eh_tmp))
3145  {
3146  char *tmp;
3147  char *pos = NULL;
3148  char *pos_url = NULL;
3149 
3150  if (NULL != strstr(eh_tmp, "://"))
3151  tmp = &strstr(eh_tmp, "://")[3];
3152  else
3153  tmp = eh_tmp;
3154 
3155  if (GNUNET_YES == external_hostname_use_port)
3156  {
3157  if ( (strlen (tmp) > 1) && (NULL != (pos = strchr(tmp, '/'))) )
3158  {
3159  pos_url = pos + 1;
3160  pos[0] = '\0';
3162  "%s:%u/%s",
3163  tmp,
3164  (uint16_t) port,
3165  pos_url);
3166  }
3167  else
3169  "%s:%u",
3170  tmp,
3171  (uint16_t) port);
3172  }
3173  else
3174  plugin->external_hostname = GNUNET_strdup (tmp);
3175  GNUNET_free (eh_tmp);
3176 
3178  _("Using external hostname `%s'\n"),
3179  plugin->external_hostname);
3181  plugin);
3182 
3183  /* Use only configured external hostname */
3185  (plugin->env->cfg,
3186  plugin->name,
3187  "EXTERNAL_HOSTNAME_ONLY"))
3188  {
3189  plugin->external_only =
3191  plugin->name,
3192  "EXTERNAL_HOSTNAME_ONLY");
3193  }
3194  else
3195  plugin->external_only = GNUNET_NO;
3196 
3197  if (GNUNET_YES == plugin->external_only)
3199  _("Notifying transport only about hostname `%s'\n"),
3200  plugin->external_hostname);
3201  }
3202  else
3204  "No external hostname configured\n");
3205 
3206  /* Optional parameters */
3207  if (GNUNET_OK !=
3209  plugin->name,
3210  "MAX_CONNECTIONS",
3211  &max_connections))
3212  max_connections = 128;
3213  plugin->max_request = max_connections;
3214 
3216  _("Maximum number of connections is %u\n"),
3217  plugin->max_request);
3218 
3219  plugin->peer_id_length = strlen (GNUNET_i2s_full (plugin->env->my_identity));
3220 
3221  return GNUNET_OK;
3222 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct sockaddr_in6 * server_addr_v6
IPv6 server socket to bind to.
int verify_external_hostname
Verify external address.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
static unsigned long long max_connections
If there are at least this many connections, old ones will be removed.
unsigned int max_request
Maximum number of sockets the plugin can use Each http request /request connections are two connectio...
uint32_t options
My options to be included in the address.
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_SCHEDULER_Task * notify_ext_task
Task calling transport service about external address.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
unsigned int external_only
Notify transport only about external address.
static void server_notify_external_hostname(void *cls)
Notify server about our external hostname.
struct sockaddr_in * server_addr_v4
IPv4 server socket to bind to.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
Verify X509 server certificate, it should be valid.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
char * external_hostname
External address.
int peer_id_length
Length of peer id.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_transport_http_server_done()

void* libgnunet_plugin_transport_http_server_done ( void *  cls)

Exit point from the plugin.

Parameters
clsapi
Returns
NULL

Definition at line 3232 of file plugin_transport_http_server.c.

References _, GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_TRANSPORT_PluginEnvironment::cls, GNUNET_TRANSPORT_PluginFunctions::cls, destroy_session_shutdown_cb(), HTTP_Server_Plugin::env, HTTP_Server_Plugin::ext_addr, HTTP_Server_Plugin::external_hostname, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_free_non_null, GNUNET_HELLO_address_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_YES, http_common_plugin_address_to_string(), HTTP_Server_Plugin::in_shutdown, LOG, HTTP_Server_Plugin::name, GNUNET_TRANSPORT_PluginEnvironment::notify_address, HTTP_Server_Plugin::notify_ext_task, HTTP_Server_Plugin::protocol, HTTP_Server_Plugin::server_addr_v4, HTTP_Server_Plugin::server_addr_v6, server_stop_report_addresses(), HTTP_Server_Plugin::server_v4, HTTP_Server_Plugin::server_v4_task, HTTP_Server_Plugin::server_v6, HTTP_Server_Plugin::server_v6_task, HTTP_Server_Plugin::sessions, and HTTP_Server_Plugin::url_regex.

3233 {
3234  struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3235  struct HTTP_Server_Plugin *plugin = api->cls;
3236 
3237  if (NULL == api->cls)
3238  {
3239  /* Free for stub mode */
3240  GNUNET_free (api);
3241  return NULL;
3242  }
3243  plugin->in_shutdown = GNUNET_YES;
3245  _("Shutting down plugin `%s'\n"),
3246  plugin->name);
3247 
3248  if (NULL != plugin->notify_ext_task)
3249  {
3251  plugin->notify_ext_task = NULL;
3252  }
3253 
3254  if (NULL != plugin->ext_addr)
3255  {
3257  "Notifying transport to remove address `%s'\n",
3259  plugin->ext_addr->address,
3260  plugin->ext_addr->address_length));
3261 #if BUILD_HTTPS
3262  plugin->env->notify_address (plugin->env->cls,
3263  GNUNET_NO,
3264  plugin->ext_addr);
3265 #else
3266  plugin->env->notify_address (plugin->env->cls,
3267  GNUNET_NO,
3268  plugin->ext_addr);
3269 #endif
3271  plugin->ext_addr = NULL;
3272  }
3273 
3274  /* Stop to report addresses to transport service */
3276  if (NULL != plugin->server_v4_task)
3277  {
3279  plugin->server_v4_task = NULL;
3280  }
3281 
3282  if (NULL != plugin->server_v6_task)
3283  {
3285  plugin->server_v6_task = NULL;
3286  }
3287 #if BUILD_HTTPS
3288  GNUNET_free_non_null (plugin->crypto_init);
3289  GNUNET_free_non_null (plugin->cert);
3290  GNUNET_free_non_null (plugin->key);
3291 #endif
3294  plugin);
3296  plugin->sessions = NULL;
3297  if (NULL != plugin->server_v4)
3298  {
3299  MHD_stop_daemon (plugin->server_v4);
3300  plugin->server_v4 = NULL;
3301  }
3302  if (NULL != plugin->server_v6)
3303  {
3304  MHD_stop_daemon (plugin->server_v6);
3305  plugin->server_v6 = NULL;
3306  }
3307  /* Clean up */
3309  GNUNET_free_non_null (plugin->ext_addr);
3312  regfree (&plugin->url_regex);
3313 
3315  _("Shutdown for plugin `%s' complete\n"),
3316  plugin->name);
3317 
3318  GNUNET_free (plugin);
3319  GNUNET_free (api);
3320  return NULL;
3321 }
struct GNUNET_SCHEDULER_Task * server_v6_task
MHD IPv6 task.
size_t address_length
Number of bytes in address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct sockaddr_in6 * server_addr_v6
IPv6 server socket to bind to.
const void * address
Binary representation of the address (plugin-specific).
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Hash map of open sessions.
struct GNUNET_SCHEDULER_Task * server_v4_task
MHD IPv4 task.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_HELLO_Address * ext_addr
External hostname the plugin can be connected to, can be different to the host&#39;s FQDN, used e.g.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int in_shutdown
Did we immediately end the session in disconnect_cb.
regex_t url_regex
Regex for parsing URLs.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208