GNUnet  0.11.x
Data Structures | Functions | Variables
gnunet-namestore-fcfsd.c File Reference

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"
Include dependency graph for gnunet-namestore-fcfsd.c:

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 StaticPageopen_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_Handlenamestore = NULL
 Connection with the namestore service. More...
 
static struct GNUNET_IDENTITY_Handleidentity = NULL
 Connection with the identity service. More...
 
static const struct GNUNET_IDENTITY_PrivateKeyzone_key = NULL
 Private key of the zone. More...
 
static struct MHD_Daemon * httpd = NULL
 The HTTP daemon. More...
 
static struct GNUNET_SCHEDULER_Taskhttpd_task = NULL
 Task executing the HTTP daemon. More...
 
static struct StaticPagemain_page = NULL
 The main page, a.k.a. More...
 
static struct StaticPagenotfound_page = NULL
 Page indicating the requested resource could not be found. More...
 
static struct StaticPageforbidden_page = NULL
 Page indicating the requested resource could not be accessed, and other errors. More...
 

Detailed Description

HTTP daemon that offers first-come-first-serve GNS domain registration.

Author
Christian Grothoff

Definition in file gnunet-namestore-fcfsd.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task ran at shutdown to clean up everything.

Parameters
clsunused

Definition at line 173 of file gnunet-namestore-fcfsd.c.

174 {
175  /* We cheat a bit here: the file descriptor is implicitly closed by MHD, so
176  calling `GNUNET_DISK_file_close' would generate a spurious warning message
177  in the log. Since that function does nothing but close the descriptor and
178  free the allocated memory, After destroying the response all that's left to
179  do is call `GNUNET_free'. */
180  if (NULL != main_page)
181  {
182  MHD_destroy_response (main_page->response);
185  }
186  if (NULL != notfound_page)
187  {
188  MHD_destroy_response (notfound_page->response);
191  }
192  if (NULL != forbidden_page)
193  {
194  MHD_destroy_response (forbidden_page->response);
197  }
198 
199  if (NULL != namestore)
200  {
202  }
203 
204  if (NULL != identity)
205  {
207  }
208 }
static struct GNUNET_NAMESTORE_Handle * namestore
Connection with the namestore service.
static struct StaticPage * main_page
The main page, a.k.a.
static struct StaticPage * notfound_page
Page indicating the requested resource could not be found.
static struct StaticPage * forbidden_page
Page indicating the requested resource could not be accessed, and other errors.
static struct GNUNET_IDENTITY_Handle * identity
Connection with the identity service.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
struct GNUNET_DISK_FileHandle * handle
Handle to file on disk.
struct MHD_Response * response
Cached response object to send to clients.

References forbidden_page, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_NAMESTORE_disconnect(), StaticPage::handle, identity, main_page, namestore, notfound_page, and StaticPage::response.

Referenced by run_service().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_httpd()

static void do_httpd ( void *  cls)
static

Called when the HTTP server has some pending operations.

Parameters
clsunused

Definition at line 270 of file gnunet-namestore-fcfsd.c.

271 {
272  httpd_task = NULL;
273  MHD_run (httpd);
274  run_httpd ();
275 }
static struct MHD_Daemon * httpd
The HTTP daemon.
static void run_httpd(void)
Schedule a task to run MHD.
static struct GNUNET_SCHEDULER_Task * httpd_task
Task executing the HTTP daemon.

References httpd, httpd_task, and run_httpd().

Referenced by run_httpd(), and run_httpd_now().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_httpd()

static void run_httpd ( void  )
static

Schedule a task to run MHD.

Definition at line 223 of file gnunet-namestore-fcfsd.c.

224 {
225  fd_set rs;
226  fd_set ws;
227  fd_set es;
228 
232 
233  FD_ZERO (&rs);
234  FD_ZERO (&ws);
235  FD_ZERO (&es);
236 
237  int max = -1;
238  GNUNET_assert (MHD_YES == MHD_get_fdset (httpd, &rs, &ws, &es, &max));
239 
240  unsigned MHD_LONG_LONG timeout = 0;
242  if (MHD_YES == MHD_get_timeout (httpd, &timeout))
243  {
245  timeout);
246  }
247 
248  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
249  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
250  GNUNET_NETWORK_fdset_copy_native (ges, &es, max + 1);
251 
253  gtime,
254  grs,
255  gws,
256  &do_httpd,
257  NULL);
261 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static void do_httpd(void *cls)
Called when the HTTP server has some pending operations.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1245
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1261
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1115
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1841
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311
#define max(x, y)
collection of IO descriptors
Time for relative time used by GNUnet, in microseconds.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_httpd_now()

static void run_httpd_now ( void  )
static

Definition at line 279 of file gnunet-namestore-fcfsd.c.

280 {
281  if (NULL != httpd_task)
282  {
284  httpd_task = NULL;
285  }
287 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_json()

static char* make_json ( const char *  key,
const char *  value,
  ... 
)
static

Generate a JSON object.

Parameters
keythe key for the first element
valuethe value for the first element
...key-value pairs of the object, terminated by NULL
Returns
a JSON string (allocated)

Definition at line 299 of file gnunet-namestore-fcfsd.c.

300 {
301  va_list args;
302  va_start (args, value);
303 
304  json_t *obj = NULL;
305 
306  obj = json_object ();
307  if ((NULL == key) || (NULL == value))
308  {
309  va_end (args);
310  return json_dumps (obj, JSON_COMPACT);
311  }
312 
313  json_object_set (obj, key, json_string (value));
314 
315  char *k = va_arg (args, char *);
316  if (NULL == k)
317  {
318  va_end (args);
319  return json_dumps (obj, JSON_COMPACT);
320  }
321  char *v = va_arg (args, char *);
322  if (NULL == v)
323  {
324  va_end (args);
325  return json_dumps (obj, JSON_COMPACT);
326  }
327 
328  while (NULL != k && NULL != v)
329  {
330  json_object_set (obj, k, json_string (v));
331  k = va_arg (args, char *);
332  if (NULL != k)
333  {
334  v = va_arg (args, char *);
335  }
336  }
337 
338  va_end (args);
339 
340  char *json = json_dumps (obj, JSON_COMPACT);
341  json_decref (obj);
342 
343  return json;
344 }
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.

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().

Here is the caller graph for this function:

◆ search_error_cb()

static void search_error_cb ( void *  cls)
static

The namestore search task failed.

Parameters
clsthe request data

Definition at line 353 of file gnunet-namestore-fcfsd.c.

354 {
355  struct RequestData *rd = cls;
356  MHD_resume_connection (rd->c);
357  rd->searching = NULL;
358  rd->body = make_json ("error", "true",
359  "message", _ ("can not search the namestore"),
360  NULL);
361  rd->body_length = strlen (rd->body);
362  rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR;
363  run_httpd_now ();
364 }
static void run_httpd_now(void)
static char * make_json(const char *key, const char *value,...)
Generate a JSON object.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
Structure containing some request-specific data.
size_t body_length
Length in bytes of the body.
int code
Response code.
struct MHD_Connection * c
The connection this request was sent in.
char * body
Body of the response object.
struct GNUNET_NAMESTORE_QueueEntry * searching
Task started to search for an entry in the namestore.

References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, make_json(), run_httpd_now(), and RequestData::searching.

Referenced by create_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_done_cb()

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 
)
static

The lookup terminated with some results.

Parameters
clsclosure
zonethe private key of the zone
labelthe result label
countnumber of records found
drecords found

Definition at line 377 of file gnunet-namestore-fcfsd.c.

382 {
383  (void) zone;
384  (void) d;
385 
386  struct RequestData *rd = cls;
387  MHD_resume_connection (rd->c);
388 
389  rd->searching = NULL;
390  rd->body = make_json ("error", "false",
391  "free", (0 == count) ? "true" : "false",
392  NULL);
393  rd->body_length = strlen (rd->body);
394  rd->code = MHD_HTTP_OK;
395 
396  run_httpd_now ();
397 }
static char * zone
Name of the zone being managed.

References RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, make_json(), run_httpd_now(), RequestData::searching, and zone.

Referenced by create_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_error_cb()

static void register_error_cb ( void *  cls)
static

An error occurred while registering a name.

Parameters
clsthe connection

Definition at line 406 of file gnunet-namestore-fcfsd.c.

407 {
408  struct RequestData *rd = cls;
409 
410  MHD_resume_connection (rd->c);
411  rd->searching = NULL;
412  rd->body = make_json ("error", "true",
413  "message", _ ("unable to scan namestore"),
414  NULL);
415  rd->body_length = strlen (rd->body);
416  rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR;
417  run_httpd_now ();
418 }

References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, make_json(), run_httpd_now(), and RequestData::searching.

Referenced by iterate_done_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_done_cb()

static void register_done_cb ( void *  cls,
int32_t  status,
const char *  emsg 
)
static

A name/key pair has been successfully registered, or maybe not.

Parameters
clsthe connection
statusresult of the operation
emsgerror message if any

Definition at line 429 of file gnunet-namestore-fcfsd.c.

432 {
433  struct RequestData *rd = cls;
434 
435  MHD_resume_connection (rd->c);
436  rd->searching = NULL;
437 
438  if ((GNUNET_SYSERR == status) || (GNUNET_NO == status))
439  {
441  _ ("Failed to create record for `%s': %s\n"),
442  rd->register_name,
443  emsg);
444  rd->body = make_json ("error", "true",
445  "message", emsg,
446  NULL);
447  rd->body_length = strlen (rd->body);
448  rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR;
449  }
450  else
451  {
452  rd->body = make_json ("error", "false",
453  "message", _ ("no errors"),
454  NULL);
455  rd->body_length = strlen (rd->body);
456  rd->code = MHD_HTTP_OK;
457  }
458 
459  run_httpd_now ();
460 }
uint16_t status
See PRISM_STATUS_*-constants.
#define GNUNET_log(kind,...)
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
@ GNUNET_ERROR_TYPE_WARNING
char * register_name
Name requested to be registered.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_do_cb()

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 
)
static

Attempt to register the requested name.

Parameters
clsthe connection
keythe zone key
labelname of the record
countnumber of records found
drecords

Definition at line 473 of file gnunet-namestore-fcfsd.c.

478 {
479  (void) key;
480  (void) d;
481 
482  struct RequestData *rd = cls;
483 
484  rd->searching = NULL;
485 
486  if (0 != count)
487  {
489  _ ("The requested key `%s' exists as `%s'\n"),
490  rd->register_key,
491  label);
492 
493  MHD_resume_connection (rd->c);
494  rd->searching = NULL;
495  rd->body = make_json ("error", "true",
496  "message", _ ("key exists"),
497  NULL);
498  rd->body_length = strlen (rd->body);
499  rd->code = MHD_HTTP_FORBIDDEN;
500  run_httpd_now ();
501  return;
502  }
503 
504  struct GNUNET_GNSRECORD_Data gd;
505  char *gdraw = NULL;
506 
508  &gdraw,
509  &(gd.data_size),
510  &(gd.record_type)))
511  {
513  _ ("Error creating record data\n"));
514  MHD_resume_connection (rd->c);
515  rd->searching = NULL;
516  rd->body = make_json ("error", "true",
517  "message", _ ("unable to store record"),
518  NULL);
519  rd->body_length = strlen (rd->body);
520  rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR;
521  run_httpd_now ();
522  return;
523  }
524 
525  gd.data = gdraw;
526  gd.expiration_time = UINT64_MAX;
527  gd.flags = GNUNET_GNSRECORD_RF_NONE;
528 
530  zone_key,
531  rd->register_name,
532  1,
533  &gd,
535  rd);
536 
537  GNUNET_free (gdraw);
538 }
static void register_done_cb(void *cls, int32_t status, const char *emsg)
A name/key pair has been successfully registered, or maybe not.
static const struct GNUNET_IDENTITY_PrivateKey * zone_key
Private key of the zone.
@ GNUNET_OK
Definition: gnunet_common.h:95
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity(const struct GNUNET_IDENTITY_PublicKey *key, char **data, size_t *data_size, uint32_t *type)
Create record data and size from an identity key.
@ GNUNET_GNSRECORD_RF_NONE
No special options.
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
struct GNUNET_IDENTITY_PublicKey key
Key to be associated with the requested name.
char * register_key
Key (encoded as a string) to be associated with the requested name.

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_NONE, GNUNET_log, GNUNET_NAMESTORE_records_store(), GNUNET_OK, key, RequestData::key, make_json(), namestore, GNUNET_GNSRECORD_Data::record_type, register_done_cb(), RequestData::register_key, RequestData::register_name, run_httpd_now(), RequestData::searching, and zone_key.

Referenced by iterate_done_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_error_cb()

static void iterate_error_cb ( void *  cls)
static

An error occurred while iterating the namestore.

Parameters
clsthe connection

Definition at line 547 of file gnunet-namestore-fcfsd.c.

548 {
549  struct RequestData *rd = cls;
550 
551  MHD_resume_connection (rd->c);
552  rd->iterating = NULL;
553  rd->body = make_json ("error", "true",
554  "message", _ ("unable to scan namestore"),
555  NULL);
556  rd->body_length = strlen (rd->body);
557  rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR;
558  run_httpd_now ();
559 }
struct GNUNET_NAMESTORE_ZoneIterator * iterating
Task started to iterate over the namestore.

References _, RequestData::body, RequestData::body_length, RequestData::c, RequestData::code, RequestData::iterating, make_json(), and run_httpd_now().

Referenced by create_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_do_cb()

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 
)
static

A block was received from the namestore.

Parameters
clsthe connection
keythe zone key
labelthe records' label
countnumber of records found
dthe found records

Definition at line 572 of file gnunet-namestore-fcfsd.c.

577 {
578  (void) key;
579  (void) label;
580  (void) d;
581 
582  struct RequestData *rd = cls;
583 
584  if (0 == strcmp (label, rd->register_name))
585  {
586  GNUNET_break (0 != count);
588  _ ("Requested name `%s' exists with `%u' records\n"),
589  rd->register_name,
590  count);
591 
592  MHD_resume_connection (rd->c);
593  rd->body = make_json ("error", "true",
594  "message", _ ("name exists\n"),
595  NULL);
596  rd->body_length = strlen (rd->body);
597  rd->code = MHD_HTTP_FORBIDDEN;
599  run_httpd_now ();
600  return;
601  }
602 
604 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_done_cb()

static void iterate_done_cb ( void *  cls)
static

All entries in the namestore have been iterated over.

Parameters
clsthe connection

Definition at line 613 of file gnunet-namestore-fcfsd.c.

614 {
615  struct RequestData *rd = cls;
616 
617  rd->iterating = NULL;
618 
619  /* See if the key was not registered already */
621  zone_key,
622  &(rd->key),
624  rd,
626  rd);
627 }
static void register_error_cb(void *cls)
An error occurred while registering a name.
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.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
Look for an existing PKEY delegation record for a given public key.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ serve_json()

static MHD_RESULT serve_json ( struct MHD_Connection *  c,
char *  body,
size_t  length,
int  code 
)
static

Generate a response containing JSON and send it to the client.

Parameters
cthe connection
bodythe response body
lengththe body length in bytes
codethe response code
Returns
MHD_NO on error

Definition at line 640 of file gnunet-namestore-fcfsd.c.

644 {
645  struct MHD_Response *response =
646  MHD_create_response_from_buffer (length,
647  body,
648  MHD_RESPMEM_PERSISTENT);
649  MHD_RESULT r = MHD_queue_response (c, code, response);
650  MHD_destroy_response (response);
651  return r;
652 }
static struct MHD_Response * response
Our canonical response.
#define MHD_RESULT
Data type to use for functions return an "MHD result".

References MHD_RESULT, and response.

Referenced by create_response().

Here is the caller graph for this function:

◆ create_response()

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 
)
static

Send a response back to a connected client.

Parameters
clsunused
connectionthe connection with the client
urlthe requested address
methodthe HTTP method used
versionthe protocol version (including the "HTTP/" part)
upload_datadata sent with a POST request
upload_data_sizelength in bytes of the POST data
ptrused to pass data between request handling phases
Returns
MHD_NO on error

Definition at line 669 of file gnunet-namestore-fcfsd.c.

677 {
678  (void) cls;
679  (void) version;
680 
681  struct RequestData *rd = *ptr;
682 
683  if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
684  {
685  /* Handle a previously suspended request */
686  if (NULL != rd)
687  {
688  return serve_json (rd->c, rd->body, rd->body_length, rd->code);
689  }
690 
691  if (0 == strcmp ("/", url))
692  {
693  return MHD_queue_response (connection,
694  MHD_HTTP_OK,
696  }
697 
698  if (0 == strcmp ("/search", url))
699  {
700  const char *name = MHD_lookup_connection_value (connection,
701  MHD_GET_ARGUMENT_KIND,
702  "name");
703  if (NULL == name)
704  {
705  return MHD_queue_response (connection,
706  MHD_HTTP_BAD_REQUEST,
708  }
709 
710  MHD_suspend_connection (connection);
711  rd = GNUNET_new (struct RequestData);
712  rd->c = connection;
714  zone_key,
715  name,
717  rd,
719  rd);
720  *ptr = rd;
721  return MHD_YES;
722  }
723 
724  return MHD_queue_response (connection,
725  MHD_HTTP_NOT_FOUND,
727  }
728 
729  if (0 == strcmp (method, MHD_HTTP_METHOD_HEAD))
730  {
731  /* We take a shortcut here by always serving the main page: starting a
732  namestore lookup, allocating the necessary resources, waiting for the
733  lookup to complete and then discard everything just because it was a HEAD
734  and thus only the headers are significative, is an unnecessary waste of
735  resources. The handling of this method could be smarter, for example by
736  sending a proper content type header based on the endpoint, but this is
737  not a service in which HEAD requests are significant, so there's no need
738  to spend too much time here. */
739  return MHD_queue_response (connection,
740  MHD_HTTP_OK,
742  }
743 
744  if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
745  {
746  if (0 == strcmp ("/register", url))
747  {
748  /* Handle a previously suspended request */
749  if ((NULL != rd) && (NULL != rd->body))
750  {
751  return serve_json (rd->c, rd->body, rd->body_length, rd->code);
752  }
753 
754  if (NULL == rd)
755  {
756  rd = GNUNET_new (struct RequestData);
757  rd->c = connection;
758  rd->body = NULL;
759  rd->ptr = NULL;
760  *ptr = rd;
761  }
762 
763  json_t *json = NULL;
765  GNUNET_JSON_post_parser (32 * 1024,
766  connection,
767  &(rd->ptr),
768  upload_data,
769  upload_data_size,
770  &json);
771 
772  switch (result)
773  {
775  /* Keep processing POST data */
776  return MHD_YES;
779  rd->body = make_json ("error", "true",
780  "message", _ ("unable to process submitted data"),
781  NULL);
782  rd->body_length = strlen (rd->body);
783  rd->code = MHD_HTTP_PAYLOAD_TOO_LARGE;
784  return MHD_YES;
786  rd->body = make_json ("error", "true",
787  "message", _ ("the submitted data is invalid"),
788  NULL);
789  rd->body_length = strlen (rd->body);
790  rd->code = MHD_HTTP_BAD_REQUEST;
791  return MHD_YES;
792  default:
793  break;
794  }
795 
796  /* POST data has been read in its entirety */
797 
798  const char *name = json_string_value (json_object_get (json, "name"));
799  const char *key = json_string_value (json_object_get (json, "key"));
800  if ((NULL == name) || (NULL == key) || (0 == strlen (name)) || (0 ==
801  strlen (
802  key)))
803  {
804  json_decref (json);
805  rd->body = make_json ("error", "true",
806  "message", _ ("invalid parameters"),
807  NULL);
808  rd->body_length = strlen (rd->body);
809  rd->code = MHD_HTTP_BAD_REQUEST;
810  return MHD_YES;
811  }
812 
813  rd->register_name = strdup (name);
814  rd->register_key = strdup (key);
815 
816  json_decref (json);
818 
819  if ((NULL != strchr (rd->register_name, '.')) ||
820  (NULL != strchr (rd->register_name, '+')))
821  {
822  rd->body = make_json ("error", "true",
823  "message", _ ("invalid name"),
824  NULL);
825  rd->body_length = strlen (rd->body);
826  rd->code = MHD_HTTP_BAD_REQUEST;
827  return MHD_YES;
828  }
829 
831  &(rd->key)))
832  {
834  _ ("Unable to parse key %s\n"),
835  rd->register_key);
836 
837  rd->body = make_json ("error", "true",
838  "message", _ ("unable to parse key"),
839  NULL);
840  rd->body_length = strlen (rd->body);
841  rd->code = MHD_HTTP_INTERNAL_SERVER_ERROR;
842  return MHD_YES;
843  }
844 
845  MHD_suspend_connection (connection);
846  /* See if the requested name is free */
847  rd->iterating =
849  zone_key,
851  rd,
852  &iterate_do_cb,
853  rd,
855  rd);
856  return MHD_YES;
857  }
858 
859  return MHD_queue_response (connection,
860  MHD_HTTP_FORBIDDEN,
862  }
863 
864  return MHD_queue_response (connection,
865  MHD_HTTP_NOT_IMPLEMENTED,
867 }
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.
static void iterate_error_cb(void *cls)
An error occurred while iterating the namestore.
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.
static void iterate_done_cb(void *cls)
All entries in the namestore have been iterated over.
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.
static void search_error_cb(void *cls)
The namestore search task failed.
static int result
Global testing status.
GNUNET_JSON_PostResult
Return codes from GNUNET_JSON_post_parser().
@ GNUNET_JSON_PR_CONTINUE
Parsing continues, call again soon!
@ GNUNET_JSON_PR_OUT_OF_MEMORY
Sorry, memory allocation (malloc()) failed.
@ GNUNET_JSON_PR_JSON_INVALID
JSON parsing failed.
@ GNUNET_JSON_PR_REQUEST_TOO_LARGE
Request size exceeded buffer_max argument.
enum GNUNET_JSON_PostResult GNUNET_JSON_post_parser(size_t buffer_max, struct MHD_Connection *connection, void **con_cls, const char *upload_data, size_t *upload_data_size, json_t **json)
Process a POST request containing a JSON object.
Definition: json_mhd.c:265
void GNUNET_JSON_post_parser_cleanup(void *con_cls)
Function called whenever we are done with a request to clean up our state.
Definition: json_mhd.c:367
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT).
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
const char * name
void * ptr
Pointer used while processing POST data.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ completed_cb()

static void completed_cb ( void *  cls,
struct MHD_Connection *  connection,
void **  ptr,
enum MHD_RequestTerminationCode  status 
)
static

Called when a request is completed.

Parameters
clsunused
connectionthe connection
ptrconnection-specific data
statusstatus code

Definition at line 879 of file gnunet-namestore-fcfsd.c.

883 {
884  (void) cls;
885  (void) connection;
886  (void) status;
887 
888  struct RequestData *rd = *ptr;
889 
890  if (NULL == rd)
891  {
892  return;
893  }
894 
895  if (NULL == rd->body)
896  {
897  GNUNET_free (rd->body);
898  }
899 
900  if (NULL != rd->searching)
901  {
903  }
904 
905  if (NULL != rd->register_name)
906  {
908  }
909 
910  if (NULL != rd->register_key)
911  {
913  }
914 
915  if (NULL != rd->iterating)
916  {
918  }
919 
920  GNUNET_free (rd);
921 }
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ identity_cb()

static void identity_cb ( void *  cls,
struct GNUNET_IDENTITY_Ego ego,
void **  ctx,
const char *  name 
)
static

Called for each ego provided by the identity service.

Parameters
clsclosure
egothe ego
ctxapplication-provided data for the ego
namethe ego name

Definition at line 933 of file gnunet-namestore-fcfsd.c.

937 {
938  (void) cls;
939  (void) ctx;
940 
941  if ((NULL == name) || (0 != strcmp (name, zone)))
942  {
943  return;
944  }
945 
946  if (NULL == ego)
947  {
949  _ ("No ego configured for `fcfsd` subsystem\n"));
951  return;
952  }
953 
955 
956  int flags = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
957  do
958  {
959  httpd = MHD_start_daemon (flags,
960  (uint16_t) port,
961  NULL, NULL,
962  &create_response, NULL,
963  MHD_OPTION_CONNECTION_LIMIT, 128,
964  MHD_OPTION_PER_IP_CONNECTION_LIMIT, 1,
965  MHD_OPTION_CONNECTION_TIMEOUT, 4 * 1024,
966  MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
967  MHD_OPTION_END);
968  flags = MHD_USE_DEBUG;
969  } while (NULL == httpd && flags != MHD_USE_DEBUG);
970 
971  if (NULL == httpd)
972  {
974  _ ("Failed to start HTTP server\n"));
976  return;
977  }
978 
979  run_httpd ();
980 }
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.
static void completed_cb(void *cls, struct MHD_Connection *connection, void **ptr, enum MHD_RequestTerminationCode status)
Called when a request is completed.
static unsigned long long port
The port the daemon is listening to for HTTP requests.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
@ GNUNET_ERROR_TYPE_ERROR
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_static_page()

static struct StaticPage* open_static_page ( const char *  name,
const char *  basedir 
)
static

Open a file on disk and generate a response object for it.

Parameters
namename of the file to open
basedirdirectory where the file is located
Returns
GNUNET_SYSERR on error

Definition at line 991 of file gnunet-namestore-fcfsd.c.

992 {
993  char *fullname = NULL;
994  GNUNET_asprintf (&fullname, "%s/fcfsd-%s", basedir, name);
995 
996  struct GNUNET_DISK_FileHandle *f =
997  GNUNET_DISK_file_open (fullname,
1000  GNUNET_free (fullname);
1001 
1002  if (NULL == f)
1003  {
1004  return NULL;
1005  }
1006 
1007  off_t size = 0;
1009  {
1011  return NULL;
1012  }
1013 
1014  struct MHD_Response *response =
1015  MHD_create_response_from_fd64 (size,
1016  f->fd);
1017 
1018  if (NULL == response)
1019  {
1021  return NULL;
1022  }
1023 
1024  struct StaticPage *page = GNUNET_new (struct StaticPage);
1025  page->handle = f;
1026  page->size = (uint64_t) size;
1027  page->response = response;
1028  return page;
1029 }
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1235
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:193
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle used to access files (and pipes).
Structure representing a static page.
uint64_t size
Size in bytes of the file.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_service()

static void run_service ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Called after the service is up.

Parameters
clsclosure
argsremaining command line arguments
cfgfilename of the configuration file
cfgthe service configuration

Definition at line 1041 of file gnunet-namestore-fcfsd.c.

1045 {
1046  (void) cls;
1047  (void) args;
1048  (void) cfgfile;
1049 
1050  GNUNET_log_setup ("fcfsd", "WARNING", NULL);
1051 
1053  "fcfsd",
1054  "HTTPPORT",
1055  &port))
1056  {
1058  _ ("No port specified, using default value\n"));
1059  }
1060 
1062 
1064  if (NULL == namestore)
1065  {
1067  _ ("Failed to connect to namestore\n"));
1069  return;
1070  }
1071 
1073  if (NULL == identity)
1074  {
1076  _ ("Failed to connect to identity\n"));
1078  return;
1079  }
1080 
1081  char *basedir = NULL;
1083  "fcfsd",
1084  "HTMLDIR",
1085  &basedir))
1086  {
1088  }
1089 
1090  main_page = open_static_page ("index.html", basedir);
1091  notfound_page = open_static_page ("notfound.html", basedir);
1092  forbidden_page = open_static_page ("forbidden.html", basedir);
1093 
1094  GNUNET_free (basedir);
1095 
1096  if ((NULL == main_page) || (NULL == notfound_page) || (NULL ==
1097  forbidden_page) )
1098  {
1100  _ ("Unable to set up the daemon\n"));
1102  return;
1103  }
1104 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct StaticPage * open_static_page(const char *name, const char *basedir)
Open a file on disk and generate a response object for it.
static void do_shutdown(void *cls)
Task ran at shutdown to clean up everything.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1331

References _, consensus-simulation::args, cfg, do_shutdown(), forbidden_page, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), 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(), and port.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function of the fcfs daemon.

Parameters
argcnumber of arguments from the command line @parsm argv the command line arguments
Returns
0 successful exit, a different value otherwise

Definition at line 1115 of file gnunet-namestore-fcfsd.c.

1116 {
1120  "zone",
1121  "EGO",
1122  gettext_noop (
1123  "name of the zone managed by FCFSD"),
1124  &zone)),
1126  };
1127 
1128  return ((GNUNET_OK == GNUNET_PROGRAM_run (argc,
1129  argv,
1130  "gnunet-namestore-fcfsd",
1131  _ (
1132  "GNU Name System First-Come-First-Served name registration service"),
1133  options,
1134  &run_service,
1135  NULL)) ?
1136  0 :
1137  1);
1138 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:69
static void run_service(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Called after the service is up.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:364
Definition of a command line option.

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.

Here is the call graph for this function:

Variable Documentation

◆ zone

char* zone = NULL
static

◆ port

unsigned long long port = 18080
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().

◆ namestore

struct GNUNET_NAMESTORE_Handle* namestore = NULL
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().

◆ identity

struct GNUNET_IDENTITY_Handle* identity = NULL
static

Connection with the identity service.

Definition at line 134 of file gnunet-namestore-fcfsd.c.

Referenced by do_shutdown(), and run_service().

◆ zone_key

const struct GNUNET_IDENTITY_PrivateKey* zone_key = NULL
static

◆ httpd

struct MHD_Daemon* httpd = NULL
static

The HTTP daemon.

Definition at line 144 of file gnunet-namestore-fcfsd.c.

Referenced by do_httpd(), identity_cb(), and run_httpd().

◆ httpd_task

struct GNUNET_SCHEDULER_Task* httpd_task = NULL
static

Task executing the HTTP daemon.

Definition at line 149 of file gnunet-namestore-fcfsd.c.

Referenced by do_httpd(), run_httpd(), and run_httpd_now().

◆ main_page

struct StaticPage* main_page = NULL
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().

◆ notfound_page

struct StaticPage* notfound_page = NULL
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().

◆ forbidden_page

struct StaticPage* forbidden_page = NULL
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().