application to provide an integrated hostlist HTTP server More...
#include "platform.h"
#include "gnunet_common.h"
#include <microhttpd.h>
#include "gnunet-daemon-hostlist_server.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet_peerstore_service.h"
#include "gnunet-daemon-hostlist.h"
#include "gnunet_resolver_service.h"
#include "gnunet_mhd_compat.h"
#include <jansson.h>
#include <strings.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 *resp) |
Add headers to a request indicating that we allow Cross-Origin Resource Sharing. More... | |
static struct MHD_Response * | build_json_response (const struct HostSet *bu) |
static void | finish_response () |
Function that assembles our response. More... | |
static enum GNUNET_GenericReturnValue | host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
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 int | header_iterator (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) |
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_PEERSTORE_Record *record, const char *err_msg) |
PEERSTORE 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... | |
static void | error_cb (void *cls) |
static void | sync_cb (void *cls) |
static void | start_notify (void *cls) |
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 | |
struct GNUNET_CONTAINER_MultiPeerMap * | hellos |
Map with hellos we build the hostlist with. More... | |
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... | |
struct GNUNET_SCHEDULER_Task * | peerstore_notify_task |
The task to delayed start the notification process initially. More... | |
static struct GNUNET_PEERSTORE_Monitor * | peerstore_notify |
Our peerstore notification context. 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 MHD_Response * | response_json |
Our json response. More... | |
static struct GNUNET_PEERSTORE_Handle * | peerstore |
Handle to the PEERSTORE 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 44 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 155 of file gnunet-daemon-hostlist_server.c.
References GNUNET_assert.
Referenced by access_handler_callback(), and finish_response().
|
static |
Definition at line 171 of file gnunet-daemon-hostlist_server.c.
References HostSet::data, GNUNET_free, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_msg(), GNUNET_HELLO_parser_to_url(), GNUNET_MessageHeader::size, and size.
Referenced by finish_response().
|
static |
Function that assembles our response.
Definition at line 206 of file gnunet-daemon-hostlist_server.c.
References add_cors_headers(), build_json_response(), builder, daemon_handle_v4, daemon_handle_v6, HostSet::data, gettext_noop, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_STATISTICS_set(), GNUNET_YES, response, response_json, HostSet::size, and stats.
Referenced by process_notify().
|
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 249 of file gnunet-daemon-hostlist_server.c.
References builder, HostSet::data, gettext_noop, GNUNET_array_grow, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, MAX_BYTES_PER_HOSTLISTS, GNUNET_MessageHeader::size, HostSet::size, stats, and value.
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 |
Definition at line 315 of file gnunet-daemon-hostlist_server.c.
References GNUNET_YES, key, and value.
Referenced by access_handler_callback().
|
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 366 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_NO, GNUNET_STATISTICS_update(), GNUNET_YES, header_iterator(), MHD_HTTP_OK, response, response_json, 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 464 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 503 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, and size.
Referenced by GNUNET_HOSTLIST_server_start().
|
static |
PEERSTORE 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 545 of file gnunet-daemon-hostlist_server.c.
References _, builder, HostSet::data, finish_response(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_PEERSTORE_monitor_next(), GNUNET_YES, hellos, host_processor(), map_size, peerstore_notify, record(), GNUNET_MessageHeader::size, and HostSet::size.
Referenced by start_notify().
|
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 639 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 616 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().
|
static |
Definition at line 679 of file gnunet-daemon-hostlist_server.c.
References GNUNET_ERROR_TYPE_WARNING, and GNUNET_log.
Referenced by start_notify().
|
static |
Definition at line 687 of file gnunet-daemon-hostlist_server.c.
References GNUNET_ERROR_TYPE_WARNING, and GNUNET_log.
Referenced by start_notify().
|
static |
Definition at line 695 of file gnunet-daemon-hostlist_server.c.
References cfg, error_cb(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_PEERSTORE_HELLO_KEY, GNUNET_PEERSTORE_monitor_start(), GNUNET_YES, peerstore_notify, process_notify(), and sync_cb().
Referenced by GNUNET_HOSTLIST_server_start().
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 725 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_CONTAINER_multipeermap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, hellos, hostlist_task_v4, hostlist_task_v6, hostlist_uri, ipv4, ipv6, MAX_URL_LEN, peerstore, peerstore_notify_task, port, prepare_daemon(), server_ch, size, st, start_notify(), and stats.
Referenced by run().
void GNUNET_HOSTLIST_server_stop | ( | void | ) |
Stop server offering our hostlist.
Definition at line 939 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_PEERSTORE_disconnect(), GNUNET_PEERSTORE_monitor_stop(), GNUNET_SCHEDULER_cancel(), hostlist_task_v4, hostlist_task_v6, peerstore, peerstore_notify, peerstore_notify_task, response, response_json, and stats.
Referenced by cleaning_task().
struct GNUNET_CONTAINER_MultiPeerMap* hellos |
Map with hellos we build the hostlist with.
Definition at line 50 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), and process_notify().
|
static |
Handle to the HTTP server as provided by libmicrohttpd for IPv6.
Definition at line 55 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 60 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 65 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), GNUNET_HOSTLIST_server_stop(), and start_notify().
|
static |
For keeping statistics.
Definition at line 70 of file gnunet-daemon-hostlist_server.c.
Referenced by access_handler_callback(), adv_transmit(), 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 75 of file gnunet-daemon-hostlist_server.c.
Referenced by connect_handler(), GNUNET_HOSTLIST_server_start(), and GNUNET_HOSTLIST_server_stop().
struct GNUNET_SCHEDULER_Task* peerstore_notify_task |
The task to delayed start the notification process initially.
We like to give transport some time to give us our hello to distribute it.
Definition at line 81 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), and GNUNET_HOSTLIST_server_stop().
|
static |
Our peerstore notification context.
We use notification to instantly learn about new peers as they are discovered.
Definition at line 87 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_stop(), process_notify(), and start_notify().
|
static |
Our primary task for IPv4.
Definition at line 92 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 97 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 102 of file gnunet-daemon-hostlist_server.c.
Referenced by accept_policy_callback(), access_handler_callback(), callback_found_message(), clean_result(), do_error(), 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(), handle_room_sync(), on_message(), open_static_resource(), and reconnect_task().
|
static |
Our json response.
Definition at line 107 of file gnunet-daemon-hostlist_server.c.
Referenced by access_handler_callback(), finish_response(), and GNUNET_HOSTLIST_server_stop().
|
static |
Handle to the PEERSTORE service.
Definition at line 112 of file gnunet-daemon-hostlist_server.c.
Referenced by GNUNET_HOSTLIST_server_start(), and GNUNET_HOSTLIST_server_stop().
|
static |
Set if we are allowed to advertise our hostlist to others.
Definition at line 117 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 122 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 145 of file gnunet-daemon-hostlist_server.c.
Referenced by finish_response(), GCH_get_mine(), GNUNET_HELLO_builder_add_address(), GNUNET_HELLO_builder_del_address(), GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_from_parser(), GNUNET_HELLO_builder_new(), GNUNET_HELLO_builder_to_block(), GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_HELLO_builder_to_env(), GNUNET_HELLO_builder_to_env_(), GNUNET_HELLO_builder_to_url(), GNUNET_HELLO_builder_to_url2(), GNUNET_HOSTLIST_server_stop(), got_hello(), host_processor(), process_notify(), and sign_hello().