GNUnet  0.11.x
gnunet-namestore-fcfsd.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
33 #include "platform.h"
34 #include <microhttpd.h>
35 #include "gnunet_util_lib.h"
37 #include "gnunet_gnsrecord_lib.h"
39 
43 #define METHOD_ERROR \
44  "<!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>"
45 
49 #define MAIN_PAGE \
50  "<!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>"
51 
55 #define SUBMIT_PAGE \
56  "<!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>"
57 
61 #define ZONEINFO_PAGE \
62  "<!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>"
63 
64 #define FCFS_ZONEINFO_URL "/Zoneinfo"
65 
69 #define MIME_HTML "text/html"
70 
74 #define COOKIE_NAME "namestore-fcfsd"
75 
76 #define DEFAULT_ZONEINFO_BUFSIZE 2048
77 
81 enum Phase
82 {
86  RP_START = 0,
87 
92 
97 
102 
107 };
108 
109 
113 struct Request
114 {
118  // FIXME: struct Session *session;
119 
124  struct MHD_PostProcessor *pp;
125 
129  struct MHD_Connection *con;
134  const char *post_url;
135 
140 
150 
154  enum Phase phase;
155 
159  char domain_name[64];
160 
164  char public_key[128];
165 
167 };
168 
173 {
178 
182  char*zoneinfo;
183 
187  size_t buf_len;
188 
192  size_t write_offset;
193 };
194 
198 static struct MHD_Daemon *httpd;
199 
204 
209 
214 
219 
223 static struct MHD_Response *info_page;
224 
229 
234 
238 static unsigned long long port;
239 
243 static char *zone;
244 
245 
251 static void
252 do_httpd (void *cls);
253 
254 
258 static void
260 {
261  if (NULL != httpd_task)
262  {
263  GNUNET_SCHEDULER_cancel (httpd_task);
264  httpd_task = NULL;
265  }
266  httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, NULL);
267 }
268 
269 
273 static void
274 update_zoneinfo_page (void *cls);
275 
276 
280 static void
282 {
283  struct ZoneinfoRequest *zr = cls;
284 
285  zr->list_it = NULL;
286  GNUNET_free (zr->zoneinfo);
287  GNUNET_SCHEDULER_cancel (uzp_task);
289  NULL);
290 }
291 
292 
296 static void
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 }
320 
321 
332 static void
333 iterate_cb (void *cls,
334  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
335  const char *name,
336  unsigned int rd_len,
337  const struct GNUNET_GNSRECORD_Data *rd)
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 }
387 
388 
394 static int
395 serve_zoneinfo_page (struct MHD_Connection *connection)
396 {
397  return MHD_queue_response (connection,
398  MHD_HTTP_OK,
399  info_page);
400 }
401 
402 
406 static void
408 {
409  static struct ZoneinfoRequest zr;
410 
411  (void) cls;
414  NULL);
415  if (NULL != zr.list_it)
416  return;
419  zr.write_offset = 0;
423  &zr,
424  &iterate_cb,
425  &zr,
427  &zr);
428 }
429 
430 
437 static int
438 serve_main_page (struct MHD_Connection *connection)
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 }
456 
457 
465 static int
466 fill_s_reply (const char *info,
467  struct Request *request,
468  struct MHD_Connection *connection)
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 }
492 
493 
513 static int
514 post_iterator (void *cls,
515  enum MHD_ValueKind kind,
516  const char *key,
517  const char *filename,
518  const char *content_type,
519  const char *transfer_encoding,
520  const char *data,
521  uint64_t off,
522  size_t size)
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 }
555 
556 
567 static void
568 put_continuation (void *cls,
569  int32_t success,
570  const char *emsg)
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 }
588 
589 
593 static void
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 }
604 
605 
615 static void
616 zone_to_name_cb (void *cls,
617  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
618  const char *name,
619  unsigned int rd_count,
620  const struct GNUNET_GNSRECORD_Data *rd)
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;
643  request->qe = GNUNET_NAMESTORE_records_store (ns,
645  request->domain_name,
646  1, &r,
648  request);
649 }
650 
651 
655 static void
656 lookup_it_error (void *cls)
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 }
665 
666 
677 static void
679  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey,
680  const char *label,
681  unsigned int rd_count,
682  const struct GNUNET_GNSRECORD_Data *rd)
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 }
700 
701 
702 static void
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 }
732 
733 
757 static int
758 create_response (void *cls,
759  struct MHD_Connection *connection,
760  const char *url,
761  const char *method,
762  const char *version,
763  const char *upload_data,
764  size_t *upload_data_size,
765  void **ptr)
766 {
767  struct MHD_Response *response;
768  struct Request *request;
769  struct GNUNET_CRYPTO_EcdsaPublicKey pub;
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 }
896 
897 
907 static void
909  struct MHD_Connection *connection,
910  void **con_cls,
911  enum MHD_RequestTerminationCode toe)
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 }
926 
927 
928 #define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG
929 
930 
934 static void
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 }
987 
988 
994 static void
995 do_httpd (void *cls)
996 {
997  (void) cls;
998  httpd_task = NULL;
999  MHD_run (httpd);
1000  run_httpd ();
1001 }
1002 
1003 
1009 static void
1010 do_shutdown (void *cls)
1011 {
1012  (void) cls;
1013  if (NULL != httpd_task)
1014  {
1015  GNUNET_SCHEDULER_cancel (httpd_task);
1016  httpd_task = NULL;
1017  }
1018  if (NULL != uzp_task)
1019  {
1020  GNUNET_SCHEDULER_cancel (uzp_task);
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  {
1035  GNUNET_IDENTITY_cancel (id_op);
1036  id_op = NULL;
1037  }
1038  if (NULL != identity)
1039  {
1040  GNUNET_IDENTITY_disconnect (identity);
1041  identity = NULL;
1042  }
1043 }
1044 
1045 
1065 static void
1066 identity_cb (void *cls,
1067  struct GNUNET_IDENTITY_Ego *ego,
1068  void **ctx,
1069  const char *name)
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 }
1120 
1121 
1130 static void
1131 run (void *cls,
1132  char *const *args,
1133  const char *cfgfile,
1134  const struct GNUNET_CONFIGURATION_Handle *cfg)
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  }
1156  identity = GNUNET_IDENTITY_connect (cfg,
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 }
1170 
1171 
1179 int
1180 main (int argc,
1181  char *const *argv)
1182 {
1183  struct GNUNET_GETOPT_CommandLineOption options[] = {
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 }
1216 
1217 
1218 /* end of gnunet-namestore-fcfsd.c */
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
struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:818
static int fill_s_reply(const char *info, struct Request *request, struct MHD_Connection *connection)
Send the &#39;SUBMIT_PAGE&#39;.
Run with high priority (important requests).
#define SUBMIT_PAGE
Second page (/S)
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.
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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
static char * pkey
Public key of the zone to look in, in ASCII.
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
static void do_httpd(void *cls)
Task run whenever HTTP server operations are pending.
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
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)...
static void put_continuation(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
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 struct GNUNET_SCHEDULER_Task * httpd_task
Main HTTP task.
char public_key[128]
Public key submitted via form.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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
#define DEFAULT_ZONEINFO_BUFSIZE
Storing of the record.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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
size_t data_size
Number of bytes in data.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
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...
Private ECC key encoded for transmission.
static struct GNUNET_IDENTITY_Handle * identity
Connection to identity service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
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.
static void do_shutdown(void *cls)
Task run on shutdown.
#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 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.
Handle for an operation with the identity service.
Definition: identity_api.c:39
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define MAIN_PAGE
Front page.
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_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
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.
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
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.
#define METHOD_ERROR
Invalid method page.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1266
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
Zoneinfo request.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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.
Handle for a zone iterator operation.
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
Handle for an ego.
Definition: identity.h:245
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
Phase
Phases a request goes through.
static struct MHD_Response * info_page
Zoneinfo page we currently use.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
const void * data
Binary value stored in the DNS record.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
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.
static void update_zoneinfo_page(void *cls)
Create fresh version of zone information.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
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.
#define UNSIGNED_MHD_LONG_LONG
Connection to the NAMESTORE service.
Handle for the service.
Definition: identity_api.c:95
uint64_t expiration_time
Expiration time for the DNS record.
struct GNUNET_NAMESTORE_ZoneIterator * zi
Active iteration with the namestore.
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
collection of IO descriptors
static char * filename
char domain_name[64]
Domain name submitted via form.
struct GNUNET_CRYPTO_EcdsaPublicKey pub
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".
Lookup to see if the domain name is taken.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
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 void lookup_it_finished(void *cls)
static void run_httpd_now()
Schedule task to run MHD server now.
Start phase (parsing POST, checking).
const char * post_url
URL to serve in response to this POST (if this request was a &#39;POST&#39;)
Send failure message.
#define ZONEINFO_PAGE
Fcfs zoneinfo page (/Zoneinfo)
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
static void zone_iteration_error(void *cls)
Function called on error in zone iteration.
static int serve_zoneinfo_page(struct MHD_Connection *connection)
Handler that returns FCFS zoneinfo page.
size_t buf_len
Buffer length.
static void zone_iteration_end(void *cls)
Function called once the zone iteration is done.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
static struct GNUNET_SCHEDULER_Task * uzp_task
Task that runs update_zoneinfo_page peridicially.
Request we should make.
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
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
uint32_t record_type
Type of the GNS/DNS record.
configuration data
Definition: configuration.c:85
const char * name
size_t write_offset
Buffer write offset.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
void * cls
Closure for cont or cb.
Definition: identity_api.c:88
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
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.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
static void run_httpd()
Schedule tasks to run MHD server.
const struct Zone * zone
Zone responsible for this request.
static struct MHD_Response * response
Our canonical response.
static struct MHD_Daemon * httpd
MHD deamon reference.
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
enum Phase phase
Current processing phase.
#define MIME_HTML
Mime type for HTML pages.
#define FCFS_ZONEINFO_URL
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static int serve_main_page(struct MHD_Connection *connection)
Handler that returns a simple static HTTP page.
uint32_t data
The data value.
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
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...
static void zone_to_name_error(void *cls)
Function called if we had an error in zone-to-name mapping.
#define GNUNET_malloc(size)
Wrapper around malloc.
static unsigned long long port
Port we use for the HTTP server.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
We&#39;re done with success.
struct MHD_PostProcessor * pp
Associated session.
static struct GNUNET_IDENTITY_Operation * id_op
Request for our ego.
#define gettext_noop(String)
Definition: gettext.h:69
int main(int argc, char *const *argv)
The main function for the fcfs daemon.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966