HTTP daemon that offers first-come-first-serve GNS domain registration. More...
#include "platform.h"
#include <microhttpd.h>
#include "gnunet_util_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_namestore_service.h"
#include "gnunet_mhd_compat.h"
#include "gnunet_json_lib.h"
Go to the source code of this file.
Data Structures | |
struct | StaticPage |
Structure representing a static page. More... | |
struct | RequestData |
Structure containing some request-specific data. More... | |
Functions | |
static void | do_shutdown (void *cls) |
Task ran at shutdown to clean up everything. More... | |
static void | do_httpd (void *cls) |
Called when the HTTP server has some pending operations. More... | |
static void | run_httpd (void) |
Schedule a task to run MHD. More... | |
static void | run_httpd_now (void) |
static char * | make_json (const char *key, const char *value,...) |
Generate a JSON object. More... | |
static void | search_error_cb (void *cls) |
The namestore search task failed. More... | |
static void | search_done_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int count, const struct GNUNET_GNSRECORD_Data *d) |
The lookup terminated with some results. More... | |
static void | register_error_cb (void *cls) |
An error occurred while registering a name. More... | |
static void | register_done_cb (void *cls, enum GNUNET_ErrorCode ec) |
static void | register_do_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *label, unsigned int count, const struct GNUNET_GNSRECORD_Data *d) |
Attempt to register the requested name. More... | |
static void | iterate_error_cb (void *cls) |
An error occurred while iterating the namestore. More... | |
static void | iterate_do_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *label, unsigned int count, const struct GNUNET_GNSRECORD_Data *d) |
A block was received from the namestore. More... | |
static void | iterate_done_cb (void *cls) |
All entries in the namestore have been iterated over. More... | |
static MHD_RESULT | serve_json (struct MHD_Connection *c, char *body, size_t length, int code) |
Generate a response containing JSON and send it to the client. More... | |
static MHD_RESULT | create_response (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 **ptr) |
Send a response back to a connected client. More... | |
static void | completed_cb (void *cls, struct MHD_Connection *connection, void **ptr, enum MHD_RequestTerminationCode status) |
Called when a request is completed. More... | |
static void | identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name) |
Called for each ego provided by the identity service. More... | |
static struct StaticPage * | open_static_page (const char *name, const char *basedir) |
Open a file on disk and generate a response object for it. More... | |
static void | run_service (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Called after the service is up. More... | |
int | main (int argc, char *const *argv) |
The main function of the fcfs daemon. More... | |
Variables | |
static char * | zone = NULL |
Name of the zone being managed. More... | |
static unsigned long long | port = 18080 |
The port the daemon is listening to for HTTP requests. More... | |
static struct GNUNET_NAMESTORE_Handle * | namestore = NULL |
Connection with the namestore service. More... | |
static struct GNUNET_IDENTITY_Handle * | identity = NULL |
Connection with the identity service. More... | |
static const struct GNUNET_IDENTITY_PrivateKey * | zone_key = NULL |
Private key of the zone. More... | |
static struct MHD_Daemon * | httpd = NULL |
The HTTP daemon. More... | |
static struct GNUNET_SCHEDULER_Task * | httpd_task = NULL |
Task executing the HTTP daemon. More... | |
static struct StaticPage * | main_page = NULL |
The main page, a.k.a. More... | |
static struct StaticPage * | notfound_page = NULL |
Page indicating the requested resource could not be found. More... | |
static struct StaticPage * | forbidden_page = NULL |
Page indicating the requested resource could not be accessed, and other errors. More... | |
static struct GNUNET_TIME_Relative | record_exp |
The relative expiration time for added records. More... | |
HTTP daemon that offers first-come-first-serve GNS domain registration.
Definition in file gnunet-namestore-fcfsd.c.
|
static |
Task ran at shutdown to clean up everything.
cls | unused |
Definition at line 178 of file gnunet-namestore-fcfsd.c.
References forbidden_page, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_NAMESTORE_disconnect(), GNUNET_SCHEDULER_cancel(), StaticPage::handle, httpd, httpd_task, identity, main_page, namestore, notfound_page, and StaticPage::response.
Referenced by run_service().
|
static |
Called when the HTTP server has some pending operations.
cls | unused |
Definition at line 284 of file gnunet-namestore-fcfsd.c.
References httpd, httpd_task, and run_httpd().
Referenced by run_httpd(), and run_httpd_now().
|
static |
Schedule a task to run MHD.
Definition at line 237 of file gnunet-namestore-fcfsd.c.
References do_httpd(), 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_relative_multiply(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_MILLISECONDS, httpd, httpd_task, max, and timeout.
Referenced by do_httpd(), and identity_cb().
|
static |
Definition at line 293 of file gnunet-namestore-fcfsd.c.
References do_httpd(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and httpd_task.
Referenced by iterate_do_cb(), iterate_error_cb(), register_do_cb(), register_done_cb(), register_error_cb(), search_done_cb(), and search_error_cb().
|
static |
Generate a JSON object.
key | the key for the first element |
value | the value for the first element |
... | key-value pairs of the object, terminated by NULL |
Definition at line 313 of file gnunet-namestore-fcfsd.c.
References consensus-simulation::args, key, and value.
Referenced by create_response(), iterate_do_cb(), iterate_error_cb(), register_do_cb(), register_done_cb(), register_error_cb(), search_done_cb(), and search_error_cb().
|
static |
The namestore search task failed.
cls | the request data |
Definition at line 367 of file gnunet-namestore-fcfsd.c.
References _, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, rd, and run_httpd_now().
Referenced by create_response().
|
static |
The lookup terminated with some results.
cls | closure |
zone | the private key of the zone |
label | the result label |
count | number of records found |
d | records found |
Definition at line 391 of file gnunet-namestore-fcfsd.c.
References make_json(), MHD_HTTP_OK, rd, run_httpd_now(), and zone.
Referenced by create_response().
|
static |
An error occurred while registering a name.
cls | the connection |
Definition at line 420 of file gnunet-namestore-fcfsd.c.
References _, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, rd, and run_httpd_now().
Referenced by iterate_done_cb().
|
static |
Definition at line 436 of file gnunet-namestore-fcfsd.c.
References _, GNUNET_EC_NONE, GNUNET_ERROR_TYPE_WARNING, GNUNET_ErrorCode_get_hint(), GNUNET_log, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_OK, rd, and run_httpd_now().
Referenced by register_do_cb().
|
static |
Attempt to register the requested name.
cls | the connection |
key | the zone key |
label | name of the record |
count | number of records found |
d | records |
Definition at line 480 of file gnunet-namestore-fcfsd.c.
References _, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_GNSRECORD_data_from_identity(), GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_log, GNUNET_NAMESTORE_records_store(), GNUNET_OK, key, make_json(), MHD_HTTP_FORBIDDEN, MHD_HTTP_INTERNAL_SERVER_ERROR, namestore, rd, record_exp, GNUNET_GNSRECORD_Data::record_type, register_done_cb(), GNUNET_TIME_Relative::rel_value_us, run_httpd_now(), and zone_key.
Referenced by iterate_done_cb().
|
static |
An error occurred while iterating the namestore.
cls | the connection |
Definition at line 554 of file gnunet-namestore-fcfsd.c.
References _, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, rd, and run_httpd_now().
Referenced by create_response().
|
static |
A block was received from the namestore.
cls | the connection |
key | the zone key |
label | the records' label |
count | number of records found |
d | the found records |
Definition at line 579 of file gnunet-namestore-fcfsd.c.
References _, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_NAMESTORE_zone_iterator_next(), key, make_json(), MHD_HTTP_FORBIDDEN, rd, and run_httpd_now().
Referenced by create_response().
|
static |
All entries in the namestore have been iterated over.
cls | the connection |
Definition at line 620 of file gnunet-namestore-fcfsd.c.
References GNUNET_NAMESTORE_zone_to_name(), namestore, rd, register_do_cb(), register_error_cb(), and zone_key.
Referenced by create_response().
|
static |
Generate a response containing JSON and send it to the client.
c | the connection |
body | the response body |
length | the body length in bytes |
code | the response code |
Definition at line 647 of file gnunet-namestore-fcfsd.c.
References MHD_RESULT, and response.
Referenced by create_response().
|
static |
Send a response back to a connected client.
cls | unused |
connection | the connection with the client |
url | the requested address |
method | the HTTP method used |
version | the protocol version (including the "HTTP/" part) |
upload_data | data sent with a POST request |
upload_data_size | length in bytes of the POST data |
ptr | used to pass data between request handling phases |
Definition at line 676 of file gnunet-namestore-fcfsd.c.
References _, forbidden_page, GNUNET_ERROR_TYPE_WARNING, GNUNET_IDENTITY_public_key_from_string(), GNUNET_JSON_post_parser(), GNUNET_JSON_post_parser_cleanup(), GNUNET_JSON_PR_CONTINUE, GNUNET_JSON_PR_JSON_INVALID, GNUNET_JSON_PR_OUT_OF_MEMORY, GNUNET_JSON_PR_REQUEST_TOO_LARGE, GNUNET_log, GNUNET_NAMESTORE_records_lookup(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_new, GNUNET_OK, iterate_do_cb(), iterate_done_cb(), iterate_error_cb(), key, main_page, make_json(), MHD_HTTP_BAD_REQUEST, MHD_HTTP_FORBIDDEN, MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_NOT_FOUND, MHD_HTTP_NOT_IMPLEMENTED, MHD_HTTP_OK, MHD_HTTP_PAYLOAD_TOO_LARGE, name, namestore, notfound_page, RequestData::ptr, rd, StaticPage::response, result, search_done_cb(), search_error_cb(), serve_json(), and zone_key.
Referenced by identity_cb().
|
static |
Called when a request is completed.
cls | unused |
connection | the connection |
ptr | connection-specific data |
status | status code |
Definition at line 890 of file gnunet-namestore-fcfsd.c.
References GNUNET_free, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_zone_iteration_stop(), RequestData::ptr, rd, and status.
Referenced by identity_cb().
|
static |
Called for each ego provided by the identity service.
cls | closure |
ego | the ego |
ctx | application-provided data for the ego |
name | the ego name |
Definition at line 944 of file gnunet-namestore-fcfsd.c.
References _, completed_cb(), create_response(), ctx, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_SCHEDULER_shutdown(), httpd, name, port, run_httpd(), zone, and zone_key.
Referenced by run_service().
|
static |
Open a file on disk and generate a response object for it.
name | name of the file to open |
basedir | directory where the file is located |
Definition at line 1002 of file gnunet-namestore-fcfsd.c.
References removetrailingwhitespace::f, GNUNET_asprintf(), GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_free, GNUNET_new, GNUNET_SYSERR, StaticPage::handle, name, response, StaticPage::response, StaticPage::size, and size.
Referenced by run_service().
|
static |
Called after the service is up.
cls | closure |
args | remaining command line arguments |
cfgfile | name of the configuration file |
cfg | the service configuration |
Definition at line 1052 of file gnunet-namestore-fcfsd.c.
References _, consensus-simulation::args, cfg, do_shutdown(), forbidden_page, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_log_setup(), GNUNET_NAMESTORE_connect(), GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), identity, identity_cb(), main_page, namestore, notfound_page, open_static_page(), port, and record_exp.
Referenced by main().
int main | ( | int | argc, |
char *const * | argv | ||
) |
The main function of the fcfs daemon.
argc | number of arguments from the command line |
argv | the command line arguments |
Definition at line 1137 of file gnunet-namestore-fcfsd.c.
References _, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_mandatory(), GNUNET_GETOPT_option_string(), GNUNET_OK, GNUNET_PROGRAM_run(), options, run_service(), and zone.
|
static |
Name of the zone being managed.
Definition at line 119 of file gnunet-namestore-fcfsd.c.
Referenced by attr_iter_cb(), cache_nick(), check_credential_iteration_start(), del_monitor(), DID_create(), do_flood(), do_shutdown(), get_nick_record(), GNS_resolver_lookup(), GNUNET_GNS_lookup(), GNUNET_GNS_lookup_limited(), GNUNET_GNSRECORD_query_from_private_key(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_NAMESTORE_zone_iteration_start2(), GNUNET_NAMESTORE_zone_monitor_start(), GNUNET_NAMESTORE_zone_monitor_start2(), GNUNET_NAMESTORE_zone_to_name(), handle_dns_request(), handle_gns_redirect_result(), handle_iteration_start(), handle_lookup(), handle_monitor_event(), handle_monitor_start(), handle_record_lookup(), handle_record_store(), handle_reverse_lookup(), handle_zone_to_name(), handle_zone_to_name_response(), identity_cb(), main(), namestore_flat_iterate_records(), namestore_flat_lookup_records(), namestore_flat_zone_to_name(), namestore_postgres_edit_records(), ns_lookup_error_cb(), ns_lookup_result_cb(), queue(), recursive_gns2dns_resolution(), and search_done_cb().
|
static |
The port the daemon is listening to for HTTP requests.
Definition at line 124 of file gnunet-namestore-fcfsd.c.
Referenced by identity_cb(), and run_service().
|
static |
Connection with the namestore service.
Definition at line 129 of file gnunet-namestore-fcfsd.c.
Referenced by create_response(), do_shutdown(), iterate_done_cb(), register_do_cb(), and run_service().
|
static |
Connection with the identity service.
Definition at line 134 of file gnunet-namestore-fcfsd.c.
Referenced by do_shutdown(), and run_service().
|
static |
Private key of the zone.
Definition at line 139 of file gnunet-namestore-fcfsd.c.
Referenced by check_monitor_start(), check_zone_to_name(), collect_orphans(), collect_zone_records_to_purge(), create_response(), display_record(), display_record_iterator(), display_record_lookup(), display_record_monitor(), get_existing_record(), identity_cb(), iterate_done_cb(), namestore_flat_store_records(), purge_orphans_iterator(), purge_zone_iterator(), register_do_cb(), send_lookup_response_with_filter(), and zone_iterate_proc().
|
static |
The HTTP daemon.
Definition at line 144 of file gnunet-namestore-fcfsd.c.
Referenced by do_httpd(), do_shutdown(), identity_cb(), and run_httpd().
|
static |
Task executing the HTTP daemon.
Definition at line 149 of file gnunet-namestore-fcfsd.c.
Referenced by do_httpd(), do_shutdown(), run_httpd(), and run_httpd_now().
|
static |
The main page, a.k.a.
"index.html"
Definition at line 154 of file gnunet-namestore-fcfsd.c.
Referenced by create_response(), do_shutdown(), and run_service().
|
static |
Page indicating the requested resource could not be found.
Definition at line 159 of file gnunet-namestore-fcfsd.c.
Referenced by create_response(), do_shutdown(), and run_service().
|
static |
Page indicating the requested resource could not be accessed, and other errors.
Definition at line 165 of file gnunet-namestore-fcfsd.c.
Referenced by create_response(), do_shutdown(), and run_service().
|
static |
The relative expiration time for added records.
Definition at line 165 of file gnunet-namestore-fcfsd.c.
Referenced by register_do_cb(), and run_service().