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 "gnunet_mhd_compat.h"
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 |
Session handle for connections. 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, ...) |
#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_Session * | http_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_Task * | server_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 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. 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 MHD_RESULT | 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 MHD_RESULT | 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_client_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_client_init (void *cls) |
Entry point for the plugin. More... | |
HTTP/S server transport plugin.
Definition in file plugin_transport_http_server.c.
#define PLUGIN_NAME "http_server" |
Definition at line 45 of file plugin_transport_http_server.c.
#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_server_init |
Definition at line 46 of file plugin_transport_http_server.c.
#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_server_done |
Definition at line 48 of file plugin_transport_http_server.c.
#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 52 of file plugin_transport_http_server.c.
#define _RECEIVE 0 |
Definition at line 54 of file plugin_transport_http_server.c.
#define _SEND 1 |
Definition at line 55 of file plugin_transport_http_server.c.
#define LOG | ( | kind, | |
... | |||
) |
Definition at line 58 of file plugin_transport_http_server.c.
#define OPTION_LONG_POLL 1 /* GET request wants long-poll semantics */ |
Definition at line 87 of file plugin_transport_http_server.c.
#define URL_REGEX ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$") |
|
static |
If a session monitor is attached, notify it about the new session state.
plugin | our plugin |
session | session that changed state |
state | new state of the session |
Definition at line 474 of file plugin_transport_http_server.c.
References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_YES, info, GNUNET_ATS_Session::msgs_in_queue, GNUNET_ATS_Session::next_receive, plugin, 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().
|
static |
Wake up an MHD connection which was suspended.
cls | the session |
Definition at line 502 of file plugin_transport_http_server.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, ServerRequest::mhd_conn, GNUNET_ATS_Session::recv_wakeup_task, GNUNET_ATS_Session::server_recv, and ServerRequest::suspended.
Referenced by http_server_plugin_update_inbound_delay(), and server_access_cb().
|
static |
Reschedule the execution of both IPv4 and IPv6 server.
plugin | the plugin |
server | which server to schedule v4 or v6? |
now | GNUNET_YES to schedule execution immediately, GNUNET_NO to wait until timeout |
Definition at line 1084 of file plugin_transport_http_server.c.
References GNUNET_SCHEDULER_cancel(), GNUNET_YES, plugin, and server_schedule().
Referenced by http_server_plugin_send(), server_connection_cb(), server_delete_session(), server_mhd_connection_timeout(), server_start(), server_v4_run(), and server_v6_run().
|
static |
Deletes the session.
Must not be used afterwards.
s | the session to delete |
Definition at line 536 of file plugin_transport_http_server.c.
References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, 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(), plugin, GNUNET_ATS_Session::plugin, GNUNET_ATS_Session::recv_wakeup_task, GNUNET_ATS_Session::server_recv, server_reschedule(), GNUNET_ATS_Session::server_send, ServerRequest::session, GNUNET_MessageHeader::size, ServerRequest::suspended, GNUNET_ATS_Session::target, GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.
Referenced by destroy_session_cb(), destroy_session_shutdown_cb(), http_server_plugin_disconnect_session(), and server_session_timeout().
|
static |
Disconnect session s by telling MHD to close the connections (reducing timeout, etc.).
cls | closure with the struct HTTP_Server_Plugin |
s | the session |
Definition at line 648 of file plugin_transport_http_server.c.
References GNUNET_OK, and server_delete_session().
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Session was idle, so disconnect it.
cls | the session |
Definition at line 662 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().
|
static |
Increment session timeout due to activity session s.
s | the session |
Definition at line 697 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().
|
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.
cls | closure |
session | which session must be used |
msgbuf | the message to transmit |
msgbuf_size | number of bytes in msgbuf |
priority | how important is the message (most plugins will ignore message priority and just FIFO) |
to | how 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) |
cont | continuation 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_cls | closure for cont |
Definition at line 733 of file plugin_transport_http_server.c.
References GNUNET_ATS_Session::bytes_in_queue, 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(), plugin, GNUNET_ATS_Session::plugin, server_reschedule(), GNUNET_ATS_Session::server_send, GNUNET_MessageHeader::size, ServerRequest::suspended, and GNUNET_ATS_Session::target.
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Terminate session during shutdown.
cls | the struct HTTP_Server_Plugin * |
peer | for which this is a session |
value | the struct GNUNET_ATS_Session to clean up |
Definition at line 805 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_client_done().
|
static |
Terminate session.
cls | the struct HTTP_Server_Plugin * |
peer | for which this is a session |
value | the struct GNUNET_ATS_Session to clean up |
Definition at line 834 of file plugin_transport_http_server.c.
References GNUNET_OK, server_delete_session(), and value.
Referenced by http_server_plugin_disconnect_peer().
|
static |
Function that can be used to force the plugin to disconnect from the given peer and cancel all previous transmissions (and their continuationc).
cls | closure |
target | peer from which to disconnect |
Definition at line 854 of file plugin_transport_http_server.c.
References destroy_session_cb(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, and plugin.
Referenced by libgnunet_plugin_transport_http_client_init().
|
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.
cls | closure |
addr | pointer to the address |
addrlen | length of addr |
Definition at line 882 of file plugin_transport_http_server.c.
References HttpAddress::addr, HttpAddressWrapper::address, HttpAddressWrapper::addrlen, GNUNET_NO, GNUNET_OK, GNUNET_YES, http_common_cmp_addresses(), HTTP_OPTIONS_VERIFY_CERTIFICATE, HttpAddressWrapper::next, HttpAddress::options, and plugin.
Referenced by libgnunet_plugin_transport_http_client_init().
|
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.
cls | the plugin |
address | the address |
Definition at line 928 of file plugin_transport_http_server.c.
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Call MHD IPv4 to process pending requests and then go back and schedule the next run.
cls | plugin as closure |
Definition at line 942 of file plugin_transport_http_server.c.
References GNUNET_assert, GNUNET_NO, plugin, and server_reschedule().
Referenced by server_schedule().
|
static |
Call MHD IPv6 to process pending requests and then go back and schedule the next run.
cls | plugin as closure |
Definition at line 960 of file plugin_transport_http_server.c.
References GNUNET_assert, GNUNET_NO, plugin, and server_reschedule().
Referenced by server_schedule().
|
static |
Function that queries MHD's select sets and starts the task waiting for them.
plugin | plugin |
daemon_handle | the MHD daemon handle |
now | schedule now |
Definition at line 981 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, LOG, max, plugin, GNUNET_TIME_Relative::rel_value_us, ret, server_v4_run(), server_v6_run(), and timeout.
Referenced by server_reschedule().
|
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.
cls | closure with the struct HTTP_Server_Plugin |
Definition at line 1131 of file plugin_transport_http_server.c.
Referenced by libgnunet_plugin_transport_http_client_init().
|
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.
cls | closure |
peer | which peer was the session for |
session | which session is being updated |
Definition at line 1147 of file plugin_transport_http_server.c.
References server_reschedule_session_timeout().
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Tell MHD that the connection should timeout after to seconds.
plugin | our plugin |
s | session for which the timeout changes |
to | timeout in seconds |
Definition at line 1164 of file plugin_transport_http_server.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, LOG, ServerRequest::mhd_conn, ServerRequest::mhd_daemon, plugin, GNUNET_ATS_Session::server_recv, server_reschedule(), and GNUNET_ATS_Session::server_send.
Referenced by server_access_cb(), and server_lookup_connection().
|
static |
Parse incoming URL for tag and target.
plugin | plugin |
url | incoming url |
target | where to store the target |
tag | where to store the tag |
options | where to store the options |
Definition at line 1203 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, warningfilter::matches, options, plugin, and GNUNET_PeerIdentity::public_key.
Referenced by server_lookup_connection().
|
static |
Find a session with a matching tag.
cls | the struct GNUNET_ATS_SessionTagContext * |
key | peer identity (unused) |
value | the struct GNUNET_ATS_Session * |
Definition at line 1351 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().
|
static |
Lookup a mhd connection and create one if none is found.
plugin | the plugin handle |
mhd_connection | the incoming mhd_connection |
url | incoming requested URL |
method | PUT or GET |
Definition at line 1377 of file plugin_transport_http_server.c.
References _RECEIVE, _SEND, HttpAddress::addr, GNUNET_ATS_Session::address, direction, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, 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, GNUNET_ATS_Session::next_receive, notify_session_monitor(), options, GNUNET_FS_SearchContext::options, plugin, GNUNET_ATS_Session::plugin, PLUGIN_NAME, GNUNET_ATS_SessionTagContext::res, sc, GNUNET_ATS_Session::scope, scope, server_mhd_connection_timeout(), server_parse_url(), GNUNET_ATS_Session::server_recv, GNUNET_ATS_Session::server_send, server_session_timeout(), session_tag_it(), 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().
|
static |
Callback called by MHD when it needs data to send.
cls | current session |
pos | position in buffer |
buf | the buffer to write data to |
max | max number of bytes available in buf |
Definition at line 1567 of file plugin_transport_http_server.c.
References buf, GNUNET_ATS_Session::bytes_in_queue, 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, max, 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, GNUNET_FS_SearchContext::options, GNUNET_ATS_Session::plugin, Plugin::protocol, sc, GNUNET_ATS_Session::server_send, GNUNET_MessageHeader::size, ServerRequest::suspended, and GNUNET_ATS_Session::target.
Referenced by server_access_cb().
|
static |
Callback called by MessageStreamTokenizer when a message has arrived.
cls | current session as closure |
message | the message to be forwarded to transport service |
Definition at line 1664 of file plugin_transport_http_server.c.
References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, delay, 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(), plugin, GNUNET_ATS_Session::plugin, GNUNET_TIME_Relative::rel_value_us, GNUNET_ATS_Session::scope, server_reschedule_session_timeout(), GNUNET_MessageHeader::size, and GNUNET_ATS_Session::target.
Referenced by server_access_cb().
|
static |
Add headers to a request indicating that we allow Cross-Origin Resource Sharing.
response | response object to modify |
Definition at line 1719 of file plugin_transport_http_server.c.
References response.
Referenced by server_access_cb().
|
static |
MHD callback for a new incoming connection.
cls | the plugin handle |
mhd_connection | the mhd connection |
url | the requested URL |
method | GET or PUT |
version | HTTP version |
upload_data | upload data |
upload_data_size | size of upload_data |
httpSessionCache | the session cache to remember the connection |
Definition at line 1747 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, delay, 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, ServerRequest::mhd_conn, MHD_HTTP_NOT_FOUND, MHD_HTTP_OK, MHD_RESULT, GNUNET_ATS_Session::msg_tk, GNUNET_ATS_Session::next_receive, plugin, 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::suspended, and GNUNET_ATS_Session::target.
Referenced by run_mhd_start_daemon().
|
static |
Callback from MHD when a connection disconnects.
cls | closure with the struct HTTP_Server_Plugin * |
connection | the disconnected MHD connection |
httpSessionCache | the pointer to distinguish |
Definition at line 1937 of file plugin_transport_http_server.c.
References _RECEIVE, _SEND, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_MST_destroy(), http_common_plugin_address_to_string(), LOG, plugin, and sc.
Referenced by run_mhd_start_daemon().
|
static |
Callback from MHD when a connection starts/stops.
cls | closure with the struct HTTP_Server_Plugin * |
connection | connection handle |
socket_context | socket-specific pointer |
toe | reason for connection notification |
Definition at line 2001 of file plugin_transport_http_server.c.
References GNUNET_assert, GNUNET_YES, info, plugin, and server_reschedule().
Referenced by run_mhd_start_daemon().
|
static |
Check if incoming connection is accepted.
cls | plugin as closure |
addr | address of incoming connection |
addr_len | number of bytes in addr |
Definition at line 2031 of file plugin_transport_http_server.c.
References _, GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, LOG, and plugin.
Referenced by run_mhd_start_daemon().
|
static |
Log function called by MHD.
arg | NULL |
fmt | format string |
ap | arguments for the format string (va_start() and va_end() will be called by MHD) |
Definition at line 2065 of file plugin_transport_http_server.c.
References GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.
Referenced by run_mhd_start_daemon().
|
static |
Invoke MHD_start_daemon
with the various options we need to setup the HTTP server with the given listen address.
plugin | our plugin |
addr | listen address to use |
v6 | MHD_NO_FLAG or MHD_USE_IPv6, depending on context |
Definition at line 2261 of file plugin_transport_http_server.c.
References _, 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, plugin, server_accept_cb(), server_access_cb(), server_connection_cb(), server_disconnect_cb(), server_log(), timeout, and VERBOSE_SERVER.
Referenced by server_start().
|
static |
Start the HTTP server.
plugin | the plugin handle |
Definition at line 2348 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, plugin, run_mhd_start_daemon(), and server_reschedule().
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Add an address to the server's set of addresses and notify transport.
cls | the plugin handle |
add_remove | GNUNET_YES on add, GNUNET_NO on remove |
addr | the address |
addrlen | address length |
Definition at line 2445 of file plugin_transport_http_server.c.
References address, HttpAddressWrapper::address, HttpAddressWrapper::addrlen, 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, and plugin.
Referenced by server_nat_port_map_callback().
|
static |
Remove an address from the server's set of addresses and notify transport.
cls | the plugin handle |
add_remove | GNUNET_YES on add, GNUNET_NO on remove |
addr | the address |
addrlen | address length |
Definition at line 2502 of file plugin_transport_http_server.c.
References address, HttpAddressWrapper::address, HttpAddressWrapper::addrlen, 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, HttpAddressWrapper::next, and plugin.
Referenced by server_nat_port_map_callback().
|
static |
Our external IP address/port mapping has changed.
cls | closure, the 'struct LocalAddrList' | |
[in,out] | app_ctx | location where the app can store stuff on add and retrieve it on remove |
add_remove | GNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one | |
ac | address class the address belongs to | |
addr | either the previous or the new public IP address | |
addrlen | actual length of the address |
Definition at line 2575 of file plugin_transport_http_server.c.
References GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, plugin, server_add_address(), and server_remove_address().
Referenced by server_start_report_addresses().
|
static |
Get valid server addresses.
plugin | the plugin handle |
service_name | the servicename |
cfg | configuration handle |
addrs | addresses |
addr_lens | address length |
Definition at line 2650 of file plugin_transport_http_server.c.
References _, cfg, 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, plugin, port, res, ret, and service_name.
Referenced by server_start_report_addresses().
|
static |
Ask NAT for addresses.
plugin | the plugin handle |
Definition at line 2838 of file plugin_transport_http_server.c.
References _, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NAT_register(), GNUNET_OK, GNUNET_SYSERR, LOG, plugin, res, server_get_addresses(), and server_nat_port_map_callback().
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Stop NAT for addresses.
plugin | the plugin handle |
Definition at line 2885 of file plugin_transport_http_server.c.
References HttpAddressWrapper::address, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NAT_unregister(), and plugin.
Referenced by libgnunet_plugin_transport_http_client_done().
|
static |
Check if IPv6 supported on this system.
plugin | the plugin handle |
Definition at line 2915 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_client_init().
|
static |
Notify server about our external hostname.
cls | plugin |
Definition at line 2958 of file plugin_transport_http_server.c.
References 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, HttpAddress::options, plugin, and HttpAddress::urlen.
Referenced by server_configure_plugin().
|
static |
Configure the plugin.
plugin | plugin handle |
Definition at line 3020 of file plugin_transport_http_server.c.
References _, 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, LOG, max_connections, plugin, port, and server_notify_external_hostname().
Referenced by libgnunet_plugin_transport_http_client_init().
void* libgnunet_plugin_transport_http_client_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | api |
Definition at line 3263 of file plugin_transport_http_server.c.
References _, GNUNET_TRANSPORT_PluginFunctions::cls, destroy_session_shutdown_cb(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_address_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_YES, http_common_plugin_address_to_string(), LOG, plugin, and server_stop_report_addresses().
|
static |
Function called for a quick conversion of the binary address to a numeric address.
Note that the caller must not free the address and that the next call to this function is allowed to override the address again.
cls | unused |
addr | binary address |
addrlen | length of the address |
Definition at line 3367 of file plugin_transport_http_server.c.
References http_common_plugin_address_to_string(), and PLUGIN_NAME.
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Function obtain the network type for a session.
cls | closure (struct HTTP_Server_Plugin * ) |
session | the session |
Definition at line 3367 of file plugin_transport_http_server.c.
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Function obtain the network type for an address.
cls | closure (struct Plugin * ) |
address | the address |
Definition at line 3367 of file plugin_transport_http_server.c.
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
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.
cls | closure |
peer | which peer was the session for |
session | which session is being updated |
delay | new delay to use for receiving |
Definition at line 3422 of file plugin_transport_http_server.c.
References delay, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_relative_to_absolute(), LOG, GNUNET_ATS_Session::next_receive, GNUNET_ATS_Session::recv_wakeup_task, and server_wake_up().
Referenced by libgnunet_plugin_transport_http_client_init().
|
static |
Return information about the given session to the monitor callback.
cls | the struct Plugin with the monitor callback (sic ) |
peer | peer we send information about |
value | our struct GNUNET_ATS_Session to send information about |
Definition at line 3453 of file plugin_transport_http_server.c.
References GNUNET_OK, GNUNET_TRANSPORT_SS_INIT, notify_session_monitor(), plugin, and value.
Referenced by http_server_plugin_setup_monitor().
|
static |
Begin monitoring sessions of a plugin.
There can only be one active monitor per plugin (i.e. if there are multiple monitors, the transport service needs to multiplex the generated events over all of them).
cls | closure of the plugin |
sic | callback to invoke, NULL to disable monitor; plugin will being by iterating over all active sessions immediately and then enter monitor mode |
sic_cls | closure for sic |
Definition at line 3480 of file plugin_transport_http_server.c.
References GNUNET_CONTAINER_multipeermap_iterate(), plugin, send_session_info_iter(), HTTP_Server_Plugin::sic, and HTTP_Server_Plugin::sic_cls.
Referenced by libgnunet_plugin_transport_http_client_init().
void* libgnunet_plugin_transport_http_client_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | env |
Definition at line 3506 of file plugin_transport_http_server.c.
References _, GNUNET_TRANSPORT_PluginFunctions::address_pretty_printer, GNUNET_TRANSPORT_PluginFunctions::address_to_string, GNUNET_TRANSPORT_PluginFunctions::check_address, GNUNET_TRANSPORT_PluginEnvironment::cls, GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_TRANSPORT_PluginFunctions::disconnect_peer, GNUNET_TRANSPORT_PluginFunctions::disconnect_session, env, GNUNET_TRANSPORT_PluginFunctions::get_network, GNUNET_TRANSPORT_PluginFunctions::get_network_for_address, GNUNET_TRANSPORT_PluginFunctions::get_session, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, http_common_plugin_address_pretty_printer(), http_common_plugin_string_to_address(), HTTP_OPTIONS_TCP_STEALTH, http_server_plugin_address_suggested(), http_server_plugin_address_to_string(), http_server_plugin_disconnect_peer(), http_server_plugin_disconnect_session(), http_server_plugin_get_network(), http_server_plugin_get_network_for_address(), http_server_plugin_get_session(), http_server_plugin_send(), http_server_plugin_setup_monitor(), http_server_plugin_update_inbound_delay(), http_server_plugin_update_session_timeout(), http_server_query_keepalive_factor(), LIBGNUNET_PLUGIN_TRANSPORT_DONE, LOG, plugin, GNUNET_TRANSPORT_PluginFunctions::query_keepalive_factor, GNUNET_TRANSPORT_PluginFunctions::send, server_check_ipv6_support(), server_configure_plugin(), server_start(), server_start_report_addresses(), GNUNET_TRANSPORT_PluginFunctions::setup_monitor, GNUNET_TRANSPORT_PluginFunctions::string_to_address, GNUNET_TRANSPORT_PluginFunctions::update_inbound_delay, GNUNET_TRANSPORT_PluginFunctions::update_session_timeout, and URL_REGEX.