GNUnet  0.11.x
Data Structures | Macros | Enumerations | 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 dependency graph for gnunet-namestore-fcfsd.c:

Go to the source code of this file.

Data Structures

struct  Request
 Request we should make. More...
 
struct  ZoneinfoRequest
 Zoneinfo request. More...
 

Macros

#define METHOD_ERROR   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>"
 Invalid method page. More...
 
#define MAIN_PAGE   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>"
 Front page. More...
 
#define SUBMIT_PAGE   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>"
 Second page (/S) More...
 
#define ZONEINFO_PAGE   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>"
 Fcfs zoneinfo page (/Zoneinfo) More...
 
#define FCFS_ZONEINFO_URL   "/Zoneinfo"
 
#define MIME_HTML   "text/html"
 Mime type for HTML pages. More...
 
#define COOKIE_NAME   "namestore-fcfsd"
 Name of our cookie. More...
 
#define DEFAULT_ZONEINFO_BUFSIZE   2048
 
#define UNSIGNED_MHD_LONG_LONG   unsigned MHD_LONG_LONG
 

Enumerations

enum  Phase {
  RP_START = 0, RP_LOOKUP, RP_PUT, RP_SUCCESS,
  RP_FAIL
}
 Phases a request goes through. More...
 

Functions

static void do_httpd (void *cls)
 Task run whenever HTTP server operations are pending. More...
 
static void run_httpd_now ()
 Schedule task to run MHD server now. More...
 
static void update_zoneinfo_page (void *cls)
 Create fresh version of zone information. More...
 
static void zone_iteration_error (void *cls)
 Function called on error in zone iteration. More...
 
static void zone_iteration_end (void *cls)
 Function called once the zone iteration is done. More...
 
static void iterate_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *name, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
 Process a record that was stored in the namestore, adding the information to the HTML. More...
 
static int serve_zoneinfo_page (struct MHD_Connection *connection)
 Handler that returns FCFS zoneinfo page. More...
 
static int serve_main_page (struct MHD_Connection *connection)
 Handler that returns a simple static HTTP page. More...
 
static int fill_s_reply (const char *info, struct Request *request, struct MHD_Connection *connection)
 Send the 'SUBMIT_PAGE'. More...
 
static int post_iterator (void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
 Iterator over key-value pairs where the value maybe made available in increments and/or may not be zero-terminated. More...
 
static void put_continuation (void *cls, int32_t success, const char *emsg)
 Continuation called to notify client about result of the operation. More...
 
static void zone_to_name_error (void *cls)
 Function called if we had an error in zone-to-name mapping. More...
 
static void zone_to_name_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *name, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Test if a name mapping was found, if so, refuse. More...
 
static void lookup_it_error (void *cls)
 We encountered an error in the name lookup. More...
 
static void lookup_it_processor (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 We got a block back from the namestore. More...
 
static void lookup_it_finished (void *cls)
 
static int 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)
 Main MHD callback for handling requests. More...
 
static void request_completed_callback (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
 Callback called upon completion of a request. More...
 
static void run_httpd ()
 Schedule tasks to run MHD server. More...
 
static void do_shutdown (void *cls)
 Task run on shutdown. More...
 
static void identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
 Method called to inform about the egos of this peer. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function for the fcfs daemon. More...
 

Variables

static struct MHD_Daemon * httpd
 MHD deamon reference. More...
 
static struct GNUNET_SCHEDULER_Taskhttpd_task
 Main HTTP task. More...
 
static struct GNUNET_NAMESTORE_Handlens
 Handle to the namestore. More...
 
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
 Private key for the fcfsd zone. More...
 
static struct GNUNET_IDENTITY_Handleidentity
 Connection to identity service. More...
 
static struct MHD_Response * info_page
 Zoneinfo page we currently use. More...
 
static struct GNUNET_SCHEDULER_Taskuzp_task
 Task that runs update_zoneinfo_page peridicially. More...
 
static struct GNUNET_IDENTITY_Operationid_op
 Request for our ego. More...
 
static unsigned long long port
 Port we use for the HTTP server. More...
 
static char * zone
 Name of the zone we manage. More...
 

Detailed Description

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

Author
Christian Grothoff

TODO:

Definition in file gnunet-namestore-fcfsd.c.

Macro Definition Documentation

◆ METHOD_ERROR

#define METHOD_ERROR   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>"

Invalid method page.

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

Referenced by create_response().

◆ MAIN_PAGE

#define MAIN_PAGE   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>"

Front page.

(/)

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

Referenced by serve_main_page().

◆ SUBMIT_PAGE

#define SUBMIT_PAGE   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>"

Second page (/S)

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

Referenced by fill_s_reply().

◆ ZONEINFO_PAGE

#define ZONEINFO_PAGE   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>"

Fcfs zoneinfo page (/Zoneinfo)

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

Referenced by zone_iteration_end().

◆ FCFS_ZONEINFO_URL

#define FCFS_ZONEINFO_URL   "/Zoneinfo"

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

Referenced by create_response().

◆ MIME_HTML

#define MIME_HTML   "text/html"

Mime type for HTML pages.

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

Referenced by fill_s_reply(), serve_main_page(), and zone_iteration_end().

◆ COOKIE_NAME

#define COOKIE_NAME   "namestore-fcfsd"

Name of our cookie.

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

◆ DEFAULT_ZONEINFO_BUFSIZE

#define DEFAULT_ZONEINFO_BUFSIZE   2048

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

Referenced by update_zoneinfo_page().

◆ UNSIGNED_MHD_LONG_LONG

#define UNSIGNED_MHD_LONG_LONG   unsigned MHD_LONG_LONG

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

Referenced by run_httpd().

Enumeration Type Documentation

◆ Phase

enum Phase

Phases a request goes through.

Enumerator
RP_START 

Start phase (parsing POST, checking).

RP_LOOKUP 

Lookup to see if the domain name is taken.

RP_PUT 

Storing of the record.

RP_SUCCESS 

We're done with success.

RP_FAIL 

Send failure message.

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

82 {
86  RP_START = 0,
87 
91  RP_LOOKUP,
92 
96  RP_PUT,
97 
101  RP_SUCCESS,
102 
106  RP_FAIL
107 };
Storing of the record.
Lookup to see if the domain name is taken.
Start phase (parsing POST, checking).
Send failure message.
We&#39;re done with success.

Function Documentation

◆ do_httpd()

static void do_httpd ( void *  cls)
static

Task run whenever HTTP server operations are pending.

Parameters
clsunused

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

References httpd, and run_httpd().

Referenced by run_httpd(), and run_httpd_now().

996 {
997  (void) cls;
998  httpd_task = NULL;
999  MHD_run (httpd);
1000  run_httpd ();
1001 }
static struct GNUNET_SCHEDULER_Task * httpd_task
Main HTTP task.
static void run_httpd()
Schedule tasks to run MHD server.
static struct MHD_Daemon * httpd
MHD deamon reference.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_httpd_now()

static void run_httpd_now ( )
static

Schedule task to run MHD server now.

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

References GNUNET_IDENTITY_Operation::cls, do_httpd(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and update_zoneinfo_page().

Referenced by lookup_it_error(), lookup_it_finished(), put_continuation(), zone_to_name_cb(), and zone_to_name_error().

260 {
261  if (NULL != httpd_task)
262  {
264  httpd_task = NULL;
265  }
267 }
static void do_httpd(void *cls)
Task run whenever HTTP server operations are pending.
static struct GNUNET_SCHEDULER_Task * httpd_task
Main HTTP task.
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:1280
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_zoneinfo_page()

static void update_zoneinfo_page ( void *  cls)
static

Create fresh version of zone information.

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

References ZoneinfoRequest::buf_len, DEFAULT_ZONEINFO_BUFSIZE, fcfs_zone_pkey, GNUNET_malloc, GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_MINUTES, iterate_cb(), ZoneinfoRequest::list_it, ZoneinfoRequest::write_offset, zone_iteration_end(), zone_iteration_error(), and ZoneinfoRequest::zoneinfo.

Referenced by run(), run_httpd_now(), and zone_iteration_error().

408 {
409  static struct ZoneinfoRequest zr;
410 
411  (void) cls;
414  NULL);
415  if (NULL != zr.list_it)
416  return;
417  zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE);
418  zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE;
419  zr.write_offset = 0;
423  &zr,
424  &iterate_cb,
425  &zr,
427  &zr);
428 }
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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)...
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define DEFAULT_ZONEINFO_BUFSIZE
static void iterate_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *name, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore, adding the information to the HTML.
Zoneinfo request.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static void update_zoneinfo_page(void *cls)
Create fresh version of zone information.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void zone_iteration_error(void *cls)
Function called on error in zone iteration.
static void zone_iteration_end(void *cls)
Function called once the zone iteration is done.
static struct GNUNET_SCHEDULER_Task * uzp_task
Task that runs update_zoneinfo_page peridicially.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zone_iteration_error()

static void zone_iteration_error ( void *  cls)
static

Function called on error in zone iteration.

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

References GNUNET_free, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), ZoneinfoRequest::list_it, update_zoneinfo_page(), and ZoneinfoRequest::zoneinfo.

Referenced by update_zoneinfo_page().

282 {
283  struct ZoneinfoRequest *zr = cls;
284 
285  zr->list_it = NULL;
286  GNUNET_free (zr->zoneinfo);
289  NULL);
290 }
struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator.
Zoneinfo request.
static void update_zoneinfo_page(void *cls)
Create fresh version of zone information.
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:1280
static struct GNUNET_SCHEDULER_Task * uzp_task
Task that runs update_zoneinfo_page peridicially.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zone_iteration_end()

static void zone_iteration_end ( void *  cls)
static

Function called once the zone iteration is done.

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

References GNUNET_asprintf(), GNUNET_free, info_page, ZoneinfoRequest::list_it, MIME_HTML, response, ZoneinfoRequest::zoneinfo, and ZONEINFO_PAGE.

Referenced by update_zoneinfo_page().

298 {
299  struct ZoneinfoRequest *zr = cls;
300  struct MHD_Response *response;
301  char*full_page;
302 
303  zr->list_it = NULL;
304 
305  /* return static form */
306  GNUNET_asprintf (&full_page,
308  zr->zoneinfo,
309  zr->zoneinfo);
310  response = MHD_create_response_from_buffer (strlen (full_page),
311  (void *) full_page,
312  MHD_RESPMEM_MUST_FREE);
313  MHD_add_response_header (response,
314  MHD_HTTP_HEADER_CONTENT_TYPE,
315  MIME_HTML);
316  MHD_destroy_response (info_page);
318  GNUNET_free (zr->zoneinfo);
319 }
struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator.
Zoneinfo request.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct MHD_Response * info_page
Zoneinfo page we currently use.
#define ZONEINFO_PAGE
Fcfs zoneinfo page (/Zoneinfo)
static struct MHD_Response * response
Our canonical response.
#define MIME_HTML
Mime type for HTML pages.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_cb()

static void iterate_cb ( void *  cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey zone_key,
const char *  name,
unsigned int  rd_len,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Process a record that was stored in the namestore, adding the information to the HTML.

Parameters
clsclosure with the struct ZoneinfoRequest *
zone_keyprivate key of the zone; NULL on disconnect
namelabel of the records; NULL on disconnect
rd_lennumber of entries in rd array, 0 if label was deleted
rdarray of records with data to store

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

References ZoneinfoRequest::buf_len, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_break, GNUNET_free, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_GNSRECORD_value_to_string(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NAMESTORE_zone_iterator_next(), ZoneinfoRequest::list_it, pkey, GNUNET_GNSRECORD_Data::record_type, ZoneinfoRequest::write_offset, and ZoneinfoRequest::zoneinfo.

Referenced by update_zoneinfo_page().

338 {
339  struct ZoneinfoRequest *zr = cls;
340  size_t bytes_free;
341  char*pkey;
342  char*new_buf;
343 
344  (void) zone_key;
345  if (1 != rd_len)
346  {
348  1);
349  return;
350  }
351 
353  {
355  1);
356  return;
357  }
358 
359  bytes_free = zr->buf_len - zr->write_offset;
361  rd->data,
362  rd->data_size);
363  if (NULL == pkey)
364  {
365  GNUNET_break (0);
367  1);
368  return;
369  }
370  if (bytes_free < (strlen (name) + strlen (pkey) + 40))
371  {
372  new_buf = GNUNET_malloc (zr->buf_len * 2);
373  GNUNET_memcpy (new_buf, zr->zoneinfo, zr->write_offset);
374  GNUNET_free (zr->zoneinfo);
375  zr->zoneinfo = new_buf;
376  zr->buf_len *= 2;
377  }
378  sprintf (zr->zoneinfo + zr->write_offset,
379  "<tr><td>%s</td><td>%s</td></tr>",
380  name,
381  pkey);
382  zr->write_offset = strlen (zr->zoneinfo);
384  1);
385  GNUNET_free (pkey);
386 }
struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator.
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
size_t data_size
Number of bytes in data.
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...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Zoneinfo request.
const void * data
Binary value stored in the DNS record.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
size_t buf_len
Buffer length.
uint32_t record_type
Type of the GNS/DNS record.
const char * name
size_t write_offset
Buffer write offset.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serve_zoneinfo_page()

static int serve_zoneinfo_page ( struct MHD_Connection *  connection)
static

Handler that returns FCFS zoneinfo page.

Parameters
connectionconnection to use

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

References info_page.

Referenced by create_response().

396 {
397  return MHD_queue_response (connection,
398  MHD_HTTP_OK,
399  info_page);
400 }
static struct MHD_Response * info_page
Zoneinfo page we currently use.
Here is the caller graph for this function:

◆ serve_main_page()

static int serve_main_page ( struct MHD_Connection *  connection)
static

Handler that returns a simple static HTTP page.

Parameters
connectionconnection to use
Returns
#MHD_YES on success

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

References MAIN_PAGE, MIME_HTML, response, and ret.

Referenced by create_response().

439 {
440  int ret;
441  struct MHD_Response *response;
442 
443  /* return static form */
444  response = MHD_create_response_from_buffer (strlen (MAIN_PAGE),
445  (void *) MAIN_PAGE,
446  MHD_RESPMEM_PERSISTENT);
447  MHD_add_response_header (response,
448  MHD_HTTP_HEADER_CONTENT_TYPE,
449  MIME_HTML);
450  ret = MHD_queue_response (connection,
451  MHD_HTTP_OK,
452  response);
453  MHD_destroy_response (response);
454  return ret;
455 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define MAIN_PAGE
Front page.
static struct MHD_Response * response
Our canonical response.
#define MIME_HTML
Mime type for HTML pages.
Here is the caller graph for this function:

◆ fill_s_reply()

static int fill_s_reply ( const char *  info,
struct Request request,
struct MHD_Connection *  connection 
)
static

Send the 'SUBMIT_PAGE'.

Parameters
infoinformation string to send to the user
requestrequest information
connectionconnection to use

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

References GNUNET_asprintf(), MIME_HTML, response, ret, and SUBMIT_PAGE.

Referenced by create_response().

469 {
470  int ret;
471  char *reply;
472  struct MHD_Response *response;
473 
474  (void) request;
475  GNUNET_asprintf (&reply,
476  SUBMIT_PAGE,
477  info,
478  info);
479  /* return static form */
480  response = MHD_create_response_from_buffer (strlen (reply),
481  (void *) reply,
482  MHD_RESPMEM_MUST_FREE);
483  MHD_add_response_header (response,
484  MHD_HTTP_HEADER_CONTENT_TYPE,
485  MIME_HTML);
486  ret = MHD_queue_response (connection,
487  MHD_HTTP_OK,
488  response);
489  MHD_destroy_response (response);
490  return ret;
491 }
#define SUBMIT_PAGE
Second page (/S)
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct MHD_Response * response
Our canonical response.
#define MIME_HTML
Mime type for HTML pages.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ post_iterator()

static int post_iterator ( void *  cls,
enum MHD_ValueKind  kind,
const char *  key,
const char *  filename,
const char *  content_type,
const char *  transfer_encoding,
const char *  data,
uint64_t  off,
size_t  size 
)
static

Iterator over key-value pairs where the value maybe made available in increments and/or may not be zero-terminated.

Used for processing POST data.

Parameters
clsuser-specified closure
kindtype of the value
key0-terminated key for the value
filenamename of the uploaded file, NULL if not known
content_typemime-type of the data, NULL if not known
transfer_encodingencoding of the data, NULL if not known
datapointer to size bytes of data at the specified offset
offoffset of data in the overall value
sizenumber of bytes in data available
Returns
MHD_YES to continue iterating, MHD_NO to abort the iteration

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

References _, Request::domain_name, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcpy, Request::public_key, and request.

Referenced by create_response().

523 {
524  struct Request *request = cls;
525 
526  (void) kind;
527  (void) filename;
528  (void) content_type;
529  (void) transfer_encoding;
530  if (0 == strcmp ("domain", key))
531  {
532  if (size + off >= sizeof(request->domain_name))
533  size = sizeof(request->domain_name) - off - 1;
534  GNUNET_memcpy (&request->domain_name[off],
535  data,
536  size);
537  request->domain_name[size + off] = '\0';
538  return MHD_YES;
539  }
540  if (0 == strcmp ("pkey", key))
541  {
542  if (size + off >= sizeof(request->public_key))
543  size = sizeof(request->public_key) - off - 1;
544  GNUNET_memcpy (&request->public_key[off],
545  data,
546  size);
547  request->public_key[size + off] = '\0';
548  return MHD_YES;
549  }
551  _ ("Unsupported form value `%s'\n"),
552  key);
553  return MHD_YES;
554 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
char public_key[128]
Public key submitted via form.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * filename
char domain_name[64]
Domain name submitted via form.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Request we should make.
#define GNUNET_log(kind,...)
uint32_t data
The data value.
Here is the caller graph for this function:

◆ put_continuation()

static void put_continuation ( void *  cls,
int32_t  success,
const char *  emsg 
)
static

Continuation called to notify client about result of the operation.

Parameters
clsclosure
successGNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) GNUNET_NO if content was already there GNUNET_YES (or other positive value) on success
emsgNULL on success, otherwise an error message

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

References _, Request::con, Request::domain_name, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, Request::phase, Request::qe, request, RP_FAIL, RP_SUCCESS, and run_httpd_now().

Referenced by zone_to_name_cb().

571 {
572  struct Request *request = cls;
573 
574  request->qe = NULL;
575  if (0 >= success)
576  {
578  _ ("Failed to create record for domain `%s': %s\n"),
579  request->domain_name,
580  emsg);
581  request->phase = RP_FAIL;
582  }
583  else
584  request->phase = RP_SUCCESS;
585  MHD_resume_connection (request->con);
586  run_httpd_now ();
587 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
struct MHD_Connection * con
MHD Connection.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
char domain_name[64]
Domain name submitted via form.
static void run_httpd_now()
Schedule task to run MHD server now.
Send failure message.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
Request we should make.
#define GNUNET_log(kind,...)
enum Phase phase
Current processing phase.
We&#39;re done with success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zone_to_name_error()

static void zone_to_name_error ( void *  cls)
static

Function called if we had an error in zone-to-name mapping.

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

References _, Request::con, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, Request::phase, request, RP_FAIL, and run_httpd_now().

Referenced by lookup_it_finished().

595 {
596  struct Request *request = cls;
597 
599  _ ("Error when mapping zone to name\n"));
600  request->phase = RP_FAIL;
601  MHD_resume_connection (request->con);
602  run_httpd_now ();
603 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
struct MHD_Connection * con
MHD Connection.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static void run_httpd_now()
Schedule task to run MHD server now.
Send failure message.
Request we should make.
#define GNUNET_log(kind,...)
enum Phase phase
Current processing phase.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zone_to_name_cb()

static void zone_to_name_cb ( void *  cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey zone_key,
const char *  name,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Test if a name mapping was found, if so, refuse.

If not, initiate storing of the record.

Parameters
clsclosure
zone_keypublic key of the zone
namename that is being mapped (at most 255 characters long)
rd_countnumber of entries in rd array
rdarray of records with data to store

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

References _, Request::con, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, Request::domain_name, GNUNET_GNSRECORD_Data::expiration_time, fcfs_zone_pkey, GNUNET_GNSRECORD_Data::flags, GNUNET_ERROR_TYPE_INFO, GNUNET_GNSRECORD_RF_NONE, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_log, GNUNET_NAMESTORE_records_store(), Request::phase, Request::pub, put_continuation(), Request::qe, GNUNET_GNSRECORD_Data::record_type, request, RP_FAIL, and run_httpd_now().

Referenced by lookup_it_finished().

621 {
622  struct Request *request = cls;
623  struct GNUNET_GNSRECORD_Data r;
624 
625  (void) rd;
626  (void) zone_key;
627  request->qe = NULL;
628  if (0 != rd_count)
629  {
631  _ ("Found existing name `%s' for the given key\n"),
632  name);
633  request->phase = RP_FAIL;
634  MHD_resume_connection (request->con);
635  run_httpd_now ();
636  return;
637  }
638  r.data = &request->pub;
639  r.data_size = sizeof(request->pub);
640  r.expiration_time = UINT64_MAX;
641  r.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
642  r.flags = GNUNET_GNSRECORD_RF_NONE;
645  request->domain_name,
646  1, &r,
648  request);
649 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
static void put_continuation(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
struct MHD_Connection * con
MHD Connection.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
char domain_name[64]
Domain name submitted via form.
struct GNUNET_CRYPTO_EcdsaPublicKey pub
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void run_httpd_now()
Schedule task to run MHD server now.
Send failure message.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
Request we should make.
const char * name
#define GNUNET_log(kind,...)
enum Phase phase
Current processing phase.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_it_error()

static void lookup_it_error ( void *  cls)
static

We encountered an error in the name lookup.

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

References Request::con, Request::phase, Request::qe, request, RP_FAIL, and run_httpd_now().

Referenced by create_response().

657 {
658  struct Request *request = cls;
659 
660  MHD_resume_connection (request->con);
661  request->qe = NULL;
662  request->phase = RP_FAIL;
663  run_httpd_now ();
664 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
struct MHD_Connection * con
MHD Connection.
static void run_httpd_now()
Schedule task to run MHD server now.
Send failure message.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
Request we should make.
enum Phase phase
Current processing phase.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_it_processor()

static void lookup_it_processor ( void *  cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey zonekey,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

We got a block back from the namestore.

Decrypt it and continue to process the result.

Parameters
clsthe 'struct Request' we are processing
zonekeyprivate key of the zone; NULL on disconnect
labellabel of the records; NULL on disconnect
rd_countnumber of entries in rd array, 0 if label was deleted
rdarray of records with data to store

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

References _, Request::domain_name, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAMESTORE_zone_iterator_next(), Request::lookup_it, Request::phase, request, and RP_FAIL.

Referenced by create_response().

683 {
684  struct Request *request = cls;
685 
686  (void) label;
687  (void) rd;
688  (void) zonekey;
689  if (0 == strcmp (label, request->domain_name))
690  {
691  GNUNET_break (0 != rd_count);
693  _ ("Found %u existing records for domain `%s'\n"),
694  rd_count,
695  request->domain_name);
696  request->phase = RP_FAIL;
697  }
699 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
struct GNUNET_NAMESTORE_ZoneIterator * lookup_it
Active lookup iterator TODO: deprecate or fix lookup by label and use above member.
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...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
char domain_name[64]
Domain name submitted via form.
Send failure message.
Request we should make.
#define GNUNET_log(kind,...)
enum Phase phase
Current processing phase.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_it_finished()

static void lookup_it_finished ( void *  cls)
static

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

References Request::con, fcfs_zone_pkey, GNUNET_break, GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_NAMESTORE_zone_to_name(), GNUNET_OK, Request::phase, Request::pub, Request::public_key, Request::qe, request, RP_FAIL, run_httpd_now(), zone_to_name_cb(), and zone_to_name_error().

Referenced by create_response().

704 {
705  struct Request *request = cls;
706 
707  if (RP_FAIL == request->phase)
708  {
709  MHD_resume_connection (request->con);
710  run_httpd_now ();
711  return;
712  }
713  if (GNUNET_OK !=
715  strlen (request->public_key),
716  &request->pub))
717  {
718  GNUNET_break (0);
719  request->phase = RP_FAIL;
720  MHD_resume_connection (request->con);
721  run_httpd_now ();
722  return;
723  }
724  request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
726  &request->pub,
728  request,
730  request);
731 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
char public_key[128]
Public key submitted via form.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MHD_Connection * con
MHD Connection.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
static void zone_to_name_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *name, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Test if a name mapping was found, if so, refuse.
struct GNUNET_CRYPTO_EcdsaPublicKey pub
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void run_httpd_now()
Schedule task to run MHD server now.
Send failure message.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
Request we should make.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:466
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const struct GNUNET_CRYPTO_EcdsaPublicKey *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.
enum Phase phase
Current processing phase.
static void zone_to_name_error(void *cls)
Function called if we had an error in zone-to-name mapping.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_response()

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

Main MHD callback for handling requests.

Parameters
clsunused
connectionMHD connection handle
urlthe requested url
methodthe HTTP method used ("GET", "PUT", etc.)
versionthe HTTP version string (i.e. "HTTP/1.1")
upload_datathe data being uploaded (excluding HEADERS, for a POST that fits into memory and that is encoded with a supported encoding, the POST data will NOT be given in upload_data and is instead available as part of MHD_get_connection_values; very large POST data will be made available incrementally in upload_data)
upload_data_sizeset initially to the size of the upload_data provided; the method must update this value to the number of bytes NOT processed;
ptrpointer to location where we store the 'struct Request'
Returns
#MHD_YES if the connection was handled successfully, #MHD_NO if the socket must be closed due to a serious error while handling the request

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

References _, Request::con, Request::domain_name, fcfs_zone_pkey, FCFS_ZONEINFO_URL, fill_s_reply(), GNUNET_break, GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_new, GNUNET_OK, Request::lookup_it, lookup_it_error(), lookup_it_finished(), lookup_it_processor(), METHOD_ERROR, Request::phase, post_iterator(), Request::pp, Request::public_key, request, response, ret, RP_FAIL, RP_LOOKUP, RP_PUT, RP_START, RP_SUCCESS, serve_main_page(), and serve_zoneinfo_page().

Referenced by identity_cb().

766 {
767  struct MHD_Response *response;
768  struct Request *request;
770  int ret;
771 
772  (void) cls;
773  (void) version;
774  if ((0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
775  (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)))
776  {
777  if (0 == strcmp (url, FCFS_ZONEINFO_URL))
778  ret = serve_zoneinfo_page (connection);
779  else
780  ret = serve_main_page (connection);
781  if (ret != MHD_YES)
783  _ ("Failed to create page for `%s'\n"),
784  url);
785  return ret;
786  }
787  if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
788  {
789  request = *ptr;
790  if (NULL == request)
791  {
792  request = GNUNET_new (struct Request);
793  request->con = connection;
794  *ptr = request;
795  request->pp = MHD_create_post_processor (connection,
796  1024,
797  &post_iterator,
798  request);
799  if (NULL == request->pp)
800  {
802  _ ("Failed to setup post processor for `%s'\n"),
803  url);
804  return MHD_NO; /* internal error */
805  }
806  return MHD_YES;
807  }
808  if (NULL != request->pp)
809  {
810  /* evaluate POST data */
811  MHD_post_process (request->pp,
812  upload_data,
813  *upload_data_size);
814  if (0 != *upload_data_size)
815  {
816  *upload_data_size = 0;
817  return MHD_YES;
818  }
819  /* done with POST data, serve response */
820  MHD_destroy_post_processor (request->pp);
821  request->pp = NULL;
822  }
823  if (GNUNET_OK !=
825  strlen (
826  request->public_key),
827  &pub))
828  {
829  /* parse error */
830  return fill_s_reply ("Failed to parse given public key",
831  request, connection);
832  }
833  switch (request->phase)
834  {
835  case RP_START:
836  if (NULL != strchr (request->domain_name, (int) '.'))
837  {
839  _ ("Domain name must not contain `.'\n"));
840  request->phase = RP_FAIL;
841  return fill_s_reply ("Domain name must not contain `.', sorry.",
842  request,
843  connection);
844  }
845  if (NULL != strchr (request->domain_name, (int) '+'))
846  {
848  _ ("Domain name must not contain `+'\n"));
849  request->phase = RP_FAIL;
850  return fill_s_reply ("Domain name must not contain `+', sorry.",
851  request, connection);
852  }
853  request->phase = RP_LOOKUP;
854  MHD_suspend_connection (request->con);
855  request->lookup_it
859  request,
861  request,
863  request);
864  break;
865 
866  case RP_LOOKUP:
867  break;
868 
869  case RP_PUT:
870  break;
871 
872  case RP_FAIL:
873  return fill_s_reply ("Request failed, sorry.",
874  request, connection);
875 
876  case RP_SUCCESS:
877  return fill_s_reply ("Success.",
878  request, connection);
879 
880  default:
881  GNUNET_break (0);
882  return MHD_NO;
883  }
884  return MHD_YES; /* will have a reply later... */
885  }
886  /* unsupported HTTP method */
887  response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
888  (void *) METHOD_ERROR,
889  MHD_RESPMEM_PERSISTENT);
890  ret = MHD_queue_response (connection,
891  MHD_HTTP_NOT_ACCEPTABLE,
892  response);
893  MHD_destroy_response (response);
894  return ret;
895 }
static int fill_s_reply(const char *info, struct Request *request, struct MHD_Connection *connection)
Send the &#39;SUBMIT_PAGE&#39;.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
struct GNUNET_NAMESTORE_ZoneIterator * lookup_it
Active lookup iterator TODO: deprecate or fix lookup by label and use above member.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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)...
char public_key[128]
Public key submitted via form.
Storing of the record.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MHD_Connection * con
MHD Connection.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define METHOD_ERROR
Invalid method page.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
static void lookup_it_processor(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We got a block back from the namestore.
char domain_name[64]
Domain name submitted via form.
Lookup to see if the domain name is taken.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void lookup_it_finished(void *cls)
Start phase (parsing POST, checking).
Send failure message.
static int serve_zoneinfo_page(struct MHD_Connection *connection)
Handler that returns FCFS zoneinfo page.
Request we should make.
static void lookup_it_error(void *cls)
We encountered an error in the name lookup.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:466
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
static struct MHD_Response * response
Our canonical response.
enum Phase phase
Current processing phase.
#define FCFS_ZONEINFO_URL
static int serve_main_page(struct MHD_Connection *connection)
Handler that returns a simple static HTTP page.
static int post_iterator(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
Iterator over key-value pairs where the value maybe made available in increments and/or may not be ze...
We&#39;re done with success.
struct MHD_PostProcessor * pp
Associated session.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ request_completed_callback()

static void request_completed_callback ( void *  cls,
struct MHD_Connection *  connection,
void **  con_cls,
enum MHD_RequestTerminationCode  toe 
)
static

Callback called upon completion of a request.

Decrements session reference counter.

Parameters
clsnot used
connectionconnection that completed
con_clssession handle
toestatus code

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

References GNUNET_free, GNUNET_NAMESTORE_cancel(), Request::pp, Request::qe, and request.

Referenced by identity_cb().

912 {
913  struct Request *request = *con_cls;
914 
915  (void) cls;
916  (void) connection;
917  (void) toe;
918  if (NULL == request)
919  return;
920  if (NULL != request->pp)
921  MHD_destroy_post_processor (request->pp);
922  if (NULL != request->qe)
923  GNUNET_NAMESTORE_cancel (request->qe);
924  GNUNET_free (request);
925 }
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
Request we should make.
#define GNUNET_free(ptr)
Wrapper around free.
struct MHD_PostProcessor * pp
Associated session.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_httpd()

static void run_httpd ( )
static

Schedule tasks to run MHD server.

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

References do_httpd(), GNUNET_assert, GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_TIME_UNIT_FOREVER_REL, httpd, GNUNET_TIME_Relative::rel_value_us, Request::rs, timeout, and UNSIGNED_MHD_LONG_LONG.

Referenced by do_httpd(), and identity_cb().

936 {
937  fd_set rs;
938  fd_set ws;
939  fd_set es;
940  struct GNUNET_NETWORK_FDSet *wrs;
941  struct GNUNET_NETWORK_FDSet *wws;
942  struct GNUNET_NETWORK_FDSet *wes;
943  int max;
944  int haveto;
946  struct GNUNET_TIME_Relative tv;
947 
948  FD_ZERO (&rs);
949  FD_ZERO (&ws);
950  FD_ZERO (&es);
954  max = -1;
955  GNUNET_assert (MHD_YES ==
956  MHD_get_fdset (httpd,
957  &rs,
958  &ws,
959  &es,
960  &max));
961  haveto = MHD_get_timeout (httpd,
962  &timeout);
963  if (haveto == MHD_YES)
964  tv.rel_value_us = (uint64_t) timeout * 1000LL;
965  else
968  &rs,
969  max + 1);
971  &ws,
972  max + 1);
974  &es,
975  max + 1);
976  httpd_task =
978  tv,
979  wrs,
980  wws,
981  &do_httpd,
982  NULL);
986 }
Run with high priority (important requests).
static void do_httpd(void *cls)
Task run whenever HTTP server operations are pending.
static struct GNUNET_SCHEDULER_Task * httpd_task
Main HTTP task.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:1120
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1266
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
#define UNSIGNED_MHD_LONG_LONG
collection of IO descriptors
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:1810
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
static struct MHD_Daemon * httpd
MHD deamon reference.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

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

References GNUNET_IDENTITY_cancel(), GNUNET_IDENTITY_disconnect(), GNUNET_NAMESTORE_disconnect(), GNUNET_SCHEDULER_cancel(), and httpd.

Referenced by run().

1011 {
1012  (void) cls;
1013  if (NULL != httpd_task)
1014  {
1016  httpd_task = NULL;
1017  }
1018  if (NULL != uzp_task)
1019  {
1021  uzp_task = NULL;
1022  }
1023  if (NULL != ns)
1024  {
1026  ns = NULL;
1027  }
1028  if (NULL != httpd)
1029  {
1030  MHD_stop_daemon (httpd);
1031  httpd = NULL;
1032  }
1033  if (NULL != id_op)
1034  {
1036  id_op = NULL;
1037  }
1038  if (NULL != identity)
1039  {
1041  identity = NULL;
1042  }
1043 }
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:818
static struct GNUNET_SCHEDULER_Task * httpd_task
Main HTTP task.
static struct GNUNET_IDENTITY_Handle * identity
Connection to identity service.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:837
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static struct GNUNET_SCHEDULER_Task * uzp_task
Task that runs update_zoneinfo_page peridicially.
static struct MHD_Daemon * httpd
MHD deamon reference.
static struct GNUNET_IDENTITY_Operation * id_op
Request for our ego.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
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

Method called to inform about the egos of this peer.

When used with GNUNET_IDENTITY_create or GNUNET_IDENTITY_get, this function is only called ONCE, and 'NULL' being passed in ego does indicate an error (i.e. name is taken or no default value is known). If ego is non-NULL and if '*ctx' is set in those callbacks, the value WILL be passed to a subsequent call to the identity callback of GNUNET_IDENTITY_connect (if that one was not NULL).

Parameters
clsclosure, NULL
egoego handle
ctxcontext for application to store data for this ego (during the lifetime of this process, initially NULL)
namename assigned by the user for this ego, NULL if the user just deleted the ego and it must thus no longer be used

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

References _, create_response(), fcfs_zone_pkey, GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_log, GNUNET_SCHEDULER_shutdown(), httpd, options, port, request_completed_callback(), run_httpd(), and Request::zone.

Referenced by run().

1070 {
1071  int options;
1072 
1073  (void) cls;
1074  (void) ctx;
1075  if (NULL == name)
1076  return;
1077  if (0 != strcmp (name,
1078  zone))
1079  return;
1080  if (NULL == ego)
1081  {
1083  _ ("No ego configured for `fcfsd` subsystem\n"));
1085  return;
1086  }
1088 
1089  options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
1090  do
1091  {
1092  httpd = MHD_start_daemon (options,
1093  (uint16_t) port,
1094  NULL, NULL,
1095  &create_response, NULL,
1096  MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128,
1097  MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned
1098  int) 1,
1099  MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
1100  MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4
1101  *
1102  1024),
1103  MHD_OPTION_NOTIFY_COMPLETED,
1105  MHD_OPTION_END);
1106  if (MHD_USE_DEBUG == options)
1107  break;
1108  options = MHD_USE_DEBUG;
1109  }
1110  while (NULL == httpd);
1111  if (NULL == httpd)
1112  {
1114  _ ("Failed to start HTTP server\n"));
1116  return;
1117  }
1118  run_httpd ();
1119 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:555
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static int 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)
Main MHD callback for handling requests.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * zone
Name of the zone we manage.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
static void request_completed_callback(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
Callback called upon completion of a request.
const char * name
#define GNUNET_log(kind,...)
static void run_httpd()
Schedule tasks to run MHD server.
static struct MHD_Daemon * httpd
MHD deamon reference.
static unsigned long long port
Port we use for the HTTP server.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

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

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

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

References _, do_shutdown(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_ERROR_TYPE_ERROR, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_log_config_missing(), GNUNET_NAMESTORE_connect(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), identity_cb(), port, and update_zoneinfo_page().

Referenced by main().

1135 {
1136  (void) cls;
1137  (void) args;
1138  (void) cfgfile;
1139  if (GNUNET_OK !=
1141  "fcfsd",
1142  "HTTPPORT",
1143  &port))
1144  {
1146  "fcfsd", "HTTPPORT");
1147  return;
1148  }
1149  ns = GNUNET_NAMESTORE_connect (cfg);
1150  if (NULL == ns)
1151  {
1153  _ ("Failed to connect to namestore\n"));
1154  return;
1155  }
1157  &identity_cb,
1158  NULL);
1159  if (NULL == identity)
1160  {
1162  _ ("Failed to connect to identity\n"));
1163  return;
1164  }
1166  NULL);
1168  NULL);
1169 }
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:527
int 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_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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_IDENTITY_Handle * identity
Connection to identity service.
static void do_shutdown(void *cls)
Task run on shutdown.
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Method called to inform about the egos of this peer.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static void update_zoneinfo_page(void *cls)
Create fresh version of zone information.
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:1280
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
static struct GNUNET_SCHEDULER_Task * uzp_task
Task that runs update_zoneinfo_page peridicially.
#define GNUNET_log(kind,...)
static unsigned long long port
Port we use for the HTTP server.
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 for the fcfs daemon.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

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

References _, fcfs_zone_pkey, gettext_noop, GNUNET_CRYPTO_ecdsa_key_clear(), GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_mandatory(), GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, run(), and Request::zone.

1182 {
1186  "zone",
1187  "EGO",
1188  gettext_noop (
1189  "name of the zone that is to be managed by FCFSD"),
1190  &zone)),
1192  };
1193  int ret;
1194 
1195  if (GNUNET_OK !=
1196  GNUNET_STRINGS_get_utf8_args (argc, argv,
1197  &argc, &argv))
1198  return 2;
1199 
1200  GNUNET_log_setup ("fcfsd",
1201  "WARNING",
1202  NULL);
1203  ret =
1204  (GNUNET_OK ==
1205  GNUNET_PROGRAM_run (argc,
1206  argv,
1207  "gnunet-namestore-fcfsd",
1208  _ (
1209  "GNU Name System First Come First Serve name registration service"),
1210  options,
1211  &run, NULL)) ? 0 : 1;
1212  GNUNET_free ((void*) argv);
1214  return ret;
1215 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
void GNUNET_CRYPTO_ecdsa_key_clear(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:583
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1438
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * zone
Name of the zone we manage.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
int 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, parse options).
Definition: program.c:367
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ httpd

struct MHD_Daemon* httpd
static

MHD deamon reference.

Definition at line 198 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
static

Main HTTP task.

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

◆ ns

struct GNUNET_NAMESTORE_Handle* ns
static

Handle to the namestore.

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

◆ fcfs_zone_pkey

struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
static

Private key for the fcfsd zone.

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

Referenced by create_response(), identity_cb(), lookup_it_finished(), main(), update_zoneinfo_page(), and zone_to_name_cb().

◆ identity

struct GNUNET_IDENTITY_Handle* identity
static

Connection to identity service.

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

◆ info_page

struct MHD_Response* info_page
static

Zoneinfo page we currently use.

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

Referenced by serve_zoneinfo_page(), and zone_iteration_end().

◆ uzp_task

struct GNUNET_SCHEDULER_Task* uzp_task
static

Task that runs update_zoneinfo_page peridicially.

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

◆ id_op

struct GNUNET_IDENTITY_Operation* id_op
static

Request for our ego.

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

◆ port

unsigned long long port
static

Port we use for the HTTP server.

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

Referenced by identity_cb(), and run().

◆ zone

char* zone
static