GNUnet  0.19.4
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, 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 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...
 
static struct GNUNET_TIME_Relative record_exp
 The relative expiration time for added records. 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 178 of file gnunet-namestore-fcfsd.c.

179 {
180  /* We cheat a bit here: the file descriptor is implicitly closed by MHD, so
181  calling `GNUNET_DISK_file_close' would generate a spurious warning message
182  in the log. Since that function does nothing but close the descriptor and
183  free the allocated memory, After destroying the response all that's left to
184  do is call `GNUNET_free'. */
185  if (NULL != main_page)
186  {
187  MHD_destroy_response (main_page->response);
190  }
191  if (NULL != notfound_page)
192  {
193  MHD_destroy_response (notfound_page->response);
196  }
197  if (NULL != forbidden_page)
198  {
199  MHD_destroy_response (forbidden_page->response);
202  }
203 
204  if (NULL != namestore)
205  {
207  }
208 
209  if (NULL != identity)
210  {
212  }
213 
214  if (NULL != httpd_task)
215  {
217  }
218  if (NULL != httpd)
219  {
220  MHD_stop_daemon (httpd);
221  }
222 }
static struct MHD_Daemon * httpd
The HTTP daemon.
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 GNUNET_SCHEDULER_Task * httpd_task
Task executing the HTTP daemon.
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:757
#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).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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(), GNUNET_SCHEDULER_cancel(), StaticPage::handle, httpd, httpd_task, 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 284 of file gnunet-namestore-fcfsd.c.

285 {
286  httpd_task = NULL;
287  MHD_run (httpd);
288  run_httpd ();
289 }
static void run_httpd(void)
Schedule a task to run MHD.

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 237 of file gnunet-namestore-fcfsd.c.

238 {
239  fd_set rs;
240  fd_set ws;
241  fd_set es;
242 
246 
247  FD_ZERO (&rs);
248  FD_ZERO (&ws);
249  FD_ZERO (&es);
250 
251  int max = -1;
252  GNUNET_assert (MHD_YES == MHD_get_fdset (httpd, &rs, &ws, &es, &max));
253 
254  unsigned MHD_LONG_LONG timeout = 0;
256  if (MHD_YES == MHD_get_timeout (httpd, &timeout))
257  {
259  timeout);
260  }
261 
262  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
263  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
264  GNUNET_NETWORK_fdset_copy_native (ges, &es, max + 1);
265 
267  gtime,
268  grs,
269  gws,
270  &do_httpd,
271  NULL);
275 }
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:1170
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1186
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:1040
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:1830
#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:484
#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 293 of file gnunet-namestore-fcfsd.c.

294 {
295  if (NULL != httpd_task)
296  {
298  httpd_task = NULL;
299  }
301 }
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:1299

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 313 of file gnunet-namestore-fcfsd.c.

314 {
315  va_list args;
316  va_start (args, value);
317 
318  json_t *obj = NULL;
319 
320  obj = json_object ();
321  if ((NULL == key) || (NULL == value))
322  {
323  va_end (args);
324  return json_dumps (obj, JSON_COMPACT);
325  }
326 
327  json_object_set (obj, key, json_string (value));
328 
329  char *k = va_arg (args, char *);
330  if (NULL == k)
331  {
332  va_end (args);
333  return json_dumps (obj, JSON_COMPACT);
334  }
335  char *v = va_arg (args, char *);
336  if (NULL == v)
337  {
338  va_end (args);
339  return json_dumps (obj, JSON_COMPACT);
340  }
341 
342  while (NULL != k && NULL != v)
343  {
344  json_object_set (obj, k, json_string (v));
345  k = va_arg (args, char *);
346  if (NULL != k)
347  {
348  v = va_arg (args, char *);
349  }
350  }
351 
352  va_end (args);
353 
354  char *json = json_dumps (obj, JSON_COMPACT);
355  json_decref (obj);
356 
357  return json;
358 }
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 367 of file gnunet-namestore-fcfsd.c.

368 {
369  struct RequestData *rd = cls;
370  MHD_resume_connection (rd->c);
371  rd->searching = NULL;
372  rd->body = make_json ("error", "true",
373  "message", _ ("can not search the namestore"),
374  NULL);
375  rd->body_length = strlen (rd->body);
377  run_httpd_now ();
378 }
static void run_httpd_now(void)
static char * make_json(const char *key, const char *value,...)
Generate a JSON object.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
@ MHD_HTTP_INTERNAL_SERVER_ERROR
Internal Server Error [RFC7231, Section 6.6.1].
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
Structure containing some request-specific data.

References _, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, rd, and run_httpd_now().

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 391 of file gnunet-namestore-fcfsd.c.

396 {
397  (void) zone;
398  (void) d;
399 
400  struct RequestData *rd = cls;
401  MHD_resume_connection (rd->c);
402 
403  rd->searching = NULL;
404  rd->body = make_json ("error", "false",
405  "free", (0 == count) ? "true" : "false",
406  NULL);
407  rd->body_length = strlen (rd->body);
408  rd->code = MHD_HTTP_OK;
409 
410  run_httpd_now ();
411 }
static char * zone
Name of the zone being managed.
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].

References make_json(), MHD_HTTP_OK, rd, run_httpd_now(), 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 420 of file gnunet-namestore-fcfsd.c.

421 {
422  struct RequestData *rd = cls;
423 
424  MHD_resume_connection (rd->c);
425  rd->searching = NULL;
426  rd->body = make_json ("error", "true",
427  "message", _ ("unable to scan namestore"),
428  NULL);
429  rd->body_length = strlen (rd->body);
431  run_httpd_now ();
432 }

References _, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, rd, and run_httpd_now().

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,
enum GNUNET_ErrorCode  ec 
)
static

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

438 {
439  struct RequestData *rd = cls;
440 
441  MHD_resume_connection (rd->c);
442  rd->searching = NULL;
443 
444  if (GNUNET_EC_NONE != ec)
445  {
447  _ ("Failed to create record for `%s': %s\n"),
448  rd->register_name,
450  rd->body = make_json ("error", "true",
451  "message",
453  NULL);
454  rd->body_length = strlen (rd->body);
456  }
457  else
458  {
459  rd->body = make_json ("error", "false",
460  "message", _ ("no errors"),
461  NULL);
462  rd->body_length = strlen (rd->body);
463  rd->code = MHD_HTTP_OK;
464  }
465 
466  run_httpd_now ();
467 }
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
@ GNUNET_EC_NONE
No error (success).
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_WARNING

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

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 480 of file gnunet-namestore-fcfsd.c.

485 {
486  (void) key;
487  (void) d;
488 
489  struct RequestData *rd = cls;
490 
491  rd->searching = NULL;
492 
493  if (0 != count)
494  {
496  _ ("The requested key `%s' exists as `%s'\n"),
497  rd->register_key,
498  label);
499 
500  MHD_resume_connection (rd->c);
501  rd->searching = NULL;
502  rd->body = make_json ("error", "true",
503  "message", _ ("key exists"),
504  NULL);
505  rd->body_length = strlen (rd->body);
506  rd->code = MHD_HTTP_FORBIDDEN;
507  run_httpd_now ();
508  return;
509  }
510 
511  struct GNUNET_GNSRECORD_Data gd;
512  char *gdraw = NULL;
513 
515  &gdraw,
516  &(gd.data_size),
517  &(gd.record_type)))
518  {
520  _ ("Error creating record data\n"));
521  MHD_resume_connection (rd->c);
522  rd->searching = NULL;
523  rd->body = make_json ("error", "true",
524  "message", _ ("unable to store record"),
525  NULL);
526  rd->body_length = strlen (rd->body);
528  run_httpd_now ();
529  return;
530  }
531 
532  gd.data = gdraw;
533  gd.expiration_time = record_exp.rel_value_us;
535 
537  zone_key,
538  rd->register_name,
539  1,
540  &gd,
542  rd);
543 
544  GNUNET_free (gdraw);
545 }
static struct GNUNET_TIME_Relative record_exp
The relative expiration time for added records.
static void register_done_cb(void *cls, enum GNUNET_ErrorCode ec)
static const struct GNUNET_IDENTITY_PrivateKey * zone_key
Private key of the zone.
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
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_OK
@ 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.
@ MHD_HTTP_FORBIDDEN
Forbidden [RFC7231, Section 6.5.3].
uint64_t rel_value_us
The actual value.

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

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 554 of file gnunet-namestore-fcfsd.c.

555 {
556  struct RequestData *rd = cls;
557 
558  MHD_resume_connection (rd->c);
559  rd->iterating = NULL;
560  rd->body = make_json ("error", "true",
561  "message", _ ("unable to scan namestore"),
562  NULL);
563  rd->body_length = strlen (rd->body);
565  run_httpd_now ();
566 }

References _, make_json(), MHD_HTTP_INTERNAL_SERVER_ERROR, rd, 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 579 of file gnunet-namestore-fcfsd.c.

584 {
585  (void) key;
586  (void) label;
587  (void) d;
588 
589  struct RequestData *rd = cls;
590 
591  if (0 == strcmp (label, rd->register_name))
592  {
593  GNUNET_break (0 != count);
595  _ ("Requested name `%s' exists with `%u' records\n"),
596  rd->register_name,
597  count);
598 
599  MHD_resume_connection (rd->c);
600  rd->body = make_json ("error", "true",
601  "message", _ ("name exists\n"),
602  NULL);
603  rd->body_length = strlen (rd->body);
604  rd->code = MHD_HTTP_FORBIDDEN;
606  run_httpd_now ();
607  return;
608  }
609 
610  GNUNET_NAMESTORE_zone_iterator_next (rd->iterating, 1);
611 }
#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 _, 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().

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 620 of file gnunet-namestore-fcfsd.c.

621 {
622  struct RequestData *rd = cls;
623 
624  rd->iterating = NULL;
625 
626  /* See if the key was not registered already */
628  zone_key,
629  &(rd->key),
631  rd,
633  rd);
634 }
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(), namestore, rd, register_do_cb(), register_error_cb(), 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 647 of file gnunet-namestore-fcfsd.c.

651 {
652  struct MHD_Response *response =
653  MHD_create_response_from_buffer (length,
654  body,
655  MHD_RESPMEM_PERSISTENT);
656  MHD_RESULT r = MHD_queue_response (c, code, response);
657  MHD_destroy_response (response);
658  return r;
659 }
static struct MHD_Response * response
Our canonical response.
#define 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 676 of file gnunet-namestore-fcfsd.c.

684 {
685  (void) cls;
686  (void) version;
687 
688  struct RequestData *rd = *ptr;
689 
690  if (0 == strcmp (method, MHD_HTTP_METHOD_GET))
691  {
692  /* Handle a previously suspended request */
693  if (NULL != rd)
694  {
695  return serve_json (rd->c, rd->body, rd->body_length, rd->code);
696  }
697 
698  if (0 == strcmp ("/", url))
699  {
700  return MHD_queue_response (connection,
701  MHD_HTTP_OK,
703  }
704 
705  if (0 == strcmp ("/search", url))
706  {
707  const char *name = MHD_lookup_connection_value (connection,
708  MHD_GET_ARGUMENT_KIND,
709  "name");
710  if (NULL == name)
711  {
712  return MHD_queue_response (connection,
715  }
716 
717  MHD_suspend_connection (connection);
718  rd = GNUNET_new (struct RequestData);
719  rd->c = connection;
721  zone_key,
722  name,
724  rd,
726  rd);
727  *ptr = rd;
728  return MHD_YES;
729  }
730 
731  return MHD_queue_response (connection,
734  }
735 
736  if (0 == strcmp (method, MHD_HTTP_METHOD_HEAD))
737  {
738  /* We take a shortcut here by always serving the main page: starting a
739  namestore lookup, allocating the necessary resources, waiting for the
740  lookup to complete and then discard everything just because it was a HEAD
741  and thus only the headers are significative, is an unnecessary waste of
742  resources. The handling of this method could be smarter, for example by
743  sending a proper content type header based on the endpoint, but this is
744  not a service in which HEAD requests are significant, so there's no need
745  to spend too much time here. */
746  return MHD_queue_response (connection,
747  MHD_HTTP_OK,
749  }
750 
751  if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
752  {
753  if (0 == strcmp ("/register", url))
754  {
755  /* Handle a previously suspended request */
756  if ((NULL != rd) && (NULL != rd->body))
757  {
758  return serve_json (rd->c, rd->body, rd->body_length, rd->code);
759  }
760 
761  if (NULL == rd)
762  {
763  rd = GNUNET_new (struct RequestData);
764  rd->c = connection;
765  rd->body = NULL;
766  rd->ptr = NULL;
767  *ptr = rd;
768  }
769 
770  json_t *json = NULL;
772  GNUNET_JSON_post_parser (32 * 1024,
773  connection,
774  &(rd->ptr),
775  upload_data,
776  upload_data_size,
777  &json);
778 
779  switch (result)
780  {
782  /* Keep processing POST data */
783  return MHD_YES;
786  rd->body = make_json ("error", "true",
787  "message", _ ("unable to process submitted data"),
788  NULL);
789  rd->body_length = strlen (rd->body);
790 #ifdef MHD_HTTP_CONTENT_TOO_LARGE
791  rd->code = MHD_HTTP_CONTENT_TOO_LARGE;
792 #else
794 #endif
795  return MHD_YES;
797  rd->body = make_json ("error", "true",
798  "message", _ ("the submitted data is invalid"),
799  NULL);
800  rd->body_length = strlen (rd->body);
801  rd->code = MHD_HTTP_BAD_REQUEST;
802  return MHD_YES;
803  default:
804  break;
805  }
806 
807  /* POST data has been read in its entirety */
808 
809  const char *name = json_string_value (json_object_get (json, "name"));
810  const char *key = json_string_value (json_object_get (json, "key"));
811  if ((NULL == name) || (NULL == key) || (0 == strlen (name)) || (0 ==
812  strlen (
813  key)))
814  {
815  json_decref (json);
816  rd->body = make_json ("error", "true",
817  "message", _ ("invalid parameters"),
818  NULL);
819  rd->body_length = strlen (rd->body);
820  rd->code = MHD_HTTP_BAD_REQUEST;
821  return MHD_YES;
822  }
823 
824  rd->register_name = strdup (name);
825  rd->register_key = strdup (key);
826 
827  json_decref (json);
829 
830  if ((NULL != strchr (rd->register_name, '.')) ||
831  (NULL != strchr (rd->register_name, '+')))
832  {
833  rd->body = make_json ("error", "true",
834  "message", _ ("invalid name"),
835  NULL);
836  rd->body_length = strlen (rd->body);
837  rd->code = MHD_HTTP_BAD_REQUEST;
838  return MHD_YES;
839  }
840 
842  &(rd->key)))
843  {
845  _ ("Unable to parse key %s\n"),
846  rd->register_key);
847 
848  rd->body = make_json ("error", "true",
849  "message", _ ("unable to parse key"),
850  NULL);
851  rd->body_length = strlen (rd->body);
853  return MHD_YES;
854  }
855 
856  MHD_suspend_connection (connection);
857  /* See if the requested name is free */
858  rd->iterating =
860  zone_key,
862  rd,
863  &iterate_do_cb,
864  rd,
866  rd);
867  return MHD_YES;
868  }
869 
870  return MHD_queue_response (connection,
873  }
874 
875  return MHD_queue_response (connection,
878 }
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)
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.
@ MHD_HTTP_BAD_REQUEST
Bad Request [RFC7231, Section 6.5.1].
@ MHD_HTTP_NOT_FOUND
Not Found [RFC7231, Section 6.5.4].
@ MHD_HTTP_PAYLOAD_TOO_LARGE
Payload Too Large [RFC7231, Section 6.5.11].
@ MHD_HTTP_NOT_IMPLEMENTED
Not Implemented [RFC7231, Section 6.6.2].
const char * name
void * ptr
Pointer used while processing POST data.

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

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 890 of file gnunet-namestore-fcfsd.c.

894 {
895  (void) cls;
896  (void) connection;
897  (void) status;
898 
899  struct RequestData *rd = *ptr;
900 
901  if (NULL == rd)
902  {
903  return;
904  }
905 
906  if (NULL == rd->body)
907  {
908  GNUNET_free (rd->body);
909  }
910 
911  if (NULL != rd->searching)
912  {
913  GNUNET_NAMESTORE_cancel (rd->searching);
914  }
915 
916  if (NULL != rd->register_name)
917  {
918  GNUNET_free (rd->register_name);
919  }
920 
921  if (NULL != rd->register_key)
922  {
923  GNUNET_free (rd->register_key);
924  }
925 
926  if (NULL != rd->iterating)
927  {
929  }
930 
931  GNUNET_free (rd);
932 }
uint16_t status
See PRISM_STATUS_*-constants.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.

References GNUNET_free, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_zone_iteration_stop(), RequestData::ptr, rd, 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 944 of file gnunet-namestore-fcfsd.c.

948 {
949  (void) cls;
950  (void) ctx;
951 
952  if ((NULL == name) || (0 != strcmp (name, zone)))
953  {
954  return;
955  }
956 
957  if (NULL == ego)
958  {
960  _ ("No ego configured for `fcfsd` subsystem\n"));
962  return;
963  }
964 
966 
967  int flags = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
968  do
969  {
970  httpd = MHD_start_daemon (flags,
971  (uint16_t) port,
972  NULL, NULL,
973  &create_response, NULL,
974  MHD_OPTION_CONNECTION_LIMIT, 128,
975  MHD_OPTION_PER_IP_CONNECTION_LIMIT, 1,
976  MHD_OPTION_CONNECTION_TIMEOUT, 4 * 1024,
977  MHD_OPTION_NOTIFY_COMPLETED, &completed_cb, NULL,
978  MHD_OPTION_END);
979  flags = MHD_USE_DEBUG;
980  } while (NULL == httpd && flags != MHD_USE_DEBUG);
981 
982  if (NULL == httpd)
983  {
985  _ ("Failed to start HTTP server\n"));
987  return;
988  }
989 
990  run_httpd ();
991 }
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:560
@ GNUNET_ERROR_TYPE_ERROR
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562

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
NULL on error

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

1003 {
1004  char *fullname = NULL;
1005  GNUNET_asprintf (&fullname, "%s/fcfsd-%s", basedir, name);
1006 
1007  struct GNUNET_DISK_FileHandle *f =
1008  GNUNET_DISK_file_open (fullname,
1011  GNUNET_free (fullname);
1012 
1013  if (NULL == f)
1014  {
1015  return NULL;
1016  }
1017 
1018  off_t size = 0;
1020  {
1022  return NULL;
1023  }
1024 
1025  struct MHD_Response *response =
1026  MHD_create_response_from_fd64 (size,
1027  f->fd);
1028 
1029  if (NULL == response)
1030  {
1032  return NULL;
1033  }
1034 
1035  struct StaticPage *page = GNUNET_new (struct StaticPage);
1036  page->handle = f;
1037  page->size = (uint64_t) size;
1038  page->response = response;
1039  return page;
1040 }
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:1237
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
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:192
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_SYSERR
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:68
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 1052 of file gnunet-namestore-fcfsd.c.

1056 {
1057  (void) cls;
1058  (void) args;
1059  (void) cfgfile;
1060 
1061  GNUNET_log_setup ("fcfsd", "WARNING", NULL);
1062 
1064  "fcfsd",
1065  "RELATIVE_RECORD_EXPIRATION",
1066  &record_exp))
1067  {
1069  _("No expiration specified for records.\n"));
1071  return;
1072  }
1073 
1075  "fcfsd",
1076  "HTTPPORT",
1077  &port))
1078  {
1080  _ ("No port specified, using default value\n"));
1081  }
1082 
1084 
1086  if (NULL == namestore)
1087  {
1089  _ ("Failed to connect to namestore\n"));
1091  return;
1092  }
1093 
1095  if (NULL == identity)
1096  {
1098  _ ("Failed to connect to identity\n"));
1100  return;
1101  }
1102 
1103  char *basedir = NULL;
1105  "fcfsd",
1106  "HTMLDIR",
1107  &basedir))
1108  {
1110  }
1111 
1112  main_page = open_static_page ("index.html", basedir);
1113  notfound_page = open_static_page ("notfound.html", basedir);
1114  forbidden_page = open_static_page ("forbidden.html", basedir);
1115 
1116  GNUNET_free (basedir);
1117 
1118  if ((NULL == main_page) || (NULL == notfound_page) || (NULL ==
1119  forbidden_page) )
1120  {
1122  _ ("Unable to set up the daemon\n"));
1124  return;
1125  }
1126 }
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
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:531
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:1334

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

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
argvthe command line arguments
Returns
0 successful exit, a different value otherwise

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

1138 {
1142  "zone",
1143  "EGO",
1144  gettext_noop (
1145  "name of the zone managed by FCFSD"),
1146  &zone)),
1148  };
1149 
1150  return ((GNUNET_OK == GNUNET_PROGRAM_run (argc,
1151  argv,
1152  "gnunet-namestore-fcfsd",
1153  _ (
1154  "GNU Name System First-Come-First-Served name registration service"),
1155  options,
1156  &run_service,
1157  NULL)) ?
1158  0 :
1159  1);
1160 }
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:70
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:400
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

◆ 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

◆ httpd

struct MHD_Daemon* httpd = NULL
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().

◆ 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(), do_shutdown(), 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().

◆ record_exp

struct GNUNET_TIME_Relative record_exp
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().