![]() |
GNUnet
0.11.x
|
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, int32_t status, const char *emsg) |
A name/key pair has been successfully registered, or maybe not. More... | |
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 _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, make_json(), run_httpd_now(), and RequestData::searching.
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 RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, make_json(), run_httpd_now(), RequestData::searching, 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 _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, make_json(), run_httpd_now(), and RequestData::searching.
Referenced by iterate_done_cb().
|
static |
A name/key pair has been successfully registered, or maybe not.
cls | the connection |
status | result of the operation |
emsg | error message if any |
Definition at line 443 of file gnunet-namestore-fcfsd.c.
References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_SYSERR, make_json(), RequestData::register_name, run_httpd_now(), RequestData::searching, and status.
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 487 of file gnunet-namestore-fcfsd.c.
References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, 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, RequestData::key, make_json(), namestore, record_exp, GNUNET_GNSRECORD_Data::record_type, register_done_cb(), RequestData::register_key, RequestData::register_name, GNUNET_TIME_Relative::rel_value_us, run_httpd_now(), RequestData::searching, and zone_key.
Referenced by iterate_done_cb().
|
static |
An error occurred while iterating the namestore.
cls | the connection |
Definition at line 561 of file gnunet-namestore-fcfsd.c.
References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, RequestData::iterating, make_json(), 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 586 of file gnunet-namestore-fcfsd.c.
References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_NAMESTORE_zone_iterator_next(), RequestData::iterating, key, make_json(), RequestData::register_name, and run_httpd_now().
Referenced by create_response().
|
static |
All entries in the namestore have been iterated over.
cls | the connection |
Definition at line 627 of file gnunet-namestore-fcfsd.c.
References GNUNET_NAMESTORE_zone_to_name(), RequestData::iterating, RequestData::key, namestore, register_do_cb(), register_error_cb(), RequestData::searching, 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 654 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 683 of file gnunet-namestore-fcfsd.c.
References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, 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(), RequestData::iterating, key, RequestData::key, main_page, make_json(), name, namestore, notfound_page, RequestData::ptr, RequestData::register_key, RequestData::register_name, StaticPage::response, result, search_done_cb(), search_error_cb(), RequestData::searching, 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 897 of file gnunet-namestore-fcfsd.c.
References RequestData::body, GNUNET_free, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_zone_iteration_stop(), RequestData::iterating, RequestData::ptr, RequestData::register_key, RequestData::register_name, RequestData::searching, 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 951 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 1009 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 1059 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 @parsm argv the command line arguments |
Definition at line 1144 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(), cred_iter_cb(), del_monitor(), 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_monitor_start(), GNUNET_NAMESTORE_zone_to_name(), handle_dns_request(), handle_gns_redirect_result(), handle_monitor_event(), handle_reverse_lookup(), identity_cb(), main(), namestore_flat_iterate_records(), namestore_flat_lookup_records(), namestore_flat_zone_to_name(), namestore_postgres_iterate_records(), namestore_postgres_lookup_records(), namestore_postgres_zone_to_name(), namestore_sqlite_iterate_records(), namestore_sqlite_lookup_records(), namestore_sqlite_zone_to_name(), 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 create_response(), display_record_iterator(), display_record_lookup(), display_record_monitor(), get_existing_record(), get_records_and_call_iterator(), handle_zone_to_name_it(), identity_cb(), iterate_done_cb(), monitor_iterate_cb(), namestore_flat_store_records(), namestore_postgres_store_records(), namestore_sqlite_store_records(), refresh_block(), register_do_cb(), send_lookup_response(), 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().