application to provide an integrated hostlist HTTP server More...
#include "platform.h"
#include <microhttpd.h>
#include "gnunet-daemon-hostlist_server.h"
#include "gnunet_hello_lib.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet-daemon-hostlist.h"
#include "gnunet_resolver_service.h"
#include "gnunet_mhd_compat.h"
Go to the source code of this file.
Data Structures | |
struct | HostSet |
Context for host_processor(). More... | |
Macros | |
#define | GNUNET_ADV_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
How long until our hostlist advertisement transmission via CORE should time out? More... | |
Functions | |
static void | add_cors_headers (struct MHD_Response *response) |
Add headers to a request indicating that we allow Cross-Origin Resource Sharing. More... | |
static void | finish_response () |
Function that assembles our response. More... | |
static int | check_has_addr (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration) |
Set cls to GNUNET_YES (we have an address!). More... | |
static void | host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
Callback that processes each of the known HELLOs for the hostlist response construction. More... | |
static MHD_RESULT | accept_policy_callback (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
Hostlist access policy (very permissive, allows everything). More... | |
static MHD_RESULT | access_handler_callback (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) |
Main request handler. More... | |
static void | adv_transmit (struct GNUNET_MQ_Handle *mq) |
Handler called by CORE when CORE is ready to transmit message. More... | |
static void * | connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq) |
Method called whenever a given peer connects. More... | |
static void | process_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
PEERINFO calls this function to let us know about a possible peer that we might want to connect to. More... | |
static struct GNUNET_SCHEDULER_Task * | prepare_daemon (struct MHD_Daemon *daemon_handle) |
Function that queries MHD's select sets and starts the task waiting for them. More... | |
static void | run_daemon (void *cls) |
Call MHD to process pending requests and then go back and schedule the next run. More... | |
int | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_STATISTICS_Handle *st, struct GNUNET_CORE_Handle *co, GNUNET_CORE_ConnectEventHandler *server_ch, int advertise) |
Start server offering our hostlist. More... | |
void | GNUNET_HOSTLIST_server_stop () |
Stop server offering our hostlist. More... | |
Variables | |
static struct MHD_Daemon * | daemon_handle_v6 |
Handle to the HTTP server as provided by libmicrohttpd for IPv6. More... | |
static struct MHD_Daemon * | daemon_handle_v4 |
Handle to the HTTP server as provided by libmicrohttpd for IPv4. More... | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Our configuration. More... | |
static struct GNUNET_STATISTICS_Handle * | stats |
For keeping statistics. More... | |
static struct GNUNET_CORE_Handle * | core |
Handle to the core service (NULL until we've connected to it). More... | |
static struct GNUNET_PEERINFO_NotifyContext * | notify |
Handle to the peerinfo notify service (NULL until we've connected to it). More... | |
static struct GNUNET_SCHEDULER_Task * | hostlist_task_v4 |
Our primary task for IPv4. More... | |
static struct GNUNET_SCHEDULER_Task * | hostlist_task_v6 |
Our primary task for IPv6. More... | |
static struct MHD_Response * | response |
Our canonical response. More... | |
static struct GNUNET_PEERINFO_Handle * | peerinfo |
Handle for accessing peerinfo service. More... | |
static int | advertising |
Set if we are allowed to advertise our hostlist to others. More... | |
static char * | hostlist_uri |
Buffer for the hostlist address. More... | |
static struct HostSet * | builder |
NULL if we are not currently iterating over peer information. More... | |
application to provide an integrated hostlist HTTP server
Definition in file gnunet-daemon-hostlist_server.c.
#define GNUNET_ADV_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
How long until our hostlist advertisement transmission via CORE should time out?
Definition at line 42 of file gnunet-daemon-hostlist_server.c.
|
static |
Add headers to a request indicating that we allow Cross-Origin Resource Sharing.
response | response to add headers to |
Definition at line 142 of file gnunet-daemon-hostlist_server.c.
References response.
Referenced by access_handler_callback(), and finish_response().
|
static |
Function that assembles our response.
Definition at line 156 of file gnunet-daemon-hostlist_server.c.
References add_cors_headers(), builder, daemon_handle_v4, daemon_handle_v6, HostSet::data, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_STATISTICS_set(), GNUNET_YES, response, HostSet::size, and stats.
Referenced by host_processor().
|
static |
Set cls to GNUNET_YES (we have an address!).
cls | closure, an int * |
address | the address (ignored) |
expiration | expiration time (call is ignored if this is in the past) |
Definition at line 190 of file gnunet-daemon-hostlist_server.c.
References find_typedefs::arg, expiration, gettext_noop, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, and stats.
Referenced by host_processor().
|
static |
Callback that processes each of the known HELLOs for the hostlist response construction.
cls | closure, NULL |
peer | id of the peer, NULL for last call |
hello | hello message for the peer (can be NULL) |
err_msg | message |
Definition at line 219 of file gnunet-daemon-hostlist_server.c.
References _, builder, check_has_addr(), HostSet::data, finish_response(), gettext_noop, GNUNET_array_grow, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_iterate_addresses(), GNUNET_HELLO_size(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), MAX_BYTES_PER_HOSTLISTS, peer, HostSet::pitr, HostSet::size, and stats.
Referenced by process_notify().
|
static |
Hostlist access policy (very permissive, allows everything).
Returns #MHD_NO only if we are not yet ready to serve.
cls | closure |
addr | address information from the client |
addrlen | length of addr |
Definition at line 299 of file gnunet-daemon-hostlist_server.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and response.
Referenced by GNUNET_HOSTLIST_server_start().
|
static |
Main request handler.
cls | argument given together with the function pointer when the handler was registered with MHD |
connection | |
url | the requested url |
method | the HTTP method used (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, etc.) |
version | the HTTP version string (e.g. #MHD_HTTP_VERSION_1_1) |
upload_data | the data being uploaded (excluding HEADERS, for a POST that fits into memory and that is encoded with a supported encoding, the POST data will NOT be given in upload_data and is instead available as part of #MHD_get_connection_values; very large POST data will be made available incrementally in upload_data) |
upload_data_size | set initially to the size of the upload_data provided; the method must update this value to the number of bytes NOT processed; |
con_cls | pointer that the callback can set to some address and that will be preserved by MHD for future calls for this request; since the access handler may be called many times (e.g. for a PUT/POST operation with plenty of upload data) this allows the application to easily associate some request-specific state. If necessary, this state can be cleaned up in the global #MHD_RequestCompletedCallback (which can be set with the #MHD_OPTION_NOTIFY_COMPLETED). Initially, *con_cls will be NULL. |
Definition at line 350 of file gnunet-daemon-hostlist_server.c.
References _, add_cors_headers(), dummy, gettext_noop, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_STATISTICS_update(), GNUNET_YES, MHD_HTTP_OK, response, and stats.
Referenced by GNUNET_HOSTLIST_server_start().
|
static |
Handler called by CORE when CORE is ready to transmit message.
cls | closure with the const struct GNUNET_PeerIdentity * of the peer we are sending to |
size | size of buffer to copy message to |
buf | buffer to copy message to |
Definition at line 437 of file gnunet-daemon-hostlist_server.c.
References env, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, GNUNET_MQ_env_set_options(), GNUNET_MQ_msg_extra, GNUNET_MQ_PREF_CORK_ALLOWED, GNUNET_MQ_PREF_UNRELIABLE, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), hostlist_uri, mq, and stats.
Referenced by connect_handler().
|
static |
Method called whenever a given peer connects.
cls | closure |
peer | peer identity this notification is about |
mq | queue for transmission to peer |
Definition at line 476 of file gnunet-daemon-hostlist_server.c.
References adv_transmit(), advertising, core, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, hostlist_uri, mq, peer, and size.
Referenced by GNUNET_HOSTLIST_server_start().
|
static |
PEERINFO calls this function to let us know about a possible peer that we might want to connect to.
cls | closure (not used) |
peer | potential peer to connect to |
hello | HELLO for this peer (or NULL) |
err_msg | NULL if successful, otherwise contains error message |
Definition at line 518 of file gnunet-daemon-hostlist_server.c.
References _, builder, HostSet::data, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_PEERINFO_iterate(), GNUNET_PEERINFO_iterate_cancel(), host_processor(), peerinfo, HostSet::pitr, and HostSet::size.
Referenced by GNUNET_HOSTLIST_server_start().
|
static |
Function that queries MHD's select sets and starts the task waiting for them.
daemon_handle | HTTP server to prepare to run |
Definition at line 589 of file gnunet-daemon-hostlist_server.c.
References GNUNET_assert, GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_TIME_UNIT_FOREVER_REL, max, GNUNET_TIME_Relative::rel_value_us, ret, run_daemon(), and timeout.
Referenced by GNUNET_HOSTLIST_server_start(), and run_daemon().
|
static |
Call MHD to process pending requests and then go back and schedule the next run.
cls | the struct MHD_Daemon of the HTTP server to run |
Definition at line 566 of file gnunet-daemon-hostlist_server.c.
References daemon_handle_v4, GNUNET_assert, hostlist_task_v4, hostlist_task_v6, and prepare_daemon().
Referenced by prepare_daemon().
int GNUNET_HOSTLIST_server_start | ( | const struct GNUNET_CONFIGURATION_Handle * | c, |
struct GNUNET_STATISTICS_Handle * | st, | ||
struct GNUNET_CORE_Handle * | co, | ||
GNUNET_CORE_ConnectEventHandler * | server_ch, | ||
int | advertise | ||
) |
Start server offering our hostlist.
c | configuration to use | |
st | statistics handle to use | |
co | core handle to use | |
[out] | server_ch | set to handler for CORE connect events |
advertise | GNUNET_YES if we should advertise our hostlist |
Definition at line 639 of file gnunet-daemon-hostlist_server.c.
References _, accept_policy_callback(), access_handler_callback(), advertising, cfg, connect_handler(), core, daemon_handle_v4, daemon_handle_v6, GNUNET_asprintf(), 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_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PEERINFO_connect(), GNUNET_PEERINFO_notify(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_SYSERR, hostlist_task_v4, hostlist_task_v6, hostlist_uri, hostname, ipv4, ipv6, MAX_URL_LEN, notify, peerinfo, port, prepare_daemon(), process_notify(), server_ch, size, st, and stats.
Referenced by run().
void GNUNET_HOSTLIST_server_stop | ( | void | ) |
Stop server offering our hostlist.
Definition at line 849 of file gnunet-daemon-hostlist_server.c.
References builder, cfg, core, daemon_handle_v4, daemon_handle_v6, HostSet::data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PEERINFO_disconnect(), GNUNET_PEERINFO_iterate_cancel(), GNUNET_PEERINFO_notify_cancel(), GNUNET_SCHEDULER_cancel(), hostlist_task_v4, hostlist_task_v6, notify, peerinfo, HostSet::pitr, response, and stats.
Referenced by cleaning_task().
|
static |
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
Definition at line 49 of file gnunet-daemon-hostlist_server.c.
Referenced by finish_response(), GNUNET_HOSTLIST_server_start(), and GNUNET_HOSTLIST_server_stop().
|
static |
Handle to the HTTP server as provided by libmicrohttpd for IPv4.
Definition at line 54 of file gnunet-daemon-hostlist_server.c.
Referenced by finish_response(), GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), and run_daemon().
|
static |
Our configuration.
Definition at line 59 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), and GNUNET_HOSTLIST_server_stop().
|
static |
For keeping statistics.
Definition at line 64 of file gnunet-daemon-hostlist_server.c.
Referenced by access_handler_callback(), adv_transmit(), check_has_addr(), finish_response(), GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), and host_processor().
|
static |
Handle to the core service (NULL until we've connected to it).
Definition at line 69 of file gnunet-daemon-hostlist_server.c.
Referenced by connect_handler(), GNUNET_HOSTLIST_server_start(), and GNUNET_HOSTLIST_server_stop().
|
static |
Handle to the peerinfo notify service (NULL until we've connected to it).
Definition at line 74 of file gnunet-daemon-hostlist_server.c.
Referenced by connect_error(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), iterate_notify_about_members(), join_room_locally(), notify_about_members(), process_notify(), signal_transmit_error(), transmit_ready(), and transmit_timeout().
|
static |
Our primary task for IPv4.
Definition at line 79 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), and run_daemon().
|
static |
Our primary task for IPv6.
Definition at line 84 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), and run_daemon().
|
static |
Our canonical response.
Definition at line 89 of file gnunet-daemon-hostlist_server.c.
Referenced by accept_policy_callback(), access_handler_callback(), add_cors_headers(), clean_result(), do_error(), do_peer_connect(), finish_response(), get_cont(), GNUNET_CURL_perform2(), GNUNET_HOSTLIST_server_stop(), GNUNET_SCALARPRODUCT_accept_computation(), GNUNET_SCALARPRODUCT_start_computation(), handle_room_close(), handle_room_entry(), handle_room_open(), open_static_page(), open_static_resource(), reconnect_task(), serve_json(), and server_access_cb().
|
static |
Handle for accessing peerinfo service.
Definition at line 94 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), and process_notify().
|
static |
Set if we are allowed to advertise our hostlist to others.
Definition at line 99 of file gnunet-daemon-hostlist_server.c.
Referenced by connect_handler(), and GNUNET_HOSTLIST_server_start().
|
static |
Buffer for the hostlist address.
Definition at line 104 of file gnunet-daemon-hostlist_server.c.
Referenced by adv_transmit(), connect_handler(), and GNUNET_HOSTLIST_server_start().
|
static |
NULL if we are not currently iterating over peer information.
Definition at line 132 of file gnunet-daemon-hostlist_server.c.
Referenced by finish_response(), GNUNET_HELLO_builder_add_address(), GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_new(), GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_HELLO_builder_to_env(), GNUNET_HOSTLIST_server_stop(), hash_addresses(), host_processor(), process_notify(), and sign_hello().